Interface FileCollection
- All Superinterfaces:
AntBuilderAware
,Buildable
,Iterable<File>
- All Known Subinterfaces:
ConfigurableFileCollection
,ConfigurableFileTree
,Configuration
,FileTree
,SourceDirectorySet
,SourceSetOutput
A FileCollection
represents a collection of files which you can query in certain ways. A file collection
is often used to define a classpath, or to add files to a container.
You can obtain a FileCollection
instance using Project.files(java.lang.Object...)
.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Ant types which aFileCollection
can be mapped to. -
Method Summary
Modifier and TypeMethodDescriptionadd
(FileCollection collection) Adds another collection to this collection.addToAntBuilder
(Object builder, String nodeName) Adds this collection to an Ant task as a nested node.void
addToAntBuilder
(Object builder, String nodeName, FileCollection.AntType type) Adds this collection to an Ant task as a nested node.Converts this collection into an object of the specified type.boolean
Determines whether this collection contains the given file.Restricts the contents of this collection to those files which match the given criteria.Restricts the contents of this collection to those files which match the given criteria.Converts this collection to aFileTree
.Returns the contents of this collection as a platform-specific path.getFiles()
Returns the contents of this collection as a Set.Returns the content of this collection, asserting it contains exactly one file.boolean
isEmpty()
Returns true if this collection is empty.minus
(FileCollection collection) Returns aFileCollection
which contains the difference between this collection and the given collection.plus
(FileCollection collection) Returns aFileCollection
which contains the union of this collection and the given collection.Throws aStopExecutionException
if this collection is empty.Methods inherited from interface org.gradle.api.Buildable
getBuildDependencies
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getSingleFile
Returns the content of this collection, asserting it contains exactly one file.- Returns:
- The file.
- Throws:
IllegalStateException
- when this collection does not contain exactly one file.
-
getFiles
Returns the contents of this collection as a Set.- Returns:
- The files. Returns an empty set if this collection is empty.
-
contains
Determines whether this collection contains the given file. Generally, this method is more efficient than callinggetFiles().contains(file)
.- Parameters:
file
- The file to check for.- Returns:
- true if this collection contains the given file, false otherwise.
-
getAsPath
String getAsPath()Returns the contents of this collection as a platform-specific path. This can be used, for example, in an Ant <path> element.- Returns:
- The path. Returns an empty string if this collection is empty.
-
plus
Returns a
FileCollection
which contains the union of this collection and the given collection. The returned collection is live, and tracks changes to both source collections.You can call this method in your build script using the
+
operator.- Parameters:
collection
- The other collection. Should not be null.- Returns:
- A new collection containing the union.
-
minus
Returns a
FileCollection
which contains the difference between this collection and the given collection. The returned collection is live, and tracks changes to both source collections.You can call this method in your build script using the
-
operator.- Parameters:
collection
- The other collection. Should not be null.- Returns:
- A new collection containing the difference.
-
filter
Restricts the contents of this collection to those files which match the given criteria. The filtered collection is live, so that it reflects any changes to this collection.
The given closure is passed the File as a parameter, and should return a boolean value.
- Parameters:
filterClosure
- The closure to use to select the contents of the filtered collection.- Returns:
- The filtered collection.
-
filter
Restricts the contents of this collection to those files which match the given criteria. The filtered collection is live, so that it reflects any changes to this collection.
- Parameters:
filterSpec
- The criteria to use to select the contents of the filtered collection.- Returns:
- The filtered collection.
-
asType
Converts this collection into an object of the specified type. Supported types are:
Collection
,List
,Set
,Object[]
,File[]
,File
, andFileTree
.You can call this method in your build script using the
as
operator.- Parameters:
type
- The type to convert to.- Returns:
- The converted value.
- Throws:
UnsupportedOperationException
- When an unsupported type is specified.
-
add
Adds another collection to this collection. This is an optional operation.
- Parameters:
collection
- The collection to add.- Returns:
- This
- Throws:
UnsupportedOperationException
- When this collection does not allow modification.
-
isEmpty
boolean isEmpty()Returns true if this collection is empty. Generally, calling this method is more efficient than callinggetFiles().isEmpty()
.- Returns:
- true if this collection is empty, false otherwise.
-
stopExecutionIfEmpty
Throws aStopExecutionException
if this collection is empty.- Returns:
- this
- Throws:
StopExecutionException
- When this collection is empty.
-
getAsFileTree
FileTree getAsFileTree()Converts this collection to aFileTree
. Generally, for each file in this collection, the resulting file tree will contain the source file at the root of the tree. For each directory in this collection, the resulting file tree will contain all the files under the source directory.- Returns:
- this collection as a
FileTree
. Never returns null.
-
addToAntBuilder
Adds this collection to an Ant task as a nested node. The given type determines how this collection is added:FileCollection.AntType.MatchingTask
: adds this collection to an Ant MatchingTask. The collection is converted to a set of source directories and include and exclude patterns. The source directories as added as an Ant Path with the given node name. The patterns are added using 'include' and 'exclude' nodes.FileCollection.AntType.FileSet
: adds this collection as zero or more Ant FileSets with the given node name.FileCollection.AntType.ResourceCollection
: adds this collection as zero or more Ant ResourceCollections with the given node name.
FileCollection.AntType.ResourceCollection
, if the target Ant task supports it, as this is generally the most efficient. Using the other types may involve copying the contents of this collection to a temporary directory.- Parameters:
builder
- The builder to add this collection to.nodeName
- The target node name.type
- The target Ant type
-
addToAntBuilder
Adds this collection to an Ant task as a nested node. Equivalent to callingaddToAntBuilder(builder, nodeName,AntType.ResourceCollection)
.- Specified by:
addToAntBuilder
in interfaceAntBuilderAware
-