maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1396632 - in /maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker: UpdatePatchMojo.java tracking/jenkins/JenkinsPatchTracker.java
Date Wed, 10 Oct 2012 15:08:17 GMT
Author: olamy
Date: Wed Oct 10 15:08:17 2012
New Revision: 1396632

URL: http://svn.apache.org/viewvc?rev=1396632&view=rev
Log:
add authz mechanism for jenkins

Modified:
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/UpdatePatchMojo.java
    maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java

Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/UpdatePatchMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/UpdatePatchMojo.java?rev=1396632&r1=1396631&r2=1396632&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/UpdatePatchMojo.java
(original)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/UpdatePatchMojo.java
Wed Oct 10 15:08:17 2012
@@ -61,7 +61,8 @@ public class UpdatePatchMojo
             getLog().debug( patchTrackerRequest.toString() );
             PatchTracker patchTracker = getPatchTracker();
             PatchTrackerResult result = patchTracker.updatePatch( patchTrackerRequest, getLog()
);
-            getLog().info( "issue updated with id:" + result.getPatchId() + ", url:" + result.getPatchUrl()
);
+
+            getLog().info( "Patch Posted updated with id:" + result.getPatchId() + ", url:"
+ result.getPatchUrl() );
         }
         catch ( ComponentLookupException e )
         {

Modified: 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=1396632&r1=1396631&r2=1396632&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
(original)
+++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/tracking/jenkins/JenkinsPatchTracker.java
Wed Oct 10 15:08:17 2012
@@ -19,12 +19,21 @@ package org.apache.maven.plugins.patchtr
  */
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.AuthCache;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.ClientContext;
 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.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.util.EntityUtils;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.plugins.patchtracker.tracking.PatchTracker;
@@ -42,11 +51,12 @@ import java.io.IOException;
 public class JenkinsPatchTracker
     implements PatchTracker
 {
-    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
+
 
     public PatchTrackerResult createPatch( PatchTrackerRequest patchTrackerRequest, Log log
)
         throws PatchTrackerException
     {
+        DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
         File tmpPathFile = null;
         try
         {
@@ -62,8 +72,35 @@ public class JenkinsPatchTracker
 
             post.setEntity( entity );
 
-            HttpResponse r = defaultHttpClient.execute( post );
+            BasicHttpContext context = null;
+
+            if ( StringUtils.isNotEmpty( patchTrackerRequest.getUserName() ) )
+            {
 
+                defaultHttpClient.getCredentialsProvider().setCredentials(
+                    new AuthScope( new AuthScope( post.getURI().getHost(), post.getURI().getPort()
) ),
+                    new UsernamePasswordCredentials( patchTrackerRequest.getUserName(),
+                                                     patchTrackerRequest.getPassword() )
);
+
+                // Jenkins doesn't challenge so use a preemptive mode
+                AuthCache authCache = new BasicAuthCache();
+                BasicScheme basicAuth = new BasicScheme();
+                HttpHost targetHost =
+                    new HttpHost( post.getURI().getHost(), post.getURI().getPort(), post.getURI().getScheme()
);
+                authCache.put( targetHost, basicAuth );
+
+                context = new BasicHttpContext();
+                context.setAttribute( ClientContext.AUTH_CACHE, authCache );
+            }
+            HttpResponse r;
+            if ( context == null )
+            {
+                r = defaultHttpClient.execute( post );
+            }
+            else
+            {
+                r = defaultHttpClient.execute( post, context );
+            }
             log.debug(
                 "r:" + r.getStatusLine().getStatusCode() + ", status: " + r.getStatusLine().getReasonPhrase()
+ ","
                     + EntityUtils.toString( r.getEntity() ) );
@@ -94,4 +131,5 @@ public class JenkinsPatchTracker
     {
         throw new RuntimeException( "updatePatch is not implemented with Jenkins" );
     }
+
 }



Mime
View raw message