Search in sources :

Example 11 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class DataNodeCaches method isCacheMissingModels.

public boolean isCacheMissingModels(@NotNull DataNode<ProjectData> cache) {
    Collection<DataNode<ModuleData>> moduleDataNodes = findAll(cache, MODULE);
    if (!moduleDataNodes.isEmpty()) {
        Map<String, DataNode<ModuleData>> moduleDataNodesByName = indexByModuleName(moduleDataNodes);
        ModuleManager moduleManager = ModuleManager.getInstance(myProject);
        for (Module module : moduleManager.getModules()) {
            DataNode<ModuleData> moduleDataNode = moduleDataNodesByName.get(module.getName());
            if (moduleDataNode == null) {
                // When a Gradle facet is present, there should be a cache node for the module.
                GradleFacet gradleFacet = GradleFacet.getInstance(module);
                if (gradleFacet != null) {
                    return true;
                }
            } else if (isCacheMissingModels(moduleDataNode, module)) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 12 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class Projects method doSelectiveImport.

/**
   * Reuse external system 'selective import' feature for importing of the project sub-set.
   * And do not ignore projectNode children data, e.g. project libraries
   */
private static void doSelectiveImport(@NotNull Collection<DataNode<ModuleData>> enabledModules, @NotNull Project project) {
    ProjectDataManager dataManager = ServiceManager.getService(ProjectDataManager.class);
    DataNode<ProjectData> projectNode = enabledModules.isEmpty() ? null : findParent(enabledModules.iterator().next(), PROJECT);
    // do not ignore projectNode child data, e.g. project libraries
    if (projectNode != null) {
        final Collection<DataNode<ModuleData>> allModules = findAll(projectNode, ProjectKeys.MODULE);
        if (enabledModules.size() != allModules.size()) {
            final Set<DataNode<ModuleData>> moduleToIgnore = ContainerUtil.newIdentityTroveSet(allModules);
            moduleToIgnore.removeAll(enabledModules);
            for (DataNode<ModuleData> moduleNode : moduleToIgnore) {
                visit(moduleNode, node -> node.setIgnored(true));
            }
        }
        dataManager.importData(projectNode, project, true);
    } else {
        dataManager.importData(enabledModules, project, true);
    }
}
Also used : ProjectDataManager(com.intellij.openapi.externalSystem.service.project.ProjectDataManager) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 13 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class ProjectSubset method findAndIncludeModules.

public void findAndIncludeModules(@NotNull Collection<String> moduleGradlePaths) {
    DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
    if (projectInfo == null) {
        return;
    }
    Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
    if (!moduleInfos.isEmpty()) {
        Project project = myProject;
        new Task.Modal(project, "Finding Missing Modules", false) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                String[] originalSelection = getSelection();
                Set<String> selection = originalSelection != null ? Sets.newHashSet(originalSelection) : Sets.newHashSet();
                List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
                boolean found = false;
                int doneCount = 0;
                for (DataNode<ModuleData> moduleInfo : moduleInfos) {
                    indicator.setFraction(++doneCount / moduleInfos.size());
                    String name = getNameOf(moduleInfo);
                    if (selection.contains(name)) {
                        selectedModules.add(moduleInfo);
                        continue;
                    }
                    DataNode<GradleModuleModel> gradleProjectNode = find(moduleInfo, GRADLE_MODULE_MODEL);
                    if (gradleProjectNode != null) {
                        GradleModuleModel gradleModuleModel = gradleProjectNode.getData();
                        if (moduleGradlePaths.contains(gradleModuleModel.getGradlePath())) {
                            selection.add(name);
                            selectedModules.add(moduleInfo);
                            found = true;
                        }
                    }
                }
                if (!selectedModules.isEmpty() && found) {
                    setSelection(selectedModules);
                    populate(project, projectInfo, selectedModules, DEFAULT_REQUEST);
                }
            }
        }.queue();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 14 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class UniquePathModuleValidatorStrategy method fixAndReportFoundIssues.

@Override
void fixAndReportFoundIssues() {
    Set<String> modulePaths = myModulesByPath.keySet();
    for (String modulePath : modulePaths) {
        Collection<Module> modules = myModulesByPath.get(modulePath);
        int moduleCount = modules.size();
        if (moduleCount <= 1) {
            continue;
        }
        StringBuilder msg = new StringBuilder();
        msg.append("The modules [");
        int i = 0;
        Set<String> moduleNames = Sets.newHashSet();
        for (Module module : modules) {
            if (i++ != 0) {
                msg.append(", ");
            }
            String name = module.getName();
            moduleNames.add(name);
            msg.append("'").append(name).append("'");
        }
        msg.append("] point to same directory in the file system.");
        String[] lines = { msg.toString(), "Each module has to have a unique path." };
        SyncMessage message = new SyncMessage(PROJECT_STRUCTURE_ISSUES, ERROR, lines);
        List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList();
        Project project = getProject();
        if (ProjectSubset.getInstance(project).isFeatureEnabled()) {
            DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(project).getCachedProjectData();
            if (projectInfo != null) {
                Collection<DataNode<ModuleData>> cachedModules = findAll(projectInfo, MODULE);
                for (DataNode<ModuleData> moduleNode : cachedModules) {
                    if (moduleNames.contains(moduleNode.getData().getExternalName())) {
                        modulesToDisplayInDialog.add(moduleNode);
                    }
                }
            }
        }
        if (!modulesToDisplayInDialog.isEmpty()) {
            message.add(new AddOrRemoveModulesHyperlink());
        }
        SyncMessages.getInstance(project).report(message);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 15 with DataNode

use of com.intellij.openapi.externalSystem.model.DataNode in project android by JetBrains.

the class ModulesToImportDialogSelectionTest method createModule.

@NotNull
private static DataNode<ModuleData> createModule(@NotNull String name) {
    String path = "~/project/" + name;
    ModuleData data = new ModuleData(name, GradleConstants.SYSTEM_ID, StdModuleTypes.JAVA.getId(), name, path, path);
    return new DataNode<>(MODULE, data, null);
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DataNode (com.intellij.openapi.externalSystem.model.DataNode)51 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)22 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)14 NotNull (org.jetbrains.annotations.NotNull)12 Module (com.intellij.openapi.module.Module)11 File (java.io.File)9 Project (com.intellij.openapi.project.Project)7 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)6 Nullable (org.jetbrains.annotations.Nullable)6 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)5 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)4 IdeaModule (org.gradle.tooling.model.idea.IdeaModule)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 Pair (com.intellij.openapi.util.Pair)3 MultiMap (com.intellij.util.containers.MultiMap)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2