use of org.jetbrains.idea.maven.project.MavenGeneralSettings in project moe-ide-integration by multi-os-engine.
the class MOEMavenTask method runTask.
public boolean runTask() {
String workDirectory = getWorkPath();
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
File mavenHome = MavenUtil.resolveMavenHomeDirectory(projectsManager.getGeneralSettings().getMavenHome());
if (mavenHome == null) {
Notification notification = new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Failed to execute goal", RunnerBundle.message("external.maven.home.no.default.with.fix"), NotificationType.ERROR, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(module.getProject(), MavenSettings.DISPLAY_NAME);
}
});
Notifications.Bus.notify(notification, module.getProject());
return false;
}
StringBuilder goalBuilder = new StringBuilder();
setGoalTarget(goalBuilder);
addArguments(goalBuilder);
MavenRunnerParameters parameters = new MavenRunnerParameters(true, workDirectory, Arrays.asList(ParametersList.parse(goalBuilder.toString())), Collections.<String>emptyList());
MavenGeneralSettings generalSettings = new MavenGeneralSettings();
generalSettings.setMavenHome(mavenHome.getPath());
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(module.getProject()).getSettings().clone();
runnerSettings.setMavenProperties(new LinkedHashMap<String, String>());
runnerSettings.setSkipTests(true);
RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(generalSettings, runnerSettings, parameters, module.getProject());
ProgramRunner runner = DefaultJavaProgramRunner.getInstance();
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ExecutionEnvironment environment = new ExecutionEnvironment(executor, runner, configSettings, module.getProject());
return executeTask(module.getProject(), getMavenProject(), environment, goalBuilder.toString());
}
use of org.jetbrains.idea.maven.project.MavenGeneralSettings in project intellij-community by JetBrains.
the class MavenIndicesManager method getMavenSettings.
private static MavenGeneralSettings getMavenSettings(@NotNull final Project project, @NotNull MavenProgressIndicator indicator) throws MavenProcessCanceledException {
MavenGeneralSettings settings;
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
settings = project.isDisposed() ? null : MavenProjectsManager.getInstance(project).getGeneralSettings().clone();
} finally {
accessToken.finish();
}
if (settings == null) {
// project was closed
indicator.cancel();
indicator.checkCanceled();
}
return settings;
}
use of org.jetbrains.idea.maven.project.MavenGeneralSettings in project intellij-community by JetBrains.
the class MavenExecuteGoalAction method actionPerformed.
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
ExecuteMavenGoalHistoryService historyService = ExecuteMavenGoalHistoryService.getInstance(project);
MavenExecuteGoalDialog dialog = new MavenExecuteGoalDialog(project, historyService.getHistory());
String lastWorkingDirectory = historyService.getWorkDirectory();
if (lastWorkingDirectory.length() == 0) {
lastWorkingDirectory = obtainAppropriateWorkingDirectory(project);
}
dialog.setWorkDirectory(lastWorkingDirectory);
if (StringUtil.isEmptyOrSpaces(historyService.getCanceledCommand())) {
if (historyService.getHistory().size() > 0) {
dialog.setGoals(historyService.getHistory().get(0));
}
} else {
dialog.setGoals(historyService.getCanceledCommand());
}
if (!dialog.showAndGet()) {
historyService.setCanceledCommand(dialog.getGoals());
return;
}
historyService.setCanceledCommand(null);
String goals = dialog.getGoals();
goals = goals.trim();
if (goals.startsWith("mvn ")) {
goals = goals.substring("mvn ".length()).trim();
}
String workDirectory = dialog.getWorkDirectory();
historyService.addCommand(goals, workDirectory);
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
File mavenHome = MavenUtil.resolveMavenHomeDirectory(projectsManager.getGeneralSettings().getMavenHome());
if (mavenHome == null) {
Notification notification = new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "Failed to execute goal", RunnerBundle.message("external.maven.home.no.default.with.fix"), NotificationType.ERROR, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(project, MavenSettings.DISPLAY_NAME);
}
});
Notifications.Bus.notify(notification, project);
return;
}
MavenRunnerParameters parameters = new MavenRunnerParameters(true, workDirectory, Arrays.asList(ParametersList.parse(goals)), Collections.<String>emptyList());
MavenGeneralSettings generalSettings = new MavenGeneralSettings();
generalSettings.setMavenHome(mavenHome.getPath());
MavenRunnerSettings runnerSettings = MavenRunner.getInstance(project).getSettings().clone();
runnerSettings.setMavenProperties(new LinkedHashMap<>());
runnerSettings.setSkipTests(false);
MavenRunConfigurationType.runConfiguration(project, parameters, generalSettings, runnerSettings, null);
}
use of org.jetbrains.idea.maven.project.MavenGeneralSettings in project intellij-community by JetBrains.
the class MavenRunConfigurationTest method testSaveLoadRunnerParameters.
public void testSaveLoadRunnerParameters() {
MavenRunConfiguration.MavenSettings s = new MavenRunConfiguration.MavenSettings(myProject);
s.myRunnerParameters.setWorkingDirPath("some path");
s.myRunnerParameters.setGoals(Arrays.asList("clean", "validate"));
s.myRunnerParameters.setProfilesMap(ImmutableMap.<String, Boolean>builder().put("prof1", true).put("prof2", true).put("prof3", false).put("aaa", true).put("tomcat (local)", false).put("tomcat (local) ", true).build());
s.myGeneralSettings = new MavenGeneralSettings();
s.myGeneralSettings.setChecksumPolicy(MavenExecutionOptions.ChecksumPolicy.WARN);
s.myGeneralSettings.setFailureBehavior(MavenExecutionOptions.FailureMode.AT_END);
s.myGeneralSettings.setOutputLevel(MavenExecutionOptions.LoggingLevel.FATAL);
s.myGeneralSettings.setThreads("1.5C");
s.myRunnerSettings = new MavenRunnerSettings();
s.myRunnerSettings.setMavenProperties(ImmutableMap.of("a", "1", "b", "2", "c", "3"));
Element xml = XmlSerializer.serialize(s);
MavenRunConfiguration.MavenSettings loaded = XmlSerializer.deserialize(xml, MavenRunConfiguration.MavenSettings.class);
assertEquals(s.myRunnerParameters.getWorkingDirPath(), loaded.myRunnerParameters.getWorkingDirPath());
assertEquals(s.myRunnerParameters.getGoals(), loaded.myRunnerParameters.getGoals());
assertEquals(s.myRunnerParameters.getProfilesMap(), loaded.myRunnerParameters.getProfilesMap());
// Compare ordering of profiles.
assertOrderedEquals(s.myRunnerParameters.getProfilesMap().keySet(), loaded.myRunnerParameters.getProfilesMap().keySet());
assertEquals(s.myGeneralSettings, loaded.myGeneralSettings);
assertEquals(s.myRunnerSettings, loaded.myRunnerSettings);
}
use of org.jetbrains.idea.maven.project.MavenGeneralSettings in project intellij-community by JetBrains.
the class MavenExternalParameters method createJavaParameters.
/**
* @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();
if (coreSettings == null) {
coreSettings = project == null ? new MavenGeneralSettings() : MavenProjectsManager.getInstance(project).getGeneralSettings();
}
if (runnerSettings == null) {
runnerSettings = project == null ? new MavenRunnerSettings() : MavenRunner.getInstance(project).getState();
}
params.setWorkingDirectory(parameters.getWorkingDirFile());
Sdk jdk = getJdk(project, runnerSettings, project != null && MavenRunner.getInstance(project).getState() == runnerSettings);
params.setJdk(jdk);
final String mavenHome = resolveMavenHome(coreSettings, project, runConfiguration);
final String mavenVersion = MavenUtil.getMavenVersion(mavenHome);
String sdkConfigLocation = "Settings | Build, Execution, Deployment | Build Tools | Maven | Runner | JRE";
verifyMavenSdkRequirements(jdk, mavenVersion, sdkConfigLocation);
params.getProgramParametersList().add("-Didea.version=" + MavenUtil.getIdeaVersionToPassToMavenProcess());
if (StringUtil.compareVersionNumbers(mavenVersion, "3.3") >= 0) {
params.getVMParametersList().addProperty("maven.multiModuleProjectDirectory", MavenServerUtil.findMavenBasedir(parameters.getWorkingDirFile()).getPath());
}
addVMParameters(params.getVMParametersList(), mavenHome, runnerSettings);
File confFile = MavenUtil.getMavenConfFile(new File(mavenHome));
if (!confFile.isFile()) {
throw new ExecutionException("Configuration file is not exists in maven home: " + confFile.getAbsolutePath());
}
if (project != null && parameters.isResolveToWorkspace()) {
try {
String resolverJar = getArtifactResolverJar(mavenVersion);
confFile = patchConfFile(confFile, resolverJar);
File modulesPathsFile = dumpModulesPaths(project);
params.getVMParametersList().addProperty(MavenModuleMap.PATHS_FILE_PROPERTY, modulesPathsFile.getAbsolutePath());
} catch (IOException e) {
LOG.error(e);
throw new ExecutionException("Failed to run maven configuration", e);
}
}
params.getVMParametersList().addProperty("classworlds.conf", confFile.getPath());
for (String path : getMavenClasspathEntries(mavenHome)) {
params.getClassPath().add(path);
}
params.setEnv(new HashMap<>(runnerSettings.getEnvironmentProperties()));
params.setPassParentEnvs(runnerSettings.isPassParentEnv());
params.setMainClass(MAVEN_LAUNCHER_CLASS);
EncodingManager encodingManager = project == null ? EncodingManager.getInstance() : EncodingProjectManager.getInstance(project);
params.setCharset(encodingManager.getDefaultCharset());
addMavenParameters(params.getProgramParametersList(), mavenHome, coreSettings, runnerSettings, parameters);
return params;
}
Aggregations