@AutoFinal @CompileStatic class FileTreeBuilder extends Object
A builder dedicated at generating a file directory structure from a specification. For example, imagine that you want to create the following tree:
src/ |--- main | |--- groovy | |--- Foo.groovy |--- test |--- groovy |--- FooTest.groovy
Then you can create the structure using:
def tree = new FileTreeBuilder()
tree.dir('src') {
dir('main') {
dir('groovy') {
file('Foo.groovy', 'println "Hello"')
}
}
dir('test') {
dir('groovy') {
file('FooTest.groovy', 'class FooTest extends GroovyTestCase {}')
}
}
}
or with this shorthand syntax:
def tree = new FileTreeBuilder()
tree.src {
main {
groovy {
'Foo.groovy'('println "Hello"')
}
}
test {
groovy {
'FooTest.groovy'('class FooTest extends GroovyTestCase {}')
}
}
}
Constructor and description |
---|
FileTreeBuilder(File baseDir) |
Type Params | Return Type | Name and description |
---|---|---|
|
File |
call(Closure spec) |
|
File |
dir(String name) Creates a new empty directory |
|
File |
dir(String name, Closure spec) Creates a new directory and allows to specify a subdirectory structure using the closure as a specification |
|
File |
file(String name, CharSequence contents) Creates a file with the specified name and the text contents using the system default encoding. |
|
File |
file(String name, byte[] contents) Creates a file with the specified name and the specified binary contents |
|
File |
file(String name, File source) Creates a file with the specified name and the contents from the source file (copy). |
|
File |
file(String name, Closure spec) Creates a new file in the current directory, whose contents is going to be generated in the closure. |
|
Object |
methodMissing(String name, Object args) |
Creates a new empty directory
name
- the name of the directory to createCreates a new directory and allows to specify a subdirectory structure using the closure as a specification
name
- name of the directory to be createdspec
- specification of the subdirectory structureCreates a file with the specified name and the text contents using the system default encoding.
name
- name of the file to be createdcontents
- the contents of the file, written using the system default encodingCreates a file with the specified name and the specified binary contents
name
- name of the file to be createdcontents
- the contents of the fileCreates a file with the specified name and the contents from the source file (copy).
name
- name of the file to be createdcontents
- the contents of the fileCreates a new file in the current directory, whose contents is going to be generated in the closure. The delegate of the closure is the file being created.
name
- name of the file to createspec
- closure for generating the file contentsCopyright © 2003-2022 The Apache Software Foundation. All rights reserved.