consider java.home on any platform

This commit is contained in:
Dmitry Avdeev
2017-04-27 18:27:58 +03:00
parent b1ea1768b9
commit 87c5e56bbf
2 changed files with 15 additions and 8 deletions
@@ -21,6 +21,8 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.JdkUtil;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.ArrayUtil;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@@ -71,12 +73,22 @@ public abstract class JavaHomeFinder {
}
}
protected static File getJavaHome() {
String property = SystemProperties.getJavaHome();
if (property == null)
return null;
File javaHome = new File(property).getParentFile();//actually java.home points to to jre home
return javaHome == null || !javaHome.isDirectory() ? null : javaHome;
}
protected static class DefaultFinder extends JavaHomeFinder {
private final String[] myPaths;
protected DefaultFinder(String... paths) {
myPaths = paths;
File javaHome = getJavaHome();
myPaths = javaHome == null ? paths : ArrayUtil.prepend(javaHome.getAbsolutePath(), paths);
}
@NotNull
@@ -29,14 +29,9 @@ class WindowsJavaFinder extends JavaHomeFinder {
@NotNull
@Override
protected List<String> findExistingJdks() {
String property = System.getProperty("java.home");
if (property == null)
return Collections.emptyList();
File javaHome = getJavaHome();
if (javaHome == null) return Collections.emptyList();
File javaHome = new File(property).getParentFile();//actually java.home points to to jre home
if (javaHome == null || !javaHome.isDirectory() || javaHome.getParentFile() == null) {
return Collections.emptyList();
}
ArrayList<String> result = new ArrayList<>();
File javasFolder = javaHome.getParentFile();
scanFolder(javasFolder, result);