Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenJDK 16+ compat: add wrapper.conf argument to allow access to internal openjdk modules #740

Merged
merged 3 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/freenet/node/updater/UpdateDeployContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import freenet.node.NodeStarter;
import freenet.node.updater.MainJarDependenciesChecker.Dependency;
import freenet.node.updater.MainJarDependenciesChecker.MainJarDependencies;
import freenet.support.JVMVersion;
import freenet.support.Logger;
import freenet.support.io.Closer;

Expand Down Expand Up @@ -146,7 +147,9 @@ void rewriteWrapperConf(boolean writtenNewJar) throws IOException, UpdateCatastr
boolean writtenAnchorInterval = false;
/** Add the relative JNA tempdir if it does not exist already */
boolean writtenJnaTmpDir = false;

/** Allow accessing internal modules in Java 16+ */
boolean writtenIllegalAccessPermit = false;

String newMain = mainJarAbsolute ? newMainJar.getAbsolutePath() : newMainJar.getPath();

String mainRHS = null;
Expand Down Expand Up @@ -177,7 +180,7 @@ void rewriteWrapperConf(boolean writtenNewJar) throws IOException, UpdateCatastr
// Ignore the numbers.
String rhs = line.substring(idx+1);
dontWrite = true;
if(rhs.equals("freenet.jar") || rhs.equals("freenet.jar.new") ||
if(rhs.equals("freenet.jar") || rhs.equals("freenet.jar.new") ||
rhs.equals("freenet-stable-latest.jar") || rhs.equals("freenet-stable-latest.jar.new") ||
rhs.equals("freenet-testing-latest.jar") || rhs.equals("freenet-testing-latest.jar.new")) {
if(writtenNewJar)
Expand Down Expand Up @@ -211,6 +214,9 @@ void rewriteWrapperConf(boolean writtenNewJar) throws IOException, UpdateCatastr
if (rhs.startsWith("-Djava.io.tmpdir=")) {
writtenJnaTmpDir = true;
}
if (rhs.startsWith("--illegal-access=permit")) {
writtenIllegalAccessPermit = true;
}
}
} else if(lowcaseLine.equals("wrapper.restart.reload_configuration=true")) {
writtenReload = true;
Expand Down Expand Up @@ -258,7 +264,12 @@ void rewriteWrapperConf(boolean writtenNewJar) throws IOException, UpdateCatastr
if (!writtenJnaTmpDir) {
bw.write("wrapper.java.additional."+count+"=-Djava.io.tmpdir=./tmp/"+'\n');
}


// allow accessing internal modules (required for Java 16+, only supported since Java 9)
if (!writtenIllegalAccessPermit && JVMVersion.supportsModules()) {
bw.write("wrapper.java.additional."+count+"=--illegal-access=permit"+'\n');
}

for(String s : otherLines)
bw.write(s+'\n');

Expand Down
14 changes: 14 additions & 0 deletions src/freenet/support/JVMVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class JVMVersion {
*/
public static final String UPDATER_THRESHOLD = "1.8";

/**
* Oldest Java version which supports Modules
*/
public static final String SUPPORTS_MODULES_THRESHOLD = "1.9";

/**
* Pre-9 is formatted as: major.feature[.maintenance[_update]]-ident
* Post-9 is formatted as: major[.minor[.security[. ...]]]-ident
Expand Down Expand Up @@ -72,6 +77,15 @@ public static final boolean is32Bit() {
}
}

public static final boolean supportsModules() {
String currentVersion = getCurrent();
if (currentVersion == null) {
return false;
}

return compareVersion(SUPPORTS_MODULES_THRESHOLD, currentVersion) <= 0;
}

/**
* Decomposes a version string into major, feature, and optional maintenance and update
* components.
Expand Down