Search in sources :

Example 11 with ProjectData

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

the class ContentRootDataService method importData.

@Override
public void importData(@NotNull Collection<DataNode<ContentRootData>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        return;
    }
    boolean isNewlyImportedProject = project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) == Boolean.TRUE;
    boolean forceDirectoriesCreation = false;
    DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(toImport.iterator().next(), ProjectKeys.PROJECT);
    if (projectDataNode != null) {
        forceDirectoriesCreation = projectDataNode.getUserData(CREATE_EMPTY_DIRECTORIES) == Boolean.TRUE;
    }
    Set<Module> modulesToExpand = ContainerUtil.newTroveSet();
    MultiMap<DataNode<ModuleData>, DataNode<ContentRootData>> byModule = ExternalSystemApiUtil.groupBy(toImport, ModuleData.class);
    for (Map.Entry<DataNode<ModuleData>, Collection<DataNode<ContentRootData>>> entry : byModule.entrySet()) {
        Module module = entry.getKey().getUserData(AbstractModuleDataService.MODULE_KEY);
        module = module != null ? module : modelsProvider.findIdeModule(entry.getKey().getData());
        if (module == null) {
            LOG.warn(String.format("Can't import content roots. Reason: target module (%s) is not found at the ide. Content roots: %s", entry.getKey(), entry.getValue()));
            continue;
        }
        importData(modelsProvider, entry.getValue(), module, forceDirectoriesCreation);
        if (forceDirectoriesCreation || (isNewlyImportedProject && projectData != null && projectData.getLinkedExternalProjectPath().equals(ExternalSystemApiUtil.getExternalProjectPath(module)))) {
            modulesToExpand.add(module);
        }
    }
    if (!modulesToExpand.isEmpty()) {
        for (Module module : modulesToExpand) {
            String productionModuleName = modelsProvider.getProductionModuleName(module);
            if (productionModuleName == null || !modulesToExpand.contains(modelsProvider.findIdeModule(productionModuleName))) {
                VirtualFile[] roots = modelsProvider.getModifiableRootModel(module).getContentRoots();
                if (roots.length > 0) {
                    VirtualFile virtualFile = roots[0];
                    ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
                        final ProjectView projectView = ProjectView.getInstance(project);
                        projectView.changeViewCB(ProjectViewPane.ID, null).doWhenProcessed(() -> projectView.selectCB(null, virtualFile, false));
                    });
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentRootData(com.intellij.openapi.externalSystem.model.project.ContentRootData) Collection(java.util.Collection) ProjectView(com.intellij.ide.projectView.ProjectView) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 12 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData 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());
}
Also used : ExternalConfigPathAware(com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 13 with ProjectData

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

the class CachedModuleDataFinder method findModuleData.

@Nullable
public DataNode<ModuleData> findModuleData(@NotNull Module module) {
    final String rootProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
    if (rootProjectPath == null)
        return null;
    final String projectId = ExternalSystemApiUtil.getExternalProjectId(module);
    if (projectId == null)
        return null;
    final String externalProjectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (externalProjectPath == null || StringUtil.endsWith(externalProjectPath, "buildSrc"))
        return null;
    ExternalProjectInfo projectData = ProjectDataManager.getInstance().getExternalProjectData(module.getProject(), GradleConstants.SYSTEM_ID, rootProjectPath);
    if (projectData == null)
        return null;
    DataNode<ProjectData> projectStructure = projectData.getExternalProjectStructure();
    if (projectStructure == null)
        return null;
    return findModuleData(projectStructure, externalProjectPath);
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with ProjectData

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

the class GradleProjectImportBuilder method applyExtraSettings.

@Override
protected void applyExtraSettings(@NotNull WizardContext context) {
    DataNode<ProjectData> node = getExternalProjectNode();
    if (node == null) {
        return;
    }
    DataNode<JavaProjectData> javaProjectNode = ExternalSystemApiUtil.find(node, JavaProjectData.KEY);
    if (javaProjectNode != null) {
        JavaProjectData data = javaProjectNode.getData();
        context.setCompilerOutputDirectory(data.getCompileOutputPath());
        JavaSdkVersion version = data.getJdkVersion();
        Sdk jdk = findJdk(version);
        if (jdk != null) {
            context.setProjectJdk(jdk);
        }
    }
}
Also used : JavaProjectData(com.intellij.externalSystem.JavaProjectData) JavaProjectData(com.intellij.externalSystem.JavaProjectData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 15 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData 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)

Aggregations

ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)40 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)13 DataNode (com.intellij.openapi.externalSystem.model.DataNode)12 Project (com.intellij.openapi.project.Project)8 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MultiMap (com.intellij.util.containers.MultiMap)4 NotNull (org.jetbrains.annotations.NotNull)4 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)3 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 Module (com.intellij.openapi.module.Module)3 Task (com.intellij.openapi.progress.Task)3 DataNodeCaches (com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches)2 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2