Search in sources :

Example 6 with GradleBuild

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

the class FetchIncludedGradleProjects method execute.

@Override
public List<GradleProject> execute(BuildController controller) {
    List<GradleProject> projects = new ArrayList<GradleProject>();
    GradleBuild build = controller.getBuildModel();
    for (GradleBuild includedBuild : build.getIncludedBuilds()) {
        projects.add(controller.getModel(includedBuild, GradleProject.class));
    }
    return projects;
}
Also used : ArrayList(java.util.ArrayList) GradleProject(org.gradle.tooling.model.GradleProject) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild)

Example 7 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)

Example 8 with GradleBuild

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

the class ProjectImportAction method execute.

@Nullable
@Override
public AllModels execute(final BuildController controller) {
    configureAdditionalTypes(controller);
    //outer conditional is needed to be compatible with 1.8
    final IdeaProject ideaProject = myIsPreviewMode ? controller.getModel(BasicIdeaProject.class) : controller.getModel(IdeaProject.class);
    if (ideaProject == null || ideaProject.getModules().isEmpty()) {
        return null;
    }
    AllModels allModels = new AllModels(ideaProject);
    allModels.setGradleProjectDirSupported(myIsGradleProjectDirSupported);
    BuildEnvironment buildEnvironment = controller.findModel(BuildEnvironment.class);
    allModels.setBuildEnvironment(buildEnvironment);
    addExtraProject(controller, allModels, null);
    for (IdeaModule module : ideaProject.getModules()) {
        addExtraProject(controller, allModels, module);
    }
    if (myIsCompositeBuildsSupported) {
        GradleBuild gradleBuild = controller.getModel(GradleBuild.class);
        for (GradleBuild build : gradleBuild.getIncludedBuilds()) {
            IdeaProject ideaIncludedProject = controller.findModel(build, IdeaProject.class);
            allModels.getIncludedBuilds().add(ideaIncludedProject);
            for (IdeaModule module : ideaIncludedProject.getModules()) {
                addExtraProject(controller, allModels, module);
            }
        }
    }
    return allModels;
}
Also used : IdeaProject(org.gradle.tooling.model.idea.IdeaProject) BasicIdeaProject(org.gradle.tooling.model.idea.BasicIdeaProject) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) BasicIdeaProject(org.gradle.tooling.model.idea.BasicIdeaProject) GradleBuild(org.gradle.tooling.model.gradle.GradleBuild) Nullable(org.jetbrains.annotations.Nullable)

Example 9 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 10 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)

Aggregations

GradleBuild (org.gradle.tooling.model.gradle.GradleBuild)10 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)3 File (java.io.File)2 IOException (java.io.IOException)2 GradleProject (org.gradle.tooling.model.GradleProject)2 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)2 BasicGradleProject (org.gradle.tooling.model.gradle.BasicGradleProject)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 EclipseProject (org.gradle.tooling.model.eclipse.EclipseProject)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 IdeaProject (org.gradle.tooling.model.idea.IdeaProject)1 Nullable (org.jetbrains.annotations.Nullable)1