Overview | Package | Class | Deprecated | Index | Help
| Groovy 1.7.10
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.ant
[Java] 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

    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
- stubdir

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.

Authors:
  James Strachan
  Hein Meling
  Russel Winder
  Danno Ferrin

Version:
  \$Revision: 21452 \$

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

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.
`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` | `getKeepStubs()` Gets the keepStubs flag.
`boolean` | `getListfiles()` Get the listfiles flag.
`String` | `getMemoryInitialSize()` Gets the memoryInitialSize flag.
`String` | `getMemoryMaximumSize()` Gets the memoryMaximumSize flag.
`String` | `getScriptExtension()` Get the extension to use when searching for Groovy source files.
`Path` | `getSourcepath()` Gets the sourcepath to be used for this compilation.
`Path` | `getSrcdir()` Gets the source dirs to find the source java files.
`File` | `getStubdir()` Gets the stub directory into which the Java source stub files should be generated
`String` | `getTargetBytecode()` Retrieves the compiler bytecode compatibility mode.
`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.
`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 compilation 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` | `setIncludeDestClasses(boolean includeDestClasses)` This property controls whether to include the destination classes directory in the classpath given to the compiler.
`void` | `setIncludeantruntime(boolean include)` If true, includes Ant's own classpath in the classpath.
`void` | `setIncludejavaruntime(boolean include)` If true, includes the Java runtime libraries in the classpath.
`void` | `setJavaHome(File home)` The JDK Home to use when forked.
`void` | `setKeepStubs(boolean keepStubs)` Set the keepStubs flag.
`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)` @param proceed inverse of failonerror
`void` | `setScriptExtension(String scriptExtension)` Set the extension to use when searching for Groovy source files.
`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` | `setStubdir(File stubDir)` Set the stub directory into which the Java source stub files should be generated.
`void` | `setTargetBytecode(String version)` Sets the bytecode compatibility mode
`void` | `setUpdatedProperty(String updatedProperty)` The property to set on compilation success.
`void` | `setVerbose(boolean verbose)` Enable verbose compiling which will display which files are being compiled.

Methods inherited from class MatchingTask
add, setProject, setIncludes, addDate, addNot, addAnd, addOr, addContains, createInclude, createIncludesFile, createExclude, createExcludesFile, createPatternSet, XsetItems, setExcludes, XsetIgnore, setDefaultexcludes, setIncludesfile, setExcludesfile, setCaseSensitive, setFollowSymlinks, hasSelectors, selectorCount, getSelectors, selectorElements, appendSelector, addSelector, addNone, addMajority, addSize, addFilename, addCustom, addPresent, addDepth, addDepend, addContainsRegexp, addDifferent, addType, addModified, log, log, log, log, init, execute, perform, maybeConfigure, setTaskType, setTaskName, setOwningTarget, getTaskName, getOwningTarget, getRuntimeConfigurableWrapper, setRuntimeConfigurableWrapper, reconfigure, getTaskType, bindToOwner, clone, getLocation, getDescription, setLocation, getProject, setDescription, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Methods inherited from class Task
log, log, log, log, init, execute, perform, maybeConfigure, setTaskType, setTaskName, setOwningTarget, getTaskName, getOwningTarget, getRuntimeConfigurableWrapper, setRuntimeConfigurableWrapper, reconfigure, getTaskType, bindToOwner, clone, getLocation, getDescription, setLocation, getProject, setDescription, setProject, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Methods inherited from class ProjectComponent
clone, log, log, getLocation, getDescription, setLocation, getProject, setDescription, setProject, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Field Detail

### compileList

    protected File[] compileList

### configuration

    protected CompilerConfiguration configuration

### failOnError

    protected boolean failOnError

### listFiles

    protected boolean listFiles

Method Detail

### addConfiguredJavac

    public void addConfiguredJavac(Javac javac)

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

### addToCompileList

    protected void addToCompileList(File[] newFiles)

### buildClassLoaderFor

    protected GroovyClassLoader buildClassLoaderFor()

### checkParameters

    protected void checkParameters()

### compile

    protected void compile()

### createClasspath

    public Path createClasspath()

  Adds a path to the classpath.
  Returns:
    a class path to be configured

### createSourcepath

    public Path createSourcepath()

  Adds a path to sourcepath.
  Returns:
    a sourcepath to be configured

### createSrc

    public Path createSrc()

  Adds a path for source compilation.
  Returns:
    a nested src element.

### execute

    public void execute()

  Executes the task.
  throws:
    BuildException if an error occurs

### getClasspath

    public Path getClasspath()

  Gets the classpath to be used for this compilation.
  Returns:
    the class path

### getDestdir

    public File getDestdir()

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

### getEncoding

    public String getEncoding()

  Returns the encoding to be used when creating files.
  Returns:
    the file encoding to use

### getFailonerror

    public boolean getFailonerror()

  Gets the failonerror flag.
  Returns:
    the failonerror flag

### getFileList

    public File[] getFileList()

  Gets the list of files to be compiled.
  Returns:
    the list of files as an array

### 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

### getIncludejavaruntime

    public boolean getIncludejavaruntime()

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

### getKeepStubs

    public boolean getKeepStubs()

  Gets the keepStubs flag.
  Returns:
    the keepStubs flag

### getListfiles

    public boolean getListfiles()

  Get the listfiles flag.
  Returns:
    the listfiles flag

### getMemoryInitialSize

    public String getMemoryInitialSize()

  Gets the memoryInitialSize flag.
  Returns:
    the memoryInitialSize flag

### getMemoryMaximumSize

    public String getMemoryMaximumSize()

  Gets the memoryMaximumSize flag.
  Returns:
    the memoryMaximumSize flag

### getScriptExtension

    public String getScriptExtension()

  Get the extension to use when searching for Groovy source files.
  Returns:
    the extension of Groovy source files

### getSourcepath

    public Path getSourcepath()

  Gets the sourcepath to be used for this compilation.
  Returns:
    the source path

### getSrcdir

    public Path getSrcdir()

  Gets the source dirs to find the source java files.
  Returns:
    the source directories as a path

### getStubdir

    public File getStubdir()

  Gets the stub directory into which the Java source stub files should be generated
  Returns:
    the stub directory

### getTargetBytecode

    public String getTargetBytecode()

  Retrieves the compiler bytecode compatibility mode.
  Returns:
    bytecode compatibility mode. Can be either `1.5` or `1.4`.

### getTaskSuccess

    public boolean getTaskSuccess()

  Get the result of the groovyc task (success or failure).
  Returns:
    true if compilation succeeded, or was not necessary, false if the compilation failed.

### getVerbose

    public boolean getVerbose()

  Gets the verbose flag.
  Returns:
    the verbose flag

### isIncludeDestClasses

    public boolean isIncludeDestClasses()

  Get the value of the includeDestClasses property.
  Returns:
    the value.

### makeCompileUnit

    protected CompilationUnit makeCompileUnit()

### recreateSrc

    protected Path recreateSrc()

  Recreate src.
  Returns:
    a nested src element.

### 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

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

### setClasspathRef

    public void setClasspathRef(Reference r)

  Adds a reference to a classpath defined elsewhere.
  Parameters:
    `r` - a reference to a classpath

### setDestdir

    public void setDestdir(File destDir)

  Set the destination directory into which the Java source files should be compiled.
  Parameters:
    `destDir` - the destination director

### setEncoding

    public void setEncoding(String encoding)

  Sets the file encoding for generated files.
  Parameters:
    `encoding` - the file encoding to be used

### setErrorProperty

    public void setErrorProperty(String errorProperty)

  The property to set on compilation failure. This property will be set if the compilation fails.
  Parameters:
    `errorProperty` - the property name to use.

### 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

### setFork

    public void setFork(boolean f)

  If true forks the Groovy compiler. Default is false.
  Parameters:
    `f` - "true|false|on|off|yes|no"

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

### setIncludeantruntime

    public void setIncludeantruntime(boolean include)

  If true, includes Ant's own classpath in the classpath. Default is true. If setting to false and using groovyc in conjunction with AntBuilder you might need to explicitly add the Groovy jar(s) to the groovyc classpath using a nested classpath task.
  Parameters:
    `include` - if true, includes Ant's own classpath in the classpath

### setIncludejavaruntime

    public void setIncludejavaruntime(boolean include)

  If true, includes the Java runtime libraries in the classpath. Default is false.
  Parameters:
    `include` - if true, includes the Java runtime libraries in the classpath

### setJavaHome

    public void setJavaHome(File home)

  The JDK Home to use when forked.
  Parameters:
    `home` - the java.home value to use, default is the current JDK's home

### setKeepStubs

    public void setKeepStubs(boolean keepStubs)

  Set the keepStubs flag. Defaults to false. Set to true for debugging. Ignored when forked.
  Parameters:
    `keepStubs` - should stubs be retained

### setListfiles

    public void setListfiles(boolean list)

  If true, list the source files being handed off to the compiler. Default is false.
  Parameters:
    `list` - if true list the source files

### 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

### 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

### setProceed

    public void setProceed(boolean proceed)

  Parameters:
    `proceed` - inverse of failonerror

### setScriptExtension

    public void setScriptExtension(String scriptExtension)

  Set the extension to use when searching for Groovy source files. Accepts extensions in the form *.groovy, .groovy or groovy
  Parameters:
    `scriptExtension` - the extension of Groovy source files

### setSourcepath

    public void setSourcepath(Path sourcepath)

  Set the sourcepath to be used for this compilation.
  Parameters:
    `sourcepath` - the source path

### setSourcepathRef

    public void setSourcepathRef(Reference r)

  Adds a reference to a source path defined elsewhere.
  Parameters:
    `r` - a reference to a source path

### setSrcdir

    public void setSrcdir(Path srcDir)

  Set the source directories to find the source Java files.
  Parameters:
    `srcDir` - the source directories as a path

### setStacktrace

    public void setStacktrace(boolean stacktrace)

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

### setStubdir

    public void setStubdir(File stubDir)

  Set the stub directory into which the Java source stub files should be generated. The directory need not exist and will not be deleted automatically - though its contents will be cleared unless 'keepStubs' is true. Ignored when forked.
  Parameters:
    `stubDir` - the stub directory

### setTargetBytecode

    public void setTargetBytecode(String version)

  Sets the bytecode compatibility mode
  Parameters:
    `version` - the bytecode compatibility mode

### setUpdatedProperty

    public void setUpdatedProperty(String updatedProperty)

  The property to set on compilation 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.

### setVerbose

    public void setVerbose(boolean verbose)

  Enable verbose compiling which will display which files are being compiled. Default is false.

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