use of org.jetbrains.plugins.gradle.model.ExternalProject in project intellij-community by JetBrains.
the class GradleResourceCompilerConfigurationGenerator method generateAffectedGradleModulesConfiguration.
@NotNull
private Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration(@NotNull CompileContext context) {
final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations = ContainerUtil.newTroveMap();
//noinspection MismatchedQueryAndUpdateOfCollection
final Map<String, ExternalProject> lazyExternalProjectMap = new FactoryMap<String, ExternalProject>() {
@Nullable
@Override
protected ExternalProject create(String gradleProjectPath) {
return externalProjectDataCache.getRootExternalProject(GradleConstants.SYSTEM_ID, new File(gradleProjectPath));
}
};
for (Module module : context.getCompileScope().getAffectedModules()) {
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
continue;
final String gradleProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
assert gradleProjectPath != null;
if (shouldBeBuiltByExternalSystem(module))
continue;
final ExternalProject externalRootProject = lazyExternalProjectMap.get(gradleProjectPath);
if (externalRootProject == null) {
context.addMessage(CompilerMessageCategory.ERROR, String.format("Unable to make the module: %s, related gradle configuration was not found. " + "Please, re-import the Gradle project and try again.", module.getName()), VfsUtilCore.pathToUrl(gradleProjectPath), -1, -1);
continue;
}
Map<String, ExternalSourceSet> externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, module);
if (externalSourceSets.isEmpty()) {
LOG.debug("Unable to find source sets config for module: " + module.getName());
continue;
}
GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration();
resourceConfig.id = new ModuleVersion(ExternalSystemApiUtil.getExternalProjectGroup(module), ExternalSystemApiUtil.getExternalProjectId(module), ExternalSystemApiUtil.getExternalProjectVersion(module));
for (ExternalSourceSet sourceSet : externalSourceSets.values()) {
addResources(resourceConfig.resources, sourceSet.getSources().get(ExternalSystemSourceType.RESOURCE), sourceSet.getSources().get(ExternalSystemSourceType.SOURCE));
addResources(resourceConfig.testResources, sourceSet.getSources().get(ExternalSystemSourceType.TEST_RESOURCE), sourceSet.getSources().get(ExternalSystemSourceType.TEST));
}
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
if (compilerModuleExtension != null && compilerModuleExtension.isCompilerOutputPathInherited()) {
String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl());
for (ResourceRootConfiguration resource : resourceConfig.resources) {
resource.targetPath = outputPath;
}
String testOutputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests());
for (ResourceRootConfiguration resource : resourceConfig.testResources) {
resource.targetPath = testOutputPath;
}
}
affectedGradleModuleConfigurations.put(module.getName(), resourceConfig);
}
return affectedGradleModuleConfigurations;
}
use of org.jetbrains.plugins.gradle.model.ExternalProject in project intellij-community by JetBrains.
the class GradleOrderEnumeratorHandler method addCustomModuleRoots.
@Override
public boolean addCustomModuleRoots(@NotNull OrderRootType type, @NotNull ModuleRootModel rootModel, @NotNull Collection<String> result, boolean includeProduction, boolean includeTests) {
if (!type.equals(OrderRootType.CLASSES))
return false;
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, rootModel.getModule()))
return false;
final String gradleProjectPath = rootModel.getModule().getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
if (gradleProjectPath == null) {
LOG.error("Root project path of the Gradle project not found for " + rootModel.getModule());
return false;
}
final ExternalProjectDataCache externalProjectDataCache = ExternalProjectDataCache.getInstance(rootModel.getModule().getProject());
assert externalProjectDataCache != null;
final ExternalProject externalRootProject = externalProjectDataCache.getRootExternalProject(GradleConstants.SYSTEM_ID, new File(gradleProjectPath));
if (externalRootProject == null) {
LOG.debug("Root external project was not yep imported for the project path: " + gradleProjectPath);
return false;
}
Map<String, ExternalSourceSet> externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, rootModel.getModule());
if (externalSourceSets.isEmpty())
return false;
for (ExternalSourceSet sourceSet : externalSourceSets.values()) {
if (includeTests) {
addOutputModuleRoots(sourceSet.getSources().get(ExternalSystemSourceType.TEST_RESOURCE), result);
}
if (includeProduction) {
addOutputModuleRoots(sourceSet.getSources().get(ExternalSystemSourceType.RESOURCE), result);
}
}
return true;
}
use of org.jetbrains.plugins.gradle.model.ExternalProject in project intellij-community by JetBrains.
the class ExternalProjectDataCache method findExternalProject.
@NotNull
private static Map<String, ExternalSourceSet> findExternalProject(@NotNull ExternalProject parentProject, @NotNull String externalProjectId) {
Queue<ExternalProject> queue = ContainerUtil.newLinkedList();
queue.add(parentProject);
while (!queue.isEmpty()) {
final ExternalProject externalProject = queue.remove();
final String projectId = externalProject.getQName();
boolean isRelatedProject = projectId.equals(externalProjectId);
final Map<String, ExternalSourceSet> result = ContainerUtil.newHashMap();
for (Map.Entry<String, ExternalSourceSet> sourceSetEntry : externalProject.getSourceSets().entrySet()) {
final String sourceSetName = sourceSetEntry.getKey();
final String sourceSetId = projectId + ":" + sourceSetName;
if (isRelatedProject || externalProjectId.equals(sourceSetId)) {
result.put(sourceSetName, sourceSetEntry.getValue());
}
}
if (!result.isEmpty() || isRelatedProject)
return result;
queue.addAll(externalProject.getChildProjects().values());
}
return Collections.emptyMap();
}
use of org.jetbrains.plugins.gradle.model.ExternalProject in project intellij-community by JetBrains.
the class ExternalProjectDataCache method getRootExternalProject.
@Nullable
public ExternalProject getRootExternalProject(@NotNull ProjectSystemId systemId, @NotNull File projectRootDir) {
ExternalProject externalProject = myExternalRootProjects.get(Pair.create(systemId, projectRootDir));
if (LOG.isDebugEnabled()) {
LOG.debug("Can not find data for project at: " + projectRootDir);
LOG.debug("Existing imported projects paths: " + ContainerUtil.map(myExternalRootProjects.entrySet(), (Function<Map.Entry<Pair<ProjectSystemId, File>, ExternalProject>, Object>) entry -> {
if (!(entry.getValue() instanceof ExternalProject))
return null;
return Pair.create(entry.getKey(), entry.getValue().getProjectDir());
}));
}
return externalProject;
}
use of org.jetbrains.plugins.gradle.model.ExternalProject in project android by JetBrains.
the class AndroidGradleProjectResolver method doCreateModule.
@NotNull
private DataNode<ModuleData> doCreateModule(@NotNull IdeaModule gradleModule, @NotNull DataNode<ProjectData> projectDataNode) {
String moduleName = gradleModule.getName();
if (moduleName == null) {
throw new IllegalStateException("Module with undefined name detected: " + gradleModule);
}
String projectPath = projectDataNode.getData().getLinkedExternalProjectPath();
String moduleConfigPath = getModuleConfigPath(resolverCtx, gradleModule, projectPath);
String gradlePath = gradleModule.getGradleProject().getPath();
String moduleId = isEmpty(gradlePath) || ":".equals(gradlePath) ? moduleName : gradlePath;
ProjectSystemId owner = GradleConstants.SYSTEM_ID;
String typeId = StdModuleTypes.JAVA.getId();
ModuleData moduleData = new ModuleData(moduleId, owner, typeId, moduleName, moduleConfigPath, moduleConfigPath);
ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
if (externalProject != null) {
moduleData.setDescription(externalProject.getDescription());
}
return projectDataNode.createChild(ProjectKeys.MODULE, moduleData);
}
Aggregations