Search in sources :

Example 1 with ExternalSourceSet

use of org.jetbrains.plugins.gradle.model.ExternalSourceSet 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;
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) ExternalSourceSet(org.jetbrains.plugins.gradle.model.ExternalSourceSet) ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Module(com.intellij.openapi.module.Module) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ExternalSourceSet

use of org.jetbrains.plugins.gradle.model.ExternalSourceSet 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;
}
Also used : ExternalSourceSet(org.jetbrains.plugins.gradle.model.ExternalSourceSet) ExternalProjectDataCache(org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataCache) ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) File(java.io.File)

Example 3 with ExternalSourceSet

use of org.jetbrains.plugins.gradle.model.ExternalSourceSet 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();
}
Also used : ExternalSourceSet(org.jetbrains.plugins.gradle.model.ExternalSourceSet) DefaultExternalProject(org.jetbrains.plugins.gradle.model.DefaultExternalProject) ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) Map(java.util.Map) ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExternalProject (org.jetbrains.plugins.gradle.model.ExternalProject)3 ExternalSourceSet (org.jetbrains.plugins.gradle.model.ExternalSourceSet)3 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 Module (com.intellij.openapi.module.Module)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 ConcurrentFactoryMap (com.intellij.util.containers.ConcurrentFactoryMap)1 FactoryMap (com.intellij.util.containers.FactoryMap)1 Map (java.util.Map)1 DefaultExternalProject (org.jetbrains.plugins.gradle.model.DefaultExternalProject)1 ExternalProjectDataCache (org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataCache)1