Search in sources :

Example 1 with CompositeBuildData

use of org.jetbrains.plugins.gradle.model.data.CompositeBuildData 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 CompositeBuildData

use of org.jetbrains.plugins.gradle.model.data.CompositeBuildData 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)2 CompositeBuildData (org.jetbrains.plugins.gradle.model.data.CompositeBuildData)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)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 GradleBuildParticipant (org.jetbrains.plugins.gradle.settings.GradleBuildParticipant)1 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)1