You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2020/01/06 16:33:58 UTC
[cxf] 02/02: CXF-8187 - Codegen-Plugin failed when maven is
executed on jdk9+ with Toolchains specifying jdk 8
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit e72ad770c9a8f4439b93e2c19e61c43562ac5877
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Jan 6 15:36:49 2020 +0000
CXF-8187 - Codegen-Plugin failed when maven is executed on jdk9+ with Toolchains specifying jdk 8
---
.../cxf/maven_plugin/AbstractCodegenMojo.java | 78 +++++++++++++++++++---
1 file changed, 69 insertions(+), 9 deletions(-)
diff --git a/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMojo.java b/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMojo.java
index 8b96592..c47bb06 100644
--- a/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMojo.java
+++ b/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMojo.java
@@ -209,14 +209,6 @@ public abstract class AbstractCodegenMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
if (JavaUtils.isJava9Compatible()) {
fork = "true";
- 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.base/java.security=ALL-UNNAMED "
- + "--add-opens java.base/java.net=ALL-UNNAMED "
- + "--add-opens java.base/java.lang=ALL-UNNAMED "
- + "--add-opens java.base/java.util=ALL-UNNAMED "
- + "--add-opens java.base/java.util.concurrent=ALL-UNNAMED "
- + (additionalJvmArgs == null ? "" : additionalJvmArgs);
}
System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true");
@@ -617,8 +609,10 @@ public abstract class AbstractCodegenMojo extends AbstractMojo {
Commandline cmd = new Commandline();
cmd.getShell().setQuotedArgumentsEnabled(true); // for JVM args
cmd.setWorkingDirectory(project.getBuild().getDirectory());
- cmd.setExecutable(getJavaExecutable().getAbsolutePath());
+ String javaPath = getJavaExecutable().getAbsolutePath();
+ cmd.setExecutable(javaPath);
+ setJvmForkArgs(javaPath);
cmd.createArg().setLine(additionalJvmArgs);
File file = null;
@@ -706,6 +700,72 @@ public abstract class AbstractCodegenMojo extends AbstractMojo {
}
/**
+ * Run the JDK version (could be set via the toolchain) and see if we need to configure the JvmArgs
+ * accordingly. Once we remove JDK8 support we can just add the additional args by default and remove
+ * this method.
+ */
+ private void setJvmForkArgs(String javaExecutablePath) {
+ Commandline cmd = new Commandline();
+ cmd.getShell().setQuotedArgumentsEnabled(true); // for JVM args
+ cmd.setWorkingDirectory(project.getBuild().getDirectory());
+ cmd.setExecutable(javaExecutablePath);
+ Java9StreamConsumer consumer = new Java9StreamConsumer();
+ try {
+ cmd.createArg().setValue("-XshowSettings:properties -version");
+ CommandLineUtils.executeCommandLine(cmd, null, consumer);
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
+
+ if (additionalJvmArgs == null) {
+ additionalJvmArgs = "";
+ }
+ if (consumer.isJava9Plus()) {
+ 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.base/java.security=ALL-UNNAMED "
+ + "--add-opens java.base/java.net=ALL-UNNAMED "
+ + "--add-opens java.base/java.lang=ALL-UNNAMED "
+ + "--add-opens java.base/java.util=ALL-UNNAMED "
+ + "--add-opens java.base/java.util.concurrent=ALL-UNNAMED "
+ + additionalJvmArgs;
+ }
+ }
+
+ /**
+ * Parse each line of the output for "java.version" and see if the version is >= 9
+ */
+ private static class Java9StreamConsumer implements StreamConsumer {
+ boolean java9;
+
+ public void consumeLine(String line) {
+ if (!java9 && line.contains("java.version")) {
+ String version = line.trim().substring("java.version = ".length());
+ if (version != null) {
+ if (version.indexOf('.') > 0) {
+ version = version.substring(0, version.indexOf('.'));
+ }
+ if (version.indexOf('-') > 0) {
+ version = version.substring(0, version.indexOf('-'));
+ }
+
+ try {
+ if (Integer.valueOf(version) >= 9) {
+ java9 = true;
+ }
+ } catch (NumberFormatException ex) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ public boolean isJava9Plus() {
+ return java9;
+ }
+ }
+
+ /**
* Determine if code should be generated from the given wsdl
*
* @param wsdlOption