use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class AbstractModuleDataService method createModules.
private void createModules(@NotNull Collection<DataNode<E>> toCreate, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Project project) {
for (final DataNode<E> module : toCreate) {
ModuleData data = module.getData();
final Module created = modelsProvider.newModule(data);
module.putUserData(MODULE_KEY, created);
Set<String> orphanFiles = project.getUserData(ORPHAN_MODULE_FILES);
if (orphanFiles != null) {
orphanFiles.remove(created.getModuleFilePath());
}
// Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via external system)
final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(created);
modifiableRootModel.inheritSdk();
RootPolicy<Object> visitor = new RootPolicy<Object>() {
@Override
public Object visitLibraryOrderEntry(LibraryOrderEntry libraryOrderEntry, Object value) {
modifiableRootModel.removeOrderEntry(libraryOrderEntry);
return value;
}
@Override
public Object visitModuleOrderEntry(ModuleOrderEntry moduleOrderEntry, Object value) {
modifiableRootModel.removeOrderEntry(moduleOrderEntry);
return value;
}
};
for (OrderEntry orderEntry : modifiableRootModel.getOrderEntries()) {
orderEntry.accept(visitor, null);
}
}
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class AssignShortcutAction method perform.
@Override
protected void perform(@NotNull Project project, @NotNull ProjectSystemId projectSystemId, @NotNull TaskData taskData, @NotNull AnActionEvent e) {
final ExternalSystemShortcutsManager shortcutsManager = ExternalProjectsManager.getInstance(project).getShortcutsManager();
final String actionId = shortcutsManager.getActionId(taskData.getLinkedExternalProjectPath(), taskData.getName());
if (actionId != null) {
AnAction action = ActionManager.getInstance().getAction(actionId);
if (action == null) {
ExternalSystemNode<?> taskNode = ContainerUtil.getFirstItem(ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext()));
assert taskNode != null;
final String group;
final ModuleNode moduleDataNode = taskNode.findParent(ModuleNode.class);
if (moduleDataNode != null) {
ModuleData moduleData = moduleDataNode.getData();
group = moduleData != null ? moduleData.getInternalName() : null;
} else {
ProjectNode projectNode = taskNode.findParent(ProjectNode.class);
ProjectData projectData = projectNode != null ? projectNode.getData() : null;
group = projectData != null ? projectData.getInternalName() : null;
}
if (group != null) {
ExternalSystemKeymapExtension.getOrRegisterAction(project, group, taskData);
}
}
new EditKeymapsDialog(project, actionId).show();
}
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class ExternalSystemKeymapExtension method createActions.
private static void createActions(Project project, Collection<DataNode<TaskData>> taskNodes) {
ActionManager actionManager = ActionManager.getInstance();
final ExternalSystemShortcutsManager shortcutsManager = ExternalProjectsManager.getInstance(project).getShortcutsManager();
if (actionManager != null) {
for (DataNode<TaskData> each : taskNodes) {
final DataNode<ModuleData> moduleData = ExternalSystemApiUtil.findParent(each, ProjectKeys.MODULE);
if (moduleData == null || moduleData.isIgnored())
continue;
TaskData taskData = each.getData();
ExternalSystemTaskAction eachAction = new ExternalSystemTaskAction(project, moduleData.getData().getInternalName(), taskData);
actionManager.unregisterAction(eachAction.getId());
if (shortcutsManager.hasShortcuts(taskData.getLinkedExternalProjectPath(), taskData.getName())) {
actionManager.registerAction(eachAction.getId(), eachAction);
}
}
}
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData 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 com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class BuildClasspathModuleGradleDataService method importData.
@Override
public void importData(@NotNull final Collection<DataNode<BuildScriptClasspathData>> toImport, @Nullable final ProjectData projectData, @NotNull final Project project, @NotNull final IdeModifiableModelsProvider modelsProvider) {
if (projectData == null || toImport.isEmpty()) {
return;
}
final GradleInstallationManager gradleInstallationManager = ServiceManager.getService(GradleInstallationManager.class);
ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
assert manager != null;
AbstractExternalSystemLocalSettings localSettings = manager.getLocalSettingsProvider().fun(project);
final String linkedExternalProjectPath = projectData.getLinkedExternalProjectPath();
final File gradleHomeDir = toImport.iterator().next().getData().getGradleHomeDir();
final GradleLocalSettings gradleLocalSettings = GradleLocalSettings.getInstance(project);
if (gradleHomeDir != null) {
gradleLocalSettings.setGradleHome(linkedExternalProjectPath, gradleHomeDir.getPath());
}
final GradleProjectSettings settings = GradleSettings.getInstance(project).getLinkedProjectSettings(linkedExternalProjectPath);
final NotNullLazyValue<Set<String>> externalProjectGradleSdkLibs = new NotNullLazyValue<Set<String>>() {
@NotNull
@Override
protected Set<String> compute() {
final Set<String> gradleSdkLibraries = ContainerUtil.newLinkedHashSet();
File gradleHome = gradleInstallationManager.getGradleHome(project, linkedExternalProjectPath);
if (gradleHome != null && gradleHome.isDirectory()) {
final Collection<File> libraries = gradleInstallationManager.getClassRoots(project, linkedExternalProjectPath);
if (libraries != null) {
for (File library : libraries) {
gradleSdkLibraries.add(FileUtil.toCanonicalPath(library.getPath()));
}
}
}
return gradleSdkLibraries;
}
};
final NotNullLazyValue<Set<String>> buildSrcProjectsRoots = new NotNullLazyValue<Set<String>>() {
@NotNull
@Override
protected Set<String> compute() {
Set<String> result = new LinkedHashSet<>();
//// add main java root of buildSrc project
result.add(linkedExternalProjectPath + "/buildSrc/src/main/java");
//// add main groovy root of buildSrc project
result.add(linkedExternalProjectPath + "/buildSrc/src/main/groovy");
for (Module module : modelsProvider.getModules(projectData)) {
final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (projectPath != null && StringUtil.startsWith(projectPath, linkedExternalProjectPath + "/buildSrc")) {
final List<String> sourceRoots = ContainerUtil.map(modelsProvider.getSourceRoots(module, false), VirtualFile::getPath);
result.addAll(sourceRoots);
}
}
return result;
}
};
final Map<String, ExternalProjectBuildClasspathPojo> localProjectBuildClasspath = ContainerUtil.newHashMap(localSettings.getProjectBuildClasspath());
for (final DataNode<BuildScriptClasspathData> node : toImport) {
if (GradleConstants.SYSTEM_ID.equals(node.getData().getOwner())) {
DataNode<ModuleData> moduleDataNode = ExternalSystemApiUtil.findParent(node, ProjectKeys.MODULE);
if (moduleDataNode == null)
continue;
String externalModulePath = moduleDataNode.getData().getLinkedExternalProjectPath();
if (settings == null || settings.getDistributionType() == null) {
LOG.warn("Gradle SDK distribution type was not configured for the project at " + linkedExternalProjectPath);
}
final Set<String> buildClasspath = ContainerUtil.newLinkedHashSet();
BuildScriptClasspathData buildScriptClasspathData = node.getData();
for (BuildScriptClasspathData.ClasspathEntry classpathEntry : buildScriptClasspathData.getClasspathEntries()) {
for (String path : classpathEntry.getSourcesFile()) {
buildClasspath.add(FileUtil.toCanonicalPath(path));
}
for (String path : classpathEntry.getClassesFile()) {
buildClasspath.add(FileUtil.toCanonicalPath(path));
}
}
ExternalProjectBuildClasspathPojo projectBuildClasspathPojo = localProjectBuildClasspath.get(linkedExternalProjectPath);
if (projectBuildClasspathPojo == null) {
projectBuildClasspathPojo = new ExternalProjectBuildClasspathPojo(moduleDataNode.getData().getExternalName(), ContainerUtil.newArrayList(), ContainerUtil.newHashMap());
localProjectBuildClasspath.put(linkedExternalProjectPath, projectBuildClasspathPojo);
}
List<String> projectBuildClasspath = ContainerUtil.newArrayList(externalProjectGradleSdkLibs.getValue());
projectBuildClasspath.addAll(buildSrcProjectsRoots.getValue());
projectBuildClasspathPojo.setProjectBuildClasspath(projectBuildClasspath);
projectBuildClasspathPojo.getModulesBuildClasspath().put(externalModulePath, new ExternalModuleBuildClasspathPojo(externalModulePath, ContainerUtil.newArrayList(buildClasspath)));
}
}
localSettings.setProjectBuildClasspath(localProjectBuildClasspath);
if (!project.isDisposed()) {
GradleBuildClasspathManager.getInstance(project).reload();
}
}
Aggregations