Search in sources :

Example 6 with TaskData

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

the class ExternalProjectsViewImpl method extractLocation.

@Nullable
private ExternalSystemTaskLocation extractLocation() {
    final List<ExternalSystemNode> selectedNodes = getSelectedNodes(ExternalSystemNode.class);
    if (selectedNodes.isEmpty())
        return null;
    List<TaskData> tasks = ContainerUtil.newSmartList();
    ExternalTaskExecutionInfo taskExecutionInfo = new ExternalTaskExecutionInfo();
    String projectPath = null;
    for (ExternalSystemNode node : selectedNodes) {
        final Object data = node.getData();
        if (data instanceof TaskData) {
            final TaskData taskData = (TaskData) data;
            if (projectPath == null) {
                projectPath = taskData.getLinkedExternalProjectPath();
            } else if (!taskData.getLinkedExternalProjectPath().equals(projectPath)) {
                return null;
            }
            taskExecutionInfo.getSettings().getTaskNames().add(taskData.getName());
            taskExecutionInfo.getSettings().getTaskDescriptions().add(taskData.getDescription());
            tasks.add(taskData);
        }
    }
    if (tasks.isEmpty())
        return null;
    taskExecutionInfo.getSettings().setExternalSystemIdString(myExternalSystemId.toString());
    taskExecutionInfo.getSettings().setExternalProjectPath(projectPath);
    return ExternalSystemTaskLocation.create(myProject, myExternalSystemId, projectPath, taskExecutionInfo);
}
Also used : ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with TaskData

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

the class ExternalSystemKeymapExtension method createActions.

private static void createActions(Project project, Collection<DataNode<TaskData>> taskNodes) {
    ActionManager actionManager = ActionManager.getInstance();
    final ExternalSystemShortcutsManager shortcutsManager = ExternalProjectsManager.getInstance(project).getShortcutsManager();
    if (actionManager != null) {
        for (DataNode<TaskData> each : taskNodes) {
            final DataNode<ModuleData> moduleData = ExternalSystemApiUtil.findParent(each, ProjectKeys.MODULE);
            if (moduleData == null || moduleData.isIgnored())
                continue;
            TaskData taskData = each.getData();
            ExternalSystemTaskAction eachAction = new ExternalSystemTaskAction(project, moduleData.getData().getInternalName(), taskData);
            actionManager.unregisterAction(eachAction.getId());
            if (shortcutsManager.hasShortcuts(taskData.getLinkedExternalProjectPath(), taskData.getName())) {
                actionManager.registerAction(eachAction.getId(), eachAction);
            }
        }
    }
}
Also used : ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Example 8 with TaskData

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

the class GradleTestRunConfigurationProducer method getTasksToRun.

@NotNull
public static List<String> getTasksToRun(@NotNull Module module) {
    for (GradleTestTasksProvider provider : GradleTestTasksProvider.EP_NAME.getExtensions()) {
        final List<String> tasks = provider.getTasks(module);
        if (!ContainerUtil.isEmpty(tasks)) {
            return tasks;
        }
    }
    final List<String> result;
    final String externalProjectId = ExternalSystemApiUtil.getExternalProjectId(module);
    if (externalProjectId == null)
        return ContainerUtil.emptyList();
    final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (projectPath == null)
        return ContainerUtil.emptyList();
    final ExternalProjectInfo externalProjectInfo = ExternalSystemUtil.getExternalProjectInfo(module.getProject(), GradleConstants.SYSTEM_ID, projectPath);
    if (externalProjectInfo == null)
        return ContainerUtil.emptyList();
    boolean trimSourceSet = false;
    if (StringUtil.endsWith(externalProjectId, ":test") || StringUtil.endsWith(externalProjectId, ":main")) {
        result = TEST_SOURCE_SET_TASKS;
        trimSourceSet = true;
    } else {
        final DataNode<ModuleData> moduleNode = GradleProjectResolverUtil.findModule(externalProjectInfo.getExternalProjectStructure(), projectPath);
        if (moduleNode == null)
            return ContainerUtil.emptyList();
        final DataNode<TaskData> taskNode;
        final String sourceSetId = StringUtil.substringAfter(externalProjectId, moduleNode.getData().getExternalName() + ':');
        if (sourceSetId == null) {
            taskNode = ExternalSystemApiUtil.find(moduleNode, ProjectKeys.TASK, node -> GradleCommonClassNames.GRADLE_API_TASKS_TESTING_TEST.equals(node.getData().getType()) && StringUtil.equals("test", node.getData().getName()));
        } else {
            trimSourceSet = true;
            taskNode = ExternalSystemApiUtil.find(moduleNode, ProjectKeys.TASK, node -> GradleCommonClassNames.GRADLE_API_TASKS_TESTING_TEST.equals(node.getData().getType()) && StringUtil.startsWith(sourceSetId, node.getData().getName()));
        }
        if (taskNode == null)
            return ContainerUtil.emptyList();
        final String taskName = taskNode.getData().getName();
        result = ContainerUtil.list("clean" + StringUtil.capitalize(taskName), taskName);
    }
    final String path;
    if (!externalProjectId.startsWith(":")) {
        path = ":";
    } else {
        final List<String> pathParts = StringUtil.split(externalProjectId, ":");
        if (trimSourceSet && !pathParts.isEmpty())
            pathParts.remove(pathParts.size() - 1);
        final String join = StringUtil.join(pathParts, ":");
        path = ":" + join + (!join.isEmpty() ? ":" : "");
    }
    return ContainerUtil.map(result, s -> path + s);
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ProjectKeys(com.intellij.openapi.externalSystem.model.ProjectKeys) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ConfigurationType(com.intellij.execution.configurations.ConfigurationType) ContainerUtil(com.intellij.util.containers.ContainerUtil) GradleSystemRunningSettings(org.jetbrains.plugins.gradle.settings.GradleSystemRunningSettings) ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) DataNode(com.intellij.openapi.externalSystem.model.DataNode) PsiElement(com.intellij.psi.PsiElement) PreferredTestRunner(org.jetbrains.plugins.gradle.settings.GradleSystemRunningSettings.PreferredTestRunner) RunManagerEx(com.intellij.execution.RunManagerEx) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) StringUtil(com.intellij.openapi.util.text.StringUtil) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) GradleProjectResolverUtil(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil) ExternalSystemUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUtil) Nullable(org.jetbrains.annotations.Nullable) GradleCommonClassNames(org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames) List(java.util.List) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with TaskData

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

