From 40b87ad449b3dc0cd3bf77a87798cc28621b0932 Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Mon, 23 Dec 2019 14:53:44 +0300 Subject: [PATCH] IDEA-CR-56535 fixed wrong messages for `gradle.jvm.is.jre` added jdk validation of gradle jvm GitOrigin-RevId: f5555495fc330aa2098ff37ade3c95fce632f3d0 --- .../service/execution/ExternalSystemJdkUtil.java | 2 ++ .../service/ui/ExternalSystemJdkComboBoxUtil.kt | 15 +++++++++++---- .../roots/ui/configuration/SdkComboBoxModel.kt | 16 ++++++++++------ .../roots/ui/configuration/SdkListItem.java | 9 +++++++-- .../roots/ui/configuration/SdkListPresenter.java | 2 +- .../resources/i18n/GradleBundle.properties | 4 ++-- .../service/execution/GradleExecutionAware.kt | 4 ++-- .../gradle/service/project/open/GradleJdk.kt | 5 ++--- .../IdeaGradleProjectSettingsControlBuilder.java | 16 +++++++++++++--- 9 files changed, 50 insertions(+), 23 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java index 01c37c666b07..2fc001d04407 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java @@ -172,6 +172,8 @@ public class ExternalSystemJdkUtil { @Contract("null -> false") public static boolean isValidJdk(@Nullable Sdk jdk) { if (jdk == null) return false; + SdkType javaSdkType = getJavaSdkType(); + if (!javaSdkType.equals(jdk.getSdkType())) return false; if (SdkDownloadTracker.getInstance().isDownloading(jdk)) return true; return isValidJdk(jdk.getHomePath()); } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalSystemJdkComboBoxUtil.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalSystemJdkComboBoxUtil.kt index 17750ae91aaa..1509cc30935e 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalSystemJdkComboBoxUtil.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalSystemJdkComboBoxUtil.kt @@ -4,6 +4,7 @@ package com.intellij.openapi.externalSystem.service.ui import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil +import com.intellij.openapi.externalSystem.service.execution.InvalidSdkException import com.intellij.openapi.roots.ui.configuration.SdkComboBox import com.intellij.openapi.roots.ui.configuration.SdkListItem @@ -11,6 +12,7 @@ fun SdkComboBox.getSelectedJdkReference(): String? { return when (val it = selectedItem) { is SdkListItem.ProjectSdkItem -> ExternalSystemJdkUtil.USE_PROJECT_JDK is SdkListItem.SdkItem -> it.sdk.name + is SdkListItem.InvalidSdkItem -> it.sdkName else -> null } } @@ -24,8 +26,13 @@ fun SdkComboBox.setSelectedJdkReference(jdkReference: String?) { } private fun SdkComboBox.resolveSdkItem(selectedJdkReference: String): SdkListItem { - val selectedJdk = ExternalSystemJdkUtil.resolveJdkName(model.sdksModel.projectSdk, selectedJdkReference) - val selectedSdkItem = selectedJdk?.let { model.listModel.findSdkItem(selectedJdk) } - if (selectedSdkItem == null) return showInvalidSdkItem(selectedJdkReference) - return selectedSdkItem + try { + val selectedJdk = ExternalSystemJdkUtil.resolveJdkName(model.sdksModel.projectSdk, selectedJdkReference) + val selectedSdkItem = selectedJdk?.let { model.listModel.findSdkItem(selectedJdk) } + if (selectedSdkItem == null) return showInvalidSdkItem(selectedJdkReference) + return selectedSdkItem + } + catch (ex: InvalidSdkException) { + return showInvalidSdkItem(selectedJdkReference) + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBoxModel.kt b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBoxModel.kt index 15a845a00440..1374719b93cd 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBoxModel.kt +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkComboBoxModel.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.projectRoots.* import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel import com.intellij.openapi.ui.ComboBoxPopupState import com.intellij.openapi.util.Condition +import java.util.function.Predicate import javax.swing.ComboBoxModel import javax.swing.ListModel @@ -36,12 +37,15 @@ class SdkComboBoxModel private constructor( fun createSdkComboBoxModel( project: Project, sdksModel: ProjectSdksModel, - sdkTypeFilter: Condition? = null, - sdkTypeCreationFilter: Condition? = null, - sdkFilter: Condition? = null + sdkTypeFilter: Predicate? = null, + sdkTypeCreationFilter: Predicate? = null, + sdkFilter: Predicate? = null ): SdkComboBoxModel { val selectedItem = SdkListItem.NoneSdkItem() - val modelBuilder = SdkListModelBuilder(project, sdksModel, sdkTypeFilter, sdkTypeCreationFilter, sdkFilter) + val sdkTypeCondition = sdkTypeFilter?.let { f -> Condition { f.test(it) } } + val sdkTypeCreationCondition = sdkTypeCreationFilter?.let { f -> Condition { f.test(it) } } + val sdkCondition = sdkFilter?.let { f -> Condition { f.test(it) } } + val modelBuilder = SdkListModelBuilder(project, sdksModel, sdkTypeCondition, sdkTypeCreationCondition, sdkCondition) if (sdksModel.projectSdk != null) modelBuilder.showProjectSdkItem() val listModel = modelBuilder.buildModel() return SdkComboBoxModel(selectedItem, project, sdksModel, listModel, modelBuilder) @@ -49,9 +53,9 @@ class SdkComboBoxModel private constructor( @JvmStatic fun createJdkComboBoxModel(project: Project, sdksModel: ProjectSdksModel): SdkComboBoxModel { - val sdkTypeFilter = Condition { it is JavaSdkType } + val sdkTypeFilter = Predicate { it is JavaSdkType } val noJavaSdkTypes = { SdkType.getAllTypes().filterNot { it is SimpleJavaSdkType }.isEmpty() } - val sdkTypeCreationFilter = Condition { noJavaSdkTypes() || it !is SimpleJavaSdkType } + val sdkTypeCreationFilter = Predicate { it !is SimpleJavaSdkType || noJavaSdkTypes() } return createSdkComboBoxModel(project, sdksModel, sdkTypeFilter, sdkTypeCreationFilter, null) } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListItem.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListItem.java index d0724cdbb74d..0abe217aea6a 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListItem.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListItem.java @@ -68,13 +68,18 @@ public abstract class SdkListItem { } } - static final class InvalidSdkItem extends SdkListItem { - final String mySdkName; + public static final class InvalidSdkItem extends SdkListItem { + private final String mySdkName; InvalidSdkItem(@NotNull String name) { mySdkName = name; } + @NotNull + public String getSdkName() { + return mySdkName; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListPresenter.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListPresenter.java index ee07ea5ff454..7d6e46b97a84 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListPresenter.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/SdkListPresenter.java @@ -129,7 +129,7 @@ public abstract class SdkListPresenter extends ColoredListCellRenderer sdkTypeFilter = it -> ExternalSystemJdkUtil.getJavaSdkType().equals(it); + Supplier allIsSimpleSdk = () -> Arrays.stream(SdkType.getAllTypes()).allMatch(it -> it instanceof SimpleJavaSdkType); + Predicate sdkTypeCreationFilter = it -> !(it instanceof SimpleJavaSdkType) || allIsSimpleSdk.get(); + Predicate sdkFilter = it -> ExternalSystemJdkUtil.isValidJdk(it); + myGradleJdkComboBox = new SdkComboBox(createSdkComboBoxModel(project, sdksModel, sdkTypeFilter, sdkTypeCreationFilter, sdkFilter)); myGradleJdkComboBoxWrapper.add(myGradleJdkComboBox, BorderLayout.CENTER); }