ffang closed pull request #440: [CXF-7830] Support for running java2ws-plugin
using JDK9+ on Windows.
URL: https://github.com/apache/cxf/pull/440
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
b/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
index 7c604d5b1a5..52ad836e40b 100644
--- a/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
@@ -46,6 +46,7 @@
"void", "volatile", "while"
));
+ private static boolean isJava11Compatible;
private static boolean isJava9Compatible;
private static boolean isJava8Before161;
@@ -66,6 +67,7 @@
}
setJava9Compatible(Integer.valueOf(version) >= 9);
+ setJava11Compatible(Integer.valueOf(version) >= 11);
}
private JavaUtils() {
@@ -91,10 +93,18 @@ public static String makeNonJavaKeyword(String keyword) {
public static boolean isJava9Compatible() {
return isJava9Compatible;
}
+
+ public static boolean isJava11Compatible() {
+ return isJava11Compatible;
+ }
private static void setJava9Compatible(boolean java9Compatible) {
JavaUtils.isJava9Compatible = java9Compatible;
}
+
+ private static void setJava11Compatible(boolean java11Compatible) {
+ JavaUtils.isJava11Compatible = java11Compatible;
+ }
public static boolean isJava8Before161() {
return isJava8Before161;
diff --git
a/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
b/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
index 08540e8465b..84b7f023d8b 100644
---
a/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
+++
b/maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java
@@ -209,12 +209,29 @@
*/
private String additionalJvmArgs;
+ /**
+ * Determines how the classpath is applied to the executed command,
+ * either as a command line argument, or as an environment variable
+ * for the executing process. Only applicable when fork is set to
<code>true</code>
+ * (which is always the case for JDK 9+).
+ * <p>
+ * Primarily useful on Windows because of length limitations for command
arguments,
+ * which is why the default is <code>true</code> in that case.
+ *
+ * @parameter default-value="false"
+ * @since 3.3
+ */
+ private Boolean classpathAsEnvVar;
+
public void execute() throws MojoExecutionException {
- if (JavaUtils.isJava9Compatible()) {
+ boolean requiresModules = JavaUtils.isJava9Compatible();
+ if (requiresModules) {
+ // Since JEP 261 ("Jigsaw"), access to some packages must be
granted
fork = true;
+ boolean skipXmlWsModule = JavaUtils.isJava11Compatible(); //
additionalJvmArgs =
"--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
+
"--add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED "
- + "--add-opens
java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED "
+ + (skipXmlWsModule ? "" : "--add-opens
java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED ")
+ "--add-opens java.base/java.security=ALL-UNNAMED "
+ "--add-opens java.base/java.net=ALL-UNNAMED "
+ "--add-opens java.base/java.lang=ALL-UNNAMED "
@@ -222,6 +239,11 @@ public void execute() throws MojoExecutionException {
+ "--add-opens java.base/java.util.concurrent=ALL-UNNAMED
"
+ (additionalJvmArgs == null ? "" : additionalJvmArgs);
}
+ if (fork && SystemUtils.IS_OS_WINDOWS) {
+ // Windows does not allow for very long command lines,
+ // so by default CLASSPATH environment variable is used.
+ classpathAsEnvVar = true;
+ }
System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches",
"true");
if (skip) {
getLog().info("Skipping Java2WS execution");
@@ -247,8 +269,8 @@ public void execute() throws MojoExecutionException {
cp = StringUtils.join(artifactsPath.iterator(),
File.pathSeparator) + File.pathSeparator + cp;
}
- List<String> args = initArgs(cp);
- processJavaClass(args);
+ List<String> args = initArgs(classpathAsEnvVar ? null : cp);
+ processJavaClass(args, classpathAsEnvVar ? cp : null);
} finally {
classLoaderSwitcher.restoreClassLoader();
}
@@ -268,9 +290,11 @@ public void execute() throws MojoExecutionException {
args.add("-DexitOnFinish=true");
}
- // classpath arg
- args.add("-cp");
- args.add(cp);
+ if (!StringUtils.isEmpty(cp)) {
+ // classpath arg
+ args.add("-cp");
+ args.add(cp);
+ }
if (fork) {
args.add(JavaToWS.class.getCanonicalName());
@@ -384,7 +408,7 @@ public void execute() throws MojoExecutionException {
return args;
}
- private void processJavaClass(List<String> args) throws
MojoExecutionException {
+ private void processJavaClass(List<String> args, String cp) throws
MojoExecutionException {
if (!fork) {
try {
CommandInterfaceUtils.commandCommonMain();
@@ -416,22 +440,37 @@ private void processJavaClass(List<String> args) throws
MojoExecutionException {
}
cmd.addArguments(args.toArray(new String[0]));
+ if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
+ cmd.addEnvironment("CLASSPATH", cp);
+ }
CommandLineUtils.StringStreamConsumer err = new
CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer out = new
CommandLineUtils.StringStreamConsumer();
+ String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
+
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
} catch (CommandLineException e) {
getLog().debug(e);
- throw new MojoExecutionException(e.getMessage(), e);
+ StringBuilder msg = new StringBuilder(e.getMessage());
+ if (!(fork && classpathAsEnvVar)) {
+ msg.append('\n');
+ msg.append("Try to run this goal using <fork>true</fork>
and "
+ + "<classpathAsEnvVar>true</classpathAsEnvVar>.");
+ }
+ msg.append('\n');
+ msg.append("Command line was: ").append(cmdLine).append('\n');
+ if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
+ msg.append(" CLASSPATH env: ").append(cp).append('\n');
+ }
+ msg.append('\n');
+ throw new MojoExecutionException(msg.toString(), e);
}
String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n'
+ out.getOutput().trim();
- String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
-
if (exitCode != 0) {
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
@@ -443,7 +482,11 @@ private void processJavaClass(List<String> args) throws
MojoExecutionException {
msg.append(" - ").append(err.getOutput());
}
msg.append('\n');
- msg.append("Command line was:
").append(cmdLine).append('\n').append('\n');
+ msg.append("Command line was: ").append(cmdLine).append('\n');
+ if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
+ msg.append(" CLASSPATH env: ").append(cp).append('\n');
+ }
+ msg.append('\n');
throw new MojoExecutionException(msg.toString());
}
@@ -452,7 +495,11 @@ private void processJavaClass(List<String> args) throws
MojoExecutionException {
StringBuilder msg = new StringBuilder();
msg.append(err.getOutput());
msg.append('\n');
- msg.append("Command line was:
").append(cmdLine).append('\n').append('\n');
+ msg.append("Command line was: ").append(cmdLine).append('\n');
+ if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
+ msg.append(" CLASSPATH env: ").append(cp).append('\n');
+ }
+ msg.append('\n');
throw new MojoExecutionException(msg.toString());
}
}
@@ -465,7 +512,7 @@ private void processJavaClass(List<String> args) throws
MojoExecutionException {
boolean hasWsdlAttached = false;
for (Artifact a : project.getAttachedArtifacts()) {
- if ("wsdl".equals(a.getType()) &&
classifier.equals(a.getClassifier())) {
+ if ("wsdl".equals(a.getType()) && classifier != null &&
classifier.equals(a.getClassifier())) {
hasWsdlAttached = true;
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services