Search in sources :

Example 1 with IdeaModuleMetadata

use of org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata in project gradle by gradle.

the class IdeaPlugin method configureIdeaModule.

private void configureIdeaModule(final ProjectInternal project) {
    final GenerateIdeaModule task = project.getTasks().create("ideaModule", GenerateIdeaModule.class);
    task.setDescription("Generates IDEA module files (IML)");
    IdeaModuleIml iml = new IdeaModuleIml(task.getXmlTransformer(), project.getProjectDir());
    final IdeaModule module = instantiator.newInstance(IdeaModule.class, project, iml);
    task.setModule(module);
    ideaModel.setModule(module);
    final String defaultModuleName = uniqueProjectNameProvider.getUniqueName(project);
    module.setName(defaultModuleName);
    ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
    conventionMapping.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            return Sets.newLinkedHashSet();
        }
    });
    conventionMapping.map("contentRoot", new Callable<File>() {

        @Override
        public File call() {
            return project.getProjectDir();
        }
    });
    conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            return Sets.newLinkedHashSet();
        }
    });
    conventionMapping.map("excludeDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() {
            Set<File> defaultExcludes = Sets.newLinkedHashSet();
            defaultExcludes.add(project.file(".gradle"));
            defaultExcludes.add(project.getBuildDir());
            return defaultExcludes;
        }
    });
    conventionMapping.map("pathFactory", new Callable<PathFactory>() {

        @Override
        public PathFactory call() {
            final PathFactory factory = new PathFactory();
            factory.addPathVariable("MODULE_DIR", task.getOutputFile().getParentFile());
            for (Map.Entry<String, File> entry : module.getPathVariables().entrySet()) {
                factory.addPathVariable(entry.getKey(), entry.getValue());
            }
            return factory;
        }
    });
    artifactRegistry.registerIdeArtifact(new IdeaModuleMetadata(module, task));
    addWorker(task);
}
Also used : Set(java.util.Set) IdeaModuleMetadata(org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata) PathFactory(org.gradle.plugins.ide.idea.model.PathFactory) ConventionMapping(org.gradle.api.internal.ConventionMapping) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) IdeaModuleIml(org.gradle.plugins.ide.idea.model.IdeaModuleIml) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File)

Example 2 with IdeaModuleMetadata

use of org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata in project gradle by gradle.

the class IdeaPlugin method allImlArtifactsInComposite.

private List<TaskDependency> allImlArtifactsInComposite(ProjectInternal project, IdeaProject ideaProject) {
    List<TaskDependency> dependencies = Lists.newArrayList();
    ProjectComponentIdentifier thisProjectId = projectPathRegistry.getProjectComponentIdentifier(project.getIdentityPath());
    for (IdeArtifactRegistry.Reference<IdeaModuleMetadata> reference : artifactRegistry.getIdeArtifactMetadata(IdeaModuleMetadata.class)) {
        BuildIdentifier otherBuildId = reference.getOwningProject().getBuild();
        if (thisProjectId.getBuild().equals(otherBuildId)) {
            // IDEA Module for project in current build: don't include any module that has been excluded from project
            boolean found = false;
            for (IdeaModule ideaModule : ideaProject.getModules()) {
                if (reference.get().getFile().equals(ideaModule.getOutputFile())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                continue;
            }
        }
        dependencies.add(reference.getBuildDependencies());
    }
    return dependencies;
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) IdeaModuleMetadata(org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata) IdeArtifactRegistry(org.gradle.plugins.ide.internal.IdeArtifactRegistry) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 3 with IdeaModuleMetadata

use of org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata in project gradle by gradle.

the class IdeaProject method configureModulePaths.

private void configureModulePaths(Project xmlProject) {
    ProjectComponentIdentifier thisProjectId = projectPathRegistry.getProjectComponentIdentifier(((ProjectInternal) project).getIdentityPath());
    for (IdeArtifactRegistry.Reference<IdeaModuleMetadata> reference : artifactRegistry.getIdeArtifactMetadata(IdeaModuleMetadata.class)) {
        BuildIdentifier otherBuildId = reference.getOwningProject().getBuild();
        if (thisProjectId.getBuild().equals(otherBuildId)) {
            // IDEA Module for project in current build: handled via `modules` model elements.
            continue;
        }
        xmlProject.addModulePath(reference.get().getFile());
    }
}
Also used : IdeaModuleMetadata(org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata) IdeArtifactRegistry(org.gradle.plugins.ide.internal.IdeArtifactRegistry) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Aggregations

IdeaModuleMetadata (org.gradle.plugins.ide.idea.internal.IdeaModuleMetadata)3 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)2 IdeArtifactRegistry (org.gradle.plugins.ide.internal.IdeArtifactRegistry)2 File (java.io.File)1 Set (java.util.Set)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 TaskDependency (org.gradle.api.tasks.TaskDependency)1 IdeaModuleIml (org.gradle.plugins.ide.idea.model.IdeaModuleIml)1 PathFactory (org.gradle.plugins.ide.idea.model.PathFactory)1