diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java index fa6a83b0cf3d..f0f2f7a84e1f 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/SdkConfigurationUtil.java @@ -215,23 +215,36 @@ public class SdkConfigurationUtil { for (SdkType sdkType : sdkTypes) { final String suggestedHomePath = sdkType.suggestHomePath(); if (suggestedHomePath != null && sdkType.isValidSdkHome(suggestedHomePath)) { - VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable() { - public VirtualFile compute() { - return LocalFileSystem.getInstance().refreshAndFindFileByPath(suggestedHomePath); - } - }); - if (sdkHome != null) { - final Sdk newSdk = setupSdk(ProjectJdkTable.getInstance().getAllJdks(), sdkHome, sdkType, true, null, null); - if (newSdk != null) { - addSdk(newSdk); - } - return newSdk; - } + Sdk an_sdk = createAndAddSDK(suggestedHomePath, sdkType); + if (an_sdk != null) return an_sdk; } } return null; } + /** + * Tries to create an SDK identified by path; if successful, add the SDK to the global SDK table. + * @param path identifies the SDK + * @param sdkType + * @return newly created SDK, or null. + */ + @Nullable + public static Sdk createAndAddSDK(final String path, SdkType sdkType) { + VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable() { + public VirtualFile compute() { + return LocalFileSystem.getInstance().refreshAndFindFileByPath(path); + } + }); + if (sdkHome != null) { + final Sdk newSdk = setupSdk(ProjectJdkTable.getInstance().getAllJdks(), sdkHome, sdkType, true, null, null); + if (newSdk != null) { + addSdk(newSdk); + } + return newSdk; + } + return null; + } + public static String createUniqueSdkName(SdkType type, String home, final Collection sdks) { return createUniqueSdkName(type.suggestSdkName(null, home), sdks); }