Search in sources :

Example 16 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.

the class ExternalSystemRunManagerListener method runConfigurationRemoved.

@Override
public void runConfigurationRemoved(@NotNull RunnerAndConfigurationSettings settings) {
    if (settings.getConfiguration() instanceof ExternalSystemRunConfiguration) {
        final Pair<String, RunnerAndConfigurationSettings> pair = myMap.remove(System.identityHashCode(settings));
        if (pair == null)
            return;
        final ExternalProjectsManager.ExternalProjectsStateProvider stateProvider = myManager.getStateProvider();
        final ExternalSystemTaskExecutionSettings taskExecutionSettings = ((ExternalSystemRunConfiguration) settings.getConfiguration()).getSettings();
        if (taskExecutionSettings.getExternalProjectPath() == null)
            return;
        final TaskActivationState activation = stateProvider.getTasksActivation(taskExecutionSettings.getExternalSystemId(), taskExecutionSettings.getExternalProjectPath());
        for (Phase phase : Phase.values()) {
            for (Iterator<String> iterator = activation.getTasks(phase).iterator(); iterator.hasNext(); ) {
                String task = iterator.next();
                if (pair.first.equals(task)) {
                    iterator.remove();
                    break;
                }
            }
        }
    }
}
Also used : Phase(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator.Phase) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 17 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.

the class ExternalSystemRunManagerListener method runConfigurationChanged.

@Override
public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings) {
    if (settings.getConfiguration() instanceof ExternalSystemRunConfiguration) {
        final Pair<String, RunnerAndConfigurationSettings> pair = myMap.get(System.identityHashCode(settings));
        if (pair != null) {
            final ExternalProjectsManager.ExternalProjectsStateProvider stateProvider = myManager.getStateProvider();
            final ExternalSystemTaskExecutionSettings taskExecutionSettings = ((ExternalSystemRunConfiguration) settings.getConfiguration()).getSettings();
            if (taskExecutionSettings.getExternalProjectPath() == null)
                return;
            final TaskActivationState activation = stateProvider.getTasksActivation(taskExecutionSettings.getExternalSystemId(), taskExecutionSettings.getExternalProjectPath());
            for (Phase phase : Phase.values()) {
                final List<String> modifiableActivationTasks = activation.getTasks(phase);
                for (String task : ContainerUtil.newArrayList(modifiableActivationTasks)) {
                    if (pair.first.equals(task)) {
                        modifiableActivationTasks.remove(task);
                        final String runConfigurationActivationTaskName = getRunConfigurationActivationTaskName(settings);
                        modifiableActivationTasks.add(runConfigurationActivationTaskName);
                        myMap.put(System.identityHashCode(settings), Pair.create(runConfigurationActivationTaskName, settings));
                        break;
                    }
                }
            }
        }
    }
}
Also used : Phase(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator.Phase) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 18 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.

the class ExternalSystemRunManagerListener method attach.

public void attach() {
    myMap.clear();
    for (ExternalSystemManager<?, ?, ?, ?, ?> systemManager : ExternalSystemApiUtil.getAllManagers()) {
        final AbstractExternalSystemTaskConfigurationType configurationType = ExternalSystemUtil.findConfigurationType(systemManager.getSystemId());
        if (configurationType == null)
            continue;
        final List<RunnerAndConfigurationSettings> configurationSettingsList = RunManager.getInstance(myManager.getProject()).getConfigurationSettingsList(configurationType);
        for (RunnerAndConfigurationSettings configurationSettings : configurationSettingsList) {
            add(myMap, configurationSettings);
        }
    }
    ((RunManagerEx) RunManager.getInstance(myManager.getProject())).addRunManagerListener(this);
}
Also used : RunManagerEx(com.intellij.execution.RunManagerEx) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AbstractExternalSystemTaskConfigurationType(com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)

Example 19 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.

the class ExternalSystemTaskActivator method runTasks.

