Search in sources :

Example 31 with DataNode

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

the class GradleProjectResolver method mergeSourceSetContentRoots.

private static void mergeSourceSetContentRoots(@NotNull Map<String, Pair<DataNode<ModuleData>, IdeaModule>> moduleMap, @NotNull ProjectResolverContext resolverCtx) {
    final Factory<Counter> counterFactory = () -> new Counter();
    final Map<String, Counter> weightMap = ContainerUtil.newHashMap();
    for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) {
        final DataNode<ModuleData> moduleNode = pair.first;
        for (DataNode<ContentRootData> contentRootNode : ExternalSystemApiUtil.findAll(moduleNode, ProjectKeys.CONTENT_ROOT)) {
            File file = new File(contentRootNode.getData().getRootPath());
            while (file != null) {
                ContainerUtil.getOrCreate(weightMap, file.getPath(), counterFactory).increment();
                file = file.getParentFile();
            }
        }
        for (DataNode<GradleSourceSetData> sourceSetNode : ExternalSystemApiUtil.findAll(moduleNode, GradleSourceSetData.KEY)) {
            final Set<String> set = ContainerUtil.newHashSet();
            for (DataNode<ContentRootData> contentRootNode : ExternalSystemApiUtil.findAll(sourceSetNode, ProjectKeys.CONTENT_ROOT)) {
                File file = new File(contentRootNode.getData().getRootPath());
                while (file != null) {
                    set.add(file.getPath());
                    file = file.getParentFile();
                }
            }
            for (String path : set) {
                ContainerUtil.getOrCreate(weightMap, path, counterFactory).increment();
            }
        }
    }
    for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) {
        final DataNode<ModuleData> moduleNode = pair.first;
        final ExternalProject externalProject = resolverCtx.getExtraProject(pair.second, ExternalProject.class);
        if (externalProject == null)
            continue;
        if (resolverCtx.isResolveModulePerSourceSet()) {
            for (DataNode<GradleSourceSetData> sourceSetNode : ExternalSystemApiUtil.findAll(moduleNode, GradleSourceSetData.KEY)) {
                mergeModuleContentRoots(weightMap, externalProject, sourceSetNode);
            }
        } else {
            mergeModuleContentRoots(weightMap, externalProject, moduleNode);
        }
    }
}
Also used : GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) DataNode(com.intellij.openapi.externalSystem.model.DataNode) File(java.io.File)

Example 32 with DataNode

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

the class GradleProjectResolver method resolveProjectInfo.

@Nullable
@Override
public DataNode<ProjectData> resolveProjectInfo(@NotNull final ExternalSystemTaskId id, @NotNull final String projectPath, final boolean isPreviewMode, @Nullable final GradleExecutionSettings settings, @NotNull final ExternalSystemTaskNotificationListener listener) throws ExternalSystemException, IllegalArgumentException, IllegalStateException {
    if (isPreviewMode) {
        // Create project preview model w/o request to gradle, there are two main reasons for the it:
        // * Slow project open - even the simplest project info provided by gradle can be gathered too long (mostly because of new gradle distribution download and downloading buildscript dependencies)
        // * Ability to open  an invalid projects (e.g. with errors in build scripts)
        String projectName = new File(projectPath).getName();
        ProjectData projectData = new ProjectData(GradleConstants.SYSTEM_ID, projectName, projectPath, projectPath);
        DataNode<ProjectData> projectDataNode = new DataNode<>(ProjectKeys.PROJECT, projectData, null);
        final String ideProjectPath = settings == null ? null : settings.getIdeProjectPath();
        final String mainModuleFileDirectoryPath = ideProjectPath == null ? projectPath : ideProjectPath + "/.idea/modules/";
        projectDataNode.createChild(ProjectKeys.MODULE, new ModuleData(projectName, GradleConstants.SYSTEM_ID, StdModuleTypes.JAVA.getId(), projectName, mainModuleFileDirectoryPath, projectPath)).createChild(ProjectKeys.CONTENT_ROOT, new ContentRootData(GradleConstants.SYSTEM_ID, projectPath));
        return projectDataNode;
    }
    if (settings != null) {
        myHelper.ensureInstalledWrapper(id, projectPath, settings, listener);
    }
    final GradleProjectResolverExtension projectResolverChain = createProjectResolverChain(settings);
    DefaultProjectResolverContext resolverContext = new DefaultProjectResolverContext(id, projectPath, settings, listener, false);
    final DataNode<ProjectData> resultProjectDataNode = myHelper.execute(projectPath, settings, new ProjectConnectionDataNodeFunction(resolverContext, projectResolverChain, false));
    // auto-discover buildSrc project if needed
    final String buildSrcProjectPath = projectPath + "/buildSrc";
    DefaultProjectResolverContext buildSrcResolverCtx = new DefaultProjectResolverContext(id, buildSrcProjectPath, settings, listener, false);
    resolverContext.copyUserDataTo(buildSrcResolverCtx);
    handleBuildSrcProject(resultProjectDataNode, new ProjectConnectionDataNodeFunction(buildSrcResolverCtx, projectResolverChain, true));
    return resultProjectDataNode;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) File(java.io.File) JavaProjectData(com.intellij.externalSystem.JavaProjectData) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with DataNode

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

