diff --git a/bin/scripts/unix/idea.sh b/bin/scripts/unix/idea.sh index 441430e804c8..fd42138a7bb7 100755 --- a/bin/scripts/unix/idea.sh +++ b/bin/scripts/unix/idea.sh @@ -61,6 +61,9 @@ if [ -n "$@@product_uc@@_JDK" -a -x "$@@product_uc@@_JDK/bin/java" ]; then JDK="$@@product_uc@@_JDK" elif [ -s "$HOME/.@@system_selector@@/config/@@vm_options@@.jdk" ]; then JDK=`$CAT $HOME/.@@system_selector@@/config/@@vm_options@@.jdk` + if [ ! -d $JDK ]; then + JDK=$IDE_HOME/$JDK + fi elif [ -x "$IDE_HOME/jre/jre/bin/java" ] && "$IDE_HOME/jre/jre/bin/java" -version > /dev/null 2>&1 ; then JDK="$IDE_HOME/jre" elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then diff --git a/native/MacLauncher/Launcher.m b/native/MacLauncher/Launcher.m index 878cbbb6f836..0d89b93dfa0e 100644 --- a/native/MacLauncher/Launcher.m +++ b/native/MacLauncher/Launcher.m @@ -236,6 +236,11 @@ NSBundle *findMatchingVm() { NSString *pathForFile = [NSString stringWithFormat:@"%@/%@.jdk", getPreferencesFolderPath(), getExecutable()]; + if (!pathForFile.isAbsolutePath) { + // Handle relative paths + pathForFile = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:pathForFile]; + } + if ([fileManager fileExistsAtPath:pathForFile]){ NSString* fileContents = [NSString stringWithContentsOfFile:pathForFile encoding:NSUTF8StringEncoding error:nil]; NSArray* allLinedStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; diff --git a/platform/lang-impl/src/com/intellij/openapi/util/SwitchBootJdkAction.java b/platform/lang-impl/src/com/intellij/openapi/util/SwitchBootJdkAction.java index 97ac68b45011..c287ff5035da 100644 --- a/platform/lang-impl/src/com/intellij/openapi/util/SwitchBootJdkAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/util/SwitchBootJdkAction.java @@ -58,7 +58,7 @@ public class SwitchBootJdkAction extends AnAction implements DumbAware { @NotNull private static File getBundledJDKFile() { - StringBuilder bundledJDKPath = new StringBuilder(PathManager.getHomePath() + File.separator + "jre"); + StringBuilder bundledJDKPath = new StringBuilder("jre"); if (SystemInfo.isMac) { bundledJDKPath.append(File.separator).append("jdk"); } @@ -75,16 +75,17 @@ public class SwitchBootJdkAction extends AnAction implements DumbAware { e.getPresentation().setText("Switch Boot JDK"); } - public static List getBundlesFromFile(@NotNull File fileWithBundles) { + private static List getBundlesFromFile(@NotNull File fileWithBundles) { List list = new ArrayList(); try { for (String line : FileUtil.loadLines(fileWithBundles, "UTF-8")) { - File file = new File(line); - if (file.exists()) { - list.add(JdkBundle.createBundle(file, false, false)); + File storedFile = new File(line); + final boolean isBundled = !storedFile.isAbsolute(); + File actualFile = isBundled ? new File(PathManager.getHomePath(), storedFile.getPath()) : storedFile; + if (actualFile.exists()) { + list.add(JdkBundle.createBundle(storedFile, false, isBundled)); } } - } catch (IllegalStateException e) { // The device builders can throw IllegalStateExceptions if // build gets called before everything is properly setup @@ -118,7 +119,7 @@ public class SwitchBootJdkAction extends AnAction implements DumbAware { try { //noinspection IOResourceOpenedButNotSafelyClosed fooWriter = new FileWriter(productJdkConfigFile, false); - fooWriter.write(selectedJdkBundleFile.getAbsolutePath()); + fooWriter.write(selectedJdkBundleFile.getPath()); } catch (IOException e) { LOG.error(e); @@ -141,7 +142,7 @@ public class SwitchBootJdkAction extends AnAction implements DumbAware { @NotNull private final ComboBox myComboBox; - protected SwitchBootJdkDialog(@Nullable Project project, final List jdkBundlesList) { + private SwitchBootJdkDialog(@Nullable Project project, final List jdkBundlesList) { super(project, false); final JdkBundleList pathsList = findJdkPaths(); @@ -223,7 +224,7 @@ public class SwitchBootJdkAction extends AnAction implements DumbAware { } public File getSelectedFile() { - return ((JdkBundle)myComboBox.getSelectedItem()).getBundleAsFile(); + return ((JdkBundle)myComboBox.getSelectedItem()).getLocation(); } } @@ -247,7 +248,7 @@ public class SwitchBootJdkAction extends AnAction implements DumbAware { jdkBundleList.addBundle(bootJdk, true); } - if (bundledJdkFile.exists()) { + if (new File(PathManager.getHomePath() + File.separator + bundledJdkFile).exists()) { JdkBundle bundledJdk = JdkBundle.createBundle(bundledJdkFile, false, true); if (bundledJdk != null) { jdkBundleList.addBundle(bundledJdk, true); diff --git a/platform/lang-impl/src/com/intellij/util/JdkBundle.java b/platform/lang-impl/src/com/intellij/util/JdkBundle.java index 43dcd49ee492..12ccacc538d5 100644 --- a/platform/lang-impl/src/com/intellij/util/JdkBundle.java +++ b/platform/lang-impl/src/com/intellij/util/JdkBundle.java @@ -18,6 +18,7 @@ package com.intellij.util; import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.util.ExecUtil; +import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; @@ -63,10 +64,12 @@ public class JdkBundle { @Nullable static JdkBundle createBundle(@NotNull File jvm, @NotNull String homeSubPath, boolean boot, boolean bundled) { File javaHome = SystemInfo.isMac ? new File(jvm, homeSubPath) : jvm; + if (bundled) javaHome = new File(PathManager.getHomePath(), javaHome.getPath()); boolean hasToolsJar = new File(javaHome, "lib" + File.separator + "tools.jar").exists(); if (!SystemInfo.isMac && !hasToolsJar) return null; // Skip jre - Pair> nameVersionAndUpdate = getJDKNameVersionAndUpdate(jvm, homeSubPath); + File absJvmLocation = bundled ? new File(PathManager.getHomePath(), jvm.getPath()) : jvm; + Pair> nameVersionAndUpdate = getJDKNameVersionAndUpdate(absJvmLocation, homeSubPath); if (SystemInfo.isMac && nameVersionAndUpdate.second != null && nameVersionAndUpdate.second.first.isOrGreaterThan(1, 7) && !hasToolsJar) return null; // Skip jre @@ -90,7 +93,12 @@ public class JdkBundle { } @NotNull - public File getBundleAsFile() { + File getAbsoluteLocation() { + return myBundled ? new File(PathManager.getHomePath(), myBundleAsFile.getPath()) : myBundleAsFile; + } + + @NotNull + public File getLocation() { return myBundleAsFile; } diff --git a/platform/lang-impl/src/com/intellij/util/JdkBundleList.java b/platform/lang-impl/src/com/intellij/util/JdkBundleList.java index 2ab00e883c28..99b12ff82c1d 100644 --- a/platform/lang-impl/src/com/intellij/util/JdkBundleList.java +++ b/platform/lang-impl/src/com/intellij/util/JdkBundleList.java @@ -33,7 +33,7 @@ public class JdkBundleList { private HashMap nameVersionMap = new HashMap(); public void addBundle(@NotNull JdkBundle bundle, boolean forceOldVersion) { - JdkBundle bundleDescr = bundleMap.get(bundle.getBundleAsFile().getAbsolutePath()); + JdkBundle bundleDescr = bundleMap.get(bundle.getAbsoluteLocation().getAbsolutePath()); if (bundleDescr == null) { addMostRecent(bundle, forceOldVersion); } @@ -59,14 +59,14 @@ public class JdkBundleList { else if (!latestJdk.isBoot() && !latestJdk.isBundled()) { // preserve boot and bundled versions bundleList.remove(latestJdk); nameVersionMap.remove(latestJdk.getNameVersion()); - bundleMap.remove(latestJdk.getBundleAsFile().getAbsolutePath()); + bundleMap.remove(latestJdk.getAbsoluteLocation().getAbsolutePath()); } } } } bundleList.add(bundleDescriptor); - bundleMap.put(bundleDescriptor.getBundleAsFile().getAbsolutePath(), bundleDescriptor); + bundleMap.put(bundleDescriptor.getAbsoluteLocation().getAbsolutePath(), bundleDescriptor); if (updateVersionMap) { nameVersionMap.put(bundleDescriptor.getNameVersion(), bundleDescriptor); diff --git a/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java b/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java index 592e260d86e6..84f470b7ea9e 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/JdkBundleTest.java @@ -76,7 +76,7 @@ public class JdkBundleTest { for (File file : jdk6Files) { testPassed = false; for (JdkBundle bundle : bundles) { - if (FileUtil.filesEqual(bundle.getBundleAsFile(), file)) { + if (FileUtil.filesEqual(bundle.getAbsoluteLocation(), file)) { testPassed = true; break; } @@ -110,8 +110,8 @@ public class JdkBundleTest { ArrayList bundles = jdkBundleList.toArrayList(); for (JdkBundle bundle : bundles) { - assertTrue("jre \"" + bundle.getBundleAsFile().getAbsolutePath() + "\" found among jdk bundles", - new File(bundle.getBundleAsFile(), "Contents/Home/lib/tools.jar").exists()); + assertTrue("jre \"" + bundle.getAbsoluteLocation().getAbsolutePath() + "\" found among jdk bundles", + new File(bundle.getAbsoluteLocation(), "Contents/Home/lib/tools.jar").exists()); } } @@ -127,15 +127,15 @@ public class JdkBundleTest { boolean macNonStandardJDK = SystemInfo.isMac && !new File(bootJDK, "Contents/Home").exists(); JdkBundle bundle = macNonStandardJDK - ? JdkBundle.createBundle(homeJDK, "", true, true) : // the test is run under jdk with non-standard layout - JdkBundle.createBundle(bootJDK, true, true); + ? JdkBundle.createBundle(homeJDK, "", true, false) : // the test is run under jdk with non-standard layout + JdkBundle.createBundle(bootJDK, true, false); assertNotNull(bundle); assertTrue(bundle.isBoot()); - assertTrue(bundle.isBundled()); + assertFalse(bundle.isBundled()); - assertTrue(FileUtil.filesEqual(bundle.getBundleAsFile(), macNonStandardJDK ? homeJDK : bootJDK)); + assertTrue(FileUtil.filesEqual(bundle.getAbsoluteLocation(), macNonStandardJDK ? homeJDK : bootJDK)); Pair verUpdate = bundle.getVersionUpdate(); assertNotNull(verUpdate); @@ -161,7 +161,7 @@ public class JdkBundleTest { assertTrue(bundle.isBoot()); assertFalse(bundle.isBundled()); - assertTrue(FileUtil.filesEqual(bundle.getBundleAsFile(), macNonStandardJDK ? homeJDK : bootJDK)); + assertTrue(FileUtil.filesEqual(bundle.getAbsoluteLocation(), macNonStandardJDK ? homeJDK : bootJDK)); Pair verUpdate = bundle.getVersionUpdate(); assertNotNull(verUpdate);