Skip to content

Commit

Permalink
Fix resolving DirectoryTee elements of a FileCollection.
Browse files Browse the repository at this point in the history
  • Loading branch information
adammurdoch committed Aug 27, 2019
1 parent d62577e commit b6bd8e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Expand Up @@ -729,6 +729,8 @@ public interface Project extends Comparable<Project>, ExtensionAware, PluginAwar
*
* <li>A {@link org.gradle.api.file.FileCollection}. The contents of the collection are included in the returned collection.</li>
*
* <li>A {@link org.gradle.api.file.FileTree} or {@link org.gradle.api.file.DirectoryTree}. The contents of the tree are included in the returned collection.</li>
*
* <li>A {@link Provider} of any supported type. The provider's value is recursively converted to files. If the provider represents an output of a task, that task is executed if the file collection is used as an input to another task.
*
* <li>A {@link java.util.concurrent.Callable} that returns any supported type. The return value of the {@code call()} method is recursively converted to files. A {@code null} return value is treated as an empty collection.</li>
Expand Down
Expand Up @@ -18,6 +18,7 @@ package org.gradle.api.internal.file

import org.gradle.api.tasks.TasksWithInputsAndOutputs
import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import spock.lang.Issue
import spock.lang.Unroll

class FileCollectionIntegrationTest extends AbstractIntegrationSpec implements TasksWithInputsAndOutputs {
Expand All @@ -37,6 +38,26 @@ class FileCollectionIntegrationTest extends AbstractIntegrationSpec implements T
type << ["Object", "Object[]", "Set", "LinkedHashSet", "List", "LinkedList", "Collection", "FileCollection"]
}

@Issue("https://github.com/gradle/gradle/issues/10322")
def "can construct file collection from the elements of a source directory set"() {
buildFile << """
def fileCollection = objects.fileCollection()
def sourceDirs = objects.sourceDirectorySet('main', 'main files')
sourceDirs.srcDirs("dir1", "dir2")
fileCollection.from(sourceDirs.srcDirTrees)
println("files = \${fileCollection.files.name.sort()}")
"""

given:
file("dir1/file1").createFile()
file("dir1/file2").createFile()
file("dir2/sub/file3").createFile()

expect:
succeeds()
outputContains("files = [file1, file2, file3]")
}

def "finalized file collection resolves locations and ignores later changes to source paths"() {
buildFile << """
def files = objects.fileCollection()
Expand Down
Expand Up @@ -18,6 +18,7 @@

import org.gradle.api.Buildable;
import org.gradle.api.Task;
import org.gradle.api.file.DirectoryTree;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.provider.ProviderInternal;
import org.gradle.api.internal.tasks.TaskDependencyContainer;
Expand All @@ -43,6 +44,10 @@ public void add(@Nullable Object element) {
context.add(element);
return;
}
if (element instanceof DirectoryTree) {
context.add(element);
return;
}
if (element instanceof ProviderInternal) {
// ProviderInternal is-a TaskDependencyContainer, so check first
ProviderInternal provider = (ProviderInternal) element;
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.gradle.api.internal.file.collections

import org.gradle.api.Task
import org.gradle.api.file.DirectoryTree
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.provider.ProviderInternal
import org.gradle.api.tasks.TaskOutputs
Expand Down Expand Up @@ -202,4 +203,14 @@ class UnpackingVisitorTest extends Specification {
0 * context._
}

def "forwards DirectoryTree"() {
def tree = Mock(DirectoryTree)

when:
visitor.add(tree)

then:
1 * context.add(tree)
0 * _
}
}

0 comments on commit b6bd8e7

Please sign in to comment.