the class GradleProjectResolver method mergeLibraryAndModuleDependencyData.

private static void mergeLibraryAndModuleDependencyData(DataNode<ProjectData> projectDataNode, @Nullable File gradleHomeDir, @Nullable GradleVersion gradleVersion) {
    final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap = projectDataNode.getUserData(RESOLVED_SOURCE_SETS);
    assert sourceSetMap != null;
    final Map<String, Pair<String, ExternalSystemSourceType>> moduleOutputsMap = projectDataNode.getUserData(MODULES_OUTPUTS);
    assert moduleOutputsMap != null;
    final Map<String, String> artifactsMap = projectDataNode.getUserData(CONFIGURATION_ARTIFACTS);
    assert artifactsMap != null;
    final Collection<DataNode<LibraryDependencyData>> libraryDependencies = ExternalSystemApiUtil.findAllRecursively(projectDataNode, ProjectKeys.LIBRARY_DEPENDENCY);
    for (DataNode<LibraryDependencyData> libraryDependencyDataNode : libraryDependencies) {
        final DataNode<?> libraryNodeParent = libraryDependencyDataNode.getParent();
        if (libraryNodeParent == null)
            continue;
        final LibraryDependencyData libraryDependencyData = libraryDependencyDataNode.getData();
        final LibraryData libraryData = libraryDependencyData.getTarget();
        final Set<String> libraryPaths = libraryData.getPaths(LibraryPathType.BINARY);
        if (libraryPaths.isEmpty())
            continue;
        if (StringUtil.isNotEmpty(libraryData.getExternalName()))
            continue;
        boolean projectDependencyCandidate = libraryPaths.size() == 1 && !libraryDependencyDataNode.getChildren().isEmpty();
        final LinkedList<String> unprocessedPaths = ContainerUtil.newLinkedList(libraryPaths);
        while (!unprocessedPaths.isEmpty()) {
            final String path = unprocessedPaths.remove();
            Set<String> targetModuleOutputPaths = null;
            final String moduleId;
            final Pair<String, ExternalSystemSourceType> sourceTypePair = moduleOutputsMap.get(path);
            if (sourceTypePair == null) {
                moduleId = artifactsMap.get(path);
                if (moduleId != null) {
                    targetModuleOutputPaths = ContainerUtil.set(path);
                }
            } else {
                moduleId = sourceTypePair.first;
            }
            if (moduleId == null)
                continue;
            final Pair<DataNode<GradleSourceSetData>, ExternalSourceSet> pair = sourceSetMap.get(moduleId);
            if (pair == null) {
                continue;
            }
            final ModuleData moduleData = pair.first.getData();
            if (targetModuleOutputPaths == null) {
                final Set<String> compileSet = ContainerUtil.newHashSet();
                Map<ExternalSystemSourceType, String> gradleOutputs = pair.first.getUserData(GRADLE_OUTPUTS);
                if (gradleOutputs != null) {
                    ContainerUtil.addAllNotNull(compileSet, gradleOutputs.get(ExternalSystemSourceType.SOURCE), gradleOutputs.get(ExternalSystemSourceType.RESOURCE));
                }
                if (!compileSet.isEmpty() && ContainerUtil.intersects(libraryPaths, compileSet)) {
                    targetModuleOutputPaths = compileSet;
                } else {
                    final Set<String> testSet = ContainerUtil.newHashSet();
                    if (gradleOutputs != null) {
                        ContainerUtil.addAllNotNull(testSet, gradleOutputs.get(ExternalSystemSourceType.TEST), gradleOutputs.get(ExternalSystemSourceType.TEST_RESOURCE));
                    }
                    if (!testSet.isEmpty() && ContainerUtil.intersects(libraryPaths, testSet)) {
                        targetModuleOutputPaths = testSet;
                    }
                }
            }
            final ModuleData ownerModule = libraryDependencyData.getOwnerModule();
            final ModuleDependencyData moduleDependencyData = new ModuleDependencyData(ownerModule, moduleData);
            moduleDependencyData.setScope(libraryDependencyData.getScope());
            if ("test".equals(pair.second.getName())) {
                moduleDependencyData.setProductionOnTestDependency(true);
            }
            final DataNode<ModuleDependencyData> found = ExternalSystemApiUtil.find(libraryNodeParent, ProjectKeys.MODULE_DEPENDENCY, node -> {
                if (moduleDependencyData.getInternalName().equals(node.getData().getInternalName())) {
                    moduleDependencyData.setModuleDependencyArtifacts(node.getData().getModuleDependencyArtifacts());
                }
                final boolean result;
                if (moduleDependencyData.getScope() == DependencyScope.PROVIDED) {
                    moduleDependencyData.setScope(node.getData().getScope());
                    result = moduleDependencyData.equals(node.getData());
                    moduleDependencyData.setScope(DependencyScope.PROVIDED);
                } else {
                    result = moduleDependencyData.equals(node.getData());
                }
                return result;
            });
            if (targetModuleOutputPaths != null) {
                if (found == null) {
                    DataNode<ModuleDependencyData> moduleDependencyNode = libraryNodeParent.createChild(ProjectKeys.MODULE_DEPENDENCY, moduleDependencyData);
                    if (projectDependencyCandidate) {
                        for (DataNode<?> node : libraryDependencyDataNode.getChildren()) {
                            moduleDependencyNode.addChild(node);
                        }
                    }
                }
                libraryPaths.removeAll(targetModuleOutputPaths);
                unprocessedPaths.removeAll(targetModuleOutputPaths);
                if (libraryPaths.isEmpty()) {
                    libraryDependencyDataNode.clear(true);
                    break;
                }
                continue;
            } else {
                // do not add the path as library dependency if another module dependency is already contain the path as one of its output paths
                if (found != null) {
                    libraryPaths.remove(path);
                    if (libraryPaths.isEmpty()) {
                        libraryDependencyDataNode.clear(true);
                        break;
                    }
                    continue;
                }
            }
            final ExternalSourceDirectorySet directorySet = pair.second.getSources().get(sourceTypePair.second);
            if (directorySet != null) {
                for (File file : directorySet.getSrcDirs()) {
                    libraryData.addPath(LibraryPathType.SOURCE, file.getAbsolutePath());
                }
            }
        }
        if (libraryDependencyDataNode.getParent() != null) {
            if (libraryPaths.size() > 1) {
                List<String> toRemove = ContainerUtil.newSmartList();
                for (String path : libraryPaths) {
                    final File binaryPath = new File(path);
                    if (binaryPath.isFile()) {
                        final LibraryData extractedLibrary = new LibraryData(libraryDependencyData.getOwner(), "");
                        extractedLibrary.addPath(LibraryPathType.BINARY, path);
                        if (gradleHomeDir != null && gradleVersion != null) {
                            attachGradleSdkSources(binaryPath, extractedLibrary, gradleHomeDir, gradleVersion);
                        }
                        LibraryDependencyData extractedDependencyData = new LibraryDependencyData(libraryDependencyData.getOwnerModule(), extractedLibrary, LibraryLevel.MODULE);
                        libraryDependencyDataNode.getParent().createChild(ProjectKeys.LIBRARY_DEPENDENCY, extractedDependencyData);
                        toRemove.add(path);
                    }
                }
                libraryPaths.removeAll(toRemove);
                if (libraryPaths.isEmpty()) {
                    libraryDependencyDataNode.clear(true);
                }
            }
        }
    }
}
Also used : GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) DataNode(com.intellij.openapi.externalSystem.model.DataNode) Pair(com.intellij.openapi.util.Pair) File(java.io.File)

