Search in sources :

Example 1 with ProjectSystemId

use of com.intellij.openapi.externalSystem.model.ProjectSystemId in project intellij-community by JetBrains.

the class ExternalModuleStructureExtension method getLinkedProjects.

private static Map<String, Pair<ProjectSystemId, ExternalProjectSettings>> getLinkedProjects(Project project) {
    Map<String, Pair<ProjectSystemId, ExternalProjectSettings>> result = new HashMap<>();
    for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        ProjectSystemId systemId = manager.getSystemId();
        AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, systemId);
        Collection projectsSettings = systemSettings.getLinkedProjectsSettings();
        for (Object settings : projectsSettings) {
            if (settings instanceof ExternalProjectSettings) {
                ExternalProjectSettings projectSettings = (ExternalProjectSettings) settings;
                result.put((projectSettings).getExternalProjectPath(), Pair.create(systemId, projectSettings));
            }
        }
    }
    return result;
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) HashMap(java.util.HashMap) Collection(java.util.Collection) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) Pair(com.intellij.openapi.util.Pair)

Example 2 with ProjectSystemId

use of com.intellij.openapi.externalSystem.model.ProjectSystemId in project intellij-community by JetBrains.

the class ExternalSystemKeymapExtension method createGroup.

public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(ExternalSystemBundle.message("external.system.keymap.group"), ExternalSystemIcons.TaskGroup);
    AnAction[] externalSystemActions = ActionsTreeUtil.getActions("ExternalSystem.Actions");
    for (AnAction action : externalSystemActions) {
        ActionsTreeUtil.addAction(result, action, condition);
    }
    if (project == null)
        return result;
    MultiMap<ProjectSystemId, String> projectToActionsMapping = MultiMap.create();
    for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
        projectToActionsMapping.putValues(manager.getSystemId(), ContainerUtil.<String>emptyList());
    }
    ActionManager actionManager = ActionManager.getInstance();
    if (actionManager != null) {
        for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
            AnAction eachAction = actionManager.getAction(eachId);
            if (!(eachAction instanceof MyExternalSystemAction))
                continue;
            if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
                continue;
            MyExternalSystemAction taskAction = (MyExternalSystemAction) eachAction;
            projectToActionsMapping.putValue(taskAction.getSystemId(), eachId);
        }
    }
    Map<ProjectSystemId, KeymapGroup> keymapGroupMap = ContainerUtil.newHashMap();
    for (ProjectSystemId systemId : projectToActionsMapping.keySet()) {
        if (!keymapGroupMap.containsKey(systemId)) {
            final Icon projectIcon = ExternalSystemUiUtil.getUiAware(systemId).getProjectIcon();
            KeymapGroup group = KeymapGroupFactory.getInstance().createGroup(systemId.getReadableName(), projectIcon);
            keymapGroupMap.put(systemId, group);
        }
    }
    for (Map.Entry<ProjectSystemId, Collection<String>> each : projectToActionsMapping.entrySet()) {
        Collection<String> tasks = each.getValue();
        final ProjectSystemId systemId = each.getKey();
        final KeymapGroup systemGroup = keymapGroupMap.get(systemId);
        if (systemGroup == null)
            continue;
        for (String actionId : tasks) {
            systemGroup.addActionId(actionId);
        }
        if (systemGroup instanceof Group) {
            Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
            ((Group) systemGroup).addHyperlink(new Hyperlink(icon, "Choose a task to assign a shortcut") {

                @Override
                public void onClick(MouseEvent e) {
                    SelectExternalTaskDialog dialog = new SelectExternalTaskDialog(systemId, project);
                    if (dialog.showAndGet() && dialog.getResult() != null) {
                        TaskData taskData = dialog.getResult().second;
                        String ownerModuleName = dialog.getResult().first;
                        ExternalSystemTaskAction externalSystemAction = (ExternalSystemTaskAction) getOrRegisterAction(project, ownerModuleName, taskData);
                        ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
                        Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
                        KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
                        if (keymapPanel != null) {
                            // clear actions filter
                            keymapPanel.showOption("");
                            keymapPanel.selectAction(externalSystemAction.myId);
                        }
                    }
                }
            });
        }
    }
    for (KeymapGroup keymapGroup : keymapGroupMap.values()) {
        if (isGroupFiltered(condition, keymapGroup)) {
            result.addGroup(keymapGroup);
        }
    }
    for (ActionsProvider extension : ActionsProvider.EP_NAME.getExtensions()) {
        KeymapGroup keymapGroup = extension.createGroup(condition, project);
        if (isGroupFiltered(condition, keymapGroup)) {
            result.addGroup(keymapGroup);
        }
    }
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) Settings(com.intellij.openapi.options.ex.Settings) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) MouseEvent(java.awt.event.MouseEvent) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) SelectExternalTaskDialog(com.intellij.openapi.externalSystem.service.ui.SelectExternalTaskDialog) Collection(java.util.Collection) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap)

Example 3 with ProjectSystemId

use of com.intellij.openapi.externalSystem.model.ProjectSystemId 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 4 with ProjectSystemId

use of com.intellij.openapi.externalSystem.model.ProjectSystemId in project intellij-community by JetBrains.

the class ExternalSystemNodeAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = getProject(e);
    if (project == null)
        return;
    ProjectSystemId projectSystemId = getSystemId(e);
    if (projectSystemId == null)
        return;
    final T data = getExternalData(e, myExternalDataClazz);
    if (data == null)
        return;
    perform(project, projectSystemId, data, e);
}
Also used : Project(com.intellij.openapi.project.Project) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId)

Example 5 with ProjectSystemId

use of com.intellij.openapi.externalSystem.model.ProjectSystemId in project intellij-community by JetBrains.

the class OpenExternalConfigAction method isEnabled.

@Override
protected boolean isEnabled(AnActionEvent e) {
    if (!super.isEnabled(e))
        return false;
    final ExternalEntityData externalData = getExternalData(e, ExternalEntityData.class);
    if (!(externalData instanceof ExternalConfigPathAware))
        return false;
    VirtualFile config = getExternalConfig((ExternalConfigPathAware) externalData, externalData.getOwner());
    if (config == null)
        return false;
    ProjectSystemId externalSystemId = getSystemId(e);
    e.getPresentation().setText(ExternalSystemBundle.message("action.open.config.text", externalSystemId.getReadableName()));
    e.getPresentation().setDescription(ExternalSystemBundle.message("action.open.config.description", externalSystemId.getReadableName()));
    final ExternalSystemUiAware uiAware = getExternalSystemUiAware(e);
    if (uiAware != null) {
        e.getPresentation().setIcon(uiAware.getProjectIcon());
    }
    return true;
}
Also used : ExternalConfigPathAware(com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExternalEntityData(com.intellij.openapi.externalSystem.model.project.ExternalEntityData) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware)

Aggregations

ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)36 Project (com.intellij.openapi.project.Project)10 Map (java.util.Map)5 ExternalConfigPathAware (com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware)4 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)4 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 ExternalSystemManager (com.intellij.openapi.externalSystem.ExternalSystemManager)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)3 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)3 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)3 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)3 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)3 Collection (java.util.Collection)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 Logger (com.intellij.openapi.diagnostic.Logger)2 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)2 ExternalSystemProcessingManager (com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager)2 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)2