Package: org.codehaus.groovy.ant

## [Java] Class Groovy

- org.codehaus.groovy.ant.Groovy

-     public class Groovy
      extends Java

  Executes a series of Groovy statements.

  Statements can either be read in from a text file using the src attribute or from between the enclosing groovy tags.

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `addClassPathes(GroovyClassLoader classLoader)` Adds the class paths (if any)
    `` | `public void` | `addConfigured(ResourceCollection a)` Set the source resource.
    `` | `public void` | `addFileset(FileSet set)` Adds a fileset (nested fileset attribute) which should represent a single source file.
    `` | `public final void` | `addFilterChain(FilterChain filter)` Add the FilterChain element.
    `` | `public void` | `addText(String txt)` Set an inline command to execute.
    `` | `public Argument` | `createArg()` Creates a nested command-line argument for the executed script.
    `` | `public Path` | `createClasspath()` Returns a new path element that can be configured.
    `` | `protected void` | `execGroovy(String txt, PrintStream out)` Exec the statement.
    `` | `public void` | `execute()` Load the file and then execute it
    `` | `public Path` | `getClasspath()` Gets the classpath.
    `` | `public boolean` | `getParameters()` Returns true if parameter metadata generation has been enabled.
    `` | `public static void` | `main(String[] args)` Command-line entry point used when the task executes scripts in forked mode.
    `` | `protected void` | `printResults(PrintStream out)` print any results in the statement.
    `` | `protected void` | `runStatements(Reader reader, PrintStream out)` Read in lines and execute them.
    `` | `public void` | `setAppend(boolean append)` Whether output should be appended to or overwrite an existing file.
    `` | `public void` | `setClasspath(Path classpath)` Sets the classpath for loading.
    `` | `public void` | `setClasspathRef(Reference ref)` Set the classpath for loading using the classpath reference.
    `` | `public void` | `setConfigscript(String configscript)` Sets the configuration script for the groovy compiler configuration.
    `` | `public void` | `setContextClassLoader(boolean contextClassLoader)` Setting to true will cause the contextClassLoader to be set with the classLoader of the shell used to run the script.
    `` | `public void` | `setEncoding(String encoding)` Declare the encoding to use when inputting from a resource; If not supplied or the empty encoding is supplied, a guess will be made for file resources, otherwise the platform's default encoding will be used.
    `` | `public void` | `setFork(boolean fork)` Should the script be executed using a forked process.
    `` | `public void` | `setIncludeAntRuntime(boolean includeAntRuntime)` Should the system classpath be included on the classpath when forking.
    `` | `public void` | `setIndy(boolean indy)` Legacy method to set the indy flag (only true is allowed)
    `` | `public void` | `setInheritAll(boolean inheritAll)` If true, pass all properties from the parent Ant project to the forked JVM as system properties so the script can read them via `System.getProperty(name)`.
    `` | `public void` | `setOutput(File output)` Set the output file; optional, defaults to the Ant log.
    `` | `public void` | `setOutputEncoding(String encoding)` Declare the encoding to use when outputting to a file; Leave unspecified or use "" for the platform's default encoding.
    `` | `public void` | `setParameters(boolean parameters)` If true, generates metadata for reflection on method parameter names (jdk8+ only).
    `` | `public void` | `setScriptBaseClass(String scriptBaseClass)` Set the script base class name
    `` | `public void` | `setSrc(File srcFile)` Set the name of the file to be run.
    `` | `public void` | `setStacktrace(boolean stacktrace)` Enable compiler to report stack trace information if a problem occurs during compilation.
    `` | `public void` | `setUseGroovyShell(boolean useGroovyShell)` Should a new GroovyShell be used when forking.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Java` | `addAssertions, addConfiguredRedirector, addEnv, addSysproperty, addSyspropertyset, bindToOwner, clearArgs, clone, createArg, createBootclasspath, createClasspath, createJvmarg, createModulepath, createPermissions, createUpgrademodulepath, equals, execute, executeJava, getClass, getCommandLine, getDescription, getLocation, getOwningTarget, getProject, getRuntimeConfigurableWrapper, getSysProperties, getTaskName, getTaskType, handleInput, hashCode, init, log, log, log, log, maybeConfigure, notify, notifyAll, perform, reconfigure, setAppend, setArgs, setClassname, setClasspath, setClasspathRef, setCloneVm, setDescription, setDir, setDiscardError, setDiscardOutput, setError, setErrorProperty, setFailonerror, setFork, setInput, setInputString, setJVMVersion, setJar, setJvm, setJvmargs, setLocation, setLogError, setMaxmemory, setModule, setModulepath, setModulepathRef, setNewenvironment, setOutput, setOutputproperty, setOwningTarget, setProject, setResultProperty, setRuntimeConfigurableWrapper, setSourceFile, setSpawn, setTaskName, setTaskType, setTimeout, toString, wait, wait, wait`

- - ### Method Detail

    - #### protected void addClassPathes(GroovyClassLoader classLoader)

      Adds the class paths (if any)

      Parameters:
        `classLoader` - the classloader to configure

    - #### public void addConfigured(ResourceCollection a)

      Set the source resource.

      Parameters:
        `a` - the resource to load as a single element Resource collection.

    - #### public void addFileset(FileSet set)

      Adds a fileset (nested fileset attribute) which should represent a single source file.

      Parameters:
        `set` - the fileset representing a source file

    - #### public final void addFilterChain(FilterChain filter)

      Add the FilterChain element.

      Parameters:
        `filter` - the filter to add

    - #### public void addText(String txt)

      Set an inline command to execute. NB: Properties are not expanded in this text.

      Parameters:
        `txt` - the inline groovy commands to execute

    - #### public Argument createArg()

      Creates a nested command-line argument for the executed script.

      Returns:
        the argument to configure

    - #### public Path createClasspath()

      Returns a new path element that can be configured. Gets called for instance by Ant when it encounters a nested <classpath> element.

      Returns:
        the resulting created path

    - #### protected void execGroovy(String txt, PrintStream out)

      Exec the statement.

      Parameters:
        `txt` - the groovy source to exec
        `out` - not used?

    - #### public void execute()

      Load the file and then execute it

    - #### public Path getClasspath()

      Gets the classpath.

      Returns:
        Returns a Path

    - #### public boolean getParameters()

      Returns true if parameter metadata generation has been enabled.

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

      Command-line entry point used when the task executes scripts in forked mode.

      Parameters:
        `args` - the script file followed by script arguments

    - #### protected void printResults(PrintStream out)

      print any results in the statement.

      Parameters:
        `out` - the output PrintStream to print to

    - #### protected void runStatements(Reader reader, PrintStream out)

      Read in lines and execute them.

      throws:
        java.io.IOException if something goes wrong
      Parameters:
        `reader` - the reader from which to get the groovy source to exec
        `out` - the outputstream to use

    - #### public void setAppend(boolean append)

      Whether output should be appended to or overwrite an existing file. Defaults to false.

      Parameters:
        `append` - set to true to append

    - #### public void setClasspath(Path classpath)

      Sets the classpath for loading.

      Parameters:
        `classpath` - The classpath to set

    - #### public void setClasspathRef(Reference ref)

      Set the classpath for loading using the classpath reference.

      Parameters:
        `ref` - the refid to use

    - #### public void setConfigscript(String configscript)

      Sets the configuration script for the groovy compiler configuration.

      Parameters:
        `configscript` - path to the configuration script

    - #### public void setContextClassLoader(boolean contextClassLoader)

      Setting to true will cause the contextClassLoader to be set with the classLoader of the shell used to run the script. Not used if fork is true. Not allowed when running from Maven but in that case the context classLoader is set appropriately for Maven.

      Parameters:
        `contextClassLoader` - set to true to set the context classloader

    - #### public void setEncoding(String encoding)

      Declare the encoding to use when inputting from a resource; If not supplied or the empty encoding is supplied, a guess will be made for file resources, otherwise the platform's default encoding will be used.

      Parameters:
        `encoding` - the character encoding to use.
      Since:
        3.0.3

    - #### public void setFork(boolean fork)

      Should the script be executed using a forked process. Defaults to false.

      Parameters:
        `fork` - true if the script should be executed in a forked process

    - #### public void setIncludeAntRuntime(boolean includeAntRuntime)

      Should the system classpath be included on the classpath when forking. Defaults to true.

      Parameters:
        `includeAntRuntime` - true if the system classpath should be on the classpath

    - #### @Deprecated
      public void setIndy(boolean indy)

      Legacy method to set the indy flag (only true is allowed)

      Parameters:
        `indy` - true means invokedynamic support is active

    - #### public void setInheritAll(boolean inheritAll)

      If true, pass all properties from the parent Ant project to the forked JVM as system properties so the script can read them via `System.getProperty(name)`. Only takes effect when `fork` is true. Defaults to false.

      For fine-grained control, use a nested `<syspropertyset>` (inherited from the `<java>` task) instead. Both may be combined; explicit `<sysproperty>` and `<syspropertyset>` entries take precedence on name collision.

      Parameters:
        `inheritAll` - true to inherit all Ant properties into the forked JVM
      Since:
        6.0.0

    - #### public void setOutput(File output)

      Set the output file; optional, defaults to the Ant log.

      Parameters:
        `output` - the output file

    - #### public void setOutputEncoding(String encoding)

      Declare the encoding to use when outputting to a file; Leave unspecified or use "" for the platform's default encoding.

      Parameters:
        `encoding` - the character encoding to use.
      Since:
        3.0.3

    - #### public void setParameters(boolean parameters)

      If true, generates metadata for reflection on method parameter names (jdk8+ only). Defaults to false.

      Parameters:
        `parameters` - set to true to generate metadata.

    - #### public void setScriptBaseClass(String scriptBaseClass)

      Set the script base class name

      Parameters:
        `scriptBaseClass` - the name of the base class for scripts

    - #### public void setSrc(File srcFile)

      Set the name of the file to be run. The folder of the file is automatically added to the classpath. Required unless statements are enclosed in the build file or a nested resource is supplied.

      Parameters:
        `srcFile` - the file containing the groovy script to execute

    - #### public void setStacktrace(boolean stacktrace)

      Enable compiler to report stack trace information if a problem occurs during compilation.

      Parameters:
        `stacktrace` - set to true to enable stacktrace reporting

    - #### public void setUseGroovyShell(boolean useGroovyShell)

      Should a new GroovyShell be used when forking. Special variables won't be available but you don't need Ant in the classpath.

      Parameters:
        `useGroovyShell` - true if GroovyShell should be used to run the script directly