## org.codehaus.groovy.ant
Class Groovyc

    java.lang.Object
      org.apache.tools.ant.ProjectComponent
          org.apache.tools.ant.Task
              org.apache.tools.ant.taskdefs.MatchingTask
                  org.codehaus.groovy.ant.Groovyc

All Implemented Interfaces:
  Cloneable, SelectorContainer

    public class Groovyc

extends MatchingTask

Compiles Groovy source files. This task can take the following arguments:

- srcdir
- destdir
- classpath
- encoding
- verbose
- failonerror
- includeantruntime
- includejavaruntime
- memoryInitialSize
- memoryMaximumSize
- fork
- stacktrace

Of these arguments, the srcdir and destdir are required.

When this task executes, it will recursively scan srcdir and destdir looking for Groovy source files to compile. This task makes its compile decision based on timestamp.

Based heavily on the Javac implementation in Ant.

Version:
  $Revision: 10601 $
Author:
  James Strachan, Hein Meling, Russel Winder

Field Summary
`protected File[]` `compileList`
`protected CompilerConfiguration` `configuration`
`protected boolean` `failOnError`
`protected boolean` `listFiles`

Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
`fileset`

Fields inherited from class org.apache.tools.ant.Task
`target, taskName, taskType, wrapper`

Fields inherited from class org.apache.tools.ant.ProjectComponent
`description, location, project`

Constructor Summary
`Groovyc()`

Method Summary
`void` `addConfiguredJavac(Javac javac)` Add the configured nested javac task if present to initiate joint compilation.
`protected void` `addToCompileList(File[] newFiles)`
`protected GroovyClassLoader` `buildClassLoaderFor()`
`protected void` `checkParameters()`
`protected void` `compile()`
`Path` `createClasspath()` Adds a path to the classpath.
`Path` `createSourcepath()` Adds a path to sourcepath.
`Path` `createSrc()` Adds a path for source compilation.
`protected File` `createTempDir()`
`void` `execute()` Executes the task.
`Path` `getClasspath()` Gets the classpath to be used for this compilation.
`File` `getDestdir()` Gets the destination directory into which the java source files should be compiled.
`String` `getEncoding()` Returns the encoding to be used when creating files.
`boolean` `getFailonerror()` Gets the failonerror flag.
`File[]` `getFileList()` Gets the list of files to be compiled.
`boolean` `getIncludeantruntime()` Gets whether or not the ant classpath is to be included in the classpath.
`boolean` `getIncludejavaruntime()` Gets whether or not the java runtime should be included in this task's classpath.
`boolean` `getListfiles()` Get the listfiles flag.
`String` `getMemoryInitialSize()` Gets the memoryInitialSize flag.
`String` `getMemoryMaximumSize()` Gets the memoryMaximumSize flag.
`Path` `getSourcepath()` Gets the sourcepath to be used for this compilation.
`Path` `getSrcdir()` Gets the source dirs to find the source java files.
`boolean` `getTaskSuccess()` Get the result of the groovyc task (success or failure).
`boolean` `getVerbose()` Gets the verbose flag.
`boolean` `isIncludeDestClasses()` Get the value of the includeDestClasses property.
`static void` `main(String[] args)` Provide an entry point for use by the java task.
`protected CompilationUnit` `makeCompileUnit()`
`protected Path` `recreateSrc()` Recreate src.
`protected void` `resetFileLists()` Clear the list of files to be compiled and copied..
`protected void` `scanDir(File srcDir, File destDir, String[] files)` Scans the directory looking for source files to be compiled.
`void` `setClasspath(Path classpath)` Set the classpath to be used for this compilation.
`void` `setClasspathRef(Reference r)` Adds a reference to a classpath defined elsewhere.
`void` `setDestdir(File destDir)` Set the destination directory into which the Java source files should be compiled.
`void` `setEncoding(String encoding)` Sets the file encoding for generated files.
`void` `setErrorProperty(String errorProperty)` The property to set on compliation failure.
`void` `setFailonerror(boolean fail)` Indicates whether the build will continue even if there are compilation errors; defaults to true.
`void` `setFork(boolean f)` If true forks the Groovy compiler.
`void` `setIncludeantruntime(boolean include)` If true, includes Ant's own classpath in the classpath.
`void` `setIncludeDestClasses(boolean includeDestClasses)` This property controls whether to include the destination classes directory in the classpath given to the compiler.
`void` `setIncludejavaruntime(boolean include)` If true, includes the Java runtime libraries in the classpath.
`void` `setListfiles(boolean list)` If true, list the source files being handed off to the compiler.
`void` `setMemoryInitialSize(String memoryInitialSize)` The initial size of the memory for the underlying VM if javac is run externally; ignored otherwise.
`void` `setMemoryMaximumSize(String memoryMaximumSize)` The maximum size of the memory for the underlying VM if javac is run externally; ignored otherwise.
`void` `setProceed(boolean proceed)`
`void` `setSourcepath(Path sourcepath)` Set the sourcepath to be used for this compilation.
`void` `setSourcepathRef(Reference r)` Adds a reference to a source path defined elsewhere.
`void` `setSrcdir(Path srcDir)` Set the source directories to find the source Java files.
`void` `setStacktrace(boolean stacktrace)` Enable compiler to report stack trace information if a problem occurs during compilation.
`void` `setUpdatedProperty(String updatedProperty)` The property to set on compliation success.
`void` `setVerbose(boolean verbose)` Enable verbose compiling which will display which files are being compiled

Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask

