Search in sources :

Example 1 with MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles 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 MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles 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 MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles 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 MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles in project intellij-community by JetBrains.

the class ToggleProfileAction method getTargetState.

@Nullable
private static MavenProfileKind getTargetState(@NotNull MavenProjectsManager projectsManager, Map<String, MavenProfileKind> profiles) {
    MavenExplicitProfiles explicitProfiles = projectsManager.getExplicitProfiles();
    MavenProfileKind targetState = null;
    // all profiles should target to the same state
    for (Map.Entry<String, MavenProfileKind> profile : profiles.entrySet()) {
        MavenProfileKind profileTargetState = getTargetState(profile, explicitProfiles);
        if (targetState == null) {
            targetState = profileTargetState;
        } else if (!targetState.equals(profileTargetState)) {
            targetState = null;
            break;
        }
    }
    return targetState;
}
Also used : MavenProfileKind(org.jetbrains.idea.maven.model.MavenProfileKind) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with MavenExplicitProfiles

use of org.jetbrains.idea.maven.model.MavenExplicitProfiles in project liferay-ide by liferay.

the class AbstractLiferayMavenGoalAction method checkOrPerform.

public boolean checkOrPerform(DataContext context, boolean perform) {
    Project project = MavenActionUtil.getProject(context);
    MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
    if ((project == null) || (mavenProject == null)) {
        return false;
    }
    if (!perform) {
        return true;
    }
    String projectDir = mavenProject.getDirectory();
    MavenProjectsManager mavenProjectsManager = MavenActionUtil.getProjectsManager(context);
    MavenExplicitProfiles explicitProfiles = mavenProjectsManager.getExplicitProfiles();
    Collection<String> enabledProfiles = explicitProfiles.getEnabledProfiles();
    Collection<String> disabledProfiles = explicitProfiles.getDisabledProfiles();
    MavenRunnerParameters params = new MavenRunnerParameters(true, projectDir, goals, enabledProfiles, disabledProfiles);
    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)

Aggregations

MavenExplicitProfiles (org.jetbrains.idea.maven.model.MavenExplicitProfiles)20 MavenRunnerParameters (org.jetbrains.idea.maven.execution.MavenRunnerParameters)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)4 Project (com.intellij.openapi.project.Project)3 MavenProfileKind (org.jetbrains.idea.maven.model.MavenProfileKind)3 MavenProject (org.jetbrains.idea.maven.project.MavenProject)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Semaphore (com.intellij.util.concurrency.Semaphore)2 NotNull (org.jetbrains.annotations.NotNull)2 MavenEmbedderWrapper (org.jetbrains.idea.maven.server.MavenEmbedderWrapper)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)1 IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Task (com.intellij.openapi.progress.Task)1 IgnoredFileBean (com.intellij.openapi.vcs.changes.IgnoredFileBean)1 PsiFile (com.intellij.psi.PsiFile)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1