Author: olamy
Date: Wed Oct 10 08:00:14 2012
New Revision: 1396502

URL: http://svn.apache.org/viewvc?rev=1396502&view=rev
Log:
now possible to generate a patch and send it to jenkins job using Patch 
Parameter plugin: 
https://wiki.jenkins-ci.org/display/JENKINS/Patch+Parameter+Plugin

Added:
    
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/
    
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
   (with props)
Modified:
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml
    
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java

Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml?rev=1396502&r1=1396501&r2=1396502&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml Wed Oct 10 
08:00:14 2012
@@ -160,11 +160,27 @@ under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>fluent-hc</artifactId>
+      <version>4.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpmime</artifactId>
+      <version>4.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpcore</artifactId>
       <version>4.2.2</version>
     </dependency>
 
     <dependency>
+      <groupId>com.ning</groupId>
+      <artifactId>async-http-client</artifactId>
+      <version>1.7.6</version>
+    </dependency>
+
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>2.2</version>

Modified: 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java?rev=1396502&r1=1396501&r2=1396502&view=diff
==============================================================================
--- 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
 (original)
+++ 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java
 Wed Oct 10 08:00:14 2012
@@ -305,7 +305,7 @@ public abstract class AbstractPatchMojo
 
         try
         {
-            return StringUtils.lowerCase( getValue( value, "path tracker 
system id ?", Arrays.asList( "jira" ), true,
+            return StringUtils.lowerCase( getValue( value, "path tracker 
system id ?", Arrays.asList( "jira", "jenkins" ), true,
                                                     "you must configure a 
patch system or at least use interactive mode",
                                                     "jira", false ) );
         }

Added: 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java?rev=1396502&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
 (added)
+++ 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
 Wed Oct 10 08:00:14 2012
@@ -0,0 +1,102 @@
+package org.apache.maven.plugins.patchtracker.tracking.jenkins;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.io.FileUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.mime.HttpMultipartMode;
+import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.patchtracker.tracking.PatchTracker;
+import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerException;
+import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerRequest;
+import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerResult;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Olivier Lamy
+ * @plexus.component 
role="org.apache.maven.plugins.patchtracker.tracking.PatchTracker" 
role-hint="jenkins"
+ */
+public class JenkinsPatchTracker
+    implements PatchTracker
+{
+    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
+
+    public PatchTrackerResult createPatch( PatchTrackerRequest 
patchTrackerRequest, Log log )
+        throws PatchTrackerException
+    {
+        File tmpPathFile = null;
+        try
+        {
+            tmpPathFile = File.createTempFile( "jenkins", "patch" );
+            FileUtils.write( tmpPathFile, 
patchTrackerRequest.getPatchContent() );
+
+            foo
+            HttpPost post = new HttpPost( patchTrackerRequest.getUrl() + 
"/buildWithParameters?delay=0sec" );
+
+            MultipartEntity entity = new MultipartEntity( 
HttpMultipartMode.BROWSER_COMPATIBLE );
+
+            FileBody fileBody = new FileBody( tmpPathFile );
+            entity.addPart( "patch.diff", fileBody );
+
+            post.setEntity( entity );
+
+            HttpResponse r = defaultHttpClient.execute( post );
+
+            log.info( "r:" + r.getStatusLine().getStatusCode() + ", status: " 
+ r.getStatusLine().getReasonPhrase()+"," + EntityUtils.toString(  
r.getEntity()) );
+
+            // FIXME verify response code !
+
+            /*AsyncHttpClient c = new AsyncHttpClient();
+            Future<Response> f = c.preparePost( patchTrackerRequest.getUrl() + 
"/build?delay=0sec" ).addBodyPart(
+                new FilePart( "patch.diff", tmpPathFile, null, null ) 
).execute();
+            Response r = f.get();
+            log.info( "r:" + r.getStatusCode() + ", status: " + 
r.getStatusText() );*/
+            return new PatchTrackerResult();
+        }
+        catch ( IOException e )
+        {
+            throw new PatchTrackerException( e.getMessage(), e );
+        }/*
+        catch ( InterruptedException e )
+        {
+            throw new PatchTrackerException( e.getMessage(), e );
+        }
+        catch ( ExecutionException e )
+        {
+            throw new PatchTrackerException( e.getMessage(), e );
+        }*/
+        finally
+        {
+            FileUtils.deleteQuietly( tmpPathFile );
+        }
+    }
+
+    public PatchTrackerResult updatePatch( PatchTrackerRequest 
patchTrackerRequest, Log log )
+        throws PatchTrackerException
+    {
+        throw new RuntimeException( "updatePatch is not implemented with 
Jenkins" );
+    }
+}

Propchange: 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision


Reply via email to