api / org.gradle.api.tasks.util / PatternFilterable

PatternFilterable

interface PatternFilterable

A PatternFilterable represents some file container which Ant-style include and exclude patterns or specs can be applied to.

Patterns may include:

Either '/' or '\' may be used in a pattern to separate directories. Patterns ending with '/' or '\' will have '**' automatically appended.

Examples:

 all files ending with 'jsp' (including subdirectories) **/*.jsp all files beginning with 'template_' in the level1/level2 directory level1/level2/template_* all files (including subdirectories) beneath src/main/webapp src/main/webapp/ all files beneath any .svn directory (including subdirectories) under src/main/java src/main/java/**/.svn/** 

You may also use a closure or Spec to specify which files to include or exclude. The closure or Spec is passed a org.gradle.api.file.FileTreeElement, and must return a boolean value.

If no include patterns or specs are specified, then all files in this container will be included. If any include patterns or specs are specified, then a file is included if it matches any of the patterns or specs.

If no exclude patterns or spec are specified, then no files will be excluded. If any exclude patterns or specs are specified, then a file is include only if it matches none of the patterns or specs.

Functions

exclude

abstract fun exclude(vararg excludes: String): PatternFilterable
abstract fun exclude(excludes: MutableIterable<String>): PatternFilterable

Adds an ANT style exclude pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

abstract fun exclude(excludeSpec: Spec<FileTreeElement>): PatternFilterable

Adds an exclude spec. This method may be called multiple times to append new specs. If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

abstract fun exclude(excludeSpec: Closure<Any>): PatternFilterable

Adds an exclude spec. This method may be called multiple times to append new specs.The given closure is passed a org.gradle.api.file.FileTreeElement as its parameter. The closure should return true or false. Example:

 copySpec { from 'source' into 'destination' //an example of excluding files from certain configuration: exclude { it.file in configurations.someConf.files } } 
If excludes are not provided, then no files will be excluded. If excludes are provided, then files must not match any exclude pattern to be processed.

getExcludes

abstract fun getExcludes(): MutableSet<String>

Returns the set of exclude patterns.

getIncludes

abstract fun getIncludes(): MutableSet<String>

Returns the set of include patterns.

include

abstract fun include(vararg includes: String): PatternFilterable
abstract fun include(includes: MutableIterable<String>): PatternFilterable

Adds an ANT style include pattern. This method may be called multiple times to append new patterns and multiple patterns may be specified in a single call. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns to be processed.

abstract fun include(includeSpec: Spec<FileTreeElement>): PatternFilterable

Adds an include spec. This method may be called multiple times to append new specs. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

abstract fun include(includeSpec: Closure<Any>): PatternFilterable

Adds an include spec. This method may be called multiple times to append new specs. The given closure is passed a org.gradle.api.file.FileTreeElement as its parameter. If includes are not provided, then all files in this container will be included. If includes are provided, then a file must match at least one of the include patterns or specs to be included.

setExcludes

abstract fun setExcludes(excludes: MutableIterable<String>): PatternFilterable

Set the allowable exclude patterns. Note that unlike #exclude(Iterable) this replaces any previously defined excludes.

setIncludes

abstract fun setIncludes(includes: MutableIterable<String>): PatternFilterable

Set the allowable include patterns. Note that unlike #include(Iterable) this replaces any previously defined includes.

Inheritors

ConfigurableFileTree

interface ConfigurableFileTree : FileTree, DirectoryTree, PatternFilterable, Buildable

A FileTree with a single base directory, which can be configured and modified.

You can obtain a ConfigurableFileTree instance by calling org.gradle.api.Project#fileTree(java.util.Map).

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 } 

PatternSet

open class PatternSet : AntBuilderAware, PatternFilterable

Standalone implementation of PatternFilterable.

SourceDirectorySet

interface SourceDirectorySet : FileTree, PatternFilterable, Named, Describable

A SourceDirectorySet represents a set of source files composed from a set of source directories, along with associated include and exclude patterns.

SourceDirectorySet extends FileTree. The contents of the file tree represent the source files of this set, arranged in a hierarchy. The file tree is live and reflects changes to the source directories and their contents.

SourceTask

open class SourceTask : ConventionTask, PatternFilterable

A SourceTask performs some operation on source files.

Test

open class Test : AbstractTestTask, JavaForkOptions, PatternFilterable

Executes JUnit (3.8.x, 4.x or 5.x) or TestNG tests. Test are always run in (one or more) separate JVMs. The sample below shows various configuration options.

 apply plugin: 'java' // adds 'test' task test { // enable TestNG support (default is JUnit) useTestNG() // enable JUnit Platform (a.k.a. JUnit 5) support useJUnitPlatform() // set a system property for the test JVM(s) systemProperty 'some.prop', 'value' // explicitly include or exclude tests include 'org/foo/**' exclude 'org/boo/**' // show standard out and standard error of the test JVM(s) on the console testLogging.showStandardStreams = true // set heap size for the test JVM(s) minHeapSize = "128m" maxHeapSize = "512m" // set JVM arguments for the test JVM(s) jvmArgs '-XX:MaxPermSize=256m' // listen to events in the test execution lifecycle beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) } // Fail the 'test' task on the first test failure failFast = true // listen to standard out and standard error of the test JVM(s) onOutput { descriptor, event -> logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message ) } } 

The test process can be started in debug mode (see #getDebug()) in an ad-hoc manner by supplying the `--debug-jvm` switch when invoking the build.

 gradle someTestTask --debug-jvm