Search in sources :

Example 16 with FileCollection

use of org.gradle.api.file.FileCollection 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 17 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class OsgiPlugin method apply.

public void apply(final Project project) {
    project.getPluginManager().apply(JavaBasePlugin.class);
    final OsgiPluginConvention osgiConvention = new OsgiPluginConvention((ProjectInternal) project);
    project.getConvention().getPlugins().put("osgi", osgiConvention);
    project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

        @Override
        public void execute(JavaPlugin javaPlugin) {
            // When creating the OSGi manifest, we must have a single view of all of the classes included in the jar.
            Sync prepareOsgiClasses = project.getTasks().create("osgiClasses", Sync.class);
            FileCollection classes = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main").getOutput().getClassesDirs();
            File singleClassesDirectory = new File(project.getBuildDir(), "osgi-classes");
            prepareOsgiClasses.setDescription("Prepares a single classes directory required for OSGi analysis.");
            prepareOsgiClasses.from(classes);
            prepareOsgiClasses.into(singleClassesDirectory);
            Jar jarTask = (Jar) project.getTasks().getByName("jar");
            jarTask.dependsOn(prepareOsgiClasses);
            OsgiManifest osgiManifest = osgiConvention.osgiManifest();
            osgiManifest.setClassesDir(singleClassesDirectory);
            osgiManifest.setClasspath(project.getConfigurations().getByName("runtime"));
            jarTask.setManifest(osgiManifest);
        }
    });
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Jar(org.gradle.api.tasks.bundling.Jar) Sync(org.gradle.api.tasks.Sync) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 18 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class CompositeFileCollection method getFiles.

public Set<File> getFiles() {
    // Gather each of the backing Sets first, so we can set the initial capacity of the LinkedHashSet
    List<Set<File>> fileSets = new LinkedList<Set<File>>();
    int fileCount = 0;
    for (FileCollection collection : getSourceCollections()) {
        Set<File> files = collection.getFiles();
        fileCount += files.size();
        fileSets.add(files);
    }
    Set<File> allFiles = new LinkedHashSet<File>(fileCount);
    for (Set<File> fileSet : fileSets) {
        allFiles.addAll(fileSet);
    }
    return allFiles;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) LinkedList(java.util.LinkedList)

Example 19 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class GroovyBasePlugin method configureGroovydoc.

private void configureGroovydoc() {
    project.getTasks().withType(Groovydoc.class, new Action<Groovydoc>() {

        public void execute(final Groovydoc groovydoc) {
            groovydoc.getConventionMapping().map("groovyClasspath", new Callable<Object>() {

                public Object call() throws Exception {
                    FileCollection groovyClasspath = groovyRuntime.inferGroovyClasspath(groovydoc.getClasspath());
                    // Jansi is required to log errors when generating Groovydoc
                    ConfigurableFileCollection jansi = project.files(moduleRegistry.getExternalModule("jansi").getImplementationClasspath().getAsFiles());
                    return groovyClasspath.plus(jansi);
                }
            });
            groovydoc.getConventionMapping().map("destinationDir", new Callable<Object>() {

                public Object call() throws Exception {
                    return new File(java(project.getConvention()).getDocsDir(), "groovydoc");
                }
            });
            groovydoc.getConventionMapping().map("docTitle", new Callable<Object>() {

                public Object call() throws Exception {
                    return project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle();
                }
            });
            groovydoc.getConventionMapping().map("windowTitle", new Callable<Object>() {

                public Object call() throws Exception {
                    return project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle();
                }
            });
        }
    });
}
Also used : ReportingExtension(org.gradle.api.reporting.ReportingExtension) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) Callable(java.util.concurrent.Callable) Groovydoc(org.gradle.api.tasks.javadoc.Groovydoc)

Example 20 with FileCollection

use of org.gradle.api.file.FileCollection in project gradle by gradle.

the class CompositeFileCollectionTest method filterDelegatesToEachSet.

@Test
public void filterDelegatesToEachSet() {
    final FileCollectionInternal filtered1 = context.mock(FileCollectionInternal.class);
    final FileCollectionInternal filtered2 = context.mock(FileCollectionInternal.class);
    @SuppressWarnings("unchecked") final Spec<File> spec = context.mock(Spec.class);
    FileCollection filtered = collection.filter(spec);
    assertThat(filtered, instanceOf(CompositeFileCollection.class));
    context.checking(new Expectations() {

        {
            oneOf(source1).filter(spec);
            will(returnValue(filtered1));
            oneOf(source2).filter(spec);
            will(returnValue(filtered2));
        }
    });
    assertThat(((CompositeFileCollection) filtered).getSourceCollections(), equalTo((Iterable) toList(filtered1, filtered2)));
}
Also used : Expectations(org.jmock.Expectations) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) Test(org.junit.Test)

Aggregations

FileCollection (org.gradle.api.file.FileCollection)39 File (java.io.File)20 Callable (java.util.concurrent.Callable)6 ArrayList (java.util.ArrayList)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)3 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)3 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)3 CompileOptions (com.android.build.gradle.internal.CompileOptions)2 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 Transformer (org.gradle.api.Transformer)2 Configuration (org.gradle.api.artifacts.Configuration)2 CompositeFileCollection (org.gradle.api.internal.file.CompositeFileCollection)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 Expectations (org.jmock.Expectations)2