use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class ExternalProjectsDataStorage method convert.
private static DataNode<ProjectData> convert(@NotNull ProjectSystemId systemId, @NotNull ExternalProjectPojo rootProject, @NotNull Collection<ExternalProjectPojo> childProjects, @NotNull Map<String, Collection<ExternalTaskPojo>> availableTasks) {
ProjectData projectData = new ProjectData(systemId, rootProject.getName(), rootProject.getPath(), rootProject.getPath());
DataNode<ProjectData> projectDataNode = new DataNode<>(PROJECT, projectData, null);
for (ExternalProjectPojo childProject : childProjects) {
String moduleConfigPath = childProject.getPath();
ModuleData moduleData = new ModuleData(childProject.getName(), systemId, ModuleTypeId.JAVA_MODULE, childProject.getName(), moduleConfigPath, moduleConfigPath);
final DataNode<ModuleData> moduleDataNode = projectDataNode.createChild(MODULE, moduleData);
final Collection<ExternalTaskPojo> moduleTasks = availableTasks.get(moduleConfigPath);
if (moduleTasks != null) {
for (ExternalTaskPojo moduleTask : moduleTasks) {
TaskData taskData = new TaskData(systemId, moduleTask.getName(), moduleConfigPath, moduleTask.getDescription());
moduleDataNode.createChild(TASK, taskData);
}
}
}
return projectDataNode;
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class ModuleDependencyDataService method importData.
@Override
protected Map<OrderEntry, OrderAware> importData(@NotNull final Collection<DataNode<ModuleDependencyData>> toImport, @NotNull final Module module, @NotNull final IdeModifiableModelsProvider modelsProvider) {
final Map<Pair<String, DependencyScope>, ModuleOrderEntry> /* dependency module scope */
toRemove = ContainerUtilRt.newHashMap();
final Map<OrderEntry, OrderAware> orderEntryDataMap = ContainerUtil.newLinkedHashMap();
for (OrderEntry entry : modelsProvider.getOrderEntries(module)) {
if (entry instanceof ModuleOrderEntry) {
ModuleOrderEntry e = (ModuleOrderEntry) entry;
toRemove.put(Pair.create(e.getModuleName(), e.getScope()), e);
}
}
final Set<ModuleDependencyData> processed = ContainerUtil.newHashSet();
final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
for (DataNode<ModuleDependencyData> dependencyNode : toImport) {
final ModuleDependencyData dependencyData = dependencyNode.getData();
if (processed.contains(dependencyData))
continue;
processed.add(dependencyData);
toRemove.remove(Pair.create(dependencyData.getInternalName(), dependencyData.getScope()));
final ModuleData moduleData = dependencyData.getTarget();
Module ideDependencyModule = modelsProvider.findIdeModule(moduleData);
ModuleOrderEntry orderEntry;
if (module.equals(ideDependencyModule)) {
// skip recursive module dependency check
continue;
} else {
if (ideDependencyModule == null) {
LOG.warn(String.format("Can't import module dependency for '%s' module. Reason: target module (%s) is not found at the ide", module.getName(), dependencyData));
}
orderEntry = modelsProvider.findIdeModuleDependency(dependencyData, module);
if (orderEntry == null) {
orderEntry = ReadAction.compute(() -> ideDependencyModule == null ? modifiableRootModel.addInvalidModuleEntry(moduleData.getInternalName()) : modifiableRootModel.addModuleOrderEntry(ideDependencyModule));
}
}
orderEntry.setScope(dependencyData.getScope());
orderEntry.setExported(dependencyData.isExported());
final boolean productionOnTestDependency = dependencyData.isProductionOnTestDependency();
if (orderEntry instanceof ModuleOrderEntryImpl) {
((ModuleOrderEntryImpl) orderEntry).setProductionOnTestDependency(productionOnTestDependency);
} else if (productionOnTestDependency) {
LOG.warn("Unable to set productionOnTestDependency for entry: " + orderEntry);
}
orderEntryDataMap.put(orderEntry, dependencyData);
}
if (!toRemove.isEmpty()) {
removeData(toRemove.values(), module, modelsProvider);
}
return orderEntryDataMap;
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class AbstractModuleDataService method setModuleOptions.
protected void setModuleOptions(Module module, DataNode<E> moduleDataNode) {
ModuleData moduleData = moduleDataNode.getData();
module.putUserData(MODULE_DATA_KEY, moduleData);
module.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, moduleData.getOwner().toString());
module.setOption(ExternalSystemConstants.LINKED_PROJECT_ID_KEY, moduleData.getId());
module.setOption(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY, moduleData.getLinkedExternalProjectPath());
final ProjectData projectData = moduleDataNode.getData(ProjectKeys.PROJECT);
module.setOption(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY, projectData != null ? projectData.getLinkedExternalProjectPath() : "");
if (moduleData.getGroup() != null) {
module.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_MODULE_GROUP_KEY, moduleData.getGroup());
}
if (moduleData.getVersion() != null) {
module.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_MODULE_VERSION_KEY, moduleData.getVersion());
}
// clear maven option
module.clearOption("org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule");
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class ExternalProjectDataSelectorDialog method createRoot.
private Couple<CheckedTreeNode> createRoot() {
final Map<DataNode, DataNodeCheckedTreeNode> treeNodeMap = ContainerUtil.newIdentityTroveMap();
final DataNodeCheckedTreeNode[] preselectedNode = { null };
final DataNodeCheckedTreeNode[] rootModuleNode = { null };
final MultiMap<String, String> moduleDependenciesMap = MultiMap.create();
final Map<String, DataNode<Identifiable>> modulesNodeMap = ContainerUtil.newHashMap();
for (DataNode<ModuleDependencyData> moduleDependencyDataNode : ExternalSystemApiUtil.findAllRecursively(myProjectInfo.getExternalProjectStructure(), ProjectKeys.MODULE_DEPENDENCY)) {
final ModuleDependencyData moduleDependencyData = moduleDependencyDataNode.getData();
moduleDependenciesMap.putValue(moduleDependencyData.getOwnerModule().getId(), moduleDependencyData.getTarget().getId());
}
final int[] modulesCount = { 0 };
ExternalSystemApiUtil.visit(myProjectInfo.getExternalProjectStructure(), node -> {
final Key key = node.getKey();
if (!myPublicKeys.contains(key))
return;
DataNode modifiableDataNode = getModifiableDataNode(node);
if (myDependencyAwareDataKeys.contains(key)) {
modulesCount[0]++;
}
if (modifiableDataNode.isIgnored() && myShowSelectedRowsOnly)
return;
DataNodeCheckedTreeNode treeNode = treeNodeMap.get(node);
if (treeNode == null) {
treeNode = new DataNodeCheckedTreeNode(node);
if (myDependencyAwareDataKeys.contains(key)) {
final Identifiable moduleData = (Identifiable) node.getData();
modulesNodeMap.put(moduleData.getId(), (DataNode<Identifiable>) node);
}
if (myPreselectedNodeObject != null && myPreselectedNodeObject.equals(node.getData())) {
preselectedNode[0] = treeNode;
}
if (node.getData() instanceof ModuleData) {
if (key.equals(ProjectKeys.MODULE) && myProjectInfo.getExternalProjectPath().equals(((ModuleData) node.getData()).getLinkedExternalProjectPath())) {
rootModuleNode[0] = treeNode;
}
}
treeNode.setEnabled(myIgnorableKeys.contains(key));
treeNodeMap.put(node, treeNode);
final DataNode parent = node.getParent();
if (parent != null) {
final CheckedTreeNode parentTreeNode = treeNodeMap.get(parent);
if (parentTreeNode != null) {
parentTreeNode.add(treeNode);
}
}
}
});
myModulesCount = modulesCount[0];
dependentNodeMap.clear();
for (String moduleId : moduleDependenciesMap.keySet()) {
final Collection<String> moduleDependencies = moduleDependenciesMap.get(moduleId);
final DataNode<Identifiable> moduleNode = modulesNodeMap.get(moduleId);
if (moduleNode != null) {
dependentNodeMap.putValues(moduleNode, ContainerUtil.mapNotNull(moduleDependencies, modulesNodeMap::get));
}
}
final CheckedTreeNode root = new CheckedTreeNode(null);
final DataNodeCheckedTreeNode projectNode = treeNodeMap.get(myProjectInfo.getExternalProjectStructure());
String rootModuleComment = "root module";
if (rootModuleNode[0] != null && projectNode != null) {
rootModuleNode[0].comment = rootModuleComment;
if (!projectNode.isNodeChild(rootModuleNode[0])) {
projectNode.add(rootModuleNode[0]);
}
}
List<TreeNode> nodes = projectNode != null ? TreeUtil.listChildren(projectNode) : ContainerUtil.emptyList();
Collections.sort(nodes, (o1, o2) -> {
if (o1 instanceof DataNodeCheckedTreeNode && o2 instanceof DataNodeCheckedTreeNode) {
if (rootModuleComment.equals(((DataNodeCheckedTreeNode) o1).comment))
return -1;
if (rootModuleComment.equals(((DataNodeCheckedTreeNode) o2).comment))
return 1;
return StringUtil.naturalCompare(((DataNodeCheckedTreeNode) o1).text, ((DataNodeCheckedTreeNode) o2).text);
}
return 0;
});
TreeUtil.addChildrenTo(root, nodes);
return Couple.of(root, preselectedNode[0]);
}
use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.
the class OpenTasksActivationManagerAction method isEnabled.
@Override
protected boolean isEnabled(AnActionEvent e) {
if (!super.isEnabled(e))
return false;
final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
if (selectedNodes == null || selectedNodes.size() != 1)
return false;
final Object externalData = selectedNodes.get(0).getData();
ProjectSystemId projectSystemId = getSystemId(e);
e.getPresentation().setText(ExternalSystemBundle.message("external.system.task.activation.title"));
e.getPresentation().setDescription(ExternalSystemBundle.message("external.system.task.activation.description", projectSystemId.getReadableName()));
final boolean isProjectNode = externalData instanceof ProjectData || externalData instanceof ModuleData;
return isProjectNode && StringUtil.isNotEmpty(((ExternalConfigPathAware) externalData).getLinkedExternalProjectPath());
}
Aggregations