Author: ffang
Date: Thu Dec 13 07:24:50 2012
New Revision: 1421097
URL: http://svn.apache.org/viewvc?rev=1421097&view=rev
Log:
[CXF-4687]cxf-codegen-plugin breaks mvn deploy when proxy exists
Modified:
cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Modified:
cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java?rev=1421097&r1=1421096&r2=1421097&view=diff
==============================================================================
---
cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
(original)
+++
cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Thu Dec 13 07:24:50 2012
@@ -34,6 +34,7 @@ import java.util.Set;
import org.apache.commons.lang.SystemUtils;
import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.SystemPropertyAction;
import org.apache.cxf.common.util.URIParserUtil;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.FileUtils;
@@ -62,6 +63,23 @@ import org.codehaus.plexus.util.cli.Stre
import org.sonatype.plexus.build.incremental.BuildContext;
public abstract class AbstractCodegenMoho extends AbstractMojo {
+
+ /**
+ * JVM/System property name holding the hostname of the http proxy.
+ */
+ private static final String HTTP_PROXY_HOST = "http.proxyHost";
+
+ /**
+ * JVM/System property name holding the port of the http proxy.
+ */
+ private static final String HTTP_PROXY_PORT = "http.proxyPort";
+
+ /**
+ * JVM/System property name holding the list of hosts/patterns that
+ * should not use the proxy configuration.
+ */
+ private static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
+
/**
* @parameter expression="${project.build.outputDirectory}"
@@ -248,6 +266,10 @@ public abstract class AbstractCodegenMoh
markerDirectory.mkdirs();
+ String originalProxyHost =
SystemPropertyAction.getProperty(HTTP_PROXY_HOST);
+ String originalProxyPort =
SystemPropertyAction.getProperty(HTTP_PROXY_PORT);
+ String originalNonProxyHosts =
SystemPropertyAction.getProperty(HTTP_NON_PROXY_HOSTS);
+
configureProxyServerSettings();
List<GenericWsdlOption> effectiveWsdlOptions =
createWsdlOptionsFromScansAndExplicitWsdlOptions();
@@ -284,6 +306,7 @@ public abstract class AbstractCodegenMoh
bus.shutdown(true);
}
classLoaderSwitcher.restoreClassLoader();
+ restoreProxySetting(originalProxyHost, originalProxyPort,
originalNonProxyHosts);
}
// refresh the generated sources
@@ -296,6 +319,13 @@ public abstract class AbstractCodegenMoh
System.gc();
}
+ private void restoreProxySetting(String originalProxyHost, String
originalProxyPort,
+ String originalNonProxyHosts) {
+ System.setProperty(HTTP_PROXY_HOST, originalProxyHost);
+ System.setProperty(HTTP_PROXY_PORT, originalProxyPort);
+ System.setProperty(HTTP_NON_PROXY_HOSTS, originalNonProxyHosts);
+ }
+
protected abstract Bus generate(GenericWsdlOption o,
Bus bus, Set<URI> cp) throws
MojoExecutionException;
@@ -338,9 +368,9 @@ public abstract class AbstractCodegenMoh
if (proxy.getHost() == null) {
throw new MojoExecutionException("Proxy in settings.xml has no
host");
} else {
- System.setProperty("proxySet", "true");
- System.setProperty("proxyHost", proxy.getHost());
- System.setProperty("proxyPort",
String.valueOf(proxy.getPort()));
+ System.setProperty(HTTP_PROXY_HOST, proxy.getHost());
+ System.setProperty(HTTP_PROXY_PORT,
String.valueOf(proxy.getPort()));
+ System.setProperty(HTTP_NON_PROXY_HOSTS,
proxy.getNonProxyHosts());
}
}