api / org.gradle.api.file / CopyProcessingSpec

CopyProcessingSpec

interface CopyProcessingSpec : ContentFilterable

Specifies the destination of a copy.

Functions

eachFile

abstract fun eachFile(action: Action<in FileCopyDetails>): CopyProcessingSpec

Adds an action to be applied to each file as it is about to be copied into its destination. The action can change the destination path of the file, filter the contents of the file, or exclude the file from the result entirely. Actions are executed in the order added, and are inherited from the parent spec.

abstract fun eachFile(closure: Closure<Any>): CopyProcessingSpec

Adds an action to be applied to each file as it about to be copied into its destination. The given closure is called with a org.gradle.api.file.FileCopyDetails as its parameter. Actions are executed in the order added, and are inherited from the parent spec.

getDirMode

abstract fun getDirMode(): Int

Returns the Unix permissions to use for the target directories. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

getFileMode

abstract fun getFileMode(): Int

Returns the Unix permissions to use for the target files. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

into

abstract fun into(destPath: Any): CopyProcessingSpec

Specifies the destination directory for a copy. The destination is evaluated as per .

rename

abstract fun rename(closure: Closure<Any>): CopyProcessingSpec

Renames a source file. The closure will be called with a single parameter, the name of the file. The closure should return a String object with a new target name. The closure may return null, in which case the original name will be used.

abstract fun rename(renamer: Transformer<String, String>): CopyProcessingSpec

Renames a source file. The function will be called with a single parameter, the name of the file. The function should return a new target name. The function may return null, in which case the original name will be used.

abstract fun rename(sourceRegEx: String, replaceWith: String): CopyProcessingSpec

Renames files based on a regular expression. Uses java.util.regex type of regular expressions. Note that the replace string should use the '$1' syntax to refer to capture groups in the source regular expression. Files that do not match the source regular expression will be copied with the original name.

Example:

 rename '(.*)_OEM_BLUE_(.*)', '$1$2' 
would map the file 'style_OEM_BLUE_.css' to 'style.css'

abstract fun rename(sourceRegEx: Pattern, replaceWith: String): CopyProcessingSpec

Renames files based on a regular expression. See #rename(String, String).

setDirMode

abstract fun setDirMode(mode: Int): CopyProcessingSpec

Sets the Unix permissions to use for the target directories. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

setFileMode

abstract fun setFileMode(mode: Int): CopyProcessingSpec

Sets the Unix permissions to use for the target files. null means that existing permissions are preserved. It is dependent on the copy action implementation whether these permissions will actually be applied.

Inherited Functions

expand

abstract fun expand(properties: MutableMap<String, *>): ContentFilterable

Expands property references in each file as it is copied. More specifically, each file is transformed using Groovy's groovy.text.SimpleTemplateEngine. This means you can use simple property references, such as $property or ${property} in the file. You can also include arbitrary Groovy code in the file, such as ${version ?: 'unknown'} or ${classpath*.name.join(' ')}

filter

abstract fun filter(properties: MutableMap<String, *>, filterType: Class<out FilterReader>): ContentFilterable

Adds a content filter to be used during the copy. Multiple calls to filter, add additional filters to the filter chain. Each filter should implement java.io.FilterReader. Include org.apache.tools.ant.filters.* for access to all the standard Ant filters.

Filter properties may be specified using groovy map syntax.

Examples:

 filter(HeadFilter, lines:25, skip:2) filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1']) 

abstract fun filter(filterType: Class<out FilterReader>): ContentFilterable

Adds a content filter to be used during the copy. Multiple calls to filter, add additional filters to the filter chain. Each filter should implement java.io.FilterReader. Include org.apache.tools.ant.filters.* for access to all the standard Ant filters.

Examples:

 filter(StripJavaComments) filter(com.mycompany.project.CustomFilter) 

abstract fun filter(closure: Closure<Any>): ContentFilterable

Adds a content filter based on the provided closure. The Closure will be called with each line (stripped of line endings) and should return a String to replace the line or null to remove the line. If every line is removed, the result will be an empty file, not an absent one.

abstract fun filter(transformer: Transformer<String, String>): ContentFilterable

Adds a content filter based on the provided transformer. The Closure will be called with each line (stripped of line endings) and should return a String to replace the line or null to remove the line. If every line is removed, the result will be an empty file, not an absent one.

Inheritors

CopySpec

interface CopySpec : CopySourceSpec, CopyProcessingSpec, PatternFilterable

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 }