From 87c5e56bbf9de1c027c0823be37bc3503e088abe Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 27 Apr 2017 18:25:03 +0300 Subject: [PATCH] consider java.home on any platform --- .../openapi/projectRoots/impl/JavaHomeFinder.java | 14 +++++++++++++- .../projectRoots/impl/WindowsJavaFinder.java | 9 ++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaHomeFinder.java b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaHomeFinder.java index 8aafb4433d8e..630d3450acf5 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaHomeFinder.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/JavaHomeFinder.java @@ -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 diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/WindowsJavaFinder.java b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/WindowsJavaFinder.java index a2a2f9971a27..acb1b2001bf0 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/impl/WindowsJavaFinder.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/impl/WindowsJavaFinder.java @@ -29,14 +29,9 @@ class WindowsJavaFinder extends JavaHomeFinder { @NotNull @Override protected List 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 result = new ArrayList<>(); File javasFolder = javaHome.getParentFile(); scanFolder(javasFolder, result);