Package: org.gradle.api.file

## [Java] Interface CopySpec

- org.gradle.api.file.ContentFilterable

- All Superinterfaces:
    CopyProcessingSpec, PatternFilterable, CopySourceSpec, ContentFilterable

  A set of specifications for copying files. This includes:

  - source directories (multiples allowed)
  - destination directory
  - ANT like include patterns
  - ANT like exclude patterns
  - File relocating rules
  - renaming rules
  - content filters
  CopySpecs may be nested by passing a closure to one of the from methods. The closure creates a child CopySpec and delegates methods in the closure to the child. Child CopySpecs inherit any values specified in the parent. This allows constructs like:

       def myCopySpec = project.copySpec {
         into('webroot')
         exclude('**/.data/**')
         from('src/main/webapp') {
           include '**/*.jsp'
         }
         from('src/main/js') {
           include '**/*.js'
         }
       }

  In this example, the `into` and `exclude` specifications at the root level are inherited by the two child CopySpecs. Copy specs can be reused in other copy specs via with(CopySpec...) method. This enables reuse of the copy spec instances.

       def contentSpec = copySpec {
         from("content") {
           include "**/*.txt"
         }
       }

       task copy(type: Copy) {
         into "$buildDir/copy"
         with contentSpec
       }

  See Also:
    Copy Task
    Project.copy

- - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `CopySpec` | `eachFile(Action<? super FileCopyDetails> action)` {@inheritDoc}
    `CopySpec` | `eachFile(groovy.lang.Closure closure)` {@inheritDoc}
    `CopySpec` | `exclude(String... excludes)` {@inheritDoc}
    `CopySpec` | `exclude(Iterable<String> excludes)` {@inheritDoc}
    `CopySpec` | `exclude(Spec<FileTreeElement> excludeSpec)` {@inheritDoc}
    `CopySpec` | `exclude(groovy.lang.Closure excludeSpec)` {@inheritDoc}
    `CopySpec` | `expand(Map<String, ?> properties)` {@inheritDoc}
    `CopySpec` | `filesMatching(String pattern, Action<? super FileCopyDetails> action)` Configure the FileCopyDetails for each file whose path matches the specified Ant-style pattern.
    `CopySpec` | `filesNotMatching(String pattern, Action<? super FileCopyDetails> action)` Configure the FileCopyDetails for each file whose path does not match the specified Ant-style pattern.
    `CopySpec` | `filter(Map<String, ?> properties, Class<? extends FilterReader> filterType)` {@inheritDoc}
    `CopySpec` | `filter(Class<? extends FilterReader> filterType)` {@inheritDoc}
    `CopySpec` | `filter(groovy.lang.Closure closure)` {@inheritDoc}
    `CopySpec` | `from(Object... sourcePaths)` {@inheritDoc}
    `CopySpec` | `from(Object sourcePath, groovy.lang.Closure c)` {@inheritDoc}
    `DuplicatesStrategy` | `getDuplicatesStrategy()` Returns the strategy to use when trying to copy more than one file to the same destination.
    `String` | `getFilteringCharset()` Gets the charset used to read and write files when filtering.
    `boolean` | `getIncludeEmptyDirs()` Tells if empty target directories will be included in the copy.
    `CopySpec` | `include(String... includes)` {@inheritDoc}
    `CopySpec` | `include(Iterable<String> includes)` {@inheritDoc}
    `CopySpec` | `include(Spec<FileTreeElement> includeSpec)` {@inheritDoc}
    `CopySpec` | `include(groovy.lang.Closure includeSpec)` {@inheritDoc}
    `CopySpec` | `into(Object destPath)` {@inheritDoc}
    `CopySpec` | `into(Object destPath, groovy.lang.Closure configureClosure)` Creates and configures a child `CopySpec` with the given destination path.
    `boolean` | `isCaseSensitive()` Specifies whether case-sensitive pattern matching should be used.
    `CopySpec` | `rename(groovy.lang.Closure closure)` {@inheritDoc}
    `CopySpec` | `rename(String sourceRegEx, String replaceWith)` {@inheritDoc}
    `CopyProcessingSpec` | `rename(Pattern sourceRegEx, String replaceWith)` {@inheritDoc}
    `void` | `setCaseSensitive(boolean caseSensitive)` Specifies whether case-sensitive pattern matching should be used for this CopySpec.
    `void` | `setDuplicatesStrategy(DuplicatesStrategy strategy)` The strategy to use when trying to copy more than one file to the same destination.
    `CopySpec` | `setExcludes(Iterable<String> excludes)` {@inheritDoc}
    `void` | `setFilteringCharset(String charset)` Specifies the charset used to read and write files when filtering.
    `void` | `setIncludeEmptyDirs(boolean includeEmptyDirs)` Controls if empty target directories should be included in the copy.
    `CopySpec` | `setIncludes(Iterable<String> includes)` {@inheritDoc}
    `CopySpec` | `with(CopySpec... sourceSpecs)` Adds the given specs as a child of this spec.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `interface CopyProcessingSpec` | `eachFile, eachFile, getDirMode, getFileMode, into, rename, rename, rename, setDirMode, setFileMode`
    `interface CopySourceSpec` | `from, from`
    `interface PatternFilterable` | `exclude, exclude, exclude, exclude, getExcludes, getIncludes, include, include, include, include, setExcludes, setIncludes`

