Search in sources :

Example 11 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);
    pluginUnderTestMetadataTask.setGroup(PLUGIN_DEVELOPMENT_GROUP);
    pluginUnderTestMetadataTask.setDescription(PLUGIN_UNDER_TEST_METADATA_TASK_DESCRIPTION);
    final Configuration gradlePluginConfiguration = project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi());
    ConventionMapping conventionMapping = new DslObject(pluginUnderTestMetadataTask).getConventionMapping();
    conventionMapping.map("pluginClasspath", new Callable<Object>() {

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

        public Object call() {
            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)

Example 12 with ConventionMapping

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

the class JavaBasePlugin method configureSourceSetDefaults.

private BridgedBinaries configureSourceSetDefaults(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();
    final List<ClassDirectoryBinarySpecInternal> binaries = Lists.newArrayList();
    pluginConvention.getSourceSets().all(new Action<SourceSet>() {

        public void execute(final SourceSet sourceSet) {
            ConventionMapping outputConventionMapping = ((IConventionAware) sourceSet.getOutput()).getConventionMapping();
            ConfigurationContainer configurations = project.getConfigurations();
            defineConfigurationsForSourceSet(sourceSet, configurations);
            definePathsForSourceSet(sourceSet, outputConventionMapping, project);
            createProcessResourcesTaskForBinary(sourceSet, sourceSet.getResources(), project);
            createCompileJavaTaskForBinary(sourceSet, sourceSet.getJava(), project);
            createBinaryLifecycleTask(sourceSet, project);
            DefaultComponentSpecIdentifier binaryId = new DefaultComponentSpecIdentifier(project.getPath(), sourceSet.getName());
            ClassDirectoryBinarySpecInternal binary = instantiator.newInstance(DefaultClassDirectoryBinarySpec.class, binaryId, sourceSet, javaToolChain, DefaultJavaPlatform.current(), instantiator, taskFactory);
            Classpath compileClasspath = new SourceSetCompileClasspath(sourceSet);
            DefaultJavaSourceSet javaSourceSet = instantiator.newInstance(DefaultJavaSourceSet.class, binaryId.child("java"), sourceSet.getJava(), compileClasspath);
            JvmResourceSet resourceSet = instantiator.newInstance(DefaultJvmResourceSet.class, binaryId.child("resources"), sourceSet.getResources());
            binary.addSourceSet(javaSourceSet);
            binary.addSourceSet(resourceSet);
            attachTasksToBinary(binary, sourceSet, project);
            binaries.add(binary);
        }
    });
    return new BridgedBinaries(binaries);
}
Also used : ClassDirectoryBinarySpecInternal(org.gradle.api.internal.jvm.ClassDirectoryBinarySpecInternal) ConventionMapping(org.gradle.api.internal.ConventionMapping) SourceSetCompileClasspath(org.gradle.api.internal.tasks.SourceSetCompileClasspath) JvmResourceSet(org.gradle.language.jvm.JvmResourceSet) DefaultJvmResourceSet(org.gradle.api.internal.java.DefaultJvmResourceSet) Project(org.gradle.api.Project) ProjectSourceSet(org.gradle.language.base.ProjectSourceSet) DefaultJavaSourceSet(org.gradle.api.internal.java.DefaultJavaSourceSet) SourceSet(org.gradle.api.tasks.SourceSet) DefaultJvmResourceSet(org.gradle.api.internal.java.DefaultJvmResourceSet) DefaultJavaSourceSet(org.gradle.api.internal.java.DefaultJavaSourceSet) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) DefaultClassDirectoryBinarySpec(org.gradle.api.internal.jvm.DefaultClassDirectoryBinarySpec) Classpath(org.gradle.jvm.Classpath) SourceSetCompileClasspath(org.gradle.api.internal.tasks.SourceSetCompileClasspath) DefaultComponentSpecIdentifier(org.gradle.platform.base.internal.DefaultComponentSpecIdentifier)

Example 13 with ConventionMapping

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

the class OsgiPluginConvention method createDefaultOsgiManifest.

private OsgiManifest createDefaultOsgiManifest() {
    OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
    ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
    final OsgiHelper osgiHelper = new OsgiHelper();
    mapping.map("version", new Callable<Object>() {

        public Object call() throws Exception {
            return osgiHelper.getVersion(project.getVersion().toString());
        }
    });
    mapping.map("name", new Callable<Object>() {

        public Object call() throws Exception {
            return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
        }
    });
    mapping.map("symbolicName", new Callable<Object>() {

        public Object call() throws Exception {
            return osgiHelper.getBundleSymbolicName(project);
        }
    });
    return osgiManifest;
}
Also used : DefaultOsgiManifest(org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest) Instantiator(org.gradle.internal.reflect.Instantiator) OsgiHelper(org.gradle.api.internal.plugins.osgi.OsgiHelper) ConventionMapping(org.gradle.api.internal.ConventionMapping) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 14 with ConventionMapping

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

the class RhinoPlugin method apply.

public void apply(Project project) {
    project.getPluginManager().apply(JavaScriptBasePlugin.class);
    JavaScriptExtension jsExtension = project.getExtensions().findByType(JavaScriptExtension.class);
    final RhinoExtension rhinoExtension = ((ExtensionAware) jsExtension).getExtensions().create(RhinoExtension.NAME, RhinoExtension.class);
    final Configuration configuration = addClasspathConfiguration(project.getConfigurations());
    configureDefaultRhinoDependency(configuration, project.getDependencies(), rhinoExtension);
    ConventionMapping conventionMapping = ((IConventionAware) rhinoExtension).getConventionMapping();
    conventionMapping.map("classpath", new Callable<Configuration>() {

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

        public String call() {
            return RhinoExtension.DEFAULT_RHINO_DEPENDENCY_VERSION;
        }
    });
    project.getTasks().withType(RhinoShellExec.class, new Action<RhinoShellExec>() {

        public void execute(RhinoShellExec task) {
            task.getConventionMapping().map("classpath", new Callable<FileCollection>() {

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

                public String call() {
                    return RhinoExtension.RHINO_SHELL_MAIN;
                }
            });
            task.setClasspath(rhinoExtension.getClasspath());
        }
    });
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) JavaScriptExtension(org.gradle.plugins.javascript.base.JavaScriptExtension) ConventionMapping(org.gradle.api.internal.ConventionMapping) IConventionAware(org.gradle.api.internal.IConventionAware) Callable(java.util.concurrent.Callable)

Example 15 with ConventionMapping

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

the class CoffeeScriptBasePlugin method apply.

public void apply(Project project) {
    project.getPluginManager().apply(RhinoPlugin.class);
    JavaScriptExtension jsExtension = project.getExtensions().getByType(JavaScriptExtension.class);
    ExtensionContainer extensionContainer = ((ExtensionAware) jsExtension).getExtensions();
    final CoffeeScriptExtension csExtension = extensionContainer.create(CoffeeScriptExtension.NAME, CoffeeScriptExtension.class);
    final Configuration jsConfiguration = addJsConfiguration(project.getConfigurations(), project.getDependencies(), csExtension);
    ConventionMapping conventionMapping = ((IConventionAware) csExtension).getConventionMapping();
    conventionMapping.map("js", new Callable<Configuration>() {

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

        @Override
        public String call() {
            return CoffeeScriptExtension.DEFAULT_JS_DEPENDENCY_VERSION;
        }
    });
    final RhinoExtension rhinoExtension = extensionContainer.getByType(RhinoExtension.class);
    project.getTasks().withType(CoffeeScriptCompile.class, new Action<CoffeeScriptCompile>() {

        @Override
        public void execute(CoffeeScriptCompile task) {
            task.getConventionMapping().map("rhinoClasspath", new Callable<FileCollection>() {

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

                public FileCollection call() {
                    return csExtension.getJs();
                }
            });
        }
    });
}
Also used : 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) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) Callable(java.util.concurrent.Callable) ExtensionAware(org.gradle.api.plugins.ExtensionAware) IConventionAware(org.gradle.api.internal.IConventionAware)

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