Search in sources :

Example 21 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class IdeaPlugin method configureIdeaModuleForJava.

private void configureIdeaModuleForJava(final Project project) {
    project.getTasks().withType(GenerateIdeaModule.class, new Action<GenerateIdeaModule>() {

        @Override
        public void execute(GenerateIdeaModule ideaModule) {
            // Defaults
            setupScopes(ideaModule);
            // Convention
            ConventionMapping convention = ((IConventionAware) ideaModule.getModule()).getConventionMapping();
            convention.map("sourceDirs", new Callable<Set<File>>() {

                @Override
                public Set<File> call() {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    return sourceSets.getByName("main").getAllSource().getSrcDirs();
                }
            });
            convention.map("testSourceDirs", new Callable<Set<File>>() {

                @Override
                public Set<File> call() {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    return sourceSets.getByName("test").getAllSource().getSrcDirs();
                }
            });
            convention.map("singleEntryLibraries", new Callable<Map<String, FileCollection>>() {

                @Override
                public Map<String, FileCollection> call() {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    LinkedHashMap<String, FileCollection> map = new LinkedHashMap<String, FileCollection>(2);
                    map.put("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
                    map.put("TEST", sourceSets.getByName("test").getOutput().getDirs());
                    return map;
                }
            });
            convention.map("targetBytecodeVersion", new Callable<JavaVersion>() {

                @Override
                public JavaVersion call() {
                    JavaVersion moduleTargetBytecodeLevel = project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
                    return includeModuleBytecodeLevelOverride(project.getRootProject(), moduleTargetBytecodeLevel) ? moduleTargetBytecodeLevel : null;
                }
            });
            convention.map("languageLevel", new Callable<IdeaLanguageLevel>() {

                @Override
                public IdeaLanguageLevel call() {
                    IdeaLanguageLevel moduleLanguageLevel = new IdeaLanguageLevel(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility());
                    return includeModuleLanguageLevelOverride(project.getRootProject(), moduleLanguageLevel) ? moduleLanguageLevel : null;
                }
            });
            // Dependencies
            ideaModule.dependsOn(new Callable<FileCollection>() {

                @Override
                public FileCollection call() {
                    SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
                    return sourceSets.getByName("main").getOutput().getDirs().plus(sourceSets.getByName("test").getOutput().getDirs());
                }
            });
        }
    });
}
Also used : IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) FileCollection(org.gradle.api.file.FileCollection) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) File(java.io.File)

Example 22 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class IdeaPlugin method configureIdeaProject.

private void configureIdeaProject(final Project project) {
    if (isRoot()) {
        final GenerateIdeaProject projectTask = project.getTasks().create("ideaProject", GenerateIdeaProject.class);
        projectTask.setDescription("Generates IDEA project file (IPR)");
        XmlFileContentMerger ipr = new XmlFileContentMerger(projectTask.getXmlTransformer());
        IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
        projectTask.setIdeaProject(ideaProject);
        ideaModel.setProject(ideaProject);
        ideaProject.setOutputFile(new File(project.getProjectDir(), project.getName() + ".ipr"));
        ConventionMapping conventionMapping = ((IConventionAware) ideaProject).getConventionMapping();
        conventionMapping.map("jdkName", new Callable<String>() {

            @Override
            public String call() {
                return JavaVersion.current().toString();
            }
        });
        conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {

            @Override
            public IdeaLanguageLevel call() {
                JavaVersion maxSourceCompatibility = getMaxJavaModuleCompatibilityVersionFor(SOURCE_COMPATIBILITY);
                return new IdeaLanguageLevel(maxSourceCompatibility);
            }
        });
        conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {

            @Override
            public JavaVersion call() {
                return getMaxJavaModuleCompatibilityVersionFor(TARGET_COMPATIBILITY);
            }
        });
        ideaProject.getWildcards().addAll(Arrays.asList("!?*.class", "!?*.scala", "!?*.groovy", "!?*.java"));
        conventionMapping.map("modules", new Callable<List<IdeaModule>>() {

            @Override
            public List<IdeaModule> call() {
                return Lists.newArrayList(Iterables.transform(Sets.filter(project.getRootProject().getAllprojects(), new Predicate<Project>() {

                    @Override
                    public boolean apply(Project p) {
                        return p.getPlugins().hasPlugin(IdeaPlugin.class);
                    }
                }), new Function<Project, IdeaModule>() {

                    @Override
                    public IdeaModule apply(Project p) {
                        return ideaModelFor(p).getModule();
                    }
                }));
            }
        });
        conventionMapping.map("pathFactory", new Callable<PathFactory>() {

            @Override
            public PathFactory call() {
                return new PathFactory().addPathVariable("PROJECT_DIR", projectTask.getOutputFile().getParentFile());
            }
        });
        addWorker(projectTask);
        addWorkspace(ideaProject);
    }
}
Also used : IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) PathFactory(org.gradle.plugins.ide.idea.model.PathFactory) XmlFileContentMerger(org.gradle.plugins.ide.api.XmlFileContentMerger) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) Predicate(com.google.common.base.Predicate) Project(org.gradle.api.Project) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) List(java.util.List) File(java.io.File) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 23 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class SigningExtension method addSignatureSpecConventions.

