diff --git a/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/JDK.java b/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/JDK.java index ea227339..4ec54354 100644 --- a/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/JDK.java +++ b/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/JDK.java @@ -62,32 +62,45 @@ public static int getSubMinor() { public static int getUpdate() { return update; } + + public static String getVendor() { + return vendor; + } public static class Version { + private final Optional vendor; private final int major; private final Optional minor; private final Optional subminor; private final Optional update; - private Version(String string) { + private Version(String version) { // Split java version into its constituent parts, i.e. // 1.2.3.4 -> [ 1, 2, 3, 4] // 1.2.3u4 -> [ 1, 2, 3, 4] // 1.2.3_4 -> [ 1, 2, 3, 4] - String[] split = string.split("[\\._u\\-]+"); + if (version.contains("-")) { + String[] versionSplit = version.split("-"); + this.vendor = versionSplit.length > 0 ? Optional.of(versionSplit[0]) : Optional.empty(); + version = versionSplit.length > 1 ? versionSplit[1] : ""; + } else { + this.vendor = Optional.empty(); + } + String[] split = version.split("[\\._u\\-]+"); major = split.length > 0 ? Integer.parseInt(split[0]) : 0; minor = split.length > 1 ? Optional.of(Integer.parseInt(split[1])) : Optional.empty(); subminor = split.length > 2 ? Optional.of(Integer.parseInt(split[2])) : Optional.empty(); update = split.length > 3 ? Optional.of(Integer.parseInt(split[3])) : Optional.empty(); } - - private Version(int major, int minor, int subminor, int update) { - this.major = major; - this.minor = Optional.of(minor); - this.subminor = Optional.of(subminor); + + private Version(int major, int minor, int subminor, int update, String vendor) { + this.major = major; + this.minor = Optional.of(minor); + this.subminor = Optional.of(subminor); this.update = Optional.of(update); + this.vendor = Optional.of(vendor); } public boolean newerThan(Version version) { @@ -221,6 +234,10 @@ public String toString() { } public static Version getVersion(String string) { + return getVersion(string, null); + } + + public static Version getVersion(String string, String vendor) { if (string != null && string.matches("([0-9]+[\\._u\\-]+)*[0-9]+")) { // Make sure the string is a valid JDK version, i.e. // 1.8.0_162 or something that is returned by "java -version" @@ -230,24 +247,27 @@ public static Version getVersion(String string) { return null; } - public static Version getVersion(String jv, String javaSpecificationVersion) { + public static Version getVersion(String jv, String javaSpecificationVersion, String vendor) { int[] versions = parseVersions(jv, javaSpecificationVersion); - - return new Version(versions[MAJOR], versions[MINOR], versions[SUBMINOR], versions[UPDATE]); + + return new Version(versions[MAJOR], versions[MINOR], versions[SUBMINOR], versions[UPDATE], vendor); } public static Version getVersion() { - return new Version(major, minor, subminor, update); + return new Version(major, minor, subminor, update, vendor); } public static boolean isCorrectJDK(Optional minVersion, Optional maxVersion) { - return isCorrectJDK(JDK_VERSION, minVersion, maxVersion); + return isCorrectJDK(JDK_VERSION, Optional.empty(), minVersion, maxVersion); } - public static boolean isCorrectJDK(Version JDKversion, Optional minVersion, Optional maxVersion) { + public static boolean isCorrectJDK(Version JDKversion, Optional vendor, Optional minVersion, Optional maxVersion) { boolean correctJDK = true; - if (minVersion.isPresent()) { + if (vendor.isPresent()) { + correctJDK = JDKversion.vendor.get().contains(vendor.get()); + } + if (correctJDK && minVersion.isPresent()) { correctJDK = JDKversion.newerOrEquals(minVersion.get()); } if (correctJDK && maxVersion.isPresent()) { @@ -279,6 +299,7 @@ public static String toStringStatic() { private static int minor; private static int subminor; private static int update; + private static String vendor; // DO initialize these variables. You'll be sorry if you don't! private final static int MAJOR = 0; @@ -287,7 +308,7 @@ public static String toStringStatic() { private final static int UPDATE = 3; // DO NOT initialize this variable. You'll again be sorry if you do! - private static Version JDK_VERSION; + public static Version JDK_VERSION; private static void initialize() { @@ -296,7 +317,8 @@ private static void initialize() { minor = subminor = update = 0; try { - String jv = System.getProperty("java.version"); + String javaVersion = System.getProperty("java.version"); + vendor = System.getProperty("java.vendor"); /*In JEP 223 java.specification.version will be a single number versioning , not a dotted versioning . So if we get a single integer as versioning we know that the JDK is post JEP 223 For JDK 8: @@ -308,7 +330,7 @@ private static void initialize() { */ String javaSpecificationVersion = System.getProperty("java.specification.version"); - int[] versions = parseVersions(jv, javaSpecificationVersion); + int[] versions = parseVersions(javaVersion, javaSpecificationVersion); major = versions[MAJOR]; minor = versions[MINOR]; @@ -319,7 +341,7 @@ private static void initialize() { // ignore -- use defaults } - JDK_VERSION = new Version(major, minor, subminor, update); + JDK_VERSION = new Version(major, minor, subminor, update, vendor); } static int[] parseVersions(String jv, String javaSpecificationVersion) { diff --git a/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/ServerTasks.java b/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/ServerTasks.java index b36f0224..01083ebf 100644 --- a/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/ServerTasks.java +++ b/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/ServerTasks.java @@ -22,6 +22,7 @@ import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; import static org.eclipse.payara.tools.sdk.server.JDK.isCorrectJDK; +import static org.eclipse.payara.tools.sdk.server.JDK.JDK_VERSION; import static org.eclipse.payara.tools.sdk.server.ServerTasks.StartMode.DEBUG; import static org.eclipse.payara.tools.sdk.server.parser.TreeParser.readXml; import static org.eclipse.payara.tools.sdk.utils.JavaUtils.javaVmExecutableFullPath; @@ -146,24 +147,14 @@ public static ResultProcess startServer(PayaraServer server, StartupArgs args, S if (!readXml(new File(domainXmlPath), jvmConfigReader)) { throw new PayaraIdeException(LOGGER.excMsg(METHOD, "readXMLerror"), domainXmlPath); } - - String[] versions = JavaUtils.getJavaVersionString(args.getJavaHome()).split(":"); - - JDK.Version targetJDKVersion; - - if (versions.length == 1) { - // Simple way, just using version string - targetJDKVersion = JDK.getVersion(versions[0]); - } else { - // More eleborate way using both version string and spec version - targetJDKVersion = JDK.getVersion(versions[0], versions[1]); - } - + + JDK.Version targetJDKVersion = JDK_VERSION != null ? JDK_VERSION : getJavaVersion(args); + // Filter out all options that are not applicable List optList = jvmConfigReader.getJvmOptions() .stream() - .filter(fullOption -> isCorrectJDK(targetJDKVersion, fullOption.minVersion, fullOption.maxVersion)) + .filter(fullOption -> isCorrectJDK(targetJDKVersion, fullOption.vendor, fullOption.minVersion, fullOption.maxVersion)) .map(fullOption -> fullOption.option) .collect(toList()); @@ -236,6 +227,21 @@ public static ResultProcess startServer(PayaraServer server, StartupArgs args, S } } + private static JDK.Version getJavaVersion(StartupArgs args) { + String[] versions = JavaUtils.getJavaVersionString(args.getJavaHome()).split(":"); + JDK.Version targetJDKVersion; + + if (versions.length == 1) { + // Simple way, just using version string + targetJDKVersion = JDK.getVersion(versions[0]); + } else { + // More eleborate way using both version string and spec version + targetJDKVersion = JDK.getVersion(versions[0], versions[1], System.getProperty("java.vendor")); + } + + return targetJDKVersion; + } + public static Integer getDebugPort(ResultProcess process) { Matcher debugPortMatcher = debugPortPattern.matcher(process.getValue().getArguments()); if (debugPortMatcher.find()) { diff --git a/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/parser/JvmConfigReader.java b/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/parser/JvmConfigReader.java index 95cdb3a2..86fdce60 100644 --- a/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/parser/JvmConfigReader.java +++ b/plugins/org.eclipse.payara.tools/src/org/eclipse/payara/tools/sdk/server/parser/JvmConfigReader.java @@ -27,7 +27,6 @@ import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.eclipse.payara.tools.sdk.server.JDK; import org.eclipse.payara.tools.sdk.server.parser.TreeParser.NodeListener; import org.eclipse.payara.tools.sdk.server.parser.TreeParser.Path; @@ -205,6 +204,7 @@ public boolean isMonitoringEnabled() { public static class JvmOption { public final String option; + public final Optional vendor; public final Optional minVersion; public final Optional maxVersion; @@ -221,11 +221,19 @@ public static class JvmOption { public JvmOption(String option) { Matcher matcher = PATTERN.matcher(option); if (matcher.matches()) { - this.minVersion = Optional.ofNullable(JDK.getVersion(matcher.group(1))); + if (matcher.group(1).contains("-")) { + String[] parts = matcher.group(1).split("-"); + this.vendor = Optional.ofNullable(parts[0]); + this.minVersion = Optional.ofNullable(JDK.getVersion(parts[1])); + } else { + this.vendor = Optional.empty(); + this.minVersion = Optional.ofNullable(JDK.getVersion(matcher.group(1))); + } this.maxVersion = Optional.ofNullable(JDK.getVersion(matcher.group(2))); this.option = matcher.group(3); } else { this.option = option; + this.vendor = Optional.empty(); this.minVersion = Optional.empty(); this.maxVersion = Optional.empty(); } @@ -233,6 +241,7 @@ public JvmOption(String option) { public JvmOption(String option, String minVersion, String maxVersion) { this.option = option; + this.vendor = Optional.empty(); this.minVersion = Optional.ofNullable(JDK.getVersion(minVersion)); this.maxVersion = Optional.ofNullable(JDK.getVersion(maxVersion)); }