public boolean runTasks(@NotNull Collection<String> modules, @NotNull Phase... phases) {
    final ExternalProjectsStateProvider stateProvider = ExternalProjectsManager.getInstance(myProject).getStateProvider();
    final Queue<Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings>> tasksQueue = new LinkedList<>();
    //noinspection MismatchedQueryAndUpdateOfCollection
    Map<ProjectSystemId, Map<String, RunnerAndConfigurationSettings>> lazyConfigurationsMap = new FactoryMap<ProjectSystemId, Map<String, RunnerAndConfigurationSettings>>() {

        @Nullable
        @Override
        protected Map<String, RunnerAndConfigurationSettings> create(ProjectSystemId key) {
            final AbstractExternalSystemTaskConfigurationType configurationType = ExternalSystemUtil.findConfigurationType(key);
            if (configurationType == null)
                return null;
            return ContainerUtil.map2Map(RunManager.getInstance(myProject).getConfigurationSettingsList(configurationType), configurationSettings -> Pair.create(configurationSettings.getName(), configurationSettings));
        }
    };
    for (final ExternalProjectsStateProvider.TasksActivation activation : stateProvider.getAllTasksActivation()) {
        final boolean hashPath = modules.contains(activation.projectPath);
        final Set<String> tasks = ContainerUtil.newLinkedHashSet();
        for (Phase phase : phases) {
            List<String> activationTasks = activation.state.getTasks(phase);
            if (hashPath || (phase.isSyncPhase() && !activationTasks.isEmpty() && isShareSameRootPath(modules, activation))) {
                ContainerUtil.addAll(tasks, activationTasks);
            }
        }
        if (tasks.isEmpty())
            continue;
        for (Iterator<String> iterator = tasks.iterator(); iterator.hasNext(); ) {
            String task = iterator.next();
            if (task.length() > RUN_CONFIGURATION_TASK_PREFIX.length() && task.startsWith(RUN_CONFIGURATION_TASK_PREFIX)) {
                iterator.remove();
                final String configurationName = task.substring(RUN_CONFIGURATION_TASK_PREFIX.length());
                Map<String, RunnerAndConfigurationSettings> settings = lazyConfigurationsMap.get(activation.systemId);
                if (settings == null)
                    continue;
                RunnerAndConfigurationSettings configurationSettings = settings.get(configurationName);
                if (configurationSettings == null)
                    continue;
                final RunConfiguration runConfiguration = configurationSettings.getConfiguration();
                if (configurationName.equals(configurationSettings.getName()) && runConfiguration instanceof ExternalSystemRunConfiguration) {
                    tasksQueue.add(Pair.create(activation.systemId, ((ExternalSystemRunConfiguration) runConfiguration).getSettings()));
                }
            }
        }
        if (tasks.isEmpty())
            continue;
        if (ExternalProjectsManager.getInstance(myProject).isIgnored(activation.systemId, activation.projectPath))
            continue;
        ExternalSystemTaskExecutionSettings executionSettings = new ExternalSystemTaskExecutionSettings();
        executionSettings.setExternalSystemIdString(activation.systemId.toString());
        executionSettings.setExternalProjectPath(activation.projectPath);
        executionSettings.getTaskNames().addAll(tasks);
        tasksQueue.add(Pair.create(activation.systemId, executionSettings));
    }
    return runTasksQueue(tasksQueue);
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) ExternalProjectsStateProvider(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) FactoryMap(com.intellij.util.containers.FactoryMap) AbstractExternalSystemTaskConfigurationType(com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType) Pair(com.intellij.openapi.util.Pair) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)

Example 20 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings in project intellij-community by JetBrains.

the class BaseRunConfigurationAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    final RunnerAndConfigurationSettings existing = context.findExisting();
    if (existing == null) {
        final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
        if (producers.isEmpty())
            return;
        if (producers.size() > 1) {
            final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
            Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationFromContext>(ExecutionBundle.message("configuration.action.chooser.title"), producers) {

                @Override
                @NotNull
                public String getTextFor(final ConfigurationFromContext producer) {
                    return childActionName(producer.getConfigurationType(), producer.getConfiguration());
                }

                @Override
                public Icon getIconFor(final ConfigurationFromContext producer) {
                    return producer.getConfigurationType().getIcon();
                }

                @Override
                public PopupStep onChosen(final ConfigurationFromContext producer, final boolean finalChoice) {
                    perform(producer, context);
                    return FINAL_CHOICE;
                }
            });
            final InputEvent event = e.getInputEvent();
            if (event instanceof MouseEvent) {
                popup.show(new RelativePoint((MouseEvent) event));
            } else if (editor != null) {
                popup.showInBestPositionFor(editor);
            } else {
                popup.showInBestPositionFor(dataContext);
            }
        } else {
            perform(producers.get(0), context);
        }
        return;
    }
    perform(context);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) InputEvent(java.awt.event.InputEvent) Editor(com.intellij.openapi.editor.Editor)

Aggregations

RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)104 Project (com.intellij.openapi.project.Project)24 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)16 RunManagerEx (com.intellij.execution.RunManagerEx)14 Nullable (org.jetbrains.annotations.Nullable)14 RunManager (com.intellij.execution.RunManager)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)9 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)7 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)7 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)7 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)6 Executor (com.intellij.execution.Executor)4 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)4 AbstractExternalSystemTaskConfigurationType (com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)4 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)4 RunConfigurationNode (com.intellij.openapi.externalSystem.view.RunConfigurationNode)4 PsiElement (com.intellij.psi.PsiElement)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)3