Search in sources :

Example 1 with GradleTask

use of org.gradle.tooling.model.GradleTask in project android by JetBrains.

the class GradleModuleModel method getTaskNames.

@NotNull
private static List<String> getTaskNames(@NotNull GradleProject gradleProject) {
    List<String> taskNames = new ArrayList<>();
    DomainObjectSet<? extends GradleTask> tasks = gradleProject.getTasks();
    if (!tasks.isEmpty()) {
        for (GradleTask task : tasks) {
            String name = task.getName();
            if (isNotEmpty(name)) {
                taskNames.add(task.getProject().getPath() + GRADLE_PATH_SEPARATOR + task.getName());
            }
        }
    }
    return taskNames;
}
Also used : GradleTask(org.gradle.tooling.model.GradleTask) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GradleTask

use of org.gradle.tooling.model.GradleTask 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

GradleTask (org.gradle.tooling.model.GradleTask)2 NotNull (org.jetbrains.annotations.NotNull)2 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GradleBuild (org.gradle.tooling.model.gradle.GradleBuild)1