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);
}
}
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();
}
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);
}
}
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;
}
Aggregations