the class BaseGradleProjectResolverExtension method populateModuleTasks.

@NotNull
@Override
public Collection<TaskData> populateModuleTasks(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule, @NotNull DataNode<ProjectData> ideProject) throws IllegalArgumentException, IllegalStateException {
    final Collection<TaskData> tasks = ContainerUtil.newArrayList();
    final String moduleConfigPath = ideModule.getData().getLinkedExternalProjectPath();
    ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
    String rootProjectPath = ideProject.getData().getLinkedExternalProjectPath();
    try {
        GradleBuild build = resolverCtx.getExtraProject(gradleModule, GradleBuild.class);
        if (build != null) {
            rootProjectPath = ExternalSystemApiUtil.toCanonicalPath(build.getRootProject().getProjectDirectory().getCanonicalPath());
        }
    } catch (IOException e) {
        LOG.warn("construction of the canonical path for the module fails", e);
    }
    final boolean isFlatProject = !FileUtil.isAncestor(rootProjectPath, moduleConfigPath, false);
    if (externalProject != null) {
        for (ExternalTask task : externalProject.getTasks().values()) {
            String taskName = isFlatProject ? task.getQName() : task.getName();
            String taskGroup = task.getGroup();
            if (taskName.trim().isEmpty() || isIdeaTask(taskName, taskGroup)) {
                continue;
            }
            final String taskPath = isFlatProject ? rootProjectPath : moduleConfigPath;
            TaskData taskData = new TaskData(GradleConstants.SYSTEM_ID, taskName, taskPath, task.getDescription());
            taskData.setGroup(taskGroup);
            taskData.setType(task.getType());
            ideModule.createChild(ProjectKeys.TASK, taskData);
            taskData.setInherited(StringUtil.equals(task.getName(), task.getQName()));
            tasks.add(taskData);
        }
        return tasks;
    }
    for (GradleTask task : gradleModule.getGradleProject().getTasks()) {
        String taskName = task.getName();
        String taskGroup = getTaskGroup(task);
        if (taskName == null || taskName.trim().isEmpty() || isIdeaTask(taskName, taskGroup)) {
            continue;
        }
        TaskData taskData = new TaskData(GradleConstants.SYSTEM_ID, taskName, moduleConfigPath, task.getDescription());
        taskData.setGroup(taskGroup);
        ideModule.createChild(ProjectKeys.TASK, taskData);
        tasks.add(taskData);
    }
    return tasks;
}
Also used : GradleTask(org.gradle.tooling.model.GradleTask) IOException(java.io.IOException) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)9 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)4 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)3 NotNull (org.jetbrains.annotations.NotNull)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)2 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)2 MultiMap (com.intellij.util.containers.MultiMap)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Nullable (org.jetbrains.annotations.Nullable)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 RunManagerEx (com.intellij.execution.RunManagerEx)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)1 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)1 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)1 ProjectKeys (com.intellij.openapi.externalSystem.model.ProjectKeys)1 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)1