Search in sources :

Example 31 with ModuleData

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

the class GradleTestRunConfigurationProducer method getTasksToRun.

@NotNull
public static List<String> getTasksToRun(@NotNull Module module) {
    for (GradleTestTasksProvider provider : GradleTestTasksProvider.EP_NAME.getExtensions()) {
        final List<String> tasks = provider.getTasks(module);
        if (!ContainerUtil.isEmpty(tasks)) {
            return tasks;
        }
    }
    final List<String> result;
    final String externalProjectId = ExternalSystemApiUtil.getExternalProjectId(module);
    if (externalProjectId == null)
        return ContainerUtil.emptyList();
    final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (projectPath == null)
        return ContainerUtil.emptyList();
    final ExternalProjectInfo externalProjectInfo = ExternalSystemUtil.getExternalProjectInfo(module.getProject(), GradleConstants.SYSTEM_ID, projectPath);
    if (externalProjectInfo == null)
        return ContainerUtil.emptyList();
    boolean trimSourceSet = false;
    if (StringUtil.endsWith(externalProjectId, ":test") || StringUtil.endsWith(externalProjectId, ":main")) {
        result = TEST_SOURCE_SET_TASKS;
        trimSourceSet = true;
    } else {
        final DataNode<ModuleData> moduleNode = GradleProjectResolverUtil.findModule(externalProjectInfo.getExternalProjectStructure(), projectPath);
        if (moduleNode == null)
            return ContainerUtil.emptyList();
        final DataNode<TaskData> taskNode;
        final String sourceSetId = StringUtil.substringAfter(externalProjectId, moduleNode.getData().getExternalName() + ':');
        if (sourceSetId == null) {
            taskNode = ExternalSystemApiUtil.find(moduleNode, ProjectKeys.TASK, node -> GradleCommonClassNames.GRADLE_API_TASKS_TESTING_TEST.equals(node.getData().getType()) && StringUtil.equals("test", node.getData().getName()));
        } else {
            trimSourceSet = true;
            taskNode = ExternalSystemApiUtil.find(moduleNode, ProjectKeys.TASK, node -> GradleCommonClassNames.GRADLE_API_TASKS_TESTING_TEST.equals(node.getData().getType()) && StringUtil.startsWith(sourceSetId, node.getData().getName()));
        }
        if (taskNode == null)
            return ContainerUtil.emptyList();
        final String taskName = taskNode.getData().getName();
        result = ContainerUtil.list("clean" + StringUtil.capitalize(taskName), taskName);
    }
    final String path;
    if (!externalProjectId.startsWith(":")) {
        path = ":";
    } else {
        final List<String> pathParts = StringUtil.split(externalProjectId, ":");
        if (trimSourceSet && !pathParts.isEmpty())
            pathParts.remove(pathParts.size() - 1);
        final String join = StringUtil.join(pathParts, ":");
        path = ":" + join + (!join.isEmpty() ? ":" : "");
    }
    return ContainerUtil.map(result, s -> path + s);
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ProjectKeys(com.intellij.openapi.externalSystem.model.ProjectKeys) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ConfigurationType(com.intellij.execution.configurations.ConfigurationType) ContainerUtil(com.intellij.util.containers.ContainerUtil) GradleSystemRunningSettings(org.jetbrains.plugins.gradle.settings.GradleSystemRunningSettings) ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) DataNode(com.intellij.openapi.externalSystem.model.DataNode) PsiElement(com.intellij.psi.PsiElement) PreferredTestRunner(org.jetbrains.plugins.gradle.settings.GradleSystemRunningSettings.PreferredTestRunner) RunManagerEx(com.intellij.execution.RunManagerEx) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) StringUtil(com.intellij.openapi.util.text.StringUtil) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) GradleProjectResolverUtil(org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil) ExternalSystemUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUtil) Nullable(org.jetbrains.annotations.Nullable) GradleCommonClassNames(org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames) List(java.util.List) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) NotNull(org.jetbrains.annotations.NotNull)

Example 32 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 33 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)

Example 34 with ModuleData

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

the class GradleExecutionWorkspace method findModuleDataByName.

public ModuleData findModuleDataByName(String moduleName) {
    ModuleData result = null;
    Pair<DataNode<ModuleData>, IdeaModule> modulePair = myModuleMap.get(moduleName);
    if (modulePair == null) {
        modulePair = myModuleMap.get(":" + moduleName);
    }
    if (modulePair != null) {
        return modulePair.first.getData();
    }
    for (GradleBuildParticipant buildParticipant : myBuildParticipants) {
        result = buildParticipant.findModuleDataByName(moduleName);
        if (result != null)
            break;
    }
    return result;
}
Also used : IdeaModule(org.gradle.tooling.model.idea.IdeaModule) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData)

Example 35 with ModuleData

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

the class ToolWindowModuleService method processData.

@Override
protected void processData(@NotNull final Collection<DataNode<ModuleData>> nodes, @NotNull Project project) {
    if (nodes.isEmpty()) {
        return;
    }
    ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final MultiMap<DataNode<ProjectData>, DataNode<ModuleData>> grouped = ExternalSystemApiUtil.groupBy(nodes, ProjectKeys.PROJECT);
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> data = ContainerUtilRt.newHashMap();
    for (Map.Entry<DataNode<ProjectData>, Collection<DataNode<ModuleData>>> entry : grouped.entrySet()) {
        data.put(ExternalProjectPojo.from(entry.getKey().getData()), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
    }
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Set<String> pathsToForget = detectRenamedProjects(data, settings.getAvailableProjects());
    if (!pathsToForget.isEmpty()) {
        settings.forgetExternalProjects(pathsToForget);
    }
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = ContainerUtilRt.newHashMap(settings.getAvailableProjects());
    projects.putAll(data);
    settings.setAvailableProjects(projects);
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) MultiMap(com.intellij.util.containers.MultiMap)

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