Search in sources :

Example 21 with FileCollection

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

the class NormalizingGroovyCompiler method resolveAndFilterSourceFiles.

private void resolveAndFilterSourceFiles(final GroovyJavaJointCompileSpec spec) {
    final List<String> fileExtensions = CollectionUtils.collect(spec.getGroovyCompileOptions().getFileExtensions(), new Transformer<String, String>() {

        @Override
        public String transform(String extension) {
            return '.' + extension;
        }
    });
    FileCollection filtered = spec.getSource().filter(new Spec<File>() {

        public boolean isSatisfiedBy(File element) {
            for (String fileExtension : fileExtensions) {
                if (hasExtension(element, fileExtension)) {
                    return true;
                }
            }
            return false;
        }
    });
    spec.setSource(new SimpleFileCollection(filtered.getFiles()));
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 22 with FileCollection

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

the class GroovyCompile method calculateAnnotationProcessorClasspath.

private List<File> calculateAnnotationProcessorClasspath() {
    AnnotationProcessorDetector annotationProcessorDetector = getServices().get(AnnotationProcessorDetector.class);
    FileCollection processorClasspath = annotationProcessorDetector.getEffectiveAnnotationProcessorClasspath(compileOptions, getClasspath());
    return Lists.newArrayList(processorClasspath);
}
Also used : AnnotationProcessorDetector(org.gradle.api.internal.tasks.compile.AnnotationProcessorDetector) FileCollection(org.gradle.api.file.FileCollection)

Example 23 with FileCollection

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

the class NormalizingJavaCompiler method resolveAndFilterSourceFiles.

private void resolveAndFilterSourceFiles(JavaCompileSpec spec) {
    // this mimics the behavior of the Ant javac task (and therefore AntJavaCompiler),
    // which silently excludes files not ending in .java
    FileCollection javaOnly = spec.getSource().filter(new Spec<File>() {

        public boolean isSatisfiedBy(File element) {
            return hasExtension(element, ".java");
        }
    });
    spec.setSource(new SimpleFileCollection(javaOnly.getFiles()));
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Example 24 with FileCollection

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

the class ShadedJar method run.

@TaskAction
public void run() throws Exception {
    long start = System.currentTimeMillis();
    PrintWriter writer = new PrintWriter(analysisFile);
    try {
        final ClassGraph classes = new ClassGraph(new PackagePatterns(keepPackages), new PackagePatterns(unshadedPackages), new PackagePatterns(ignorePackages), shadowPackage);
        List<FileCollection> classFiles = new ArrayList<>();
        for (File sourceFile : sourceFiles) {
            classFiles.add(getProject().zipTree(sourceFile));
        }
        analyse(getProject().files(classFiles), classes, writer);
        writeJar(classes, classesDir, jarFile, writer);
    } finally {
        writer.close();
    }
    long end = System.currentTimeMillis();
    System.out.println("Analysis took " + (end - start) + "ms.");
}
Also used : FileCollection(org.gradle.api.file.FileCollection) JarFile(java.util.jar.JarFile)

Example 25 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)32 File (java.io.File)16 Callable (java.util.concurrent.Callable)6 ArrayList (java.util.ArrayList)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)4 Set (java.util.Set)3 CompileOptions (com.android.build.gradle.internal.CompileOptions)2 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 List (java.util.List)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 Configuration (org.gradle.api.artifacts.Configuration)2 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Predicate (com.google.common.base.Predicate)1 Injector (com.google.inject.Injector)1 Closure (groovy.lang.Closure)1