IDEA-182780 Use system properties to detect boot jdk version in SystemHealthMonitor

Aligned bundle name from jvm properties with one obtained from java -version
This commit is contained in:
Alexey Ushakov
2017-12-14 14:19:22 +03:00
parent a7f52f3d32
commit 49c35f06d3
2 changed files with 30 additions and 4 deletions
@@ -68,7 +68,7 @@ public class JdkBundle {
private static final Pattern BUILD_STR_PATTERN = Pattern.compile(".*\\([^-]*-(.*)\\).*", Pattern.MULTILINE);
@NotNull
private static final Pattern PROP_BUILD_PATTERN = Pattern.compile(".*-(.*)", Pattern.MULTILINE);
private static final Pattern PROP_BUILD_PATTERN = Pattern.compile("[^-]*-(.*)", Pattern.MULTILINE);
@NotNull public static final Bitness runtimeBitness = is64BitJVM(System.getProperty("java.vm.name")) ? Bitness.x64 : Bitness.x32;
@@ -277,7 +277,7 @@ public class JdkBundle {
String versionLine = outputLines.get(0);
versionAndUpdate = VersionUtil.parseNewVersionAndUpdate(versionLine, LINE_TO_VERSION_PATTERNS);
displayVersion = versionLine.replaceFirst("\".*\"", "");
displayVersion = displayVersion.replaceFirst("version", "");
displayVersion = displayVersion.replaceFirst("version ", "");
if (outputLines.size() >= 2) {
Matcher matcher = BUILD_STR_PATTERN.matcher(outputLines.get(1));
if (matcher.find()) {
@@ -301,11 +301,14 @@ public class JdkBundle {
VersionUtil.parseNewVersionAndUpdate(System.getProperty("java.version"), PROP_TO_VERSION_PATTERNS);
if (versionAndUpdate == null) return null;
Matcher matcher = PROP_BUILD_PATTERN.matcher(System.getProperty("java.runtime.version"));
String displayVersion = "java ";
String vmName = System.getProperty("java.vm.name","");
String displayVersion = vmName.startsWith("OpenJDK") ? "openjdk ": "java ";
if (matcher.find()) {
displayVersion += "(" + matcher.group(1) + ")";
}
return Pair.create(Pair.create(displayVersion, is64BitJVM(System.getProperty("java.vm.name"))), versionAndUpdate);
return Pair.create(Pair.create(displayVersion, is64BitJVM(vmName)), versionAndUpdate);
}
private static boolean is64BitJVM(String archLine) {
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
public class JdkBundleTest {
@@ -173,4 +174,26 @@ public class JdkBundleTest {
final String evalVerStr = verUpdate.first.toString() + "_" + verUpdate.second.toString();
assertTrue(evalVerStr + " is not the same with " + verStr, verStr.contains(evalVerStr));
}
@Test
public void testBootName() {
File homeJDK = new File(System.getProperty("java.home")).getParentFile();
if (!new File(homeJDK, "lib/tools.jar").exists()) return; // Skip pure jre
File bootJDK = SystemInfo.isMac ? homeJDK.getParentFile().getParentFile() : homeJDK;
boolean macNonStandardJDK = SystemInfo.isMac && !new File(bootJDK, "Contents/Home").exists();
JdkBundle bootBundle = macNonStandardJDK ? JdkBundle.createBoot(false) : // the test is run under jdk with non-standard layout
JdkBundle.createBoot();
JdkBundle bundle = JdkBundle.createBundle(bootJDK, false, false);
assertNotNull(bootBundle);
assertNotNull(bundle);
assertEquals(bundle.getNameVersion(), bootBundle.getNameVersion());
assertEquals(bundle.getBundleName(), bootBundle.getBundleName());
}
}