You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2012/12/25 06:15:59 UTC
svn commit: r1425722 - in /cxf/branches/2.6.x-fixes: ./
maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Author: ffang
Date: Tue Dec 25 05:15:59 2012
New Revision: 1425722
URL: http://svn.apache.org/viewvc?rev=1425722&view=rev
Log:
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.6.x-fixes/ (props changed)
cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:1425718
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.6.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.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java?rev=1425722&r1=1425721&r2=1425722&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java (original)
+++ cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java Tue Dec 25 05:15:59 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;
@@ -80,6 +83,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}"
@@ -269,7 +282,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();
@@ -306,7 +321,8 @@ public abstract class AbstractCodegenMoh
bus.shutdown(true);
}
classLoaderSwitcher.restoreClassLoader();
- restoreProxySetting(originalProxyHost, originalProxyPort, originalNonProxyHosts);
+ restoreProxySetting(originalProxyHost, originalProxyPort, originalNonProxyHosts,
+ originalProxyUser, originalProxyPassword);
}
// refresh the generated sources
@@ -320,15 +336,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);
}
}
@@ -374,9 +413,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);
+ }
}
}