Search in sources :

Example 16 with FileTree

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

the class CompositeFileCollectionTest method fileTreeIsLive.

@Test
public void fileTreeIsLive() {
    final File dir1 = new File("dir1");
    final File dir2 = new File("dir1");
    final File dir3 = new File("dir1");
    final MinimalFileSet source3 = context.mock(MinimalFileSet.class);
    FileTree fileTree = collection.getAsFileTree();
    assertThat(fileTree, instanceOf(CompositeFileTree.class));
    context.checking(new Expectations() {

        {
            oneOf(source1).getFiles();
            will(returnValue(toSet(dir1)));
            oneOf(source2).getFiles();
            will(returnValue(toSet(dir2)));
        }
    });
    ((CompositeFileTree) fileTree).getSourceCollections();
    collection.sourceCollections.add(source3);
    context.checking(new Expectations() {

        {
            oneOf(source1).getFiles();
            will(returnValue(toSet(dir1)));
            oneOf(source2).getFiles();
            will(returnValue(toSet(dir2)));
            oneOf(source3).getFiles();
            will(returnValue(toSet(dir3)));
        }
    });
    ((CompositeFileTree) fileTree).getSourceCollections();
}
Also used : Expectations(org.jmock.Expectations) FileTree(org.gradle.api.file.FileTree) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) MinimalFileSet(org.gradle.api.internal.file.collections.MinimalFileSet) File(java.io.File) Test(org.junit.Test)

Example 17 with FileTree

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

the class CompositeFileTreeTest method matchingWithClosureReturnsUnionOfFilteredSets.

@Test
public void matchingWithClosureReturnsUnionOfFilteredSets() {
    final Closure closure = TestUtil.TEST_CLOSURE;
    final FileTreeInternal filtered1 = context.mock(FileTreeInternal.class);
    final FileTreeInternal filtered2 = context.mock(FileTreeInternal.class);
    context.checking(new Expectations() {

        {
            oneOf(source1).matching(closure);
            will(returnValue(filtered1));
            oneOf(source2).matching(closure);
            will(returnValue(filtered2));
        }
    });
    FileTree filtered = tree.matching(closure);
    assertThat(filtered, instanceOf(CompositeFileTree.class));
    CompositeFileTree filteredCompositeSet = (CompositeFileTree) filtered;
    assertThat(toList(filteredCompositeSet.getSourceCollections()), equalTo(toList(filtered1, filtered2)));
}
Also used : Expectations(org.jmock.Expectations) Closure(groovy.lang.Closure) FileTree(org.gradle.api.file.FileTree) Test(org.junit.Test)

Example 18 with FileTree

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

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

the class DefaultScalaJavaJointCompiler method execute.

public WorkResult execute(ScalaJavaJointCompileSpec spec) {
    scalaCompiler.execute(spec);
    PatternFilterable patternSet = new PatternSet();
    patternSet.include("**/*.java");
    FileTree javaSource = spec.getSource().getAsFileTree().matching(patternSet);
    if (!javaSource.isEmpty()) {
        spec.setSource(javaSource);
        javaCompiler.execute(spec);
    }
    return new WorkResult() {

        public boolean getDidWork() {
            return true;
        }
    };
}
Also used : FileTree(org.gradle.api.file.FileTree) WorkResult(org.gradle.api.tasks.WorkResult) PatternSet(org.gradle.api.tasks.util.PatternSet) PatternFilterable(org.gradle.api.tasks.util.PatternFilterable)

Example 20 with FileTree

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

the class SourceTask method getSource.

/**
 * Returns the source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.
 *
 * @return The source.
 */
@InputFiles
@SkipWhenEmpty
public FileTree getSource() {
    ArrayList<Object> copy = new ArrayList<Object>(this.source);
    FileTree src = getProject().files(copy).getAsFileTree();
    return src.matching(patternSet);
}
Also used : ArrayList(java.util.ArrayList) FileTree(org.gradle.api.file.FileTree)

Aggregations

FileTree (org.gradle.api.file.FileTree)24 File (java.io.File)8 Test (org.junit.Test)6 GradleException (org.gradle.api.GradleException)5 Expectations (org.jmock.Expectations)5 IOException (java.io.IOException)4 FileCollection (org.gradle.api.file.FileCollection)4 TaskAction (org.gradle.api.tasks.TaskAction)4 PatternSet (org.gradle.api.tasks.util.PatternSet)4 Project (org.gradle.api.Project)2 DirectoryFileTree (org.gradle.api.internal.file.collections.DirectoryFileTree)2 MinimalFileSet (org.gradle.api.internal.file.collections.MinimalFileSet)2 TestClassProcessor (org.gradle.api.internal.tasks.testing.TestClassProcessor)2 TestFramework (org.gradle.api.internal.tasks.testing.TestFramework)2 WorkerTestClassProcessorFactory (org.gradle.api.internal.tasks.testing.WorkerTestClassProcessorFactory)2 MaxNParallelTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.MaxNParallelTestClassProcessor)2 RestartEveryNTestClassProcessor (org.gradle.api.internal.tasks.testing.processors.RestartEveryNTestClassProcessor)2 TestMainAction (org.gradle.api.internal.tasks.testing.processors.TestMainAction)2 ForkingTestClassProcessor (org.gradle.api.internal.tasks.testing.worker.ForkingTestClassProcessor)2 SourceSet (org.gradle.api.tasks.SourceSet)2