Search in sources :

Example 11 with GradleBuild

use of org.gradle.tooling.model.gradle.GradleBuild in project gradle by gradle.

the class UseGradleBuildToFetchProjectModel method execute.

public Map<String, CustomModel> execute(BuildController controller) {
    GradleBuild gradleBuild = controller.getBuildModel();
    Map<String, CustomModel> projects = new HashMap<String, CustomModel>();
    for (BasicGradleProject project : gradleBuild.getProjects()) {
        projects.put(project.getName(), controller.getModel(project, CustomModel.class));
    }
    return projects;
}
Also used : HashMap(java.util.HashMap) BasicGradleProject(org.gradle.tooling.model.gradle.BasicGradleProject) CustomModel(org.gradle.integtests.tooling.r16.CustomModel) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild)

Example 12 with GradleBuild

use of org.gradle.tooling.model.gradle.GradleBuild in project gradle by gradle.

the class FetchEclipseProjects method execute.

@Override
public List<EclipseProject> execute(BuildController controller) {
    List<EclipseProject> eclipseProjects = new ArrayList<EclipseProject>();
    GradleBuild build = controller.getBuildModel();
    collectEclipseProjects(build, eclipseProjects, controller);
    return eclipseProjects;
}
Also used : EclipseProject(org.gradle.tooling.model.eclipse.EclipseProject) ArrayList(java.util.ArrayList) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild)

Example 13 with GradleBuild

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

the class ModuleFactory method getModulePath.

@NotNull
private String getModulePath(@NotNull IdeaModule ideaModule, @NotNull SyncAction.ModuleModels moduleModels) {
    GradleProject gradleProject = ideaModule.getGradleProject();
    GradleBuild gradleBuild = moduleModels.findModel(GradleBuild.class);
    if (gradleBuild != null) {
        File moduleDirPath = getModuleDirPath(gradleBuild, gradleProject.getPath());
        if (moduleDirPath == null) {
            throw new IllegalStateException(String.format("Unable to find root directory for module '%1$s'", ideaModule.getName()));
        }
        return toCanonicalPath(moduleDirPath.getPath());
    }
    String projectPath = myProject.getBasePath();
    // We should not be dealing with 'default' project.
    assert projectPath != null;
    return toSystemDependentName(getConfigPath(gradleProject, projectPath));
}
Also used : GradleProject(org.gradle.tooling.model.GradleProject) File(java.io.File) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with GradleBuild

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

Example 15 with GradleBuild

use of org.gradle.tooling.model.gradle.GradleBuild in project intellij-community by JetBrains.

the class GradleProjectResolverUtil method getModuleConfigPath.

@NotNull
public static String getModuleConfigPath(@NotNull ProjectResolverContext resolverCtx, @NotNull IdeaModule gradleModule, @NotNull String rootProjectPath) {
    GradleBuild build = resolverCtx.getExtraProject(gradleModule, GradleBuild.class);
    if (build != null) {
        String gradlePath = gradleModule.getGradleProject().getPath();
        File moduleDirPath = getModuleDirPath(build, gradlePath);
        if (moduleDirPath == null) {
            throw new IllegalStateException(String.format("Unable to find root directory for module '%s'", gradleModule.getName()));
        }
        try {
            return ExternalSystemApiUtil.toCanonicalPath(moduleDirPath.getCanonicalPath());
        } catch (IOException e) {
            LOG.warn("construction of the canonical path for the module fails", e);
        }
    }
    return GradleUtil.getConfigPath(gradleModule.getGradleProject(), rootProjectPath);
}
Also used : IOException(java.io.IOException) File(java.io.File) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleBuild (org.gradle.tooling.model.gradle.GradleBuild)22 ArrayList (java.util.ArrayList)15 BasicGradleProject (org.gradle.tooling.model.gradle.BasicGradleProject)8 EclipseProject (org.gradle.tooling.model.eclipse.EclipseProject)4 SomeToolingModel (org.gradle.configurationcache.fixtures.SomeToolingModel)3 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)3 NotNull (org.jetbrains.annotations.NotNull)3 File (java.io.File)2 IOException (java.io.IOException)2 GradleProject (org.gradle.tooling.model.GradleProject)2 AndroidProject (com.android.builder.model.AndroidProject)1 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 CustomModel (org.gradle.integtests.tooling.r16.CustomModel)1 GradleTask (org.gradle.tooling.model.GradleTask)1 CppProject (org.gradle.tooling.model.cpp.CppProject)1 BuildInvocations (org.gradle.tooling.model.gradle.BuildInvocations)1 BasicIdeaProject (org.gradle.tooling.model.idea.BasicIdeaProject)1 IdeaModule (org.gradle.tooling.model.idea.IdeaModule)1