Search in sources :

Example 6 with ConventionMapping

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

the class FindBugsPlugin method configureTaskConventionMapping.

private void configureTaskConventionMapping(Configuration configuration, FindBugs task) {
    ConventionMapping taskMapping = task.getConventionMapping();
    taskMapping.map("findbugsClasspath", Callables.returning(configuration));
    taskMapping.map("ignoreFailures", new Callable<Boolean>() {

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

        @Override
        public String call() {
            return extension.getEffort();
        }
    });
    taskMapping.map("reportLevel", new Callable<String>() {

        @Override
        public String call() {
            return extension.getReportLevel();
        }
    });
    taskMapping.map("visitors", new Callable<Collection<String>>() {

        @Override
        public Collection<String> call() {
            return extension.getVisitors();
        }
    });
    taskMapping.map("omitVisitors", new Callable<Collection<String>>() {

        @Override
        public Collection<String> call() {
            return extension.getOmitVisitors();
        }
    });
    taskMapping.map("excludeFilterConfig", new Callable<TextResource>() {

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

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

        @Override
        public TextResource call() {
            return extension.getExcludeBugsFilterConfig();
        }
    });
    taskMapping.map("extraArgs", new Callable<Collection<String>>() {

        @Override
        public Collection<String> call() {
            return extension.getExtraArgs();
        }
    });
}
Also used : TextResource(org.gradle.api.resources.TextResource) Collection(java.util.Collection) FileCollection(org.gradle.api.file.FileCollection) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Example 7 with ConventionMapping

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

the class EnvJsPlugin method apply.

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

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

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

        public void execute(BrowserEvaluate task) {
            ((IConventionAware) task).getConventionMapping().map("evaluator", new Callable<EnvJsBrowserEvaluator>() {

                public EnvJsBrowserEvaluator call() {
                    RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(workerProcessBuilderFactory);
                    File workDir = project.getProjectDir();
                    Factory<File> envJsFactory = new Factory<File>() {

                        public File create() {
                            return envJsExtension.getJs().getSingleFile();
                        }
                    };
                    return new EnvJsBrowserEvaluator(handleFactory, rhinoExtension.getClasspath(), envJsFactory, project.getGradle().getStartParameter().getLogLevel(), workDir);
                }
            });
        }
    });
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) Configuration(org.gradle.api.artifacts.Configuration) RhinoExtension(org.gradle.plugins.javascript.rhino.RhinoExtension) BrowserEvaluate(org.gradle.plugins.javascript.envjs.browser.BrowserEvaluate) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.RhinoWorkerHandleFactory) JavaScriptExtension(org.gradle.plugins.javascript.base.JavaScriptExtension) WorkerProcessFactory(org.gradle.process.internal.worker.WorkerProcessFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.RhinoWorkerHandleFactory) Factory(org.gradle.internal.Factory) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) EnvJsBrowserEvaluator(org.gradle.plugins.javascript.envjs.internal.EnvJsBrowserEvaluator) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File)

Example 8 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 9 with ConventionMapping

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

the class JavaGradlePluginPlugin method createAndConfigurePluginUnderTestMetadataTask.

private PluginUnderTestMetadata createAndConfigurePluginUnderTestMetadataTask(final Project project, final GradlePluginDevelopmentExtension extension) {
    final PluginUnderTestMetadata pluginUnderTestMetadataTask = project.getTasks().create(PLUGIN_UNDER_TEST_METADATA_TASK_NAME, PluginUnderTestMetadata.class);
    final Configuration gradlePluginConfiguration = project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi());
    ConventionMapping conventionMapping = new DslObject(pluginUnderTestMetadataTask).getConventionMapping();
    conventionMapping.map("pluginClasspath", new Callable<Object>() {

        public Object call() throws Exception {
            FileCollection gradleApi = gradlePluginConfiguration.getIncoming().getFiles();
            return extension.getPluginSourceSet().getRuntimeClasspath().minus(gradleApi);
        }
    });
    conventionMapping.map("outputDirectory", new Callable<Object>() {

        public Object call() throws Exception {
            return new File(project.getBuildDir(), pluginUnderTestMetadataTask.getName());
        }
    });
    return pluginUnderTestMetadataTask;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) PluginUnderTestMetadata(org.gradle.plugin.devel.tasks.PluginUnderTestMetadata) DslObject(org.gradle.api.internal.plugins.DslObject) DslObject(org.gradle.api.internal.plugins.DslObject) FileCollection(org.gradle.api.file.FileCollection) ConventionMapping(org.gradle.api.internal.ConventionMapping) File(java.io.File) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException)

Example 10 with ConventionMapping

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

the class PlayIdeaPlugin method configureIdeaModule.

@Mutate
public void configureIdeaModule(@Path("tasks.ideaModule") GenerateIdeaModule ideaModule, @Path("binaries.playBinary") final PlayApplicationBinarySpec playApplicationBinarySpec, @Path("buildDir") final File buildDir, ConfigurationContainer configurations, final FileResolver fileResolver) {
    IdeaModule module = ideaModule.getModule();
    module.setScopes(buildScopes(configurations));
    ConventionMapping conventionMapping = conventionMappingFor(module);
    conventionMapping.map("sourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            // TODO: Assets should probably be a source set too
            Set<File> sourceDirs = Sets.newHashSet(playApplicationBinarySpec.getAssets().getAssetDirs());
            return CollectionUtils.inject(sourceDirs, playApplicationBinarySpec.getInputs(), new Action<CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet>>() {

                @Override
                public void execute(CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet> step) {
                    step.getTarget().addAll(step.getItem().getSource().getSrcDirs());
                }
            });
        }
    });
    conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {

        @Override
        public Set<File> call() throws Exception {
            // TODO: This should be modeled as a source set
            return Collections.singleton(fileResolver.resolve("test"));
        }
    });
    conventionMapping.map("singleEntryLibraries", new Callable<Map<String, Iterable<File>>>() {

        @Override
        public Map<String, Iterable<File>> call() throws Exception {
            return ImmutableMap.<String, Iterable<File>>builder().put("COMPILE", Collections.singleton(playApplicationBinarySpec.getClasses().getClassesDir())).put("RUNTIME", playApplicationBinarySpec.getClasses().getResourceDirs()).put("TEST", Collections.singleton(new File(buildDir, "playBinary/testClasses"))).build();
        }
    });
    module.setScalaPlatform(playApplicationBinarySpec.getTargetPlatform().getScalaPlatform());
    conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {

        @Override
        public JavaVersion call() throws Exception {
            return getTargetJavaVersion(playApplicationBinarySpec);
        }
    });
    conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {

        @Override
        public IdeaLanguageLevel call() throws Exception {
            return new IdeaLanguageLevel(getTargetJavaVersion(playApplicationBinarySpec));
        }
    });
    ideaModule.dependsOn(playApplicationBinarySpec.getInputs());
    ideaModule.dependsOn(playApplicationBinarySpec.getAssets());
}
Also used : Action(org.gradle.api.Action) LanguageSourceSet(org.gradle.language.base.LanguageSourceSet) Set(java.util.Set) CollectionUtils(org.gradle.util.CollectionUtils) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) GenerateIdeaModule(org.gradle.plugins.ide.idea.GenerateIdeaModule) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) LanguageSourceSet(org.gradle.language.base.LanguageSourceSet) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Mutate(org.gradle.model.Mutate)

Aggregations

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