Package: org.codehaus.groovy.tools

## [Java] Class FileSystemCompiler

- org.codehaus.groovy.tools.FileSystemCompiler

-     public class FileSystemCompiler
      extends Object

  Command-line compiler (aka. `groovyc`).

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `FileSystemCompiler.CompilationOptions` | Command-line options accepted by the `groovyc` launcher.
    `static class` | `FileSystemCompiler.VersionProvider` | Supplies version text for the `groovyc` command line.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `FileSystemCompiler(CompilerConfiguration configuration)` Creates a file-system compiler using the supplied configuration.
    `FileSystemCompiler(CompilerConfiguration configuration, CompilationUnit cu)` Creates a file-system compiler using the supplied configuration and optional prebuilt compilation unit.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static int` | `checkFiles(String[] filenames)` Counts unreadable or missing source files in the supplied list.
    `` | `public static void` | `commandLineCompile(String[] args)` Same as main(args) except that exceptions are thrown out instead of causing the VM to exit.
    `` | `public static void` | `commandLineCompile(String[] args, boolean lookupUnnamedFiles)` Same as main(args) except that exceptions are thrown out instead of causing the VM to exit and the lookup for .groovy files can be controlled
    `` | `public static void` | `commandLineCompileWithErrorHandling(String[] args, boolean lookupUnnamedFiles)` Primary entry point for compiling from the command line (using the groovyc script).
    `` | `public void` | `compile(String[] paths)` Compiles the sources at the supplied paths.
    `` | `public void` | `compile(File[] files)` Compiles the supplied source files.
    `` | `public static CommandLine` | `configureParser(FileSystemCompiler.CompilationOptions options)` Creates and configures the command-line parser for compilation options.
    `` | `public static void` | `deleteRecursive(File file)` Deletes the supplied file or directory tree if it exists.
    `` | `public static void` | `displayHelp()` Prints the usage help message for CompilationOptions to stderr.
    `` | `public static void` | `displayHelp(PrintWriter writer)` Prints the usage help message for the CompilationOptions to the specified PrintWriter.
    `` | `public static void` | `displayVersion()` Prints version information to stderr.
    `` | `public static void` | `displayVersion(PrintWriter writer)` Prints version information to the specified PrintWriter.
    `` | `public static void` | `doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames)` Compiles the supplied source files using the given configuration.
    `` | `public static void` | `doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames, boolean lookupUnnamedFiles)` Compiles the supplied source files using the given configuration and controls whether unnamed Groovy sources are searched relative to the provided file list.
    `` | `public static void` | `doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames, boolean lookupUnnamedFiles, Writer warningWriter)` Compiles the supplied source files, optionally displaying any warnings collected during a successful compilation.
    `` | `public static void` | `main(String[] args)` Primary entry point for compiling from the command line (using the groovyc script).
    `` | `public static boolean` | `validateFiles(String[] filenames)` Returns whether all supplied file names resolve to readable files.

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public FileSystemCompiler(CompilerConfiguration configuration)

      Creates a file-system compiler using the supplied configuration.

      throws:
        ConfigurationException if the compilation unit cannot be created
      Parameters:
        `configuration` - the compiler configuration to apply

    - #### public FileSystemCompiler(CompilerConfiguration configuration, CompilationUnit cu)

      Creates a file-system compiler using the supplied configuration and optional prebuilt compilation unit.

      throws:
        ConfigurationException if the compilation unit cannot be created
      Parameters:
        `configuration` - the compiler configuration to apply
        `cu` - an existing compilation unit to reuse, or `null` to build a suitable one

  - ### Method Detail

    - #### public static int checkFiles(String[] filenames)

      Counts unreadable or missing source files in the supplied list.

      Parameters:
        `filenames` - the file names to validate
      Returns:
        the number of invalid file entries

    - #### public static void commandLineCompile(String[] args)

      Same as main(args) except that exceptions are thrown out instead of causing the VM to exit.

    - #### public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles)

      Same as main(args) except that exceptions are thrown out instead of causing the VM to exit and the lookup for .groovy files can be controlled

    - #### public static void commandLineCompileWithErrorHandling(String[] args, boolean lookupUnnamedFiles)

      Primary entry point for compiling from the command line (using the groovyc script).

      If calling inside a process and you don't want the JVM to exit on an error call commandLineCompile(String[]), which this method simply wraps

      Parameters:
        `args` - command line arguments
        `lookupUnnamedFiles` - do a lookup for .groovy files not part of the given list of files to compile

    - #### public void compile(String[] paths)

      Compiles the sources at the supplied paths.

      throws:
        Exception if compilation fails
      Parameters:
        `paths` - the source paths to compile

    - #### public void compile(File[] files)

      Compiles the supplied source files.

      throws:
        Exception if compilation fails
      Parameters:
        `files` - the source files to compile

    - #### public static CommandLine configureParser(FileSystemCompiler.CompilationOptions options)

      Creates and configures the command-line parser for compilation options.

      Parameters:
        `options` - the options object to bind parser results to
      Returns:
        the configured parser

    - #### public static void deleteRecursive(File file)

      Deletes the supplied file or directory tree if it exists.

      Parameters:
        `file` - the file or directory to delete

    - #### public static void displayHelp()

      Prints the usage help message for CompilationOptions to stderr.

      See Also:
        displayHelp(PrintWriter)
      Since:
        2.5

    - #### public static void displayHelp(PrintWriter writer)

      Prints the usage help message for the CompilationOptions to the specified PrintWriter.

      Since:
        2.5

    - #### public static void displayVersion()

      Prints version information to stderr.

      See Also:
        displayVersion(PrintWriter)

    - #### public static void displayVersion(PrintWriter writer)

      Prints version information to the specified PrintWriter.

      Since:
        2.5

    - #### public static void doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames)

      Compiles the supplied source files using the given configuration.

      throws:
        Exception if compilation fails
      Parameters:
        `configuration` - the compiler configuration to use
        `unit` - an existing compilation unit to reuse, or `null`
        `filenames` - the source files to compile

    - #### public static void doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames, boolean lookupUnnamedFiles)

      Compiles the supplied source files using the given configuration and controls whether unnamed Groovy sources are searched relative to the provided file list.

      throws:
        Exception if compilation fails
      Parameters:
        `configuration` - the compiler configuration to use
        `unit` - an existing compilation unit to reuse, or `null`
        `filenames` - the source files to compile
        `lookupUnnamedFiles` - whether to search for unnamed Groovy sources beside the listed files

    - #### public static void doCompilation(CompilerConfiguration configuration, CompilationUnit unit, String[] filenames, boolean lookupUnnamedFiles, Writer warningWriter)

      Compiles the supplied source files, optionally displaying any warnings collected during a successful compilation.

      Warning display is opt-in via `warningWriter` rather than hard-wired to `System.err`, so that this shared entry point does not impose console output on embedders (e.g. the in-process Ant `<groovyc>` task) that route diagnostics their own way or read the ErrorCollector directly. The `groovyc` command line supplies a `System.err` writer; other callers pass `null`.

      throws:
        Exception if compilation fails
      Parameters:
        `configuration` - the compiler configuration to use
        `unit` - an existing compilation unit to reuse, or `null`
        `filenames` - the source files to compile
        `lookupUnnamedFiles` - whether to search for unnamed Groovy sources beside the listed files
        `warningWriter` - where to write warnings collected on a successful compile, or `null` to leave warning handling to the caller
      Since:
        6.0.0

    - #### public static void main(String[] args)

      Primary entry point for compiling from the command line (using the groovyc script).

      If calling inside a process and you don't want the JVM to exit on an error call commandLineCompile(String[]), which this method simply wraps

      Parameters:
        `args` - command line arguments

    - #### public static boolean validateFiles(String[] filenames)

      Returns whether all supplied file names resolve to readable files.

      Parameters:
        `filenames` - the file names to validate
      Returns:
        `true` if every file exists and can be read