gradle: Add support choosing Gradle JVM
authorVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Mon, 15 Dec 2014 12:40:58 +0000 (15:40 +0300)
committerVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Mon, 15 Dec 2014 12:40:58 +0000 (15:40 +0300)
16 files changed:
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkException.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkUtil.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/InvalidJavaHomeException.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/InvalidSdkException.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ProjectJdkNotFoundException.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/UndefinedJavaHomeException.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/ExternalSystemNotificationExtensionImpl.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/callback/OpenExternalSystemSettingsCallback.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/callback/OpenProjectJdkSettingsCallback.java [new file with mode: 0644]
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalSystemJdkComboBox.java [moved from plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenJdkComboBox.java with 73% similarity]
plugins/gradle/resources/i18n/GradleBundle.properties
plugins/gradle/src/org/jetbrains/plugins/gradle/GradleManager.java
plugins/gradle/src/org/jetbrains/plugins/gradle/remote/GradleJavaHelper.java [deleted file]
plugins/gradle/src/org/jetbrains/plugins/gradle/service/GradleInstallationManager.java
plugins/gradle/src/org/jetbrains/plugins/gradle/service/settings/GradleProjectSettingsControl.java
plugins/gradle/src/org/jetbrains/plugins/gradle/settings/GradleProjectSettings.java

diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkException.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemJdkException.java
new file mode 100644 (file)
index 0000000..8396849
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.externalSystem.model.ExternalSystemException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/12/2014
+ */
+public class ExternalSystemJdkException extends ExternalSystemException {
+
+  public ExternalSystemJdkException(@Nullable String message, @Nullable Throwable cause) {
+    super(message, cause);
+  }
+}
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
new file mode 100644 (file)
index 0000000..09dd7df
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2000-2009 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.
+ */
+package com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.externalSystem.model.ExternalSystemException;
+import com.intellij.openapi.externalSystem.service.notification.callback.OpenExternalSystemSettingsCallback;
+import com.intellij.openapi.externalSystem.service.notification.callback.OpenProjectJdkSettingsCallback;
+import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.projectRoots.JavaSdk;
+import com.intellij.openapi.projectRoots.JavaSdkType;
+import com.intellij.openapi.projectRoots.ProjectJdkTable;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.util.Function;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import java.util.Collection;
+
+public class ExternalSystemJdkUtil {
+
+  @NonNls public static final String USE_INTERNAL_JAVA = "#JAVA_INTERNAL";
+  @NonNls public static final String USE_PROJECT_JDK = "#USE_PROJECT_JDK";
+  @NonNls public static final String USE_JAVA_HOME = "#JAVA_HOME";
+
+
+  @Nullable
+  public static Sdk getJdk(@Nullable Project project, @Nullable String jdkName) {
+    if (jdkName == null) return null;
+
+    if (USE_INTERNAL_JAVA.equals(jdkName)) {
+      return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
+    }
+
+    if (USE_PROJECT_JDK.equals(jdkName)) {
+      if (project != null) {
+        Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
+        if (res != null) {
+          return res;
+        }
+        Module[] modules = ModuleManager.getInstance(project).getModules();
+        for (Module module : modules) {
+          Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
+          if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
+            return sdk;
+          }
+        }
+      }
+
+      if (project == null) {
+        Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
+        if (recent != null) return recent;
+        return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
+      }
+
+      throw new ExternalSystemException(
+        String.format("Project JDK is not specified. <a href='%s'>Configure</a>", OpenProjectJdkSettingsCallback.ID),
+        OpenProjectJdkSettingsCallback.ID);
+    }
+
+    if (USE_JAVA_HOME.equals(jdkName)) {
+      final String javaHome = System.getenv("JAVA_HOME");
+      if (StringUtil.isEmptyOrSpaces(javaHome)) {
+        throw new ExternalSystemException(ExternalSystemBundle.message("external.system.java.home.undefined"));
+      }
+      final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
+      if (jdk == null) {
+        throw new ExternalSystemException(ExternalSystemBundle.message("external.system.java.home.invalid", javaHome));
+      }
+      return jdk;
+    }
+
+    for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
+      if (projectJdk.getName().equals(jdkName)) {
+        return projectJdk;
+      }
+    }
+
+    throw new ExternalSystemException(ExternalSystemBundle.message("external.system.java.home.invalid", jdkName));
+  }
+
+
+  private static class Item {
+    private final Object value;
+    private final String label;
+
+    private Item(Object value, String label) {
+      this.value = value;
+      this.label = label;
+    }
+
+    public Object getValue() {
+      return value;
+    }
+
+    public String toString() {
+      return label;
+    }
+  }
+
+  public static void addToModel(DefaultComboBoxModel model, Object value, String label) {
+    model.addElement(new Item(value, label));
+  }
+
+  public static <T> void setModel(JComboBox comboBox, DefaultComboBoxModel model, Collection<T> values, Function<T, Pair<String, ?>> func) {
+    model.removeAllElements();
+    for (T each : values) {
+      Pair<String, ?> pair = func.fun(each);
+      addToModel(model, pair.second, pair.first);
+    }
+    comboBox.setModel(model);
+  }
+
+  public static void select(DefaultComboBoxModel model, Object value) {
+    for (int i = 0; i < model.getSize(); i++) {
+      Item comboBoxUtil = (Item)model.getElementAt(i);
+      if (comboBoxUtil.getValue().equals(value)) {
+        model.setSelectedItem(comboBoxUtil);
+        return;
+      }
+    }
+    if (model.getSize() != 0) {
+      model.setSelectedItem(model.getElementAt(0));
+    }
+  }
+
+  @Nullable
+  public static String getSelectedString(DefaultComboBoxModel model) {
+    return String.valueOf(getSelectedValue(model));
+  }
+
+  @Nullable
+  public static Object getSelectedValue(DefaultComboBoxModel model) {
+    final Object item = model.getSelectedItem();
+    return item != null ? ((Item)item).getValue() : null;
+  }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/InvalidJavaHomeException.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/InvalidJavaHomeException.java
new file mode 100644 (file)
index 0000000..b8379c6
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.execution;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/12/2014
+ */
+public class InvalidJavaHomeException extends ExternalSystemJdkException {
+
+  public InvalidJavaHomeException(@Nullable String message) {
+    super(message);
+  }
+
+  public InvalidJavaHomeException(@Nullable Throwable cause) {
+    super(cause);
+  }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/InvalidSdkException.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/InvalidSdkException.java
new file mode 100644 (file)
index 0000000..d71e011
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/12/2014
+ */
+public class InvalidSdkException extends ExternalSystemJdkException {
+
+  public InvalidSdkException(String invalidPath) {
+    super(ExternalSystemBundle.message("external.system.platform.sdk.invalid", invalidPath), null);
+  }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ProjectJdkNotFoundException.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ProjectJdkNotFoundException.java
new file mode 100644 (file)
index 0000000..5777288
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.externalSystem.service.notification.callback.OpenProjectJdkSettingsCallback;
+import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/12/2014
+ */
+public class ProjectJdkNotFoundException extends ExternalSystemJdkException {
+
+  public ProjectJdkNotFoundException() {
+    super(ExternalSystemBundle.message("external.system.project_jdk.not_specified", OpenProjectJdkSettingsCallback.ID), null,
+          OpenProjectJdkSettingsCallback.ID);
+  }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/UndefinedJavaHomeException.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/UndefinedJavaHomeException.java
new file mode 100644 (file)
index 0000000..d91c8b2
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.execution;
+
+import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/12/2014
+ */
+public class UndefinedJavaHomeException extends ExternalSystemJdkException {
+
+  public UndefinedJavaHomeException() {
+    super(ExternalSystemBundle.message("external.system.java.home.undefined"), null);
+  }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/ExternalSystemNotificationExtensionImpl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/ExternalSystemNotificationExtensionImpl.java
new file mode 100644 (file)
index 0000000..4af9e2b
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2013 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.
+ */
+package com.intellij.openapi.externalSystem.service.notification;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/11/2014
+ */
+public class ExternalSystemNotificationExtensionImpl implements ExternalSystemNotificationExtension {
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/callback/OpenExternalSystemSettingsCallback.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/callback/OpenExternalSystemSettingsCallback.java
new file mode 100644 (file)
index 0000000..1fbc933
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.notification.callback;
+
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.event.HyperlinkEvent;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/11/2014
+ */
+public class OpenExternalSystemSettingsCallback extends NotificationListener.Adapter {
+
+  public final static String ID = "open_project_jdk_settings";
+  private final Project myProject;
+
+  public OpenExternalSystemSettingsCallback(Project project) {
+    myProject = project;
+  }
+
+  @Override
+  protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+    ProjectSettingsService.getInstance(myProject).openProjectSettings();
+  }
+}
diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/callback/OpenProjectJdkSettingsCallback.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/notification/callback/OpenProjectJdkSettingsCallback.java
new file mode 100644 (file)
index 0000000..aac3b85
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2000-2014 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.
+ */
+package com.intellij.openapi.externalSystem.service.notification.callback;
+
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.event.HyperlinkEvent;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 12/11/2014
+ */
+public class OpenProjectJdkSettingsCallback extends NotificationListener.Adapter {
+
+  public final static String ID = "open_project_jdk_settings";
+  private final Project myProject;
+
+  public OpenProjectJdkSettingsCallback(Project project) {
+    myProject = project;
+  }
+
+  @Override
+  protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+    ProjectSettingsService.getInstance(myProject).openProjectSettings();
+  }
+}
similarity index 73%
rename from plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenJdkComboBox.java
rename to platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/ui/ExternalSystemJdkComboBox.java
index f982ef9ceaeb21e746c942d6ae22bfbcdbd33a26..13cd37893b70fa830d8c75d8e2a174bf6ccbd508 100644 (file)
@@ -1,5 +1,6 @@
-package org.jetbrains.idea.maven.execution;
+package com.intellij.openapi.externalSystem.service.ui;
 
+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;
@@ -8,23 +9,24 @@ import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
 import com.intellij.openapi.roots.ProjectRootManager;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.jetbrains.idea.maven.utils.ComboBoxUtil;
 
 import javax.swing.*;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import static com.intellij.openapi.externalSystem.service.ui.ComboBoxUtil.*;
+
 /**
  * @author Sergey Evdokimov
  */
-public class MavenJdkComboBox extends JComboBox {
+public class ExternalSystemJdkComboBox extends JComboBox {
 
   private static final int MAX_PATH_LENGTH = 50;
 
   @Nullable
   private final Project myProject;
 
-  public MavenJdkComboBox(@Nullable Project project) {
+  public ExternalSystemJdkComboBox(@Nullable Project project) {
     myProject = project;
   }
 
@@ -43,14 +45,14 @@ public class MavenJdkComboBox extends JComboBox {
     removeAllItems();
 
     for (Map.Entry<String, String> entry : jdkMap.entrySet()) {
-      ComboBoxUtil.addToModel((DefaultComboBoxModel)getModel(), entry.getKey(), entry.getValue());
+      addToModel((DefaultComboBoxModel)getModel(), entry.getKey(), entry.getValue());
     }
 
-    ComboBoxUtil.select((DefaultComboBoxModel)getModel(), selectedValue);
+    select((DefaultComboBoxModel)getModel(), selectedValue);
   }
 
   public String getSelectedValue() {
-    return ComboBoxUtil.getSelectedString((DefaultComboBoxModel)getModel());
+    return getSelectedString((DefaultComboBoxModel)getModel());
   }
 
   private Map<String, String> collectJdkNamesAndDescriptions() {
@@ -74,18 +76,18 @@ public class MavenJdkComboBox extends JComboBox {
 
     String internalJdkPath = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().getHomePath();
     assert internalJdkPath != null;
-    result.put(MavenRunnerSettings.USE_INTERNAL_JAVA, RunnerBundle.message("maven.java.internal", truncateLongPath(internalJdkPath)));
+    result.put(USE_INTERNAL_JAVA, ExternalSystemBundle.message("maven.java.internal", truncateLongPath(internalJdkPath)));
 
     if (myProject != null) {
       String projectJdk = ProjectRootManager.getInstance(myProject).getProjectSdkName();
       String projectJdkTitle = String.format("<html>Use Project JDK <font color=gray>(%s)</font></html>", projectJdk == null ? "not defined yet" : projectJdk);
-      result.put(MavenRunnerSettings.USE_PROJECT_JDK, projectJdkTitle);
+      result.put(USE_PROJECT_JDK, projectJdkTitle);
     }
 
     String javaHomePath = System.getenv("JAVA_HOME");
-    String javaHomeLabel = RunnerBundle.message("maven.java.home.env", javaHomePath == null ? "not defined yet" : truncateLongPath(javaHomePath));
+    String javaHomeLabel = ExternalSystemBundle.message("maven.java.home.env", javaHomePath == null ? "not defined yet" : truncateLongPath(javaHomePath));
 
-    result.put(MavenRunnerSettings.USE_JAVA_HOME, javaHomeLabel);
+    result.put(USE_JAVA_HOME, javaHomeLabel);
 
     return result;
   }
index 219ce221e1656c7c89c82f17deae9d56ef917fd8..678411a320ffb8f84324ccfe8c70839a30ca3a04 100644 (file)
@@ -8,6 +8,7 @@ gradle.settings.text.use.local.distribution=Use local gradle distribution
 gradle.settings.text.use.bundled.distribution=Use bundled gradle distribution: ({0})
 
 gradle.settings.text.home.path=Gradle home:
+gradle.settings.text.jvm.path=Gradle JVM:
 gradle.settings.text.service.dir.path=Service directory path:
 gradle.settings.text.vm.options=Gradle VM options:
 gradle.settings.text.offline_work=Offline work
index 4f4ceeeb3c7a5bd286153277648367800262b644..33ab74a762a8c714d00fd31eb9c6dc8085bca202 100644 (file)
@@ -44,6 +44,7 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.options.Configurable;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
 import com.intellij.openapi.startup.StartupActivity;
 import com.intellij.openapi.util.AtomicNotNullLazyValue;
@@ -152,6 +153,8 @@ public class GradleManager
       public GradleExecutionSettings fun(Pair<Project, String> pair) {
         GradleSettings settings = GradleSettings.getInstance(pair.first);
         File gradleHome = myInstallationManager.getGradleHome(pair.first, pair.second);
+        Sdk gradleJdk = myInstallationManager.getGradleJdk(pair.first, pair.second);
+
         String localGradlePath = null;
         if (gradleHome != null) {
           try {
@@ -183,11 +186,17 @@ public class GradleManager
         for (GradleProjectResolverExtension extension : RESOLVER_EXTENSIONS.getValue()) {
           result.addResolverExtensionClass(ClassHolder.from(extension.getClass()));
         }
-        String javaHome = myJavaHelper.getJdkHome(pair.first);
-        if (!StringUtil.isEmpty(javaHome)) {
-          LOG.info("Instructing gradle to use java from " + javaHome);
+
+        if (gradleJdk != null) {
+          result.setJavaHome(gradleJdk.getHomePath());
+        } else {
+          String javaHome = myJavaHelper.getJdkHome(pair.first);
+          if (!StringUtil.isEmpty(javaHome)) {
+            LOG.info("Instructing gradle to use java from " + javaHome);
+          }
+          result.setJavaHome(javaHome);
         }
-        result.setJavaHome(javaHome);
+
         return result;
       }
     };
diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/remote/GradleJavaHelper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/remote/GradleJavaHelper.java
deleted file mode 100644 (file)
index 62f664c..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.jetbrains.plugins.gradle.remote;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.JdkUtil;
-import com.intellij.openapi.projectRoots.ProjectJdkTable;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.ProjectRootManager;
-import com.intellij.util.containers.ContainerUtilRt;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Encapsulates functionality of deciding what java should be used by the gradle process.
- * <p/>
- * Thread-safe.
- * 
- * @author Denis Zhdanov
- * @since 2/27/12 2:20 PM
- */
-public class GradleJavaHelper {
-
-  public static final String GRADLE_JAVA_HOME_KEY = "gradle.java.home";
-  
-  @SuppressWarnings("MethodMayBeStatic")
-  @Nullable
-  public String getJdkHome(@Nullable Project project) {
-    List<String> candidates = ContainerUtilRt.newArrayList();
-    candidates.add(System.getProperty(GRADLE_JAVA_HOME_KEY));
-    candidates.add(System.getenv("JAVA_HOME"));
-    for (String candidate : candidates) {
-      if (candidate != null && JdkUtil.checkForJdk(new File(candidate))) {
-        return candidate;
-      }
-    }
-
-    if (project != null) {
-      Sdk sdk = ProjectRootManager.getInstance(project).getProjectSdk();
-      if (sdk != null) {
-        String path = sdk.getHomePath();
-        if (path != null && JdkUtil.checkForJdk(new File(path))) {
-          return path;
-        }
-      }
-    }
-
-    Sdk[] sdks = ProjectJdkTable.getInstance().getAllJdks();
-    if (sdks != null) {
-      for (Sdk sdk : sdks) {
-        String path = sdk.getHomePath();
-        if (path != null && JdkUtil.checkForJdk(new File(path))) {
-          return path;
-        }
-      }
-    }
-    
-    return null;
-  }
-}
index b363eb8b3395258b7fb17d5634e1c0b8cf1643dd..941e551211f7e7620fe7273272a7d80847062926 100644 (file)
@@ -4,6 +4,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.Sdk;
 import com.intellij.openapi.roots.OrderEnumerator;
 import com.intellij.openapi.util.Ref;
 import com.intellij.openapi.util.text.StringUtil;
@@ -112,6 +113,25 @@ public class GradleInstallationManager {
     return doGetGradleHome(project, linkedProjectPath);
   }
 
+  @Nullable
+  public Sdk getGradleJdk(@Nullable Project project, @NotNull String linkedProjectPath) {
+    return doGetGradleJdk(project, linkedProjectPath);
+  }
+
+  @Nullable
+  private Sdk doGetGradleJdk(@Nullable Project project, String linkedProjectPath) {
+    if (project == null) {
+      return null;
+    }
+
+    final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedProjectPath);
+    if (settings == null) {
+      return null;
+    }
+
+    return settings.getGradleJvm();
+  }
+
   /**
    * Tries to return file handle that points to the gradle installation home.
    *
index adb4356f34479a611b956e867c430ed14d474f99..936424b0729e24de0bb71be0ad0b15d8bd511315 100644 (file)
@@ -22,6 +22,10 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil;
 import com.intellij.openapi.externalSystem.util.PaintAwarePanel;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.projectRoots.ProjectJdkTable;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.ui.configuration.JdkComboBox;
+import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
 import com.intellij.openapi.ui.MessageType;
 import com.intellij.openapi.ui.TextComponentAccessor;
 import com.intellij.openapi.ui.TextFieldWithBrowseButton;
@@ -67,14 +71,18 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
 
   @NotNull private final GradleInstallationManager myInstallationManager;
 
+  // @formatter:off
   @SuppressWarnings("FieldCanBeLocal") // Used implicitly by reflection at disposeUIResources() and showUi()
   private JLabel                    myGradleHomeLabel;
+  private JLabel                    myGradleJdkLabel;
+  private JdkComboBox               myGradleJdkComboBox;
   private TextFieldWithBrowseButton myGradleHomePathField;
   private JBRadioButton             myUseWrapperButton;
   private JBRadioButton             myUseWrapperWithVerificationButton;
   private JBLabel                   myUseWrapperVerificationLabel;
   private JBRadioButton             myUseLocalDistributionButton;
   private JBRadioButton             myUseBundledDistributionButton;
+  // @formatter:on
 
   private boolean myShowBalloonIfNecessary;
 
@@ -110,8 +118,10 @@ 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"));
 
+    initGradleHome();
+    initGradleJdk();
     initControls();
     content.add(myUseWrapperButton, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
     content.add(myUseWrapperWithVerificationButton, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
@@ -123,6 +133,9 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
 
     content.add(myGradleHomeLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
     content.add(myGradleHomePathField, ExternalSystemUiUtil.getFillLineConstraints(0));
+
+    content.add(myGradleJdkLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
+    content.add(myGradleJdkComboBox, ExternalSystemUiUtil.getFillLineConstraints(0));
   }
 
   private void initControls() {
@@ -173,6 +186,16 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
     buttonGroup.add(myUseLocalDistributionButton);
   }
 
+  private void initGradleJdk() {
+    final ProjectSdksModel jdkModel = new ProjectSdksModel();
+
+    for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
+      jdkModel.addSdk(sdk);
+    }
+
+    myGradleJdkComboBox = new JdkComboBox(jdkModel);
+  }
+
   private void initGradleHome() {
     myGradleHomePathField = new TextFieldWithBrowseButton();
 
@@ -231,6 +254,8 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
       GradleUtil.storeLastUsedGradleHome(gradleHomePath);
     }
 
+    settings.setGradleJvm(myGradleJdkComboBox.getSelectedJdk());
+
     if (myUseLocalDistributionButton.isSelected()) {
       settings.setDistributionType(DistributionType.LOCAL);
     } else if(myUseWrapperButton.isSelected()) {
@@ -244,6 +269,7 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
   protected void updateInitialExtraSettings() {
     String gradleHomePath = FileUtil.toCanonicalPath(myGradleHomePathField.getText());
     getInitialSettings().setGradleHome(StringUtil.isEmpty(gradleHomePath) ? null : gradleHomePath);
+    getInitialSettings().setGradleJvm(myGradleJdkComboBox.getSelectedJdk());
     if (myUseLocalDistributionButton.isSelected()) {
       getInitialSettings().setDistributionType(DistributionType.LOCAL);
     } else if(myUseWrapperButton.isSelected()) {
@@ -272,6 +298,10 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
       return true;
     }
 
+    if (myGradleJdkComboBox.getSelectedJdk() != getInitialSettings()) {
+      return true;
+    }
+
     String gradleHome = FileUtil.toCanonicalPath(myGradleHomePathField.getText());
     if (StringUtil.isEmpty(gradleHome)) {
       return !StringUtil.isEmpty(getInitialSettings().getGradleHome());
@@ -286,7 +316,14 @@ public class GradleProjectSettingsControl extends AbstractExternalProjectSetting
     String gradleHome = getInitialSettings().getGradleHome();
     myGradleHomePathField.setText(gradleHome == null ? "" : gradleHome);
     myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
-    
+
+    final Sdk gradleJvm = getInitialSettings().getGradleJvm();
+    if (gradleJvm != null) {
+      myGradleJdkComboBox.setSelectedJdk(gradleJvm);
+    } else {
+      myGradleJdkComboBox.setInvalidJdk("Not set");
+    }
+
     updateWrapperControls(getInitialSettings().getExternalProjectPath(), isDefaultModuleCreation);
     if (!myUseLocalDistributionButton.isSelected()) {
       myGradleHomePathField.setEnabled(false);
index d01f36c737d14bd946ece66c36390827af0a149b..658c8fc1ab926666f70de939cea945c65aa6fc91 100644 (file)
@@ -16,6 +16,7 @@
 package org.jetbrains.plugins.gradle.settings;
 
 import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
+import com.intellij.openapi.projectRoots.Sdk;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -26,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
 public class GradleProjectSettings extends ExternalProjectSettings {
 
   @Nullable private String myGradleHome;
+  @Nullable private Sdk myGradleJvm;
   @Nullable private DistributionType distributionType;
   private boolean disableWrapperSourceDistributionNotification;
 
@@ -38,6 +40,15 @@ public class GradleProjectSettings extends ExternalProjectSettings {
     myGradleHome = gradleHome;
   }
 
+  @Nullable
+  public Sdk getGradleJvm() {
+    return myGradleJvm;
+  }
+
+  public void setGradleJvm(@Nullable Sdk gradleJvm) {
+    myGradleJvm = gradleJvm;
+  }
+
   @Nullable
   public DistributionType getDistributionType() {
     return distributionType;