Package: groovy.util

## [Groovy] Class FileTreeBuilder

- groovy.util.FileTreeBuilder

-     @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 {}')
                 }
              }
           }

  Since:
    2.4.2

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `File` | `baseDir` The base directory for created files and directories.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `FileTreeBuilder(File baseDir)` Creates a builder rooted at the specified base directory.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `File` | `call(Closure spec)` Applies the supplied tree specification to the current base directory.
    `` | `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)` Supports shorthand directory and file creation syntax.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Property Detail

    - #### File baseDir

      The base directory for created files and directories.

  - ### Constructor Detail

    - #### FileTreeBuilder(File baseDir)

      Creates a builder rooted at the specified base directory.

      Parameters:
        `baseDir` - the base directory

  - ### Method Detail

    - #### File call(@DelegatesTo(value=FileTreeBuilder, strategy=Closure.DELEGATE_FIRST)
      Closure spec)

      Applies the supplied tree specification to the current base directory.

      Parameters:
        `spec` - the directory tree specification
      Returns:
        the current base directory

    - #### File dir(String name)

      Creates a new empty directory

      Parameters:
        `name` - the name of the directory to create
      Returns:
        the created directory

    - #### File dir(String name, @DelegatesTo(value=FileTreeBuilder, strategy=Closure.DELEGATE_FIRST)
      Closure spec)

      Creates a new directory and allows to specify a subdirectory structure using the closure as a specification

      Parameters:
        `name` - name of the directory to be created
        `spec` - specification of the subdirectory structure
      Returns:
        the created directory

    - #### File file(String name, CharSequence contents)

      Creates a file with the specified name and the text contents using the system default encoding.

      Parameters:
        `name` - name of the file to be created
        `contents` - the contents of the file, written using the system default encoding
      Returns:
        the file being created

    - #### File file(String name, byte[] contents)

      Creates a file with the specified name and the specified binary contents

      Parameters:
        `name` - name of the file to be created
        `contents` - the contents of the file
      Returns:
        the file being created

    - #### File file(String name, File source)

      Creates a file with the specified name and the contents from the source file (copy).

      Parameters:
        `name` - name of the file to be created
        `source` - the source file to copy
      Returns:
        the file being created

    - #### File file(String name, @ClosureParams(value=FromString, options="File")
      @DelegatesTo(value=File, strategy=Closure.DELEGATE_FIRST)
      Closure spec)

      Creates 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.

      Parameters:
        `name` - name of the file to create
        `spec` - closure for generating the file contents
      Returns:
        the created file

    - #### Object methodMissing(String name, Object args)

      Supports shorthand directory and file creation syntax.

      Parameters:
        `name` - the directory or file name
        `args` - the shorthand arguments describing what to create
      Returns:
        the created file or directory, or `null` if the arguments are unsupported