mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-85101 (Provide a "Project JDK" option for the maven runner's JRE option)
This commit is contained in:
+38
-2
@@ -31,6 +31,8 @@ import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectSettingsService;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
|
||||
@@ -99,7 +101,7 @@ public class MavenExternalParameters {
|
||||
|
||||
params.setWorkingDirectory(parameters.getWorkingDirFile());
|
||||
|
||||
params.setJdk(getJdk(runnerSettings, project != null && MavenRunner.getInstance(project).getState() == runnerSettings));
|
||||
params.setJdk(getJdk(project, runnerSettings, project != null && MavenRunner.getInstance(project).getState() == runnerSettings));
|
||||
|
||||
final String mavenHome = resolveMavenHome(coreSettings, project, runConfiguration);
|
||||
|
||||
@@ -121,12 +123,29 @@ public class MavenExternalParameters {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Sdk getJdk(MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
|
||||
private static Sdk getJdk(@Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
|
||||
String name = runnerSettings.getJreName();
|
||||
if (name.equals(MavenRunnerSettings.USE_INTERNAL_JAVA)) {
|
||||
return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
|
||||
}
|
||||
|
||||
if (name.equals(MavenRunnerSettings.USE_PROJECT_JDK)) {
|
||||
if (project != null) {
|
||||
Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
|
||||
if (res != null) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
if (project == null) {
|
||||
Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
|
||||
if (recent != null) return recent;
|
||||
return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
|
||||
}
|
||||
|
||||
throw new ProjectJdkSettingsOpenerExecutionException("Project JDK is not specified. <a href='#'>Configure</a>", project);
|
||||
}
|
||||
|
||||
if (name.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
|
||||
final String javaHome = System.getenv(JAVA_HOME);
|
||||
if (StringUtil.isEmptyOrSpaces(javaHome)) {
|
||||
@@ -355,6 +374,23 @@ public class MavenExternalParameters {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ProjectJdkSettingsOpenerExecutionException extends ExecutionException implements HyperlinkListener {
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
public ProjectJdkSettingsOpenerExecutionException(final String s, Project project) {
|
||||
super(s);
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hyperlinkUpdate(HyperlinkEvent e) {
|
||||
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;
|
||||
|
||||
ProjectSettingsService.getInstance(myProject).openProjectSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private static class RunConfigurationOpenerExecutionException extends ExecutionException implements HyperlinkListener {
|
||||
|
||||
private final MavenRunConfiguration myRunConfiguration;
|
||||
|
||||
+32
-2
@@ -21,6 +21,10 @@ import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
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.roots.ProjectRootManager;
|
||||
import com.intellij.ui.IdeBorderFactory;
|
||||
import com.intellij.ui.RawCommandLineEditor;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -50,7 +54,7 @@ public abstract class MavenRunnerConfigurable implements SearchableConfigurable,
|
||||
|
||||
private Map<String, String> myProperties;
|
||||
|
||||
public MavenRunnerConfigurable(Project p, boolean isRunConfiguration) {
|
||||
public MavenRunnerConfigurable(@NotNull Project p, boolean isRunConfiguration) {
|
||||
myProject = p;
|
||||
myRunConfigurationMode = isRunConfiguration;
|
||||
}
|
||||
@@ -189,7 +193,7 @@ public abstract class MavenRunnerConfigurable implements SearchableConfigurable,
|
||||
myVMParametersEditor.setText(data.getVmOptions());
|
||||
mySkipTestsCheckBox.setSelected(data.isSkipTests());
|
||||
|
||||
Map<String, String> jdkMap = data.collectJdkNamesAndDescriptions();
|
||||
Map<String, String> jdkMap = collectJdkNamesAndDescriptions();
|
||||
if (!jdkMap.containsKey(data.getJreName())) {
|
||||
jdkMap.put(data.getJreName(), data.getJreName());
|
||||
}
|
||||
@@ -204,6 +208,32 @@ public abstract class MavenRunnerConfigurable implements SearchableConfigurable,
|
||||
myPropertiesPanel.setDataFromMap(data.getMavenProperties());
|
||||
}
|
||||
|
||||
private Map<String, String> collectJdkNamesAndDescriptions() {
|
||||
Map<String, String> result = new LinkedHashMap<String, String>();
|
||||
|
||||
for (Sdk projectJdk : ProjectJdkTable.getInstance().getSdksOfType(JavaSdk.getInstance())) {
|
||||
String name = projectJdk.getName();
|
||||
result.put(name, name);
|
||||
}
|
||||
|
||||
result.put(MavenRunnerSettings.USE_INTERNAL_JAVA, RunnerBundle.message("maven.java.internal"));
|
||||
|
||||
String projectJdkTitle;
|
||||
|
||||
String projectJdk = ProjectRootManager.getInstance(myProject).getProjectSdkName();
|
||||
if (projectJdk == null) {
|
||||
projectJdkTitle = "Use Project JDK (not defined yet)";
|
||||
}
|
||||
else {
|
||||
projectJdkTitle = "Use Project JDK (" + projectJdk + ')';
|
||||
}
|
||||
|
||||
result.put(MavenRunnerSettings.USE_PROJECT_JDK, projectJdkTitle);
|
||||
result.put(MavenRunnerSettings.USE_JAVA_HOME, RunnerBundle.message("maven.java.home.env"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void setData(MavenRunnerSettings data) {
|
||||
data.setRunMavenInBackground(myRunInBackgroundCheckbox.isSelected());
|
||||
data.setVmOptions(myVMParametersEditor.getText().trim());
|
||||
|
||||
+2
-22
@@ -21,15 +21,12 @@ package org.jetbrains.idea.maven.execution;
|
||||
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.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -37,6 +34,7 @@ import java.util.Map;
|
||||
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";
|
||||
|
||||
private boolean runMavenInBackground = true;
|
||||
@@ -98,26 +96,8 @@ public class MavenRunnerSettings implements Cloneable {
|
||||
this.mavenProperties = mavenProperties;
|
||||
}
|
||||
|
||||
public Map<String, String> collectJdkNamesAndDescriptions() {
|
||||
Map<String, String> result = new LinkedHashMap<String, String>();
|
||||
|
||||
for (Sdk projectJdk : ProjectJdkTable.getInstance().getSdksOfType(getSdkType())) {
|
||||
String name = projectJdk.getName();
|
||||
result.put(name, name);
|
||||
}
|
||||
|
||||
result.put(USE_INTERNAL_JAVA, RunnerBundle.message("maven.java.internal"));
|
||||
result.put(USE_JAVA_HOME, RunnerBundle.message("maven.java.home.env"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private SdkType getSdkType() {
|
||||
return JavaSdk.getInstance();
|
||||
}
|
||||
|
||||
public String getDefaultJdkName() {
|
||||
Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(getSdkType());
|
||||
Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
|
||||
if (recent == null) return USE_INTERNAL_JAVA;
|
||||
return recent.getName();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user