Example 34 with DataNode

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

the class GradleProjectResolver method doResolveProjectInfo.

@NotNull
private DataNode<ProjectData> doResolveProjectInfo(@NotNull final DefaultProjectResolverContext resolverCtx, @NotNull final GradleProjectResolverExtension projectResolverChain, boolean isBuildSrcProject) throws IllegalArgumentException, IllegalStateException {
    final BuildEnvironment buildEnvironment = GradleExecutionHelper.getBuildEnvironment(resolverCtx.getConnection());
    GradleVersion gradleVersion = null;
    boolean isGradleProjectDirSupported = false;
    boolean isCompositeBuildsSupported = false;
    if (buildEnvironment != null) {
        gradleVersion = GradleVersion.version(buildEnvironment.getGradle().getGradleVersion());
        isGradleProjectDirSupported = gradleVersion.compareTo(GradleVersion.version("2.4")) >= 0;
        isCompositeBuildsSupported = isGradleProjectDirSupported && gradleVersion.compareTo(GradleVersion.version("3.1")) >= 0;
    }
    final ProjectImportAction projectImportAction = new ProjectImportAction(resolverCtx.isPreviewMode(), isGradleProjectDirSupported, isCompositeBuildsSupported);
    GradleExecutionSettings executionSettings = resolverCtx.getSettings();
    if (executionSettings == null) {
        executionSettings = new GradleExecutionSettings(null, null, DistributionType.BUNDLED, false);
    }
    executionSettings.withArgument("-Didea.version=" + getIdeaVersion());
    if (resolverCtx.isPreviewMode()) {
        executionSettings.withArgument("-Didea.isPreviewMode=true");
        final Set<Class> previewLightWeightToolingModels = ContainerUtil.set(ExternalProjectPreview.class, GradleBuild.class);
        projectImportAction.addExtraProjectModelClasses(previewLightWeightToolingModels);
    }
    if (resolverCtx.isResolveModulePerSourceSet()) {
        executionSettings.withArgument("-Didea.resolveSourceSetDependencies=true");
    }
    if (!isBuildSrcProject) {
        for (GradleBuildParticipant buildParticipant : executionSettings.getExecutionWorkspace().getBuildParticipants()) {
            executionSettings.withArguments(GradleConstants.INCLUDE_BUILD_CMD_OPTION, buildParticipant.getProjectPath());
        }
    }
    final Set<Class> toolingExtensionClasses = ContainerUtil.newHashSet();
    final GradleImportCustomizer importCustomizer = GradleImportCustomizer.get();
    for (GradleProjectResolverExtension resolverExtension = projectResolverChain; resolverExtension != null; resolverExtension = resolverExtension.getNext()) {
        // inject ProjectResolverContext into gradle project resolver extensions
        resolverExtension.setProjectResolverContext(resolverCtx);
        // pre-import checks
        resolverExtension.preImportCheck();
        if (!resolverCtx.isPreviewMode()) {
            // register classes of extra gradle project models required for extensions (e.g. com.android.builder.model.AndroidProject)
            projectImportAction.addExtraProjectModelClasses(resolverExtension.getExtraProjectModelClasses());
        }
        if (importCustomizer == null || importCustomizer.useExtraJvmArgs()) {
            // collect extra JVM arguments provided by gradle project resolver extensions
            final ParametersList parametersList = new ParametersList();
            for (Pair<String, String> jvmArg : resolverExtension.getExtraJvmArgs()) {
                parametersList.addProperty(jvmArg.first, jvmArg.second);
            }
            executionSettings.withVmOptions(parametersList.getParameters());
        }
        // collect extra command-line arguments
        executionSettings.withArguments(resolverExtension.getExtraCommandLineArgs());
        // collect tooling extensions classes
        toolingExtensionClasses.addAll(resolverExtension.getToolingExtensionsClasses());
    }
    BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = resolverCtx.getConnection().action(projectImportAction);
    File initScript = GradleExecutionHelper.generateInitScript(isBuildSrcProject, toolingExtensionClasses);
    if (initScript != null) {
        executionSettings.withArguments(GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath());
    }
    GradleExecutionHelper.prepare(buildActionExecutor, resolverCtx.getExternalSystemTaskId(), executionSettings, resolverCtx.getListener(), resolverCtx.getConnection());
    resolverCtx.checkCancelled();
    ProjectImportAction.AllModels allModels;
    final CancellationTokenSource cancellationTokenSource = GradleConnector.newCancellationTokenSource();
    final long startTime = System.currentTimeMillis();
    try {
        resolverCtx.setCancellationTokenSource(cancellationTokenSource);
        buildActionExecutor.withCancellationToken(cancellationTokenSource.token());
        synchronized (myCancellationMap) {
            myCancellationMap.putValue(resolverCtx.getExternalSystemTaskId(), cancellationTokenSource);
            if (gradleVersion != null && gradleVersion.compareTo(GradleVersion.version("2.1")) < 0) {
                myCancellationMap.putValue(resolverCtx.getExternalSystemTaskId(), new UnsupportedCancellationToken());
            }
        }
        allModels = buildActionExecutor.run();
        if (allModels == null) {
            throw new IllegalStateException("Unable to get project model for the project: " + resolverCtx.getProjectPath());
        }
    } catch (UnsupportedVersionException unsupportedVersionException) {
        resolverCtx.checkCancelled();
        // Old gradle distribution version used (before ver. 1.8)
        // fallback to use ModelBuilder gradle tooling API
        Class<? extends IdeaProject> aClass = resolverCtx.isPreviewMode() ? BasicIdeaProject.class : IdeaProject.class;
        ModelBuilder<? extends IdeaProject> modelBuilder = myHelper.getModelBuilder(aClass, resolverCtx.getExternalSystemTaskId(), executionSettings, resolverCtx.getConnection(), resolverCtx.getListener());
        final IdeaProject ideaProject = modelBuilder.get();
        allModels = new ProjectImportAction.AllModels(ideaProject);
    } finally {
        final long timeInMs = (System.currentTimeMillis() - startTime);
        synchronized (myCancellationMap) {
            myCancellationMap.remove(resolverCtx.getExternalSystemTaskId(), cancellationTokenSource);
        }
        LOG.debug(String.format("Gradle data obtained in %d ms", timeInMs));
    }
    resolverCtx.checkCancelled();
    allModels.setBuildEnvironment(buildEnvironment);
    final long startDataConversionTime = System.currentTimeMillis();
    extractExternalProjectModels(allModels, resolverCtx);
    // import project data
    ProjectData projectData = projectResolverChain.createProject();
    DataNode<ProjectData> projectDataNode = new DataNode<>(ProjectKeys.PROJECT, projectData, null);
    // import java project data
    JavaProjectData javaProjectData = projectResolverChain.createJavaProjectData();
    projectDataNode.createChild(JavaProjectData.KEY, javaProjectData);
    IdeaProject ideaProject = resolverCtx.getModels().getIdeaProject();
    projectResolverChain.populateProjectExtraModels(ideaProject, projectDataNode);
    DomainObjectSet<? extends IdeaModule> gradleModules = ideaProject.getModules();
    if (gradleModules == null || gradleModules.isEmpty()) {
        throw new IllegalStateException("No modules found for the target project: " + ideaProject);
    }
    Collection<IdeaModule> includedModules = exposeCompositeBuild(allModels, resolverCtx, projectDataNode);
    final Map<String, Pair<DataNode<ModuleData>, IdeaModule>> /* module id */
    moduleMap = ContainerUtilRt.newHashMap();
    final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> /* module id */
    sourceSetsMap = ContainerUtil.newHashMap();
    projectDataNode.putUserData(RESOLVED_SOURCE_SETS, sourceSetsMap);
    final Map<String, Pair<String, ExternalSystemSourceType>> /* module id*/
    moduleOutputsMap = ContainerUtil.newTroveMap(FileUtil.PATH_HASHING_STRATEGY);
    projectDataNode.putUserData(MODULES_OUTPUTS, moduleOutputsMap);
    final Map<String, String> /* module id*/
    artifactsMap = ContainerUtil.newTroveMap(FileUtil.PATH_HASHING_STRATEGY);
    projectDataNode.putUserData(CONFIGURATION_ARTIFACTS, artifactsMap);
    // import modules data
    for (IdeaModule gradleModule : ContainerUtil.concat(gradleModules, includedModules)) {
        if (gradleModule == null) {
            continue;
        }
        resolverCtx.checkCancelled();
        if (ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
            LOG.info(String.format("Importing module data: %s", gradleModule));
        }
        final String moduleName = gradleModule.getName();
        if (moduleName == null) {
            throw new IllegalStateException("Module with undefined name detected: " + gradleModule);
        }
        DataNode<ModuleData> moduleDataNode = projectResolverChain.createModule(gradleModule, projectDataNode);
        String mainModuleId = getModuleId(resolverCtx, gradleModule);
        if (moduleMap.containsKey(mainModuleId)) {
            // we should ensure deduplicated module names in the scope of single import
            throw new IllegalStateException("Duplicate modules names detected: " + gradleModule);
        }
        moduleMap.put(mainModuleId, Pair.create(moduleDataNode, gradleModule));
    }
    executionSettings.getExecutionWorkspace().addModuleMap(moduleMap);
    File gradleHomeDir = null;
    // populate modules nodes
    for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) {
        final DataNode<ModuleData> moduleDataNode = pair.first;
        final IdeaModule ideaModule = pair.second;
        if (gradleHomeDir == null) {
            final BuildScriptClasspathModel buildScriptClasspathModel = resolverCtx.getExtraProject(ideaModule, BuildScriptClasspathModel.class);
            if (buildScriptClasspathModel != null) {
                gradleHomeDir = buildScriptClasspathModel.getGradleHomeDir();
            }
        }
        projectResolverChain.populateModuleContentRoots(ideaModule, moduleDataNode);
        projectResolverChain.populateModuleCompileOutputSettings(ideaModule, moduleDataNode);
        if (!isBuildSrcProject) {
            projectResolverChain.populateModuleTasks(ideaModule, moduleDataNode, projectDataNode);
        }
        final List<DataNode<? extends ModuleData>> modules = ContainerUtil.newSmartList();
        modules.add(moduleDataNode);
        modules.addAll(ExternalSystemApiUtil.findAll(moduleDataNode, GradleSourceSetData.KEY));
        final ExternalSystemSourceType[] sourceTypes = new ExternalSystemSourceType[] { ExternalSystemSourceType.SOURCE, ExternalSystemSourceType.RESOURCE, ExternalSystemSourceType.TEST, ExternalSystemSourceType.TEST_RESOURCE };
        for (DataNode<? extends ModuleData> module : modules) {
            final ModuleData moduleData = module.getData();
            for (ExternalSystemSourceType sourceType : sourceTypes) {
                final String path = moduleData.getCompileOutputPath(sourceType);
                if (path != null) {
                    moduleOutputsMap.put(path, Pair.create(moduleData.getId(), sourceType));
                }
            }
            if (moduleData instanceof GradleSourceSetData) {
                for (File artifactFile : moduleData.getArtifacts()) {
                    artifactsMap.put(ExternalSystemApiUtil.toCanonicalPath(artifactFile.getAbsolutePath()), moduleData.getId());
                }
            }
        }
    }
    for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) {
        final DataNode<ModuleData> moduleDataNode = pair.first;
        final IdeaModule ideaModule = pair.second;
        projectResolverChain.populateModuleDependencies(ideaModule, moduleDataNode, projectDataNode);
        projectResolverChain.populateModuleExtraModels(ideaModule, moduleDataNode);
    }
    mergeSourceSetContentRoots(moduleMap, resolverCtx);
    if (resolverCtx.isResolveModulePerSourceSet()) {
        mergeLibraryAndModuleDependencyData(projectDataNode, gradleHomeDir, gradleVersion);
    }
    projectDataNode.putUserData(RESOLVED_SOURCE_SETS, null);
    projectDataNode.putUserData(MODULES_OUTPUTS, null);
    projectDataNode.putUserData(CONFIGURATION_ARTIFACTS, null);
    // ensure unique library names
    Collection<DataNode<LibraryData>> libraries = ExternalSystemApiUtil.getChildren(projectDataNode, ProjectKeys.LIBRARY);
    myLibraryNamesMixer.mixNames(libraries);
    final long timeConversionInMs = (System.currentTimeMillis() - startDataConversionTime);
    LOG.debug(String.format("Project data resolved in %d ms", timeConversionInMs));
    return projectDataNode;
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) IdeaProject(org.gradle.tooling.model.idea.IdeaProject) BasicIdeaProject(org.gradle.tooling.model.idea.BasicIdeaProject) JavaProjectData(com.intellij.externalSystem.JavaProjectData) GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) UnsupportedCancellationToken(org.jetbrains.plugins.gradle.service.execution.UnsupportedCancellationToken) ParametersList(com.intellij.execution.configurations.ParametersList) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) DataNode(com.intellij.openapi.externalSystem.model.DataNode) GradleVersion(org.gradle.util.GradleVersion) JavaProjectData(com.intellij.externalSystem.JavaProjectData) Pair(com.intellij.openapi.util.Pair) BasicIdeaProject(org.gradle.tooling.model.idea.BasicIdeaProject) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) GradleBuildParticipant(org.jetbrains.plugins.gradle.settings.GradleBuildParticipant) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with DataNode

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

