Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Add workaround for illegal access warnings on Java 9
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Mar 19, 2018
1 parent 7e00283 commit c870da4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/io/airlift/maven/sphinx/SphinxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,33 @@ private void runForkedSphinx()
throws MavenReportException
{
String jvmBinary = jvm;
boolean sameJvmBinary = false;

if ((jvmBinary == null) || "".equals(jvmBinary)) {
jvmBinary = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
sameJvmBinary = true;
}
getLog().debug("Using JVM: " + jvmBinary);

Commandline cmdLine = new Commandline();

cmdLine.setWorkingDirectory(basedir);
cmdLine.setExecutable(jvmBinary);

// work around for http://bugs.jython.org/issue2582
if (sameJvmBinary && isAtLeastJava9()) {
cmdLine.createArg().setLine("--add-opens java.base/java.lang=ALL-UNNAMED");
cmdLine.createArg().setLine("--add-opens java.base/java.io=ALL-UNNAMED");
cmdLine.createArg().setLine("--add-opens java.base/java.nio=ALL-UNNAMED");
cmdLine.createArg().setLine("--add-opens java.base/sun.nio.ch=ALL-UNNAMED");
cmdLine.createArg().setLine("--add-opens java.xml/com.sun.org.apache.xerces.internal.jaxp=ALL-UNNAMED");
cmdLine.createArg().setLine("--add-opens java.xml/com.sun.org.apache.xerces.internal.parsers=ALL-UNNAMED");
}

if (argLine != null) {
cmdLine.createArg().setLine(argLine.replace("\n", " ").replace("\r", " "));
}

try {
cmdLine.addEnvironment("CLASSPATH", getPluginClasspath());
}
Expand Down Expand Up @@ -443,4 +457,16 @@ private String getPluginClasspath()
}
return classpath.toString();
}

@SuppressWarnings("JavaReflectionMemberAccess")
private static boolean isAtLeastJava9()
{
try {
Runtime.class.getMethod("version");
return true;
}
catch (NoSuchMethodException e) {
return false;
}
}
}

0 comments on commit c870da4

Please sign in to comment.