diff --git a/platform/lang-impl/src/com/intellij/util/JdkBundle.java b/platform/lang-impl/src/com/intellij/util/JdkBundle.java index ffddabc3b233..9458c43acf5a 100644 --- a/platform/lang-impl/src/com/intellij/util/JdkBundle.java +++ b/platform/lang-impl/src/com/intellij/util/JdkBundle.java @@ -56,20 +56,32 @@ public class JdkBundle { @Nullable public static JdkBundle createBundle(@NotNull File jvm, boolean boot, boolean bundled) { - File javaHome = SystemInfo.isMac ? new File(jvm, "Contents/Home") : jvm; - if (!new File(javaHome, "lib/tools.jar").exists()) return null; // Skip JRE + String homeSubPath = SystemInfo.isMac ? "Contents/Home" : ""; + return createBundle(jvm, homeSubPath, boot, bundled); + } - Pair> nameVersionAndUpdate = getJDKNameVersionAndUpdate(jvm.getAbsolutePath()); + @Nullable + public static JdkBundle createBundle(@NotNull File jvm, @NotNull String homeSubPath, boolean boot, boolean bundled) { + File javaHome = SystemInfo.isMac ? new File(jvm, homeSubPath) : jvm; + if (!new File(javaHome, "lib" + File.separator + "tools.jar").exists()) return null; // Skip JRE + + Pair> nameVersionAndUpdate = getJDKNameVersionAndUpdate(jvm, homeSubPath); return new JdkBundle(jvm, nameVersionAndUpdate.first, nameVersionAndUpdate.second, boot, bundled); } @Nullable public static JdkBundle createBoot() { + return createBoot(true); + } + + @Nullable + public static JdkBundle createBoot(boolean adjustToMacBundle) { File bootJDK = new File(System.getProperty("java.home")).getParentFile(); - if (SystemInfo.isMac) { + if (SystemInfo.isMac && adjustToMacBundle) { bootJDK = bootJDK.getParentFile().getParentFile(); + return createBundle(bootJDK, true, false); } - return createBundle(bootJDK, true, false); + return createBundle(bootJDK, "", true, false); } @NotNull @@ -120,10 +132,10 @@ public class JdkBundle { return myBundleName + ((myVersionUpdate != null) ? myVersionUpdate.first.toString() : ""); } - private static Pair> getJDKNameVersionAndUpdate(String jvmPath) { + private static Pair> getJDKNameVersionAndUpdate(File jvm, String homeSubPath) { GeneralCommandLine commandLine = new GeneralCommandLine(); - commandLine.setExePath(jvmPath + (SystemInfo.isMac ? "/Contents/Home/" : "/") + "jre" + - File.separator + "bin" + File.separator + "java"); + commandLine.setExePath(new File(jvm, homeSubPath + File.separator + "jre" + + File.separator + "bin" + File.separator + "java").getAbsolutePath()); commandLine.addParameter("-version"); String displayVersion = null; @@ -140,7 +152,7 @@ public class JdkBundle { displayVersion = displayVersion.replaceFirst("\".*\"", ""); } else { - displayVersion = new File(jvmPath).getName(); + displayVersion = jvm.getName(); } return Pair.create(displayVersion, versionAndUpdate); diff --git a/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java b/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java index 86fbf5609a30..541d77509904 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java @@ -31,16 +31,17 @@ public class JdkBundleTest { @Test public void testCreateBundle() throws Exception { if (SystemInfo.isWindows) return; // Windows is not supported so far - File bootJDK = new File(System.getProperty("java.home")).getParentFile(); + File homeJDK = new File(System.getProperty("java.home")).getParentFile(); - if (!new File(bootJDK, "lib/tools.jar").exists()) return; // Skip pure jre + if (!new File(homeJDK, "lib/tools.jar").exists()) return; // Skip pure jre - if (SystemInfo.isMac) { - bootJDK = bootJDK.getParentFile().getParentFile(); - } + File bootJDK = SystemInfo.isMac ? homeJDK.getParentFile().getParentFile() : homeJDK; String verStr = System.getProperty("java.version"); - JdkBundle bundle = JdkBundle.createBundle(bootJDK, true, true); + JdkBundle bundle = (SystemInfo.isMac && !new File(bootJDK, "Contents/Home").exists()) + ? JdkBundle.createBundle(homeJDK, "", true, true) : // the test is run under jdk with non-standard layout + JdkBundle.createBundle(bootJDK, true, true); + assertNotNull(bundle); assertTrue(bundle.isBoot()); @@ -57,16 +58,16 @@ public class JdkBundleTest { @Test public void testCreateBoot() throws Exception { if (SystemInfo.isWindows) return; // Windows is not supported so far - File bootJDK = new File(System.getProperty("java.home")).getParentFile(); + File homeJDK = new File(System.getProperty("java.home")).getParentFile(); - if (!new File(bootJDK, "lib/tools.jar").exists()) return; // Skip pure jre + if (!new File(homeJDK, "lib/tools.jar").exists()) return; // Skip pure jre - if (SystemInfo.isMac) { - bootJDK = bootJDK.getParentFile().getParentFile(); - } + File bootJDK = SystemInfo.isMac ? homeJDK.getParentFile().getParentFile() : homeJDK; String verStr = System.getProperty("java.version"); - JdkBundle bundle = JdkBundle.createBoot(); + JdkBundle bundle = (SystemInfo.isMac && !new File(bootJDK, "Contents/Home").exists()) + ? JdkBundle.createBoot(false) : // the test is run under jdk with non-standard layout + JdkBundle.createBoot(); assertNotNull(bundle); assertTrue(bundle.isBoot());