api / org.gradle.api.file / ContentFilterable

ContentFilterable

interface ContentFilterable

Represents some binary resource whose content can be filtered.

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.

Extension Functions

filter

fun <T : FilterReader> ContentFilterable.filter(vararg properties: Pair<String, Any?>): ContentFilterable
fun <T : FilterReader> ContentFilterable.filter(properties: Map<String, Any?>): ContentFilterable
fun <T : FilterReader> ContentFilterable.filter(filterType: KClass<T>, vararg properties: Pair<String, Any?>): ContentFilterable
fun <T : FilterReader> ContentFilterable.filter(filterType: KClass<T>, properties: Map<String, Any?>): ContentFilterable

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

Inheritors

CopyProcessingSpec

interface CopyProcessingSpec : ContentFilterable

Specifies the destination of a copy.

FileCopyDetails

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.