the class GradleProjectResolverUtil method getIdeDependencies.

@SuppressWarnings("unchecked")
public static Collection<DependencyData> getIdeDependencies(@NotNull ProjectResolverContext resolverCtx, @NotNull DataNode<? extends ModuleData> moduleDataNode, @NotNull Collection<ExternalDependency> dependencies) throws IllegalStateException {
    final DataNode<ProjectData> ideProject = ExternalSystemApiUtil.findParent(moduleDataNode, ProjectKeys.PROJECT);
    assert ideProject != null;
    final Map<String, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetMap = ideProject.getUserData(GradleProjectResolver.RESOLVED_SOURCE_SETS);
    assert sourceSetMap != null;
    final Map<String, String> artifactsMap = ideProject.getUserData(CONFIGURATION_ARTIFACTS);
    assert artifactsMap != null;
    DataNode fakeNode = new DataNode(CONTAINER_KEY, moduleDataNode.getData(), null);
    buildDependencies(resolverCtx, sourceSetMap, artifactsMap, fakeNode, dependencies, null);
    final Collection<DataNode<?>> dataNodes = ExternalSystemApiUtil.findAllRecursively(fakeNode, node -> node.getData() instanceof DependencyData);
    return ContainerUtil.map(dataNodes, node -> (DependencyData) node.getData());
}
Also used : GradleSourceSetData(org.jetbrains.plugins.gradle.model.data.GradleSourceSetData) DataNode(com.intellij.openapi.externalSystem.model.DataNode) Pair(com.intellij.openapi.util.Pair)

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