Search in sources :

Example 1 with ConventionMapping

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

the class AbstractCodeQualityPlugin method configureExtensionRule.

private void configureExtensionRule() {
    final ConventionMapping extensionMapping = conventionMappingOf(extension);
    extensionMapping.map("sourceSets", Callables.returning(new ArrayList()));
    extensionMapping.map("reportsDir", new Callable<File>() {

        @Override
        public File call() {
            return project.getExtensions().getByType(ReportingExtension.class).file(getReportName());
        }
    });
    withBasePlugin(new Action<Plugin>() {

        @Override
        public void execute(Plugin plugin) {
            extensionMapping.map("sourceSets", new Callable<SourceSetContainer>() {

                @Override
                public SourceSetContainer call() {
                    return getJavaPluginConvention().getSourceSets();
                }
            });
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ConventionMapping(org.gradle.api.internal.ConventionMapping) File(java.io.File) Callable(java.util.concurrent.Callable) ReportingBasePlugin(org.gradle.api.plugins.ReportingBasePlugin) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) Plugin(org.gradle.api.Plugin)

Example 2 with ConventionMapping

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

the class CodeNarcPlugin method configureTaskConventionMapping.

private void configureTaskConventionMapping(Configuration configuration, CodeNarc task) {
    ConventionMapping taskMapping = task.getConventionMapping();
    taskMapping.map("codenarcClasspath", Callables.returning(configuration));
    taskMapping.map("config", new Callable<TextResource>() {

        @Override
        public TextResource call() {
            return extension.getConfig();
        }
    });
    taskMapping.map("maxPriority1Violations", new Callable<Integer>() {

        @Override
        public Integer call() {
            return extension.getMaxPriority1Violations();
        }
    });
    taskMapping.map("maxPriority2Violations", new Callable<Integer>() {

        @Override
        public Integer call() {
            return extension.getMaxPriority2Violations();
        }
    });
    taskMapping.map("maxPriority3Violations", new Callable<Integer>() {

        @Override
        public Integer call() {
            return extension.getMaxPriority3Violations();
        }
    });
    taskMapping.map("ignoreFailures", new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return extension.isIgnoreFailures();
        }
    });
}
Also used : TextResource(org.gradle.api.resources.TextResource) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Example 3 with ConventionMapping

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

the class JsHintPlugin method apply.

public void apply(Project project) {
    project.getPluginManager().apply(RhinoPlugin.class);
    project.getPluginManager().apply(ReportingBasePlugin.class);
    JavaScriptExtension jsExtension = project.getExtensions().getByType(JavaScriptExtension.class);
    final JsHintExtension jsHintExtension = ((ExtensionAware) jsExtension).getExtensions().create(JsHintExtension.NAME, JsHintExtension.class);
    final Configuration configuration = addConfiguration(project.getConfigurations(), project.getDependencies(), jsHintExtension);
    ConventionMapping conventionMapping = ((IConventionAware) jsHintExtension).getConventionMapping();
    conventionMapping.map("js", new Callable<Configuration>() {

        public Configuration call() {
            return configuration;
        }
    });
    conventionMapping.map("version", new Callable<String>() {

        public String call() {
            return JsHintExtension.DEFAULT_DEPENDENCY_VERSION;
        }
    });
    final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().getByType(RhinoExtension.class);
    final ReportingExtension reportingExtension = project.getExtensions().getByType(ReportingExtension.class);
    project.getTasks().withType(JsHint.class, new Action<JsHint>() {

        public void execute(final JsHint task) {
            task.getConventionMapping().map("rhinoClasspath", new Callable<FileCollection>() {

                public FileCollection call() {
                    return rhinoExtension.getClasspath();
                }
            });
            task.getConventionMapping().map("jsHint", new Callable<FileCollection>() {

                public FileCollection call() {
                    return jsHintExtension.getJs();
                }
            });
            task.getConventionMapping().map("jsonReport", new Callable<File>() {

                public File call() {
                    return reportingExtension.file(task.getName() + "/report.json");
                }
            });
        }
    });
}
Also used : ReportingExtension(org.gradle.api.reporting.ReportingExtension) Configuration(org.gradle.api.artifacts.Configuration) RhinoExtension(org.gradle.plugins.javascript.rhino.RhinoExtension) JavaScriptExtension(org.gradle.plugins.javascript.base.JavaScriptExtension) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 4 with ConventionMapping

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

the class IdeaPlugin method configureIdeaModule.

private void configureIdeaModule(final Project 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);
    ConventionMapping conventionMapping = ((IConventionAware) module).getConventionMapping();
    conventionMapping.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            return Sets.newHashSet();
        }
    });
    conventionMapping.map("name", new Callable<String>() {

        @Override
        public String call() throws Exception {
            return project.getName();
        }
    });
    conventionMapping.map("contentRoot", new Callable<File>() {

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

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

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

        @Override
        public PathFactory call() throws Exception {
            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;
        }
    });
    addWorker(task);
}
Also used : Set(java.util.Set) 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 5 with ConventionMapping

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

the class CheckstylePlugin method configureTaskConventionMapping.

private void configureTaskConventionMapping(Configuration configuration, Checkstyle task) {
    ConventionMapping taskMapping = task.getConventionMapping();
    taskMapping.map("checkstyleClasspath", Callables.returning(configuration));
    taskMapping.map("config", new Callable<TextResource>() {

        @Override
        public TextResource call() {
            return extension.getConfig();
        }
    });
    taskMapping.map("configProperties", new Callable<Map<String, Object>>() {

        @Override
        public Map<String, Object> call() {
            return extension.getConfigProperties();
        }
    });
    taskMapping.map("ignoreFailures", new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return extension.isIgnoreFailures();
        }
    });
    taskMapping.map("showViolations", new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return extension.isShowViolations();
        }
    });
    taskMapping.map("maxErrors", new Callable<Integer>() {

        @Override
        public Integer call() {
            return extension.getMaxErrors();
        }
    });
    taskMapping.map("maxWarnings", new Callable<Integer>() {

        @Override
        public Integer call() {
            return extension.getMaxWarnings();
        }
    });
    task.setConfigDir(project.provider(new Callable<File>() {

        @Override
        public File call() {
            return extension.getConfigDir();
        }
    }));
}
Also used : TextResource(org.gradle.api.resources.TextResource) ConventionMapping(org.gradle.api.internal.ConventionMapping) Map(java.util.Map) Callable(java.util.concurrent.Callable)

Aggregations

ConventionMapping (org.gradle.api.internal.ConventionMapping)28 Callable (java.util.concurrent.Callable)11 IConventionAware (org.gradle.api.internal.IConventionAware)11 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 DslObject (org.gradle.api.internal.plugins.DslObject)5 JavaVersion (org.gradle.api.JavaVersion)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 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Project (org.gradle.api.Project)3 TextResource (org.gradle.api.resources.TextResource)3 EarPlugin (org.gradle.plugins.ear.EarPlugin)3 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)3