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();
}
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)));
}
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);
}
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;
}
};
}
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);
}
Aggregations