- - ### Method Detail

    - #### public CopySpec eachFile(Action<? super FileCopyDetails> action)

      {@inheritDoc}

    - #### public CopySpec eachFile(groovy.lang.Closure closure)

      {@inheritDoc}

    - #### public CopySpec exclude(String... excludes)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec exclude(Iterable<String> excludes)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec exclude(Spec<FileTreeElement> excludeSpec)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec exclude(groovy.lang.Closure excludeSpec)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec expand(Map<String, ?> properties)

      {@inheritDoc}

    - #### @Incubating public CopySpec filesMatching(String pattern, Action<? super FileCopyDetails> action)

      Configure the FileCopyDetails for each file whose path matches the specified Ant-style pattern. This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.

      Parameters:
        `pattern` - Ant-style pattern used to match against files' relative paths
        `action` - action called for the FileCopyDetails of each file matching pattern
      Returns:
        this

    - #### @Incubating public CopySpec filesNotMatching(String pattern, Action<? super FileCopyDetails> action)

      Configure the FileCopyDetails for each file whose path does not match the specified Ant-style pattern. This is equivalent to using eachFile() and selectively applying a configuration based on the file's path.

      Parameters:
        `pattern` - Ant-style pattern used to match against files' relative paths
        `action` - action called for the FileCopyDetails of each file that does not match pattern
      Returns:
        this

    - #### public CopySpec filter(Map<String, ?> properties, Class<? extends FilterReader> filterType)

      {@inheritDoc}

    - #### public CopySpec filter(Class<? extends FilterReader> filterType)

      {@inheritDoc}

    - #### public CopySpec filter(groovy.lang.Closure closure)

      {@inheritDoc}

    - #### public CopySpec from(Object... sourcePaths)

      {@inheritDoc}

    - #### public CopySpec from(Object sourcePath, groovy.lang.Closure c)

      {@inheritDoc}

    - #### @Incubating public DuplicatesStrategy getDuplicatesStrategy()

      Returns the strategy to use when trying to copy more than one file to the same destination.

      The value can be set with a case insensitive string of the enum value (e.g. `'exclude'` for DuplicatesStrategy.EXCLUDE).

      This strategy can be overridden for individual files by using eachFile(org.gradle.api.Action) or filesMatching(String, org.gradle.api.Action).

      Returns:
        the strategy to use for files included by this copy spec.
      See Also:
        DuplicatesStrategy

    - #### @Incubating public String getFilteringCharset()

      Gets the charset used to read and write files when filtering. By default, the JVM default charset is used.

      Returns:
        the charset used to read and write files when filtering
      Since:
        2.14

    - #### public boolean getIncludeEmptyDirs()

      Tells if empty target directories will be included in the copy.

      Returns:
        `true` if empty target directories will be included in the copy, `false` otherwise

    - #### public CopySpec include(String... includes)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec include(Iterable<String> includes)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec include(Spec<FileTreeElement> includeSpec)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec include(groovy.lang.Closure includeSpec)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec into(Object destPath)

      {@inheritDoc}

    - #### public CopySpec into(Object destPath, groovy.lang.Closure configureClosure)

      Creates and configures a child `CopySpec` with the given destination path. The destination is evaluated as per Project.file.

      Parameters:
        `destPath` - Path to the destination directory for a Copy
        `configureClosure` - The closure to use to configure the child `CopySpec`.
      Returns:
        this

    - #### public boolean isCaseSensitive()

      Specifies whether case-sensitive pattern matching should be used.

      Returns:
        true for case-sensitive matching.

    - #### public CopySpec rename(groovy.lang.Closure closure)

      {@inheritDoc}

    - #### public CopySpec rename(String sourceRegEx, String replaceWith)

      {@inheritDoc}

    - #### public CopyProcessingSpec rename(Pattern sourceRegEx, String replaceWith)

      {@inheritDoc}

    - #### public void setCaseSensitive(boolean caseSensitive)

      Specifies whether case-sensitive pattern matching should be used for this CopySpec.

      Parameters:
        `caseSensitive` - true for case-sensitive matching.

    - #### @Incubating public void setDuplicatesStrategy(@Nullable DuplicatesStrategy strategy)

      The strategy to use when trying to copy more than one file to the same destination. Set to `null` to use the default strategy, which is inherited from the parent copy spec, if any, or DuplicatesStrategy.INCLUDE if this copy spec has no parent.

    - #### public CopySpec setExcludes(Iterable<String> excludes)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### @Incubating public void setFilteringCharset(String charset)

      Specifies the charset used to read and write files when filtering.

      Parameters:
        `charset` - the name of the charset to use when filtering files
      Since:
        2.14

    - #### public void setIncludeEmptyDirs(boolean includeEmptyDirs)

      Controls if empty target directories should be included in the copy.

      Parameters:
        `includeEmptyDirs` - `true` if empty target directories should be included in the copy, `false` otherwise

    - #### public CopySpec setIncludes(Iterable<String> includes)

      {@inheritDoc}

      See Also:
        Pattern Format

    - #### public CopySpec with(CopySpec... sourceSpecs)

      Adds the given specs as a child of this spec.

           def contentSpec = copySpec {
             from("content") {
               include "**/*.txt"
             }
           }

           task copy(type: Copy) {
             into "$buildDir/copy"
             with contentSpec
           }

      Parameters:
        `sourceSpecs` - The specs to add
      Returns:
        this