`add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems`

Methods inherited from class org.apache.tools.ant.Task
`bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType`

Methods inherited from class org.apache.tools.ant.ProjectComponent
`clone, getDescription, getLocation, getProject, setDescription, setLocation`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### failOnError

    protected boolean failOnError

### listFiles

    protected boolean listFiles

### compileList

    protected File[] compileList

### configuration

    protected CompilerConfiguration configuration

Constructor Detail

### Groovyc

    public Groovyc()

Method Detail

### createSrc

    public Path createSrc()

  Adds a path for source compilation.

  Returns:
    a nested src element.

### recreateSrc

    protected Path recreateSrc()

  Recreate src.

  Returns:
    a nested src element.

### setSrcdir

    public void setSrcdir(Path srcDir)

  Set the source directories to find the source Java files.

  Parameters:
    `srcDir` - the source directories as a path

### getSrcdir

    public Path getSrcdir()

  Gets the source dirs to find the source java files.

  Returns:
    the source directorys as a path

### setDestdir

    public void setDestdir(File destDir)

  Set the destination directory into which the Java source files should be compiled.

  Parameters:
    `destDir` - the destination director

### getDestdir

    public File getDestdir()

  Gets the destination directory into which the java source files should be compiled.

  Returns:
    the destination directory

### setSourcepath

    public void setSourcepath(Path sourcepath)

  Set the sourcepath to be used for this compilation.

  Parameters:
    `sourcepath` - the source path

### getSourcepath

    public Path getSourcepath()

  Gets the sourcepath to be used for this compilation.

  Returns:
    the source path

### createSourcepath

    public Path createSourcepath()

  Adds a path to sourcepath.

  Returns:
    a sourcepath to be configured

### setSourcepathRef

    public void setSourcepathRef(Reference r)

  Adds a reference to a source path defined elsewhere.

  Parameters:
    `r` - a reference to a source path

### setClasspath

    public void setClasspath(Path classpath)

  Set the classpath to be used for this compilation.

  Parameters:
    `classpath` - an Ant Path object containing the compilation classpath.

### getClasspath

    public Path getClasspath()

  Gets the classpath to be used for this compilation.

  Returns:
    the class path

### createClasspath

    public Path createClasspath()

  Adds a path to the classpath.

  Returns:
    a class path to be configured

### setClasspathRef

    public void setClasspathRef(Reference r)

  Adds a reference to a classpath defined elsewhere.

  Parameters:
    `r` - a reference to a classpath

### setListfiles

    public void setListfiles(boolean list)

  If true, list the source files being handed off to the compiler.

  Parameters:
    `list` - if true list the source files

### getListfiles

    public boolean getListfiles()

  Get the listfiles flag.

  Returns:
    the listfiles flag

### setFailonerror

    public void setFailonerror(boolean fail)

  Indicates whether the build will continue even if there are compilation errors; defaults to true.

  Parameters:
    `fail` - if true halt the build on failure

### setProceed

    public void setProceed(boolean proceed)

  Parameters:
    `proceed` - inverse of failonerror

### getFailonerror

    public boolean getFailonerror()

  Gets the failonerror flag.

  Returns:
    the failonerror flag

### setMemoryInitialSize

    public void setMemoryInitialSize(String memoryInitialSize)

  The initial size of the memory for the underlying VM if javac is run externally; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)

  Parameters:
    `memoryInitialSize` - string to pass to VM

### getMemoryInitialSize

    public String getMemoryInitialSize()

  Gets the memoryInitialSize flag.

  Returns:
    the memoryInitialSize flag

