gradle: importer JDK fixes, related issues:

IDEA-136230 Gradle: for projects created in IDEA 14.0.x Gradle JVM is not set
IDEA-136402 Gradle Problem - IU-140-2285.5
This commit is contained in:
Vladislav.Soroka
2015-02-13 16:26:36 +03:00
parent 90644b4f2e
commit 1c52f618d3
4 changed files with 29 additions and 16 deletions
@@ -18,10 +18,7 @@ package com.intellij.openapi.externalSystem.service.ui;
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.*;
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.util.CompositeAppearance;
@@ -46,6 +43,7 @@ public class ExternalSystemJdkComboBox extends ComboBoxWithWidePopup {
@Nullable
private Project myProject;
private boolean suggestJre = true;
public ExternalSystemJdkComboBox() {
this(null);
@@ -94,6 +92,11 @@ public class ExternalSystemJdkComboBox extends ComboBoxWithWidePopup {
myProject = project;
}
public ExternalSystemJdkComboBox withoutJre() {
suggestJre = false;
return this;
}
public void refreshData(@Nullable String selectedValue) {
Map<String, JdkComboBoxItem> jdkMap = collectComboBoxItem();
if (selectedValue != null && !jdkMap.containsKey(selectedValue)) {
@@ -140,16 +143,17 @@ public class ExternalSystemJdkComboBox extends ComboBoxWithWidePopup {
result.put(name, new JdkComboBoxItem(name, name, comment, ((SdkType)projectJdk.getSdkType()).sdkHasValidPath(projectJdk)));
}
final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
assert internalJdk.getHomePath() != null;
result.put(ExternalSystemJdkUtil.USE_INTERNAL_JAVA,
new JdkComboBoxItem(
ExternalSystemJdkUtil.USE_INTERNAL_JAVA,
ExternalSystemBundle.message("external.system.java.internal.jre"),
buildComment(internalJdk),
true
));
if(suggestJre) {
final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
assert internalJdk.getHomePath() != null;
result.put(ExternalSystemJdkUtil.USE_INTERNAL_JAVA,
new JdkComboBoxItem(
ExternalSystemJdkUtil.USE_INTERNAL_JAVA,
ExternalSystemBundle.message("external.system.java.internal.jre"),
buildComment(internalJdk),
true
));
}
if (myProject != null) {
final Sdk projectSdk = ProjectRootManager.getInstance(myProject).getProjectSdk();
@@ -7,6 +7,7 @@ import com.intellij.openapi.externalSystem.service.project.PlatformFacade;
import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JdkUtil;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.OrderEnumerator;
import com.intellij.openapi.util.Ref;
@@ -150,6 +151,14 @@ public class GradleInstallationManager {
OpenExternalSystemSettingsCallback.ID),
linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
}
final File sdkHomePath = sdk != null && sdk.getHomePath() != null ? new File(sdk.getHomePath()) : null;
if (sdkHomePath != null && JdkUtil.checkForJre(sdkHomePath.getPath()) && !JdkUtil.checkForJdk(sdkHomePath)) {
throw new ExternalSystemJdkException(
String.format("Please, use JDK instead of JRE for Gradle importer. <a href='%s'>Open Gradle Settings</a> \n",
OpenExternalSystemSettingsCallback.ID),
linkedProjectPath, null, OpenExternalSystemSettingsCallback.ID);
}
return sdk;
}
@@ -122,7 +122,7 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
myGradleHomeLabel = new JBLabel(GradleBundle.message("gradle.settings.text.home.path"));
initGradleHome();
myGradleJdkLabel = new JBLabel(GradleBundle.message("gradle.settings.text.jvm.path"));
myGradleJdkComboBox = new ExternalSystemJdkComboBox();
myGradleJdkComboBox = new ExternalSystemJdkComboBox().withoutJre();
initControls();
content.add(myUseWrapperButton, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
@@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable;
public class GradleProjectSettings extends ExternalProjectSettings {
@Nullable private String myGradleHome;
@Nullable private String myGradleJvm;
@Nullable private String myGradleJvm = ExternalSystemJdkUtil.USE_PROJECT_JDK;;
@Nullable private DistributionType distributionType;
private boolean disableWrapperSourceDistributionNotification;