Search in sources :

Example 1 with MavenRunnerParameters

use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.

the class MavenBeforeRunTasksProvider method executeTask.

public boolean executeTask(final DataContext context, RunConfiguration configuration, ExecutionEnvironment env, final MavenBeforeRunTask task) {
    final Semaphore targetDone = new Semaphore();
    final boolean[] result = new boolean[] { true };
    try {
        ApplicationManager.getApplication().invokeAndWait(() -> {
            final Project project = CommonDataKeys.PROJECT.getData(context);
            final MavenProject mavenProject = getMavenProject(task);
            if (project == null || project.isDisposed() || mavenProject == null)
                return;
            FileDocumentManager.getInstance().saveAllDocuments();
            final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
            final MavenRunner mavenRunner = MavenRunner.getInstance(project);
            targetDone.down();
            new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {

                public void run(@NotNull ProgressIndicator indicator) {
                    try {
                        MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse(task.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
                        result[0] = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
                    } finally {
                        targetDone.up();
                    }
                }

                @Override
                public boolean shouldStartInBackground() {
                    return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
                }

                @Override
                public void processSentToBackground() {
                    MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
                }
            }.queue();
        }, ModalityState.NON_MODAL);
    } catch (Exception e) {
        MavenLog.LOG.error(e);
        return false;
    }
    targetDone.waitFor();
    return result[0];
}
Also used : Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Task(com.intellij.openapi.progress.Task) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenRunner(org.jetbrains.idea.maven.execution.MavenRunner) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Semaphore(com.intellij.util.concurrency.Semaphore) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 2 with MavenRunnerParameters

use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.

the class MavenTasksManager method doExecute.

private boolean doExecute(boolean before, CompileContext context) {
    List<MavenRunnerParameters> parametersList;
    synchronized (this) {
        parametersList = new ArrayList<>();
        Set<MavenCompilerTask> tasks = before ? myState.beforeCompileTasks : myState.afterCompileTasks;
        if (context.isRebuild()) {
            tasks = Sets.union(before ? myState.beforeRebuildTask : myState.afterRebuildTask, tasks);
        }
        for (MavenCompilerTask each : tasks) {
            VirtualFile file = LocalFileSystem.getInstance().findFileByPath(each.getProjectPath());
            if (file == null)
                continue;
            MavenExplicitProfiles explicitProfiles = myProjectsManager.getExplicitProfiles();
            parametersList.add(new MavenRunnerParameters(true, file.getParent().getPath(), Arrays.asList(each.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles()));
        }
    }
    return myRunner.runBatch(parametersList, null, null, TasksBundle.message("maven.tasks.executing"), context.getProgressIndicator());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 3 with MavenRunnerParameters

use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.

the class RunBuildAction method checkOrPerform.

private static boolean checkOrPerform(DataContext context, boolean perform) {
    final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
    if (goals == null || goals.isEmpty())
        return false;
    final Project project = MavenActionUtil.getProject(context);
    if (project == null)
        return false;
    final MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
    if (mavenProject == null)
        return false;
    if (!perform)
        return true;
    final MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
    if (projectsManager == null)
        return false;
    MavenExplicitProfiles explicitProfiles = projectsManager.getExplicitProfiles();
    final MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), goals, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
    MavenRunConfigurationType.runConfiguration(project, params, null);
    return true;
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 4 with MavenRunnerParameters

use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project intellij-community by JetBrains.

the class MavenModuleBuilderHelper method generateFromArchetype.

private void generateFromArchetype(final Project project, final VirtualFile pom) {
    final File workingDir;
    try {
        workingDir = FileUtil.createTempDirectory("archetype", "tmp");
        workingDir.deleteOnExit();
    } catch (IOException e) {
        showError(project, e);
        return;
    }
    MavenRunnerParameters params = new MavenRunnerParameters(false, workingDir.getPath(), Collections.singletonList("org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate"), Collections.emptyList());
    MavenRunner runner = MavenRunner.getInstance(project);
    MavenRunnerSettings settings = runner.getState().clone();
    Map<String, String> props = settings.getMavenProperties();
    props.put("interactiveMode", "false");
    //props.put("archetypeGroupId", myArchetype.groupId);
    //props.put("archetypeArtifactId", myArchetype.artifactId);
    //props.put("archetypeVersion", myArchetype.version);
    //if (myArchetype.repository != null) props.put("archetypeRepository", myArchetype.repository);
    //props.put("groupId", myProjectId.getGroupId());
    //props.put("artifactId", myProjectId.getArtifactId());
    //props.put("version", myProjectId.getVersion());
    props.putAll(myPropertiesToCreateByArtifact);
    runner.run(params, settings, () -> copyGeneratedFiles(workingDir, pom, project));
}
Also used : MavenRunnerSettings(org.jetbrains.idea.maven.execution.MavenRunnerSettings) MavenRunner(org.jetbrains.idea.maven.execution.MavenRunner) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Example 5 with MavenRunnerParameters

use of org.jetbrains.idea.maven.execution.MavenRunnerParameters in project android by JetBrains.

the class AndroidMavenExecutor method generateResources.

public static Map<CompilerMessageCategory, List<String>> generateResources(final Module module) {
    MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(module.getProject());
    final MavenRunnerParameters parameters = new MavenRunnerParameters(true, projectsManager.findProject(module).getDirectory(), Collections.singletonList("process-resources"), projectsManager.getExplicitProfiles());
    final Map<CompilerMessageCategory, List<String>> result = new HashMap<CompilerMessageCategory, List<String>>();
    result.put(CompilerMessageCategory.ERROR, new ArrayList<String>());
    try {
        JavaParameters javaParams = ApplicationManager.getApplication().runReadAction(new Computable<JavaParameters>() {

            @Nullable
            @Override
            public JavaParameters compute() {
                try {
                    return MavenExternalParameters.createJavaParameters(module.getProject(), parameters);
                } catch (ExecutionException e) {
                    LOG.info(e);
                    result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
                    return null;
                }
            }
        });
        if (javaParams == null) {
            return result;
        }
        GeneralCommandLine commandLine = javaParams.toCommandLine();
        final StringBuildingOutputProcessor processor = new StringBuildingOutputProcessor();
        boolean success = AndroidUtils.executeCommand(commandLine, processor, WaitingStrategies.WaitForever.getInstance()) == ExecutionStatus.SUCCESS;
        String message = processor.getMessage();
        if (!success) {
            LOG.info(message);
            String lcmessage = message.toLowerCase();
            int buildErrorIndex = lcmessage.indexOf(BUILD_ERROR_INDICATOR);
            if (buildErrorIndex >= 0) {
                result.get(CompilerMessageCategory.ERROR).add(message.substring(buildErrorIndex));
            }
        }
    } catch (ExecutionException e) {
        LOG.info(e);
        result.get(CompilerMessageCategory.ERROR).add(e.getMessage());
    }
    return result;
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) HashMap(com.intellij.util.containers.HashMap) StringBuildingOutputProcessor(org.jetbrains.android.util.StringBuildingOutputProcessor) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters)

Aggregations

MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)6 MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)3 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 MavenRunner (org.jetbrains.idea.maven.execution.MavenRunner)2 MavenRunnerSettings (org.jetbrains.idea.maven.execution.MavenRunnerSettings)2 MavenProject (org.jetbrains.idea.maven.project.MavenProject)2 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)2 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 CompilerMessageCategory (com.intellij.openapi.compiler.CompilerMessageCategory)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 PsiFile (com.intellij.psi.PsiFile)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 HashMap (com.intellij.util.containers.HashMap)1 THashMap (gnu.trove.THashMap)1