Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD

## org.gradle.api.file
[Java] Interface FileCollection

    org.gradle.api.Buildable
      org.gradle.api.tasks.AntBuilderAware
          org.gradle.api.file.FileCollection

All Superinterfaces:
  Buildable, AntBuilderAware

    public interface FileCollection
    extends AntBuilderAware, Buildable, Iterable

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.

Nested Class Summary
`enum` | `FileCollection.AntType` Ant types which a `FileCollection` can be mapped to.

Method Summary
`FileCollection` | `add(FileCollection collection)`
`void` | `addToAntBuilder(Object builder, String nodeName, FileCollection.AntType type)`
`Object` | `addToAntBuilder(Object builder, String nodeName)` Adds this collection to an Ant task as a nested node.
`Object` | `asType(Class type)`
`boolean` | `contains(File file)` Determines whether this collection contains the given file.
`FileCollection` | `filter(Closure filterClosure)`
`FileCollection` | `filter(Spec filterSpec)`
`FileTree` | `getAsFileTree()` Converts this collection to a FileTree.
`String` | `getAsPath()` Returns the contents of this collection as a platform-specific path.
`Set` | `getFiles()` Returns the contents of this collection as a Set.
`File` | `getSingleFile()` Returns the content of this collection, asserting it contains exactly one file.
`boolean` | `isEmpty()` Returns true if this collection is empty.
`FileCollection` | `minus(FileCollection collection)`
`FileCollection` | `plus(FileCollection collection)`
`FileCollection` | `stopExecutionIfEmpty()` Throws a StopExecutionException if this collection is empty.

Methods inherited from interface Buildable
getBuildDependencies

Methods inherited from interface AntBuilderAware
addToAntBuilder

Methods inherited from interface Iterable
iterator

Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Method Detail

### add

    public FileCollection add(FileCollection collection)

  Adds another collection to this collection. This is an optional operation.

  throws:
    UnsupportedOperationException When this collection does not allow modification.
  Parameters:
    `collection` - The collection to add.
  Returns:
    This

### addToAntBuilder

    public void addToAntBuilder(Object builder, String nodeName, FileCollection.AntType type)

  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.

### addToAntBuilder

    public Object addToAntBuilder(Object builder, String nodeName)

  Adds this collection to an Ant task as a nested node. Equivalent to calling `addToAntBuilder(builder, nodeName,AntType.ResourceCollection)`.

### asType

    public Object asType(Class type)

  Converts this collection into an object of the specified type. Supported types are: `Collection`, `List`, `Set`, `Object[]`, `File[]`, `File`, and FileTree.

  You can call this method in your build script using the `as` operator.

  throws:
    UnsupportedOperationException When an unsupported type is specified.
  Parameters:
    `type` - The type to convert to.
  Returns:
    The converted value.

### contains

    public boolean contains(File file)

  Determines whether this collection contains the given file. Generally, this method is more efficient than calling `getFiles().contains(file)`.
  Parameters:
    `file` - The file to check for.
  Returns:
    true if this collection contains the given file, false otherwise.

### filter

    public FileCollection filter(Closure filterClosure)

  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

    public FileCollection filter(Spec filterSpec)

  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.

### getAsFileTree

    public FileTree getAsFileTree()

  Converts this collection to a FileTree. 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.

### getAsPath

    public String getAsPath()

  Returns the contents of this collection as a platform-specific path. This can be used, for example, in an Ant element.
  Returns:
    The path. Returns an empty string if this collection is empty.

### getFiles

    public Set getFiles()

  Returns the contents of this collection as a Set.
  Returns:
    The files. Returns an empty set if this collection is empty.

### getSingleFile

    public File getSingleFile()

  Returns the content of this collection, asserting it contains exactly one file.
  throws:
    IllegalStateException when this collection does not contain exactly one file.
  Returns:
    The file.

### isEmpty

    public boolean isEmpty()

  Returns true if this collection is empty. Generally, calling this method is more efficient than calling `getFiles().isEmpty()`.
  Returns:
    true if this collection is empty, false otherwise.

### minus

    public FileCollection minus(FileCollection collection)

  Returns a `FileCollection` which contains the intersection 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 intersection.

### plus

    public FileCollection plus(FileCollection collection)

  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.

### stopExecutionIfEmpty

    public FileCollection stopExecutionIfEmpty()

  Throws a StopExecutionException if this collection is empty.
  throws:
    StopExecutionException When this collection is empty.
  Returns:
    this

Gradle API 1.10