Search in sources :

Example 1 with ModuleData

use of com.intellij.openapi.externalSystem.model.project.ModuleData in project intellij-community by JetBrains.

the class ProjectDataManager method importData.

@SuppressWarnings("unchecked")
public void importData(@NotNull Collection<DataNode<?>> nodes, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider, boolean synchronous) {
    if (project.isDisposed())
        return;
    MultiMap<Key<?>, DataNode<?>> grouped = ExternalSystemApiUtil.recursiveGroup(nodes);
    for (Key<?> key : myServices.getValue().keySet()) {
        if (!grouped.containsKey(key)) {
            grouped.put(key, Collections.<DataNode<?>>emptyList());
        }
    }
    final Collection<DataNode<?>> projects = grouped.get(ProjectKeys.PROJECT);
    // only one project(can be multi-module project) expected for per single import
    assert projects.size() == 1 || projects.isEmpty();
    final DataNode<ProjectData> projectNode = (DataNode<ProjectData>) ContainerUtil.getFirstItem(projects);
    final ProjectData projectData;
    ProjectSystemId projectSystemId;
    if (projectNode != null) {
        projectData = projectNode.getData();
        projectSystemId = projectNode.getData().getOwner();
        ExternalProjectsDataStorage.getInstance(project).saveInclusionSettings(projectNode);
    } else {
        projectData = null;
        DataNode<ModuleData> aModuleNode = (DataNode<ModuleData>) ContainerUtil.getFirstItem(grouped.get(ProjectKeys.MODULE));
        projectSystemId = aModuleNode != null ? aModuleNode.getData().getOwner() : null;
    }
    if (projectSystemId != null) {
        ExternalSystemUtil.scheduleExternalViewStructureUpdate(project, projectSystemId);
    }
    List<Runnable> onSuccessImportTasks = ContainerUtil.newSmartList();
    try {
        final Set<Map.Entry<Key<?>, Collection<DataNode<?>>>> entries = grouped.entrySet();
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
            indicator.setIndeterminate(false);
        }
        final int size = entries.size();
        int count = 0;
        List<Runnable> postImportTasks = ContainerUtil.newSmartList();
        for (Map.Entry<Key<?>, Collection<DataNode<?>>> entry : entries) {
            if (indicator != null) {
                String message = ExternalSystemBundle.message("progress.update.text", projectSystemId != null ? projectSystemId.getReadableName() : "", "Refresh " + getReadableText(entry.getKey()));
                indicator.setText(message);
                indicator.setFraction((double) count++ / size);
            }
            doImportData(entry.getKey(), entry.getValue(), projectData, project, modelsProvider, postImportTasks, onSuccessImportTasks);
        }
        for (Runnable postImportTask : postImportTasks) {
            postImportTask.run();
        }
        commit(modelsProvider, project, synchronous, "Imported data");
        if (indicator != null) {
            indicator.setIndeterminate(true);
        }
    } catch (Throwable t) {
        dispose(modelsProvider, project, synchronous);
        ExceptionUtil.rethrowAllAsUnchecked(t);
    }
    for (Runnable onSuccessImportTask : ContainerUtil.reverse(onSuccessImportTasks)) {
        onSuccessImportTask.run();
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 2 with ModuleData

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;
}
Also used : ExternalTaskPojo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData)

Example 3 with ModuleData

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;
}
Also used : ModuleOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleOrderEntryImpl) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderAware(com.intellij.openapi.externalSystem.model.project.OrderAware) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ModuleDependencyData(com.intellij.openapi.externalSystem.model.project.ModuleDependencyData) Pair(com.intellij.openapi.util.Pair)

Example 4 with ModuleData

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");
}
Also used : ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 5 with ModuleData

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]);
}
Also used : Identifiable(com.intellij.openapi.externalSystem.model.project.Identifiable) DataNode(com.intellij.openapi.externalSystem.model.DataNode) TreeNode(javax.swing.tree.TreeNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ModuleDependencyData(com.intellij.openapi.externalSystem.model.project.ModuleDependencyData) Key(com.intellij.openapi.externalSystem.model.Key)

Aggregations

ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)36 DataNode (com.intellij.openapi.externalSystem.model.DataNode)22 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)13 Module (com.intellij.openapi.module.Module)9 NotNull (org.jetbrains.annotations.NotNull)6 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)5 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)2 SourceFileContainerInfo (com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2 ModuleDependencyData (com.intellij.openapi.externalSystem.model.project.ModuleDependencyData)2 AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)2 ProjectNode (com.intellij.openapi.externalSystem.view.ProjectNode)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 Variant (com.android.builder.model.Variant)1