IDEA-83529 ("No 'm2' defined" balloon could contain link to open settings)

This commit is contained in:
Sergey Evdokimov
2012-04-10 15:01:04 +04:00
parent f8341df613
commit a201aeb452
6 changed files with 142 additions and 11 deletions
@@ -85,6 +85,10 @@ public class ExecutionUtil {
LOG.error(fullMessage);
}
if (listener == null && e instanceof HyperlinkListener) {
listener = (HyperlinkListener)e;
}
final HyperlinkListener finalListener = listener;
final String finalDescription = description;
UIUtil.invokeLaterIfNeeded(new Runnable() {
@@ -50,8 +50,6 @@ public class AndroidMavenExecutor {
public static Map<CompilerMessageCategory, List<String>> generateResources(Module module) {
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
assert projectsManager != null;
MavenRunnerParameters parameters =
new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(),
Collections.singletonList("process-resources"),
@@ -61,9 +59,7 @@ public class AndroidMavenExecutor {
result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
try {
JavaParameters javaParams = MavenExternalParameters.createJavaParameters(module.getProject(), parameters,
projectsManager.getGeneralSettings(),
MavenRunner.getInstance(module.getProject()).getSettings());
JavaParameters javaParams = MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
GeneralCommandLine commandLine = CommandLineBuilder.createFromJavaParameters(javaParams);
StringBuilder messageBuilder = new StringBuilder();
+1
View File
@@ -55,6 +55,7 @@
<orderEntry type="module" module-name="jetgroovy" />
<orderEntry type="module" module-name="maven2-server-impl" scope="RUNTIME" />
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="module" module-name="lang-impl" />
</component>
<component name="copyright">
<Base>
@@ -19,9 +19,13 @@
package org.jetbrains.idea.maven.execution;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.RunManager;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.execution.impl.EditConfigurationsDialog;
import com.intellij.execution.impl.RunManagerImpl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
@@ -35,11 +39,16 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.project.MavenGeneralSettings;
import org.jetbrains.idea.maven.project.MavenProjectsManager;
import org.jetbrains.idea.maven.utils.MavenSettings;
import org.jetbrains.idea.maven.utils.MavenUtil;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Ralf Quebbemann
@@ -49,10 +58,34 @@ public class MavenExternalParameters {
@NonNls private static final String JAVA_HOME = "JAVA_HOME";
@NonNls private static final String MAVEN_OPTS = "MAVEN_OPTS";
@Deprecated // Use createJavaParameters(Project,MavenRunnerParameters, MavenGeneralSettings,MavenRunnerSettings,MavenRunConfiguration)
public static JavaParameters createJavaParameters(@Nullable final Project project,
@NotNull final MavenRunnerParameters parameters,
@Nullable MavenGeneralSettings coreSettings,
@Nullable MavenRunnerSettings runnerSettings) throws ExecutionException {
return createJavaParameters(project, parameters, coreSettings, runnerSettings, null);
}
public static JavaParameters createJavaParameters(@Nullable final Project project,
@NotNull final MavenRunnerParameters parameters) throws ExecutionException {
return createJavaParameters(project, parameters, null, null, null);
}
/**
*
* @param project
* @param parameters
* @param coreSettings
* @param runnerSettings
* @param runConfiguration used to creation fix if maven home not found
* @return
* @throws ExecutionException
*/
public static JavaParameters createJavaParameters(@Nullable final Project project,
@NotNull final MavenRunnerParameters parameters,
@Nullable MavenGeneralSettings coreSettings,
@Nullable MavenRunnerSettings runnerSettings,
@Nullable MavenRunConfiguration runConfiguration) throws ExecutionException {
final JavaParameters params = new JavaParameters();
ApplicationManager.getApplication().assertReadAccessAllowed();
@@ -68,7 +101,7 @@ public class MavenExternalParameters {
params.setJdk(getJdk(runnerSettings, project != null && MavenRunner.getInstance(project).getState() == runnerSettings));
final String mavenHome = resolveMavenHome(coreSettings);
final String mavenHome = resolveMavenHome(coreSettings, project, runConfiguration);
addVMParameters(params.getVMParametersList(), mavenHome, runnerSettings);
@@ -165,18 +198,38 @@ public class MavenExternalParameters {
}
public static String resolveMavenHome(@NotNull MavenGeneralSettings coreSettings) throws ExecutionException {
return resolveMavenHome(coreSettings, null, null);
}
/**
*
* @param coreSettings
* @param project used to creation fix if maven home not found
* @param runConfiguration used to creation fix if maven home not found
* @return
* @throws ExecutionException
*/
public static String resolveMavenHome(@NotNull MavenGeneralSettings coreSettings,
@Nullable Project project,
@Nullable MavenRunConfiguration runConfiguration) throws ExecutionException {
final File file = MavenUtil.resolveMavenHomeDirectory(coreSettings.getMavenHome());
if (file == null) {
throw new ExecutionException(RunnerBundle.message("external.maven.home.no.default"));
throw createExecutionException(RunnerBundle.message("external.maven.home.no.default"),
RunnerBundle.message("external.maven.home.no.default.with.fix"),
coreSettings, project, runConfiguration);
}
if (!file.exists()) {
throw new ExecutionException(RunnerBundle.message("external.maven.home.does.not.exist", file.getPath()));
throw createExecutionException(RunnerBundle.message("external.maven.home.does.not.exist", file.getPath()),
RunnerBundle.message("external.maven.home.does.not.exist.with.fix", file.getPath()),
coreSettings, project, runConfiguration);
}
if (!MavenUtil.isValidMavenHome(file)) {
throw new ExecutionException(RunnerBundle.message("external.maven.home.invalid", file.getPath()));
throw createExecutionException(RunnerBundle.message("external.maven.home.invalid", file.getPath()),
RunnerBundle.message("external.maven.home.invalid.with.fix", file.getPath()),
coreSettings, project, runConfiguration);
}
try {
@@ -187,6 +240,34 @@ public class MavenExternalParameters {
}
}
private static ExecutionException createExecutionException(String text,
String textWithFix,
@NotNull MavenGeneralSettings coreSettings,
@Nullable Project project,
@Nullable MavenRunConfiguration runConfiguration) {
Project notNullProject = project;
if (notNullProject == null) {
if (runConfiguration == null) return new ExecutionException(text);
notNullProject = runConfiguration.getProject();
if (notNullProject == null) return new ExecutionException(text);
}
if (coreSettings == MavenProjectsManager.getInstance(notNullProject).getGeneralSettings()) {
return new ProjectSettingsOpenerExecutionException(textWithFix, notNullProject);
}
if (runConfiguration != null) {
Project runCfgProject = runConfiguration.getProject();
if (runCfgProject != null) {
if (((RunManagerImpl)RunManager.getInstance(runCfgProject)).getSettings(runConfiguration) != null) {
return new RunConfigurationOpenerExecutionException(textWithFix, runConfiguration);
}
}
}
return new ExecutionException(text);
}
@SuppressWarnings({"HardCodedStringLiteral"})
private static List<String> getMavenClasspathEntries(final String mavenHome) {
File mavenHomeBootAsFile = new File(new File(mavenHome, "core"), "boot");
@@ -256,4 +337,48 @@ public class MavenExternalParameters {
}
return stringBuilder.toString();
}
private static class ProjectSettingsOpenerExecutionException extends ExecutionException implements HyperlinkListener {
private final Project myProject;
public ProjectSettingsOpenerExecutionException(final String s, Project project) {
super(s);
myProject = project;
}
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;
ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenSettings.DISPLAY_NAME);
}
}
private static class RunConfigurationOpenerExecutionException extends ExecutionException implements HyperlinkListener {
private final MavenRunConfiguration myRunConfiguration;
public RunConfigurationOpenerExecutionException(final String s, MavenRunConfiguration runConfiguration) {
super(s);
myRunConfiguration = runConfiguration;
}
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;
Project project = myRunConfiguration.getProject();
//RunManagerImpl runManager = (RunManagerImpl)RunManager.getInstance(project);
//RunnerAndConfigurationSettings settings = runManager.getSettings(myRunConfiguration);
//if (settings == null) {
// return;
//}
//
//runManager.setSelectedConfiguration(settings);
EditConfigurationsDialog dialog = new EditConfigurationsDialog(project);
dialog.show();
}
}
}
@@ -68,7 +68,7 @@ public class MavenRunConfiguration extends RunConfigurationBase implements Locat
public JavaParameters createJavaParameters(@Nullable Project project) throws ExecutionException {
return MavenExternalParameters
.createJavaParameters(project, mySettings.myRunnerParameters, mySettings.myGeneralSettings, mySettings.myRunnerSettings);
.createJavaParameters(project, mySettings.myRunnerParameters, mySettings.myGeneralSettings, mySettings.myRunnerSettings, this);
}
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
@@ -8,8 +8,13 @@ external.startup.failed=Cannot start Maven: {0}
external.maven.home.no.default=No valid Maven installation found. \
Either set the home directory in the configuration dialog \
or set the M2_HOME environment variable on your system.
external.maven.home.no.default.with.fix=No valid Maven installation found. \
Either set the home directory in the <a href="#">configuration dialog</a> \
or set the M2_HOME environment variable on your system.
external.maven.home.does.not.exist=Specified Maven home directory ({0}) does not exist
external.maven.home.does.not.exist.with.fix=Specified Maven home directory ({0}) does not exist. <a href="#">Configure Maven home</a>
external.maven.home.invalid={0} is not a valid Maven home directory
external.maven.home.invalid.with.fix={0} is not a valid Maven home directory. <a href="#">Configure Maven home</a>
embedded.executor.caption=Executing Maven - using embedded Maven
embedded.cannot.create=Cannot create Maven Embedder