From 163b96c0d11e4dc85e573ddfbf886c7b2a63dc4b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 1 Aug 2018 12:32:55 +0200 Subject: [PATCH] Fix broken SDK paths scan on Mac OS X /Contents/Home wasn't taken into account, so only the /usr/libexec/java_home check succeeded in finding a JDK --- .../projectRoots/impl/JavaHomeFinder.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 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 2a7e706025a2..d0feccc412d4 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 @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.projectRoots.impl; import com.intellij.execution.configurations.GeneralCommandLine; @@ -64,17 +50,22 @@ public abstract class JavaHomeFinder { return new DefaultFinder(); } - protected static void scanFolder(File folder, List result) { + protected void scanFolder(File folder, List result) { if (JdkUtil.checkForJdk(folder)) result.add(folder.getAbsolutePath()); for (File file : ObjectUtils.notNull(folder.listFiles(), ArrayUtil.EMPTY_FILE_ARRAY)) { + file = adjustPath(file); if (JdkUtil.checkForJdk(file)) { result.add(file.getAbsolutePath()); } } } + protected File adjustPath(File file) { + return file; + } + protected static File getJavaHome() { String property = SystemProperties.getJavaHome(); if (property == null) @@ -98,7 +89,7 @@ public abstract class JavaHomeFinder { public List findExistingJdks() { List result = new ArrayList<>(); for (String path : myPaths) { - JavaHomeFinder.scanFolder(new File(path), result); + scanFolder(new File(path), result); } return result; } @@ -122,5 +113,16 @@ public abstract class JavaHomeFinder { } return list; } + + @Override + protected File adjustPath(File file) { + File home = new File(file, "/Home"); + if (home.exists()) return home; + + home = new File(file, "Contents/Home"); + if (home.exists()) return home; + + return file; + } } }