Search in sources :

Example 1 with DirectoryFileTree

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

the class CompositeFileCollection method getAsFileTrees.

@Override
protected Collection<DirectoryFileTree> getAsFileTrees() {
    List<DirectoryFileTree> fileTree = new ArrayList<DirectoryFileTree>();
    for (FileCollection source : getSourceCollections()) {
        AbstractFileCollection collection = (AbstractFileCollection) source;
        fileTree.addAll(collection.getAsFileTrees());
    }
    return fileTree;
}
Also used : ArrayList(java.util.ArrayList) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) FileCollection(org.gradle.api.file.FileCollection)

Example 2 with DirectoryFileTree

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

the class CacheBackedTaskHistoryRepository method getDeclaredOutputFilePaths.

private static ImmutableSet<String> getDeclaredOutputFilePaths(final TaskProperties taskProperties, final StringInterner stringInterner) {
    final ImmutableSet.Builder<String> declaredOutputFilePaths = ImmutableSortedSet.naturalOrder();
    FileCollectionInternal outputFiles = (FileCollectionInternal) taskProperties.getOutputFiles();
    outputFiles.visitRootElements(new FileCollectionVisitor() {

        @Override
        public void visitCollection(FileCollectionInternal fileCollection) {
            addAllPaths(fileCollection, declaredOutputFilePaths, stringInterner);
        }

        @Override
        public void visitTree(FileTreeInternal fileTree) {
            DeprecationLogger.nagUserOfDeprecated("Adding file trees which are not directory trees as output files");
            addAllPaths(fileTree, declaredOutputFilePaths, stringInterner);
        }

        @Override
        public void visitDirectoryTree(DirectoryFileTree directoryTree) {
            addPath(directoryTree.getDir(), declaredOutputFilePaths, stringInterner);
        }
    });
    return declaredOutputFilePaths.build();
}
Also used : FileCollectionVisitor(org.gradle.api.internal.file.FileCollectionVisitor) ImmutableSet(com.google.common.collect.ImmutableSet) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) FileTreeInternal(org.gradle.api.internal.file.FileTreeInternal)

Example 3 with DirectoryFileTree

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

the class CompositeFileCollectionTest method getAsFileTreesReturnsUnionOfFileTrees.

@Test
public void getAsFileTreesReturnsUnionOfFileTrees() {
    final DirectoryFileTreeFactory directoryFileTreeFactory = new DefaultDirectoryFileTreeFactory();
    final DirectoryFileTree set1 = directoryFileTreeFactory.create(new File("dir1").getAbsoluteFile());
    final DirectoryFileTree set2 = directoryFileTreeFactory.create(new File("dir2").getAbsoluteFile());
    context.checking(new Expectations() {

        {
            oneOf(source1).getAsFileTrees();
            will(returnValue(toList((Object) set1)));
            oneOf(source2).getAsFileTrees();
            will(returnValue(toList((Object) set2)));
        }
    });
    assertThat(collection.getAsFileTrees(), equalTo((Collection) toList(set1, set2)));
}
Also used : Expectations(org.jmock.Expectations) DefaultDirectoryFileTreeFactory(org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory) DirectoryFileTreeFactory(org.gradle.api.internal.file.collections.DirectoryFileTreeFactory) DefaultDirectoryFileTreeFactory(org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory) FileCollection(org.gradle.api.file.FileCollection) Collection(java.util.Collection) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) File(java.io.File) Test(org.junit.Test)

Example 4 with DirectoryFileTree

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

the class DefaultSourceDirectorySet method getSourceTrees.

protected Set<DirectoryFileTree> getSourceTrees() {
    Set<DirectoryFileTree> result = new LinkedHashSet<>();
    for (Object path : source) {
        if (path instanceof DefaultSourceDirectorySet) {
            DefaultSourceDirectorySet nested = (DefaultSourceDirectorySet) path;
            result.addAll(nested.getSourceTrees());
        } else {
            for (File srcDir : fileCollectionFactory.resolving(path)) {
                if (srcDir.exists() && !srcDir.isDirectory()) {
                    throw new InvalidUserDataException(String.format("Source directory '%s' is not a directory.", srcDir));
                }
                result.add(directoryFileTreeFactory.create(srcDir, patterns));
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DirectoryFileTree(org.gradle.api.internal.file.collections.DirectoryFileTree) File(java.io.File)

Aggregations

DirectoryFileTree (org.gradle.api.internal.file.collections.DirectoryFileTree)4 File (java.io.File)2 FileCollection (org.gradle.api.file.FileCollection)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)1 FileCollectionVisitor (org.gradle.api.internal.file.FileCollectionVisitor)1 FileTreeInternal (org.gradle.api.internal.file.FileTreeInternal)1 DefaultDirectoryFileTreeFactory (org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory)1 DirectoryFileTreeFactory (org.gradle.api.internal.file.collections.DirectoryFileTreeFactory)1 Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1