### setMemoryMaximumSize

    public void setMemoryMaximumSize(String memoryMaximumSize)

  The maximum size of the memory for the underlying VM if javac is run externally; ignored otherwise. Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)

  Parameters:
    `memoryMaximumSize` - string to pass to VM

### getMemoryMaximumSize

    public String getMemoryMaximumSize()

  Gets the memoryMaximumSize flag.

  Returns:
    the memoryMaximumSize flag

### setEncoding

    public void setEncoding(String encoding)

  Sets the file encoding for generated files.

  Parameters:
    `encoding` - the file encoding to be used

### getEncoding

    public String getEncoding()

  Returns the encoding to be used when creating files.

  Returns:
    the file encoding to use

### setVerbose

    public void setVerbose(boolean verbose)

  Enable verbose compiling which will display which files are being compiled

### getVerbose

    public boolean getVerbose()

  Gets the verbose flag.

  Returns:
    the verbose flag

### setIncludeantruntime

    public void setIncludeantruntime(boolean include)

  If true, includes Ant's own classpath in the classpath.

  Parameters:
    `include` - if true, includes Ant's own classpath in the classpath

### getIncludeantruntime

    public boolean getIncludeantruntime()

  Gets whether or not the ant classpath is to be included in the classpath.

  Returns:
    whether or not the ant classpath is to be included in the classpath

### setIncludejavaruntime

    public void setIncludejavaruntime(boolean include)

  If true, includes the Java runtime libraries in the classpath.

  Parameters:
    `include` - if true, includes the Java runtime libraries in the classpath

### getIncludejavaruntime

    public boolean getIncludejavaruntime()

  Gets whether or not the java runtime should be included in this task's classpath.

  Returns:
    the includejavaruntime attribute

### setFork

    public void setFork(boolean f)

  If true forks the Groovy compiler.

  Parameters:
    `f` - "true|false|on|off|yes|no"

### setUpdatedProperty

    public void setUpdatedProperty(String updatedProperty)

  The property to set on compliation success. This property will not be set if the compilation fails, or if there are no files to compile.

  Parameters:
    `updatedProperty` - the property name to use.

### setErrorProperty

    public void setErrorProperty(String errorProperty)

  The property to set on compliation failure. This property will be set if the compilation fails.

  Parameters:
    `errorProperty` - the property name to use.

### setIncludeDestClasses

    public void setIncludeDestClasses(boolean includeDestClasses)

  This property controls whether to include the destination classes directory in the classpath given to the compiler. The default value is "true".

  Parameters:
    `includeDestClasses` - the value to use.

### isIncludeDestClasses

    public boolean isIncludeDestClasses()

  Get the value of the includeDestClasses property.

  Returns:
    the value.

### getTaskSuccess

    public boolean getTaskSuccess()

  Get the result of the groovyc task (success or failure).

  Returns:
    true if compilation succeeded, or was not neccessary, false if the compilation failed.

### addConfiguredJavac

    public void addConfiguredJavac(Javac javac)

  Add the configured nested javac task if present to initiate joint compilation.

### setStacktrace

    public void setStacktrace(boolean stacktrace)

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

### execute

    public void execute()
                 throws BuildException

  Executes the task.

  Overrides:
    `execute` in class `Task`
  Throws:
    `BuildException` - if an error occurs

### resetFileLists

    protected void resetFileLists()

  Clear the list of files to be compiled and copied..

### scanDir

    protected void scanDir(File srcDir,
                           File destDir,
                           String[] files)

  Scans the directory looking for source files to be compiled. The results are returned in the class variable compileList

  Parameters:
    `srcDir` - The source directory
    `destDir` - The destination directory
    `files` - An array of filenames

### addToCompileList

    protected void addToCompileList(File[] newFiles)

### getFileList

    public File[] getFileList()

  Gets the list of files to be compiled.

  Returns:
    the list of files as an array

### checkParameters

    protected void checkParameters()
                            throws BuildException

  Throws:
    `BuildException`

### compile

    protected void compile()

### makeCompileUnit

    protected CompilationUnit makeCompileUnit()

### createTempDir

    protected File createTempDir()

### buildClassLoaderFor

    protected GroovyClassLoader buildClassLoaderFor()

### main

    public static void main(String[] args)

  Provide an entry point for use by the java task. Also used for forking. FIXME: the includes and excludes are not handled -- there is no command line option for them.

Copyright © 2003-2008 The Codehaus. All rights reserved.