Search in sources :

Example 1 with MavenGeneralSettings

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());
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) HyperlinkEvent(javax.swing.event.HyperlinkEvent) MavenRunnerSettings(org.jetbrains.idea.maven.execution.MavenRunnerSettings) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) MavenRunConfigurationType.createRunnerAndConfigurationSettings(org.jetbrains.idea.maven.execution.MavenRunConfigurationType.createRunnerAndConfigurationSettings) DefaultJavaProgramRunner(com.intellij.execution.impl.DefaultJavaProgramRunner) ProgramRunner(com.intellij.execution.runners.ProgramRunner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotificationListener(com.intellij.notification.NotificationListener) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 2 with MavenGeneralSettings

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;
}
Also used : MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) AccessToken(com.intellij.openapi.application.AccessToken)

Example 3 with MavenGeneralSettings

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);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) File(java.io.File) NotificationListener(com.intellij.notification.NotificationListener)

Example 4 with MavenGeneralSettings

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);
}
Also used : MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) Element(org.jdom.Element)

Example 5 with MavenGeneralSettings

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;
}
Also used : EncodingManager(com.intellij.openapi.vfs.encoding.EncodingManager) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) JavaParameters(com.intellij.execution.configurations.JavaParameters) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

MavenGeneralSettings (org.jetbrains.idea.maven.project.MavenGeneralSettings)6 Notification (com.intellij.notification.Notification)3 File (java.io.File)3 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)3 NotificationListener (com.intellij.notification.NotificationListener)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CommonBundle (com.intellij.CommonBundle)1 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 DefaultJavaProgramRunner (com.intellij.execution.impl.DefaultJavaProgramRunner)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 AccessToken (com.intellij.openapi.application.AccessToken)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1