Search in sources :

Example 6 with SimpleFileCollection

use of org.gradle.api.internal.file.collections.SimpleFileCollection 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 7 with SimpleFileCollection

use of org.gradle.api.internal.file.collections.SimpleFileCollection in project gradle by gradle.

the class IncrementalCompilationInitializer method initializeCompilation.

public void initializeCompilation(JavaCompileSpec spec, Collection<String> staleClasses) {
    if (staleClasses.isEmpty()) {
        spec.setSource(new SimpleFileCollection());
        //do nothing. No classes need recompilation.
        return;
    }
    Factory<PatternSet> patternSetFactory = fileOperations.getFileResolver().getPatternSetFactory();
    PatternSet classesToDelete = patternSetFactory.create();
    PatternSet sourceToCompile = patternSetFactory.create();
    preparePatterns(staleClasses, classesToDelete, sourceToCompile);
    //selectively configure the source
    spec.setSource(spec.getSource().getAsFileTree().matching(sourceToCompile));
    //since we're compiling selectively we need to include the classes compiled previously
    List<File> classpath = Lists.newArrayList(spec.getCompileClasspath());
    classpath.add(spec.getDestinationDir());
    spec.setCompileClasspath(classpath);
    //get rid of stale files
    FileTree deleteMe = fileOperations.fileTree(spec.getDestinationDir()).matching(classesToDelete);
    fileOperations.delete(deleteMe);
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) FileTree(org.gradle.api.file.FileTree) PatternSet(org.gradle.api.tasks.util.PatternSet) File(java.io.File)

Example 8 with SimpleFileCollection

use of org.gradle.api.internal.file.collections.SimpleFileCollection 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 9 with SimpleFileCollection

use of org.gradle.api.internal.file.collections.SimpleFileCollection in project gradle by gradle.

the class IncrementalCompilationInitializer method initializeCompilation.

public void initializeCompilation(JavaCompileSpec spec, RecompilationSpec recompilationSpec) {
    if (!recompilationSpec.isBuildNeeded()) {
        spec.setSource(new SimpleFileCollection());
        spec.setClasses(Collections.<String>emptySet());
        return;
    }
    Factory<PatternSet> patternSetFactory = fileOperations.getFileResolver().getPatternSetFactory();
    PatternSet classesToDelete = patternSetFactory.create();
    PatternSet sourceToCompile = patternSetFactory.create();
    preparePatterns(recompilationSpec.getClassesToCompile(), classesToDelete, sourceToCompile);
    narrowDownSourcesToCompile(spec, sourceToCompile);
    includePreviousCompilationOutputOnClasspath(spec);
    addClassesToProcess(spec, recompilationSpec);
    deleteStaleFilesIn(classesToDelete, spec.getDestinationDir());
    deleteStaleFilesIn(classesToDelete, spec.getCompileOptions().getAnnotationProcessorGeneratedSourcesDirectory());
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 10 with SimpleFileCollection

use of org.gradle.api.internal.file.collections.SimpleFileCollection in project gradle by gradle.

the class CompileOptions method setBootClasspath.

/**
 * Sets the bootstrap classpath to be used for the compiler process. Defaults to {@code null}.
 *
 * @deprecated Use {@link #setBootstrapClasspath(FileCollection)} instead.
 */
@Deprecated
public void setBootClasspath(String bootClasspath) {
    DeprecationLogger.nagUserOfReplacedProperty("CompileOptions.bootClasspath", "CompileOptions.bootstrapClasspath");
    if (bootClasspath == null) {
        this.bootstrapClasspath = null;
    } else {
        String[] paths = StringUtils.split(bootClasspath, File.pathSeparatorChar);
        List<File> files = Lists.newArrayListWithCapacity(paths.length);
        for (String path : paths) {
            files.add(new File(path));
        }
        this.bootstrapClasspath = new SimpleFileCollection(files);
    }
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) File(java.io.File)

Aggregations

SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)12 File (java.io.File)9 FileCollection (org.gradle.api.file.FileCollection)3 PatternSet (org.gradle.api.tasks.util.PatternSet)3 FileCollectionSnapshot (org.gradle.api.internal.changedetection.state.FileCollectionSnapshot)2 Test (org.gradle.api.tasks.testing.Test)2 DefaultBuildCacheHasher (org.gradle.caching.internal.DefaultBuildCacheHasher)2 HashCode (com.google.common.hash.HashCode)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)1 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)1 SimpleMessage (org.codehaus.groovy.control.messages.SimpleMessage)1 JavaAwareCompilationUnit (org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit)1 JavaCompiler (org.codehaus.groovy.tools.javac.JavaCompiler)1 JavaCompilerFactory (org.codehaus.groovy.tools.javac.JavaCompilerFactory)1 GradleException (org.gradle.api.GradleException)1 ArtifactTransformException (org.gradle.api.artifacts.transform.ArtifactTransformException)1