Use JavaVersion class in ProcessExecutor to conditionally add JVM options (e.g. --add-opens) based on JRE version.

Resolves gh-497.
This commit is contained in:
John Blum
2021-06-28 18:54:20 -07:00
parent 3e9c8a7f46
commit 705979c2be

View File

@@ -26,6 +26,7 @@ import java.util.stream.Collectors;
import org.springframework.data.gemfire.test.support.FileSystemUtils;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.data.gemfire.util.JavaVersion;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -86,12 +87,7 @@ public abstract class ProcessExecutor {
command.add(JAVA_EXE.getAbsolutePath());
command.add("-server");
command.add("-ea");
command.add("--add-opens");
command.add("java.base/java.lang=ALL-UNNAMED");
command.add("--add-opens");
command.add("java.base/java.nio=ALL-UNNAMED");
command.add("--add-opens");
command.add("java.base/java.util=ALL-UNNAMED");
configureJava16JvmOptions(command);
command.add("-classpath");
command.add(StringUtils.hasText(classpath) ? classpath : JAVA_CLASSPATH);
command.addAll(getSpringGemFireSystemProperties());
@@ -125,6 +121,20 @@ public abstract class ProcessExecutor {
return commandString.toString().trim();
}
protected static List<String> configureJava16JvmOptions(List<String> command) {
if (JavaVersion.current().isNewerThanOrEqualTo(JavaVersion.SIXTEEN)) {
command.add("--add-opens");
command.add("java.base/java.lang=ALL-UNNAMED");
command.add("--add-opens");
command.add("java.base/java.nio=ALL-UNNAMED");
command.add("--add-opens");
command.add("java.base/java.util=ALL-UNNAMED");
}
return command;
}
protected static Collection<? extends String> getSpringGemFireSystemProperties() {
return System.getProperties().stringPropertyNames().stream()