Search in sources :

Example 1 with ExternalProjectsStateProvider

use of com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider 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 2 with ExternalProjectsStateProvider

use of com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider in project intellij-community by JetBrains.

the class ExternalSystemTaskActivator method addTasks.

public void addTasks(@NotNull Collection<TaskActivationEntry> entries) {
    if (entries.isEmpty())
        return;
    final ExternalProjectsStateProvider stateProvider = ExternalProjectsManager.getInstance(myProject).getStateProvider();
    for (TaskActivationEntry entry : entries) {
        final TaskActivationState taskActivationState = stateProvider.getTasksActivation(entry.systemId, entry.projectPath);
        taskActivationState.getTasks(entry.phase).add(entry.taskName);
    }
    fireTasksChanged();
}
Also used : ExternalProjectsStateProvider(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider)

Example 3 with ExternalProjectsStateProvider

use of com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider in project intellij-community by JetBrains.

the class ExternalSystemTaskActivator method isTaskOfPhase.

public boolean isTaskOfPhase(@NotNull TaskData taskData, @NotNull Phase phase) {
    final ExternalProjectsStateProvider stateProvider = ExternalProjectsManager.getInstance(myProject).getStateProvider();
    final TaskActivationState taskActivationState = stateProvider.getTasksActivation(taskData.getOwner(), taskData.getLinkedExternalProjectPath());
    if (taskActivationState == null)
        return false;
    return taskActivationState.getTasks(phase).contains(taskData.getName());
}
Also used : ExternalProjectsStateProvider(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider)

Example 4 with ExternalProjectsStateProvider

use of com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider in project intellij-community by JetBrains.

the class ExternalSystemTaskActivator method getDescription.

public String getDescription(ProjectSystemId systemId, String projectPath, String taskName) {
    List<String> result = new ArrayList<>();
    final ExternalProjectsStateProvider stateProvider = ExternalProjectsManager.getInstance(myProject).getStateProvider();
    final TaskActivationState taskActivationState = stateProvider.getTasksActivation(systemId, projectPath);
    if (taskActivationState == null)
        return null;
    for (Phase phase : Phase.values()) {
        if (taskActivationState.getTasks(phase).contains(taskName)) {
            result.add(phase.toString());
        }
    }
    return StringUtil.join(result, ", ");
}
Also used : ExternalProjectsStateProvider(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider)

Example 5 with ExternalProjectsStateProvider

use of com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider in project intellij-community by JetBrains.

the class ExternalSystemTaskActivator method removeTasks.

public void removeTasks(@NotNull Collection<TaskActivationEntry> entries) {
    if (entries.isEmpty())
        return;
    final ExternalProjectsStateProvider stateProvider = ExternalProjectsManager.getInstance(myProject).getStateProvider();
    for (TaskActivationEntry activationEntry : entries) {
        final TaskActivationState taskActivationState = stateProvider.getTasksActivation(activationEntry.systemId, activationEntry.projectPath);
        taskActivationState.getTasks(activationEntry.phase).remove(activationEntry.taskName);
    }
    fireTasksChanged();
}
Also used : ExternalProjectsStateProvider(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider)

Aggregations

ExternalProjectsStateProvider (com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager.ExternalProjectsStateProvider)7 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)1 AbstractExternalSystemTaskConfigurationType (com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)1 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)1 Pair (com.intellij.openapi.util.Pair)1 FactoryMap (com.intellij.util.containers.FactoryMap)1