/**
 * Adds conventions to the given spec, using this settings object's default signatory and signature type as the default signatory and signature type for the spec.
 */
protected void addSignatureSpecConventions(SignatureSpec spec) {
    if (!(spec instanceof IConventionAware)) {
        throw new InvalidUserDataException("Cannot add conventions to signature spec \'" + String.valueOf(spec) + "\' as it is not convention aware");
    }
    ConventionMapping conventionMapping = ((IConventionAware) spec).getConventionMapping();
    conventionMapping.map("signatory", new Callable<Signatory>() {

        public Signatory call() {
            return getSignatory();
        }
    });
    conventionMapping.map("signatureType", new Callable<SignatureType>() {

        public SignatureType call() {
            return getSignatureType();
        }
    });
    conventionMapping.map("required", new Callable<Boolean>() {

        public Boolean call() {
            return isRequired();
        }
    });
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) Signatory(org.gradle.plugins.signing.signatory.Signatory) SignatureType(org.gradle.plugins.signing.type.SignatureType) DefaultTypeTransformation.castToBoolean(org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean) IConventionAware(org.gradle.api.internal.IConventionAware) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Example 24 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class FindBugsPlugin method configureForSourceSet.

@Override
protected void configureForSourceSet(final SourceSet sourceSet, FindBugs task) {
    task.setDescription("Run FindBugs analysis for " + sourceSet.getName() + " classes");
    task.setSource(sourceSet.getAllJava());
    ConventionMapping taskMapping = task.getConventionMapping();
    taskMapping.map("classes", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            return sourceSet.getOutput().getClassesDirs();
        }
    });
    taskMapping.map("classpath", new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            return sourceSet.getCompileClasspath();
        }
    });
}
Also used : FileCollection(org.gradle.api.file.FileCollection) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Example 25 with ConventionMapping

use of org.gradle.api.internal.ConventionMapping in project gradle by gradle.

the class JavaBasePlugin method configureForSourceSet.

@Deprecated
public void configureForSourceSet(final SourceSet sourceSet, final AbstractCompile compile) {
    SingleMessageLogger.nagUserOfDiscontinuedMethod("configureForSourceSet(SourceSet, AbstractCompile)");
    ConventionMapping conventionMapping;
    compile.setDescription("Compiles the " + sourceSet.getJava() + ".");
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {

        public Object call() throws Exception {
            return sourceSet.getCompileClasspath().plus(compile.getProject().files(sourceSet.getJava().getOutputDir()));
        }
    });
    // TODO: This doesn't really work any more, but configureForSourceSet is a public API.
    // This should allow builds to continue to work, but it will kill build caching for JavaCompile
    conventionMapping.map("destinationDir", new Callable<Object>() {

        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
Also used : DslObject(org.gradle.api.internal.plugins.DslObject) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Aggregations

ConventionMapping (org.gradle.api.internal.ConventionMapping)27 IConventionAware (org.gradle.api.internal.IConventionAware)11 Callable (java.util.concurrent.Callable)10 File (java.io.File)9 Set (java.util.Set)6 FileCollection (org.gradle.api.file.FileCollection)6 Action (org.gradle.api.Action)5 Configuration (org.gradle.api.artifacts.Configuration)5 JavaVersion (org.gradle.api.JavaVersion)4 DslObject (org.gradle.api.internal.plugins.DslObject)4 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)4 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)4 JavaScriptExtension (org.gradle.plugins.javascript.base.JavaScriptExtension)4 Predicate (com.google.common.base.Predicate)3 List (java.util.List)3 TextResource (org.gradle.api.resources.TextResource)3 EarPlugin (org.gradle.plugins.ear.EarPlugin)3 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2