Search in sources :

Example 21 with ModuleData

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

Example 22 with ModuleData

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();
    }
}
Also used : ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) EditKeymapsDialog(com.intellij.openapi.keymap.impl.ui.EditKeymapsDialog) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectNode(com.intellij.openapi.externalSystem.view.ProjectNode) AnAction(com.intellij.openapi.actionSystem.AnAction) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ModuleNode(com.intellij.openapi.externalSystem.view.ModuleNode)

Example 23 with ModuleData

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

Example 24 with ModuleData

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);
    }
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) DataNode(com.intellij.openapi.externalSystem.model.DataNode) GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) BuildParticipant(org.jetbrains.plugins.gradle.model.data.BuildParticipant) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData)

Example 25 with ModuleData

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();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) NotNullLazyValue(com.intellij.openapi.util.NotNullLazyValue) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleLocalSettings(org.jetbrains.plugins.gradle.settings.GradleLocalSettings) GradleInstallationManager(org.jetbrains.plugins.gradle.service.GradleInstallationManager) ExternalProjectBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo) ExternalModuleBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalModuleBuildClasspathPojo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) BuildScriptClasspathData(org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

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