Search in sources :

Example 1 with BuildParticipant

use of org.jetbrains.plugins.gradle.model.data.BuildParticipant in project intellij-community by JetBrains.

the class CompositeBuildDataService method importData.

public void importData(@NotNull final Collection<DataNode<CompositeBuildData>> toImport, @Nullable ProjectData projectData, @NotNull final Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        if (projectData != null) {
            GradleProjectSettings projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(projectData.getLinkedExternalProjectPath());
            if (projectSettings != null && projectSettings.getCompositeBuild() != null && projectSettings.getCompositeBuild().getCompositeDefinitionSource() == CompositeDefinitionSource.SCRIPT) {
                projectSettings.setCompositeBuild(null);
            }
        }
        return;
    }
    if (toImport.size() != 1) {
        throw new IllegalArgumentException(String.format("Expected to get a single composite data node but got %d: %s", toImport.size(), toImport));
    }
    CompositeBuildData compositeBuildData = toImport.iterator().next().getData();
    GradleProjectSettings projectSettings = GradleSettings.getInstance(project).getLinkedProjectSettings(compositeBuildData.getRootProjectPath());
    if (projectSettings != null) {
        GradleProjectSettings.CompositeBuild compositeBuild = new GradleProjectSettings.CompositeBuild();
        compositeBuild.setCompositeDefinitionSource(CompositeDefinitionSource.SCRIPT);
        for (BuildParticipant buildParticipant : compositeBuildData.getCompositeParticipants()) {
            compositeBuild.getCompositeParticipants().add(buildParticipant.copy());
        }
        projectSettings.setCompositeBuild(compositeBuild);
    }
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) CompositeBuildData(org.jetbrains.plugins.gradle.model.data.CompositeBuildData) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant)

Example 2 with BuildParticipant

use of org.jetbrains.plugins.gradle.model.data.BuildParticipant in project intellij-community by JetBrains.

the class GradleProjectCompositeSelectorDialog method doOKAction.

@Override
protected void doOKAction() {
    if (myCompositeRootSettings != null) {
        Pair[] compositeParticipants = myTree.getCheckedNodes(Pair.class, null);
        if (compositeParticipants.length == 0) {
            myCompositeRootSettings.setCompositeBuild(null);
        } else {
            GradleProjectSettings.CompositeBuild compositeBuild = new GradleProjectSettings.CompositeBuild();
            compositeBuild.setCompositeDefinitionSource(CompositeDefinitionSource.IDE);
            for (Pair participant : compositeParticipants) {
                BuildParticipant buildParticipant = new BuildParticipant();
                buildParticipant.setRootProjectName(participant.first.toString());
                buildParticipant.setRootPath(participant.second.toString());
                compositeBuild.getCompositeParticipants().add(buildParticipant);
            }
            myCompositeRootSettings.setCompositeBuild(compositeBuild);
        }
    }
    super.doOKAction();
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant) Pair(com.intellij.openapi.util.Pair)

Example 3 with BuildParticipant

use of org.jetbrains.plugins.gradle.model.data.BuildParticipant in project intellij-community by JetBrains.

the class GradleManager method configureExecutionWorkspace.

/**
   * Add composite participants
   */
private static void configureExecutionWorkspace(@Nullable GradleProjectSettings compositeRootSettings, GradleSettings settings, GradleExecutionSettings result, Project project, String projectPath) {
    if (compositeRootSettings == null || compositeRootSettings.getCompositeBuild() == null)
        return;
    GradleProjectSettings.CompositeBuild compositeBuild = compositeRootSettings.getCompositeBuild();
    if (compositeBuild.getCompositeDefinitionSource() == CompositeDefinitionSource.SCRIPT) {
        if (pathsEqual(compositeRootSettings.getExternalProjectPath(), projectPath))
            return;
        for (BuildParticipant buildParticipant : compositeBuild.getCompositeParticipants()) {
            if (pathsEqual(buildParticipant.getRootPath(), projectPath))
                continue;
            if (buildParticipant.getProjects().stream().anyMatch(path -> pathsEqual(path, projectPath))) {
                continue;
            }
            result.getExecutionWorkspace().addBuildParticipant(new GradleBuildParticipant(buildParticipant.getRootPath()));
        }
        return;
    }
    for (GradleProjectSettings projectSettings : settings.getLinkedProjectsSettings()) {
        if (projectSettings == compositeRootSettings)
            continue;
        if (compositeBuild.getCompositeParticipants().stream().noneMatch(participant -> pathsEqual(participant.getRootPath(), projectSettings.getExternalProjectPath()))) {
            continue;
        }
        GradleBuildParticipant buildParticipant = new GradleBuildParticipant(projectSettings.getExternalProjectPath());
        ExternalProjectInfo projectData = ProjectDataManager.getInstance().getExternalProjectData(project, GradleConstants.SYSTEM_ID, projectSettings.getExternalProjectPath());
        if (projectData == null || projectData.getExternalProjectStructure() == null)
            continue;
        Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(projectData.getExternalProjectStructure(), ProjectKeys.MODULE);
        for (DataNode<ModuleData> moduleNode : moduleNodes) {
            ModuleData moduleData = moduleNode.getData();
            if (moduleData.getArtifacts().isEmpty()) {
                Collection<DataNode<GradleSourceSetData>> sourceSetNodes = ExternalSystemApiUtil.findAll(moduleNode, GradleSourceSetData.KEY);
                for (DataNode<GradleSourceSetData> sourceSetNode : sourceSetNodes) {
                    buildParticipant.addModule(sourceSetNode.getData());
                }
            } else {
                buildParticipant.addModule(moduleData);
            }
        }
        result.getExecutionWorkspace().addBuildParticipant(buildParticipant);
    }
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) DataNode(com.intellij.openapi.externalSystem.model.DataNode) GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData)

