api / org.gradle.api.file / FileCopyDetails

FileCopyDetails

@NonExtensible interface FileCopyDetails : FileTreeElement, ContentFilterable

Provides details about a file or directory about to be copied, and allows some aspects of the destination file to be modified.

Using this interface, you can change the destination path of the file, filter the content of the file, or exclude the file from the result entirely.

Access to the source file itself after any filters have been added is not a supported operation.

Functions

exclude

abstract fun exclude(): Unit

Excludes this file from the copy.

getDuplicatesStrategy

abstract fun getDuplicatesStrategy(): DuplicatesStrategy

The strategy to use if there is already a file at this file's destination.

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

getName

abstract fun getName(): String

Returns the base name of this file at the copy destination.

getPath

abstract fun getPath(): String

Returns the path of this file, relative to the root of the copy destination.

Always uses '/' as the hierarchy separator, regardless of platform file separator. Same as calling getRelativePath().getPathString().

getRelativePath

abstract fun getRelativePath(): RelativePath

Returns the path of this file, relative to the root of the copy destination.

getRelativeSourcePath

abstract fun getRelativeSourcePath(): RelativePath

Returns the path of this file, relative to the root of the containing file tree.

getSourceName

abstract fun getSourceName(): String

Returns the base name of this file at the copy source.

getSourcePath

abstract fun getSourcePath(): String

Returns the path of this file, relative to the root of the containing file tree.

Always uses '/' as the hierarchy separator, regardless of platform file separator. Same as calling getRelativeSourcePath().getPathString().

setDuplicatesStrategy

abstract fun setDuplicatesStrategy(strategy: DuplicatesStrategy): Unit

The strategy to use if there is already a file at this file's destination.

setMode

abstract fun setMode(mode: Int): Unit

Sets the Unix permissions of this file.

setName

abstract fun setName(name: String): Unit

Sets the destination name of this file.

setPath

abstract fun setPath(path: String): Unit

Sets the destination path of this file.

setRelativePath

abstract fun setRelativePath(path: RelativePath): Unit

Sets the destination path of this file.

Inherited Functions

copyTo

abstract fun copyTo(output: OutputStream): Unit

Copies the content of this file to an output stream. Generally, calling this method is more performant than calling new FileInputStream(getFile()).

abstract fun copyTo(target: File): Boolean

Copies this file to the given target file. Does not copy the file if the target is already a copy of this file.

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.

getFile

abstract fun getFile(): File

Returns the file being visited.

getLastModified

abstract fun getLastModified(): Long

Returns the last modified time of this file at the time of file traversal.

getMode

abstract fun getMode(): Int

Returns the Unix permissions of this file, e.g. 0644.

getSize

abstract fun getSize(): Long

Returns the size of this file at the time of file traversal.

isDirectory

abstract fun isDirectory(): Boolean

Returns true if this element is a directory, or false if this element is a regular file.

open

abstract fun open(): InputStream

Opens this file as an input stream. Generally, calling this method is more performant than calling new FileInputStream(getFile()).