cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1425723 - in /cxf/branches/2.5.x-fixes: ./ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Date Tue, 25 Dec 2012 05:24:47 GMT
Author: ffang
Date: Tue Dec 25 05:24:47 2012
New Revision: 1425723

URL: http://svn.apache.org/viewvc?rev=1425723&view=rev
Log:
Merged revisions 1425722 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1425722 | ffang | 2012-12-25 13:15:59 +0800 (二, 25 12 2012) | 9 lines
  
  Merged revisions 1425718 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1425718 | ffang | 2012-12-25 12:59:05 +0800 (二, 25 12 2012) | 1 line
    
    [CXF-4724]cxf-codegen-plugin should be able to use proxy.user/proxy.password from maven
settings.xml
  ........
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Dec 25 05:24:47 2012
@@ -0,0 +1,2 @@
+/cxf/branches/2.6.x-fixes:1425722
+/cxf/trunk:1425718

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java?rev=1425723&r1=1425722&r2=1425723&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
(original)
+++ cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Tue Dec 25 05:24:47 2012
@@ -22,6 +22,8 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
 import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
@@ -56,6 +58,7 @@ import org.apache.maven.settings.Proxy;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.archiver.jar.Manifest;
 import org.codehaus.plexus.archiver.jar.Manifest.Attribute;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
@@ -79,6 +82,16 @@ public abstract class AbstractCodegenMoh
      */
     private static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
     
+    /**
+     * JVM/System property name holding the username of the http proxy.
+     */
+    private static final String HTTP_PROXY_USER = "http.proxyUser";
+    
+    /**
+     * JVM/System property name holding the password of the http proxy.
+     */
+    private static final String HTTP_PROXY_PASSWORD = "http.proxyPassword";
+    
 
     /**
      * @parameter expression="${project.build.outputDirectory}"
@@ -248,7 +261,9 @@ public abstract class AbstractCodegenMoh
         String originalProxyHost = SystemPropertyAction.getProperty(HTTP_PROXY_HOST);
         String originalProxyPort = SystemPropertyAction.getProperty(HTTP_PROXY_PORT);
         String originalNonProxyHosts = SystemPropertyAction.getProperty(HTTP_NON_PROXY_HOSTS);
-        
+        String originalProxyUser = SystemPropertyAction.getProperty(HTTP_PROXY_USER);
+        String originalProxyPassword = SystemPropertyAction.getProperty(HTTP_PROXY_PASSWORD);
+                
         configureProxyServerSettings();
 
         List<GenericWsdlOption> effectiveWsdlOptions = createWsdlOptionsFromScansAndExplicitWsdlOptions();
@@ -285,7 +300,8 @@ public abstract class AbstractCodegenMoh
                 bus.shutdown(true);
             }
             classLoaderSwitcher.restoreClassLoader();
-            restoreProxySetting(originalProxyHost, originalProxyPort, originalNonProxyHosts);
+            restoreProxySetting(originalProxyHost, originalProxyPort, originalNonProxyHosts,
+                                originalProxyUser, originalProxyPassword);
         }
 
         // add the generated source into compile source
@@ -300,15 +316,38 @@ public abstract class AbstractCodegenMoh
     }
 
     private void restoreProxySetting(String originalProxyHost, String originalProxyPort,
-                                     String originalNonProxyHosts) {
+                                     String originalNonProxyHosts,
+                                     String originalProxyUser,
+                                     String originalProxyPassword) {
         if (originalProxyHost != null) {
             System.setProperty(HTTP_PROXY_HOST, originalProxyHost);
+        } else {
+            System.getProperties().remove(HTTP_PROXY_HOST);
         }
         if (originalProxyPort != null) {
             System.setProperty(HTTP_PROXY_PORT, originalProxyPort);
+        } else {
+            System.getProperties().remove(HTTP_PROXY_PORT);
         }
         if (originalNonProxyHosts != null) {
             System.setProperty(HTTP_NON_PROXY_HOSTS, originalNonProxyHosts);
+        } else {
+            System.getProperties().remove(HTTP_NON_PROXY_HOSTS);
+        }
+        if (originalProxyUser != null) {
+            System.setProperty(HTTP_PROXY_USER, originalProxyUser);
+        } else {
+            System.getProperties().remove(HTTP_PROXY_USER);
+        }
+        if (originalProxyPassword != null) {
+            System.setProperty(HTTP_PROXY_PASSWORD, originalProxyPassword);
+        } else {
+            System.getProperties().remove(HTTP_PROXY_PASSWORD);
+        }
+        Proxy proxy = mavenSession.getSettings().getActiveProxy();
+        if (proxy != null && !StringUtils.isEmpty(proxy.getUsername()) 
+            && !StringUtils.isEmpty(proxy.getPassword())) {
+            Authenticator.setDefault(null);
         }
     }
 
@@ -354,9 +393,28 @@ public abstract class AbstractCodegenMoh
             if (proxy.getHost() == null) {
                 throw new MojoExecutionException("Proxy in settings.xml has no host");
             } else {
-                System.setProperty(HTTP_PROXY_HOST, proxy.getHost());
-                System.setProperty(HTTP_PROXY_PORT, String.valueOf(proxy.getPort()));
-                System.setProperty(HTTP_NON_PROXY_HOSTS, proxy.getNonProxyHosts());
+                if (proxy.getHost() != null) {
+                    System.setProperty(HTTP_PROXY_HOST, proxy.getHost());
+                }
+                if (String.valueOf(proxy.getPort()) != null) {
+                    System.setProperty(HTTP_PROXY_PORT, String.valueOf(proxy.getPort()));
+                }
+                if (proxy.getNonProxyHosts() != null) {
+                    System.setProperty(HTTP_NON_PROXY_HOSTS, proxy.getNonProxyHosts());
+                }
+                if (!StringUtils.isEmpty(proxy.getUsername()) 
+                    && !StringUtils.isEmpty(proxy.getPassword())) {
+                    final String authUser = proxy.getUsername();
+                    final String authPassword = proxy.getPassword();
+                    Authenticator.setDefault(new Authenticator() {
+                        public PasswordAuthentication getPasswordAuthentication() {
+                            return new PasswordAuthentication(authUser, authPassword.toCharArray());
+                        }
+                    });
+
+                    System.setProperty(HTTP_PROXY_USER, authUser);
+                    System.setProperty(HTTP_PROXY_PORT, authPassword);
+                }
             }
 
         }



Mime
View raw message