Example 4 with BuildParticipant

use of org.jetbrains.plugins.gradle.model.data.BuildParticipant in project intellij-community by JetBrains.

the class GradleProjectResolver method exposeCompositeBuild.

@NotNull
private static Collection<IdeaModule> exposeCompositeBuild(ProjectImportAction.AllModels allModels, DefaultProjectResolverContext resolverCtx, DataNode<ProjectData> projectDataNode) {
    if (resolverCtx.getSettings() != null && !resolverCtx.getSettings().getExecutionWorkspace().getBuildParticipants().isEmpty()) {
        return Collections.emptyList();
    }
    CompositeBuildData compositeBuildData;
    List<IdeaModule> gradleIncludedModules = new SmartList<>();
    List<IdeaProject> includedBuilds = allModels.getIncludedBuilds();
    if (!includedBuilds.isEmpty()) {
        ProjectData projectData = projectDataNode.getData();
        compositeBuildData = new CompositeBuildData(projectData.getLinkedExternalProjectPath());
        for (IdeaProject project : includedBuilds) {
            if (!project.getModules().isEmpty()) {
                String rootProjectName = project.getName();
                BuildParticipant buildParticipant = new BuildParticipant();
                gradleIncludedModules.addAll(project.getModules());
                GradleProject gradleProject = project.getModules().getAt(0).getGradleProject();
                String projectPath = null;
                do {
                    try {
                        projectPath = ExternalSystemApiUtil.toCanonicalPath(gradleProject.getProjectDirectory().getCanonicalPath());
                    } catch (IOException e) {
                        LOG.warn("construction of the canonical path for the module fails", e);
                    }
                } while ((gradleProject = gradleProject.getParent()) != null);
                if (projectPath != null) {
                    buildParticipant.setRootProjectName(rootProjectName);
                    buildParticipant.setRootPath(projectPath);
                    for (IdeaModule module : project.getModules()) {
                        try {
                            String modulePath = ExternalSystemApiUtil.toCanonicalPath(module.getGradleProject().getProjectDirectory().getCanonicalPath());
                            buildParticipant.getProjects().add(modulePath);
                        } catch (IOException e) {
                            LOG.warn("construction of the canonical path for the module fails", e);
                        }
                    }
                    compositeBuildData.getCompositeParticipants().add(buildParticipant);
                }
            }
        }
        projectDataNode.createChild(CompositeBuildData.KEY, compositeBuildData);
    }
    return gradleIncludedModules;
}
Also used : IdeaModule(org.gradle.tooling.model.idea.IdeaModule) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) BasicIdeaProject(org.gradle.tooling.model.idea.BasicIdeaProject) CompositeBuildData(org.jetbrains.plugins.gradle.model.data.CompositeBuildData) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant) GradleBuildParticipant(org.jetbrains.plugins.gradle.settings.GradleBuildParticipant) GradleProject(org.gradle.tooling.model.GradleProject) IOException(java.io.IOException) SmartList(com.intellij.util.SmartList) JavaProjectData(com.intellij.externalSystem.JavaProjectData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuildParticipant (org.jetbrains.plugins.gradle.model.data.BuildParticipant)4 CompositeBuildData (org.jetbrains.plugins.gradle.model.data.CompositeBuildData)2 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)1 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)1 Pair (com.intellij.openapi.util.Pair)1 SmartList (com.intellij.util.SmartList)1 IOException (java.io.IOException)1 GradleProject (org.gradle.tooling.model.GradleProject)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 NotNull (org.jetbrains.annotations.NotNull)1 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)1 GradleBuildParticipant (org.jetbrains.plugins.gradle.settings.GradleBuildParticipant)1