@Nullable public static Sdk findOrCreateSdk( @Nullable Comparator<Sdk> comparator, final SdkType... sdkTypes) { final Project defaultProject = ProjectManager.getInstance().getDefaultProject(); final Sdk sdk = ProjectRootManager.getInstance(defaultProject).getProjectSdk(); if (sdk != null) { for (SdkType type : sdkTypes) { if (sdk.getSdkType() == type) { return sdk; } } } for (SdkType type : sdkTypes) { List<Sdk> sdks = ProjectJdkTable.getInstance().getSdksOfType(type); if (!sdks.isEmpty()) { if (comparator != null) { Collections.sort(sdks, comparator); } return sdks.get(0); } } for (SdkType sdkType : sdkTypes) { final String suggestedHomePath = sdkType.suggestHomePath(); if (suggestedHomePath != null && sdkType.isValidSdkHome(suggestedHomePath)) { Sdk an_sdk = createAndAddSDK(suggestedHomePath, sdkType); if (an_sdk != null) return an_sdk; } } return null; }
@Nullable public static VirtualFile getSuggestedSdkRoot(@NotNull SdkType sdkType) { final String homePath = sdkType.suggestHomePath(); return homePath == null ? null : LocalFileSystem.getInstance().findFileByPath(homePath); }