run.text.ended.single.task={0}: External task execution finished ''{1}''.\n
run.error.undefined.task=No task to execute is specified
+external.system.java.internal.jre=Use Internal JRE
+external.system.java.home.env=Use JAVA_HOME
+external.system.project_jdk.not_specified=Project JDK is not specified. <a href=''{0}''>Open Project SDK Configuration</a>
+external.system.java.home.undefined=JAVA_HOME environment variable not defined
+external.system.java.home.invalid=JAVA_HOME environment variable does not point to valid JDK or JRE ({0})
+external.system.platform.sdk.invalid=Platform SDK does not point to valid JDK ({0})
+
tasks.select.task.title=Select {0} task
tasks.edit.task.title=Edit {0} Task
tasks.before.run.empty=Run {0} task
private final String[] myQuickFixes;
public ExternalSystemException() {
- this(null, null);
+ this(null, (Throwable)null);
}
public ExternalSystemException(@Nullable String message) {
- this(message, null);
+ this(message, (Throwable)null);
}
public ExternalSystemException(@Nullable Throwable cause) {
this("", cause);
}
+ public ExternalSystemException(@Nullable String message, @NotNull String... quickFixes) {
+ this(message, null, quickFixes);
+ }
+
public ExternalSystemException(@Nullable String message, @Nullable Throwable cause, @NotNull String... quickFixes) {
super(extractMessage(message, cause));
- myQuickFixes = quickFixes;
+ myQuickFixes = mergeArrays(cause instanceof ExternalSystemException
+ ? ((ExternalSystemException)cause).getQuickFixes()
+ : new String[0], quickFixes);
if (cause == null) {
myOriginalReason = "";
return;
}
myOriginalReason = stringWriter.toString();
}
-
+
/**
* @return textual description of the wrapped exception (if any); empty string otherwise
*/
}
buffer.append(m);
}
-
- return buffer.toString();
+
+ return buffer.toString();
+ }
+
+ private static String[] mergeArrays(@NotNull String[] a1, @NotNull String[] a2) {
+ if (a1.length == 0) return a2;
+ if (a2.length == 0) return a1;
+ String[] result = new String[a1.length + a2.length];
+ System.arraycopy(a1, 0, result, 0, a1.length);
+ System.arraycopy(a2, 0, result, a1.length, a2.length);
+ return result;
}
}
<orderEntry type="module" module-name="testFramework" scope="TEST" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
<orderEntry type="module" module-name="compiler-impl" scope="TEST" />
+ <orderEntry type="module" module-name="java-impl" />
+ <orderEntry type="module" module-name="openapi" />
</component>
-</module>
-
+</module>
\ No newline at end of file
*/
public class ExternalSystemJdkException extends ExternalSystemException {
- public ExternalSystemJdkException(@Nullable String message, @Nullable Throwable cause) {
- super(message, cause);
+ public ExternalSystemJdkException(@Nullable String message, @Nullable Throwable cause, @NotNull String... quickFixes) {
+ super(message, cause, quickFixes);
}
}
*/
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.*;
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;
+import java.io.File;
public class ExternalSystemJdkUtil {
@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) {
+ public static Sdk getJdk(@Nullable Project project, @Nullable String jdkName) throws ExternalSystemJdkException {
if (jdkName == null) return null;
if (USE_INTERNAL_JAVA.equals(jdkName)) {
if (USE_PROJECT_JDK.equals(jdkName)) {
if (project != null) {
Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
- if (res != null) {
- return res;
- }
+ 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 (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);
+ throw new ProjectJdkNotFoundException();
}
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"));
+ throw new UndefinedJavaHomeException();
}
- final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
- if (jdk == null) {
- throw new ExternalSystemException(ExternalSystemBundle.message("external.system.java.home.invalid", javaHome));
+
+ if (JdkUtil.checkForJdk(new File(javaHome)) || JdkUtil.checkForJre(javaHome)) {
+ final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
+ if (jdk == null) {
+ throw new InvalidJavaHomeException(javaHome);
+ }
+ return jdk;
+ }
+ else {
+ throw new InvalidJavaHomeException(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 (projectJdk.getHomePath() != null &&
+ (JdkUtil.checkForJdk(new File(projectJdk.getHomePath())) || JdkUtil.checkForJre(projectJdk.getHomePath()))) {
+ return projectJdk;
+ }
+ else {
+ throw new InvalidSdkException(projectJdk.getHomePath());
+ }
}
}
- 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;
+ return null;
}
}
*/
package com.intellij.openapi.externalSystem.service.execution;
-import org.jetbrains.annotations.Nullable;
+import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
/**
* @author Vladislav.Soroka
*/
public class InvalidJavaHomeException extends ExternalSystemJdkException {
- public InvalidJavaHomeException(@Nullable String message) {
- super(message);
- }
-
- public InvalidJavaHomeException(@Nullable Throwable cause) {
- super(cause);
+ public InvalidJavaHomeException(String invalidPath) {
+ super(ExternalSystemBundle.message("external.system.java.home.invalid", invalidPath), null);
}
}
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
*/
package com.intellij.openapi.externalSystem.service.notification;
+import com.intellij.execution.rmi.RemoteUtil;
+import com.intellij.openapi.externalSystem.model.ExternalSystemException;
+import com.intellij.openapi.externalSystem.model.ProjectSystemId;
+import com.intellij.openapi.externalSystem.service.notification.callback.OpenProjectJdkSettingsCallback;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
/**
* @author Vladislav.Soroka
* @since 12/11/2014
*/
public class ExternalSystemNotificationExtensionImpl implements ExternalSystemNotificationExtension {
+ @NotNull
+ @Override
+ public ProjectSystemId getTargetExternalSystemId() {
+ return ProjectSystemId.IDE;
+ }
+
+ @Override
+ public void customize(@NotNull NotificationData notification,
+ @NotNull Project project,
+ @Nullable Throwable error) {
+ if (error == null) return;
+ //noinspection ThrowableResultOfMethodCallIgnored
+ Throwable unwrapped = RemoteUtil.unwrap(error);
+ if (unwrapped instanceof ExternalSystemException) {
+ updateNotification(notification, project, (ExternalSystemException)unwrapped);
+ }
+ }
+
+ private static void updateNotification(@NotNull final NotificationData notificationData,
+ @NotNull final Project project,
+ @NotNull ExternalSystemException e) {
+
+ for (String fix : e.getQuickFixes()) {
+ if (OpenProjectJdkSettingsCallback.ID.equals(fix)) {
+ notificationData.setListener(OpenProjectJdkSettingsCallback.ID, new OpenProjectJdkSettingsCallback(project));
+ }
+ }
+ }
}
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.externalSystem.ExternalSystemConfigurableAware;
import com.intellij.openapi.externalSystem.ExternalSystemManager;
-import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
import com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager;
filePath, ObjectUtils.notNull(line, -1), ObjectUtils.notNull(column, -1), false);
for (ExternalSystemNotificationExtension extension : ExternalSystemNotificationExtension.EP_NAME.getExtensions()) {
- if (!externalSystemId.equals(extension.getTargetExternalSystemId())) {
+ final ProjectSystemId targetExternalSystemId = extension.getTargetExternalSystemId();
+ if (!externalSystemId.equals(targetExternalSystemId) && !targetExternalSystemId.equals(ProjectSystemId.IDE)) {
continue;
}
extension.customize(notificationData, myProject, error);
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
+import com.intellij.openapi.externalSystem.model.ProjectSystemId;
+import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.HyperlinkEvent;
*/
public class OpenExternalSystemSettingsCallback extends NotificationListener.Adapter {
- public final static String ID = "open_project_jdk_settings";
+ public final static String ID = "#open_external_system_settings";
private final Project myProject;
+ @NotNull private final ProjectSystemId mySystemId;
- public OpenExternalSystemSettingsCallback(Project project) {
+ public OpenExternalSystemSettingsCallback(Project project, @NotNull ProjectSystemId systemId) {
myProject = project;
+ mySystemId = systemId;
}
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
- ProjectSettingsService.getInstance(myProject).openProjectSettings();
+ ShowSettingsUtil.getInstance().showSettingsDialog(myProject, mySystemId.getReadableName());
}
}
*/
public class OpenProjectJdkSettingsCallback extends NotificationListener.Adapter {
- public final static String ID = "open_project_jdk_settings";
+ public final static String ID = "#open_project_jdk_settings";
private final Project myProject;
public OpenProjectJdkSettingsCallback(Project project) {
myExternalSystemId = externalSystemId;
}
+ @NotNull
+ public Project getProject() {
+ return myProject;
+ }
+
@Nullable
@Override
public Runnable enableSearch(String option) {
+/*
+ * 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.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.impl.JavaAwareProjectJdkTableImpl;
import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.roots.ui.util.CompositeAppearance;
+import com.intellij.openapi.ui.ComboBoxWithWidePopup;
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.ui.ColoredListCellRendererWrapper;
+import com.intellij.ui.JBColor;
+import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.LinkedHashMap;
import java.util.Map;
-import static com.intellij.openapi.externalSystem.service.ui.ComboBoxUtil.*;
-
/**
* @author Sergey Evdokimov
*/
-public class ExternalSystemJdkComboBox extends JComboBox {
+public class ExternalSystemJdkComboBox extends ComboBoxWithWidePopup {
private static final int MAX_PATH_LENGTH = 50;
public ExternalSystemJdkComboBox(@Nullable Project project) {
myProject = project;
+ setRenderer(new ColoredListCellRendererWrapper() {
+
+ @Override
+ protected void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
+ JdkComboBoxItem item = (JdkComboBoxItem)value;
+ CompositeAppearance appearance = new CompositeAppearance();
+ SdkType sdkType = JavaSdk.getInstance();
+ appearance.setIcon(sdkType.getIcon());
+ SimpleTextAttributes attributes = getTextAttributes(item.valid, selected);
+ CompositeAppearance.DequeEnd ending = appearance.getEnding();
+
+ ending.addText(item.label, attributes);
+ if (item.comment != null) {
+ if (!item.comment.equals(item.jdkName)) {
+ SimpleTextAttributes textAttributes =
+ SystemInfo.isMac && selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN,
+ JBColor.WHITE) : SimpleTextAttributes.GRAY_ATTRIBUTES;
+ ending.addComment(item.comment, textAttributes);
+ }
+ }
+
+ final CompositeAppearance compositeAppearance = ending.getAppearance();
+ compositeAppearance.customize(this);
+ }
+ });
}
@Nullable
}
public void refreshData(@Nullable String selectedValue) {
- Map<String, String> jdkMap = collectJdkNamesAndDescriptions();
+ Map<String, JdkComboBoxItem> jdkMap = collectComboBoxItem();
if (selectedValue != null && !jdkMap.containsKey(selectedValue)) {
assert selectedValue.length() > 0;
- jdkMap.put(selectedValue, selectedValue);
+ jdkMap.put(selectedValue, new JdkComboBoxItem(selectedValue, selectedValue, selectedValue, true));
}
removeAllItems();
- for (Map.Entry<String, String> entry : jdkMap.entrySet()) {
- addToModel((DefaultComboBoxModel)getModel(), entry.getKey(), entry.getValue());
+ for (Map.Entry<String, JdkComboBoxItem> entry : jdkMap.entrySet()) {
+ //noinspection unchecked
+ ((DefaultComboBoxModel)getModel()).addElement(entry.getValue());
}
select((DefaultComboBoxModel)getModel(), selectedValue);
}
+ private static void select(DefaultComboBoxModel model, Object value) {
+ for (int i = 0; i < model.getSize(); i++) {
+ JdkComboBoxItem comboBoxUtil = (JdkComboBoxItem)model.getElementAt(i);
+ if (comboBoxUtil.jdkName.equals(value)) {
+ model.setSelectedItem(comboBoxUtil);
+ return;
+ }
+ }
+ if (model.getSize() != 0) {
+ model.setSelectedItem(model.getElementAt(0));
+ }
+ }
+
+ @Nullable
public String getSelectedValue() {
- return getSelectedString((DefaultComboBoxModel)getModel());
+ final DefaultComboBoxModel model = (DefaultComboBoxModel)getModel();
+ final Object item = model.getSelectedItem();
+ return item != null ? ((JdkComboBoxItem)item).jdkName : null;
}
- private Map<String, String> collectJdkNamesAndDescriptions() {
- Map<String, String> result = new LinkedHashMap<String, String>();
+ private Map<String, JdkComboBoxItem> collectComboBoxItem() {
+ Map<String, JdkComboBoxItem> result = new LinkedHashMap<String, JdkComboBoxItem>();
for (Sdk projectJdk : ProjectJdkTable.getInstance().getSdksOfType(JavaSdk.getInstance())) {
String name = projectJdk.getName();
- String label;
-
String path = projectJdk.getHomePath();
- if (path == null) {
- label = name;
+ String comment;
+ String versionString = projectJdk.getVersionString();
+ if (versionString != null && !versionString.equals(name)) {
+ comment = versionString;
}
else {
- label = String.format("<html>%s <font color=gray>(%s)</font></html>", name, truncateLongPath(path));
+ comment = path == null ? name : truncateLongPath(path);
}
- result.put(name, label);
+ result.put(name, new JdkComboBoxItem(name, name, comment, ((SdkType)projectJdk.getSdkType()).sdkHasValidPath(projectJdk)));
}
String internalJdkPath = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().getHomePath();
assert internalJdkPath != null;
- result.put(USE_INTERNAL_JAVA, ExternalSystemBundle.message("maven.java.internal", truncateLongPath(internalJdkPath)));
+ result.put(ExternalSystemJdkUtil.USE_INTERNAL_JAVA,
+ new JdkComboBoxItem(ExternalSystemJdkUtil.USE_INTERNAL_JAVA,
+ ExternalSystemBundle.message("external.system.java.internal.jre"), truncateLongPath(internalJdkPath),
+ true));
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(USE_PROJECT_JDK, projectJdkTitle);
+ result.put(ExternalSystemJdkUtil.USE_PROJECT_JDK,
+ new JdkComboBoxItem(ExternalSystemJdkUtil.USE_PROJECT_JDK, "Use Project JDK",
+ projectJdk == null ? "not defined yet" : projectJdk, projectJdk != null));
}
String javaHomePath = System.getenv("JAVA_HOME");
- String javaHomeLabel = ExternalSystemBundle.message("maven.java.home.env", javaHomePath == null ? "not defined yet" : truncateLongPath(javaHomePath));
+ String javaHomeLabel = ExternalSystemBundle.message("external.system.java.home.env");
- result.put(USE_JAVA_HOME, javaHomeLabel);
+ result.put(ExternalSystemJdkUtil.USE_JAVA_HOME,
+ new JdkComboBoxItem(ExternalSystemJdkUtil.USE_JAVA_HOME, javaHomeLabel,
+ javaHomePath == null ? "not defined yet" : truncateLongPath(javaHomePath), javaHomePath != null));
return result;
}
return path;
}
+ private static SimpleTextAttributes getTextAttributes(final boolean valid, final boolean selected) {
+ if (!valid) {
+ return SimpleTextAttributes.ERROR_ATTRIBUTES;
+ }
+ else if (selected && !(SystemInfo.isWinVistaOrNewer && UIManager.getLookAndFeel().getName().contains("Windows"))) {
+ return SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES;
+ }
+ else {
+ return SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES;
+ }
+ }
+
+ private static class JdkComboBoxItem {
+ private String jdkName;
+ private String label;
+ private String comment;
+ private boolean valid;
+
+ public JdkComboBoxItem(String jdkName, String label, String comment, boolean valid) {
+ this.jdkName = jdkName;
+ this.label = label;
+ this.comment = comment;
+ this.valid = valid;
+ }
+ }
}
<applicationService serviceImplementation="com.intellij.openapi.externalSystem.service.project.ProjectStructureHelper"/>
<applicationService serviceImplementation="com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager"/>
<projectService serviceImplementation="com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationManager"/>
+ <externalSystemNotificationExtension implementation="com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationExtensionImpl" />
<!--Project structure management services-->
<applicationService serviceImplementation="com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager"/>
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.config.GradleSettingsListenerAdapter;
-import org.jetbrains.plugins.gradle.remote.GradleJavaHelper;
import org.jetbrains.plugins.gradle.service.GradleInstallationManager;
import org.jetbrains.plugins.gradle.service.project.GradleAutoImportAware;
import org.jetbrains.plugins.gradle.service.project.GradleProjectResolver;
public Function<Pair<Project, String>, GradleExecutionSettings> getExecutionSettingsProvider() {
return new Function<Pair<Project, String>, GradleExecutionSettings>() {
- private final GradleJavaHelper myJavaHelper = new GradleJavaHelper();
-
@Override
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 {
result.addResolverExtensionClass(ClassHolder.from(extension.getClass()));
}
- 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);
+ final Sdk gradleJdk = myInstallationManager.getGradleJdk(pair.first, pair.second);
+ final String javaHome = gradleJdk != null ? gradleJdk.getHomePath() : null;
+ if (!StringUtil.isEmpty(javaHome)) {
+ LOG.info("Instructing gradle to use java from " + javaHome);
}
-
+ result.setJavaHome(javaHome);
return result;
}
};
package org.jetbrains.plugins.gradle.service;
+import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkException;
+import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil;
+import com.intellij.openapi.externalSystem.service.notification.callback.OpenExternalSystemSettingsCallback;
import com.intellij.openapi.externalSystem.service.project.PlatformFacade;
import com.intellij.openapi.externalSystem.util.ExternalSystemConstants;
import com.intellij.openapi.module.Module;
return null;
}
- return settings.getGradleJvm();
+ final String gradleJvm = settings.getGradleJvm();
+ try {
+ return ExternalSystemJdkUtil.getJdk(project, gradleJvm);
+ }
+ catch (ExternalSystemJdkException e) {
+ throw new ExternalSystemJdkException(
+ String.format("Invalid Gradle JDK configuration found: <a href='%s'>Open Gradle Settings</a> \n",
+ OpenExternalSystemSettingsCallback.ID),
+ e, OpenExternalSystemSettingsCallback.ID);
+ }
}
/**
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.service.notification.ExternalSystemNotificationExtension;
import com.intellij.openapi.externalSystem.service.notification.NotificationData;
+import com.intellij.openapi.externalSystem.service.notification.callback.OpenExternalSystemSettingsCallback;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
else if (GotoSourceNotificationCallback.ID.equals(fix)) {
notificationData.setListener(GotoSourceNotificationCallback.ID, new GotoSourceNotificationCallback(notificationData, project));
}
+ else if (OpenExternalSystemSettingsCallback.ID.equals(fix)) {
+ notificationData.setListener(
+ OpenExternalSystemSettingsCallback.ID, new OpenExternalSystemSettingsCallback(project, GradleConstants.SYSTEM_ID));
+ }
}
}
}
}
};
- final GradleProjectSettingsControl settingsControl = new GradleProjectSettingsControl(getExternalProjectSettings());
+ final GradleProjectSettingsControl settingsControl = new GradleProjectSettingsControl(getExternalProjectSettings(), myWizardContext.getProject());
return new ExternalModuleSettingsStep<GradleProjectSettings>(this, settingsControl);
}
@NotNull
@Override
protected ExternalSystemSettingsControl<GradleProjectSettings> createProjectSettingsControl(@NotNull GradleProjectSettings settings) {
- return new GradleProjectSettingsControl(settings);
+ return new GradleProjectSettingsControl(settings, getProject());
}
@Nullable
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.externalSystem.model.settings.LocationSettingType;
import com.intellij.openapi.externalSystem.service.settings.AbstractExternalProjectSettingsControl;
+import com.intellij.openapi.externalSystem.service.ui.ExternalSystemJdkComboBox;
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.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
@NotNull private LocationSettingType myGradleHomeSettingType = LocationSettingType.UNKNOWN;
@NotNull private final GradleInstallationManager myInstallationManager;
+ @Nullable private final Project myProject;
- // @formatter:off
@SuppressWarnings("FieldCanBeLocal") // Used implicitly by reflection at disposeUIResources() and showUi()
private JLabel myGradleHomeLabel;
- private JLabel myGradleJdkLabel;
- private JdkComboBox myGradleJdkComboBox;
+ @SuppressWarnings("FieldCanBeLocal") // Used implicitly by reflection at disposeUIResources() and showUi()
+ private JLabel myGradleJdkLabel;
+ private ExternalSystemJdkComboBox myGradleJdkComboBox;
private TextFieldWithBrowseButton myGradleHomePathField;
private JBRadioButton myUseWrapperButton;
private JBRadioButton myUseWrapperWithVerificationButton;
private JBLabel myUseWrapperVerificationLabel;
private JBRadioButton myUseLocalDistributionButton;
private JBRadioButton myUseBundledDistributionButton;
- // @formatter:on
private boolean myShowBalloonIfNecessary;
public GradleProjectSettingsControl(@NotNull GradleProjectSettings initialSettings) {
+ this(initialSettings, null);
+ }
+
+ public GradleProjectSettingsControl(@NotNull GradleProjectSettings initialSettings, @Nullable Project project) {
super(initialSettings);
myInstallationManager = ServiceManager.getService(GradleInstallationManager.class);
+ myProject = project;
}
@Override
});
myGradleHomeLabel = new JBLabel(GradleBundle.message("gradle.settings.text.home.path"));
+ initGradleHome();
myGradleJdkLabel = new JBLabel(GradleBundle.message("gradle.settings.text.jvm.path"));
+ myGradleJdkComboBox = new ExternalSystemJdkComboBox(myProject);
- initGradleHome();
- initGradleJdk();
initControls();
content.add(myUseWrapperButton, ExternalSystemUiUtil.getFillLineConstraints(indentLevel));
content.add(myUseWrapperWithVerificationButton, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
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();
GradleUtil.storeLastUsedGradleHome(gradleHomePath);
}
- settings.setGradleJvm(myGradleJdkComboBox.getSelectedJdk());
+ final String gradleJvm = FileUtil.toCanonicalPath(myGradleJdkComboBox.getSelectedValue());
+ settings.setGradleJvm(StringUtil.isEmpty(gradleJvm) ? null : gradleJvm);
if (myUseLocalDistributionButton.isSelected()) {
settings.setDistributionType(DistributionType.LOCAL);
protected void updateInitialExtraSettings() {
String gradleHomePath = FileUtil.toCanonicalPath(myGradleHomePathField.getText());
getInitialSettings().setGradleHome(StringUtil.isEmpty(gradleHomePath) ? null : gradleHomePath);
- getInitialSettings().setGradleJvm(myGradleJdkComboBox.getSelectedJdk());
+ final String gradleJvm = FileUtil.toCanonicalPath(myGradleJdkComboBox.getSelectedValue());
+ getInitialSettings().setGradleJvm(StringUtil.isEmpty(gradleJvm) ? null : gradleJvm);
if (myUseLocalDistributionButton.isSelected()) {
getInitialSettings().setDistributionType(DistributionType.LOCAL);
} else if(myUseWrapperButton.isSelected()) {
return true;
}
- if (myGradleJdkComboBox.getSelectedJdk() != getInitialSettings()) {
+ if (!StringUtil.equals(myGradleJdkComboBox.getSelectedValue(), getInitialSettings().getGradleJvm())) {
return true;
}
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");
- }
+ final String gradleJvm = getInitialSettings().getGradleJvm();
+ myGradleJdkComboBox.refreshData(StringUtil.isEmpty(gradleJvm) ? null : gradleJvm);
updateWrapperControls(getInitialSettings().getExternalProjectPath(), isDefaultModuleCreation);
if (!myUseLocalDistributionButton.isSelected()) {
@NotNull
@Override
protected ExternalSystemSettingsControl<GradleProjectSettings> createProjectSettingsControl(@NotNull GradleProjectSettings settings) {
- GradleProjectSettingsControl settingsControl = new GradleProjectSettingsControl(settings);
+ GradleProjectSettingsControl settingsControl = new GradleProjectSettingsControl(settings, getSystemSettings().getProject());
settingsControl.hideUseAutoImportBox();
return settingsControl;
}
*/
package org.jetbrains.plugins.gradle.settings;
+import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil;
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
-import com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class GradleProjectSettings extends ExternalProjectSettings {
@Nullable private String myGradleHome;
- @Nullable private Sdk myGradleJvm;
+ @Nullable private String myGradleJvm = ExternalSystemJdkUtil.USE_PROJECT_JDK;
@Nullable private DistributionType distributionType;
private boolean disableWrapperSourceDistributionNotification;
}
@Nullable
- public Sdk getGradleJvm() {
+ public String getGradleJvm() {
return myGradleJvm;
}
- public void setGradleJvm(@Nullable Sdk gradleJvm) {
+ public void setGradleJvm(@Nullable String gradleJvm) {
myGradleJvm = gradleJvm;
}
GradleProjectSettings result = new GradleProjectSettings();
copyTo(result);
result.myGradleHome = myGradleHome;
+ result.myGradleJvm = myGradleJvm;
result.distributionType = distributionType;
result.disableWrapperSourceDistributionNotification = disableWrapperSourceDistributionNotification;
return result;
package org.jetbrains.idea.maven.execution;
import com.intellij.execution.configuration.EnvironmentVariablesComponent;
+import com.intellij.openapi.externalSystem.service.ui.ExternalSystemJdkComboBox;
import com.intellij.openapi.project.Project;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.RawCommandLineEditor;
private JCheckBox myRunInBackgroundCheckbox;
private RawCommandLineEditor myVMParametersEditor;
private EnvironmentVariablesComponent myEnvVariablesComponent;
- private MavenJdkComboBox myJdkCombo;
+ private ExternalSystemJdkComboBox myJdkCombo;
private JCheckBox mySkipTestsCheckBox;
private MavenPropertiesPanel myPropertiesPanel;
JLabel jdkLabel = new JLabel("JRE:");
jdkLabel.setDisplayedMnemonic('j');
- jdkLabel.setLabelFor(myJdkCombo = new MavenJdkComboBox(myProject));
+ jdkLabel.setLabelFor(myJdkCombo = new ExternalSystemJdkComboBox(myProject));
c.gridx = 0;
c.gridy++;
c.weightx = 0;
package org.jetbrains.idea.maven.execution;
+import com.intellij.openapi.externalSystem.service.execution.ExternalSystemJdkUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NonNls;
public class MavenRunnerSettings implements Cloneable {
- @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";
+ @NonNls public static final String USE_INTERNAL_JAVA = ExternalSystemJdkUtil.USE_INTERNAL_JAVA;
+ @NonNls public static final String USE_PROJECT_JDK = ExternalSystemJdkUtil.USE_PROJECT_JDK;
+ @NonNls public static final String USE_JAVA_HOME = ExternalSystemJdkUtil.USE_JAVA_HOME;
private boolean runMavenInBackground = true;
@NotNull private String jreName = USE_PROJECT_JDK;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.idea.maven.execution.MavenJdkComboBox;
+import com.intellij.openapi.externalSystem.service.ui.ExternalSystemJdkComboBox;
import org.jetbrains.idea.maven.server.MavenServerManager;
import javax.swing.*;
private final JCheckBox myUseMaven3CheckBox;
private final JTextField myEmbedderVMOptions;
- private final MavenJdkComboBox myEmbedderJdk;
+ private final ExternalSystemJdkComboBox myEmbedderJdk;
public MavenImportingConfigurable(Project project) {
myImportingSettings = MavenProjectsManager.getInstance(project).getImportingSettings();
myUseMaven3CheckBox.setToolTipText("If this option is disabled maven 2 will be used");
myEmbedderVMOptions = new JTextField(30);
- myEmbedderJdk = new MavenJdkComboBox(null); // Embedder JDK is an application setting, not a project setting, so don't pass project
+ myEmbedderJdk = new ExternalSystemJdkComboBox(null); // Embedder JDK is an application setting, not a project setting, so don't pass project
assert myEmbedderJdk.getProject() == null;
}