DataNode<ProjectData> (@NotNull ProjectImportAction.AllModels allModels, @NotNull GradleExecutionSettings executionSettings, @NotNull DefaultProjectResolverContext resolverCtx, @Nullable GradleVersion gradleVersion, @NotNull GradleProjectResolverExtension tracedResolverChain, @NotNull PerformanceTrace performanceTrace, boolean isBuildSrcProject, boolean useCustomSerialization) { final long activityId = resolverCtx.getExternalSystemTaskId().getId(); syncMetrics.getOrStartSpan(Phase.PROJECT_RESOLVERS.name(), ExternalSystemSyncDiagnostic.gradleSyncSpanName); ExternalSystemSyncActionsCollector.logPhaseStarted(null, activityId, Phase.PROJECT_RESOLVERS); extractExternalProjectModels(allModels, resolverCtx, useCustomSerialization); String projectName = allModels.getMainBuild().getName(); ModifiableGradleProjectModelImpl modifiableGradleProjectModel = new ModifiableGradleProjectModelImpl(projectName, resolverCtx.getProjectPath()); ToolingModelsProvider modelsProvider = new ToolingModelsProviderImpl(allModels); ProjectModelContributor.EP_NAME.forEachExtensionSafe(extension -> { resolverCtx.checkCancelled(); final long starResolveTime = System.currentTimeMillis(); extension.accept(modifiableGradleProjectModel, modelsProvider, resolverCtx); final long resolveTimeInMs = (System.currentTimeMillis() - starResolveTime); performanceTrace.logPerformance("Project model contributed by " + extension.getClass().getSimpleName(), resolveTimeInMs); LOG.debug(String.format("Project model contributed by `" + extension.getClass().getSimpleName() + "` in %d ms", resolveTimeInMs)); }); DataNode<ProjectData> projectDataNode = modifiableGradleProjectModel.buildDataNodeGraph(); DataNode<PerformanceTrace> performanceTraceNode = new DataNode<>(PerformanceTrace.TRACE_NODE_KEY, performanceTrace, projectDataNode); projectDataNode.addChild(performanceTraceNode); Set<? extends IdeaModule> gradleModules = Collections.emptySet(); IdeaProject ideaProject = allModels.getModel(IdeaProject.class); if (ideaProject != null) { tracedResolverChain.populateProjectExtraModels(ideaProject, projectDataNode); 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 /* module id */, Pair<DataNode<ModuleData>, IdeaModule>> moduleMap = new HashMap<>(); final Map<String /* module id */, Pair<DataNode<GradleSourceSetData>, ExternalSourceSet>> sourceSetsMap = new HashMap<>(); projectDataNode.putUserData(RESOLVED_SOURCE_SETS, sourceSetsMap); final Map<String/* output path */, Pair<String /* module id*/, ExternalSystemSourceType>> moduleOutputsMap = CollectionFactory.createFilePathMap(); projectDataNode.putUserData(MODULES_OUTPUTS, moduleOutputsMap); final ArtifactMappingService artifactsMap = resolverCtx.getArtifactsMap(); // 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 = tracedResolverChain.createModule(gradleModule, projectDataNode); if (moduleDataNode == null) continue; String mainModuleId = getModuleId(resolverCtx, gradleModule); if (moduleMap.containsKey(mainModuleId)) { // we should ensure deduplicated module names in the scope of single import throw new IllegalStateException("Attempt to add module with already existing id [" + mainModuleId + "]\n" + " new module: " + gradleModule + "\n" + " existing module: " + moduleMap.get(mainModuleId).second); } moduleMap.put(mainModuleId, Pair.create(moduleDataNode, gradleModule)); } executionSettings.getExecutionWorkspace().setModuleIdIndex(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(); } } tracedResolverChain.populateModuleContentRoots(ideaModule, moduleDataNode); tracedResolverChain.populateModuleCompileOutputSettings(ideaModule, moduleDataNode); if (!isBuildSrcProject) { tracedResolverChain.populateModuleTasks(ideaModule, moduleDataNode, projectDataNode); } final List<DataNode<? extends ModuleData>> modules = new SmartList<>(); modules.add(moduleDataNode); modules.addAll(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.storeModuleId(toCanonicalPath(artifactFile.getPath()), moduleData.getId()); } } } ExternalProject externalProject = resolverCtx.getExtraProject(ideaModule, ExternalProject.class); if (externalProject != null) { externalProject.getSourceSetModel().getAdditionalArtifacts().forEach((artifactFile) -> { String path = toCanonicalPath(artifactFile.getPath()); ModuleMappingInfo mapping = artifactsMap.getModuleMapping(path); if (mapping != null && OWNER_BASE_GRADLE.equals(mapping.getOwnerId())) { artifactsMap.markArtifactPath(path, true); } }); } } // reuse same gradle home (for auto-discovered buildSrc projects) also for partial imports which doesn't request BuildScriptClasspathModel if (gradleHomeDir == null && executionSettings.getGradleHome() != null) { gradleHomeDir = new File(executionSettings.getGradleHome()); } resolverCtx.putUserData(GRADLE_HOME_DIR, gradleHomeDir); for (final Pair<DataNode<ModuleData>, IdeaModule> pair : moduleMap.values()) { final DataNode<ModuleData> moduleDataNode = pair.first; final IdeaModule ideaModule = pair.second; tracedResolverChain.populateModuleDependencies(ideaModule, moduleDataNode, projectDataNode); tracedResolverChain.populateModuleExtraModels(ideaModule, moduleDataNode); } mergeSourceSetContentRoots(moduleMap, resolverCtx); if (resolverCtx.isResolveModulePerSourceSet()) { mergeLibraryAndModuleDependencyData(resolverCtx, projectDataNode, resolverCtx.getGradleUserHome(), gradleHomeDir, gradleVersion); } processBuildSrcModules(resolverCtx, projectDataNode); for (GradleProjectResolverExtension resolver = tracedResolverChain; resolver != null; resolver = resolver.getNext()) { resolver.resolveFinished(projectDataNode); } projectDataNode.putUserData(RESOLVED_SOURCE_SETS, null); projectDataNode.putUserData(MODULES_OUTPUTS, null); // ensure unique library names Collection<DataNode<LibraryData>> libraries = getChildren(projectDataNode, ProjectKeys.LIBRARY); myLibraryNamesMixer.mixNames(libraries); return projectDataNode; }