Search in sources :

Example 1 with ExternalProject

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;
}
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 ExternalProject

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;
}
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 ExternalProject

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();
}
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)

Example 4 with ExternalProject

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;
}
Also used : ContainerUtil(com.intellij.util.containers.ContainerUtil) ExternalSourceSet(org.jetbrains.plugins.gradle.model.ExternalSourceSet) File(java.io.File) ExternalSystemUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUtil) Nullable(org.jetbrains.annotations.Nullable) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) ServiceManager(com.intellij.openapi.components.ServiceManager) DefaultExternalProject(org.jetbrains.plugins.gradle.model.DefaultExternalProject) ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) Function(com.intellij.util.Function) Map(java.util.Map) Pair(com.intellij.openapi.util.Pair) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) Project(com.intellij.openapi.project.Project) ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) Queue(java.util.Queue) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) DefaultExternalProject(org.jetbrains.plugins.gradle.model.DefaultExternalProject) ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with 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);
}
Also used : ExternalProject(org.jetbrains.plugins.gradle.model.ExternalProject) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExternalProject (org.jetbrains.plugins.gradle.model.ExternalProject)5 NotNull (org.jetbrains.annotations.NotNull)4 ExternalSourceSet (org.jetbrains.plugins.gradle.model.ExternalSourceSet)4 File (java.io.File)3 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)2 Module (com.intellij.openapi.module.Module)2 ConcurrentFactoryMap (com.intellij.util.containers.ConcurrentFactoryMap)2 Map (java.util.Map)2 DefaultExternalProject (org.jetbrains.plugins.gradle.model.DefaultExternalProject)2 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)1 ExternalSystemApiUtil (com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil)1 ExternalSystemUtil (com.intellij.openapi.externalSystem.util.ExternalSystemUtil)1 Project (com.intellij.openapi.project.Project)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 Pair (com.intellij.openapi.util.Pair)1 Function (com.intellij.util.Function)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 FactoryMap (com.intellij.util.containers.FactoryMap)1