org.codehaus.groovy.ant
Class Groovy

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.taskdefs.Java
              extended by org.codehaus.groovy.ant.Groovy
All Implemented Interfaces:
java.lang.Cloneable

public class Groovy
extends org.apache.tools.ant.taskdefs.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.

Version:
$Id: Groovy.java 14872 2009-01-06 09:04:49Z jimwhite $

Field Summary
private  boolean append
          Append to an existing file or overwrite it?
private  org.apache.tools.ant.types.Path classpath
           
private  org.apache.tools.ant.types.Commandline cmdline
           
private  java.lang.String command
          input command
private  CompilerConfiguration configuration
          Compiler configuration.
private  java.util.Vector filesets
          files to load
private  boolean fork
           
private  boolean includeAntRuntime
           
private  LoggingHelper log
           
private  java.io.File output
          Results Output file.
private static java.lang.String PREFIX
           
private  java.io.File srcFile
          input file
private static java.lang.String SUFFIX
           
private  boolean useGroovyShell
           
 
Fields inherited from class org.apache.tools.ant.taskdefs.Java
redirector, redirectorElement
 
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
Groovy()
           
 
Method Summary
protected  void addClassPathes(GroovyClassLoader classLoader)
          Adds the class pathes (if any)
 void addFileset(org.apache.tools.ant.types.FileSet set)
          Adds a set of files (nested fileset attribute).
 void addText(java.lang.String txt)
          Set an inline command to execute.
private  java.lang.String computeScriptName()
          Try to build a script name for the script of the groovy task to have an helpful value in stack traces in case of exception
 org.apache.tools.ant.types.Commandline.Argument createArg()
           
 org.apache.tools.ant.types.Path createClasspath()
          Returns a new path element that can be configured.
private  void createClasspathParts()
           
private  void createNewArgs(java.lang.String txt)
           
protected  void execGroovy(java.lang.String txt, java.io.PrintStream out)
          Exec the statement.
 void execute()
          Load the file and then execute it
 org.apache.tools.ant.types.Path getClasspath()
          Gets the classpath.
private static java.lang.String getText(java.io.BufferedReader reader)
           
static void main(java.lang.String[] args)
           
private  void parseAndRunScript(GroovyShell shell, java.lang.String txt, java.lang.Object mavenPom, java.lang.String scriptName, java.io.File scriptFile, AntBuilder builder)
           
protected  void printResults(java.io.PrintStream out)
          print any results in the statement.
private  void processError(java.lang.Exception e)
           
protected  void runStatements(java.io.Reader reader, java.io.PrintStream out)
          Read in lines and execute them.
 void setAppend(boolean append)
          Whether output should be appended to or overwrite an existing file.
 void setClasspath(org.apache.tools.ant.types.Path classpath)
          Sets the classpath for loading.
 void setClasspathRef(org.apache.tools.ant.types.Reference ref)
          Set the classpath for loading using the classpath reference.
 void setFork(boolean fork)
          Should the script be executed using a forked process.
 void setIncludeAntRuntime(boolean includeAntRuntime)
          Should the system classpath be included on the classpath when forking.
 void setOutput(java.io.File output)
          Set the output file; optional, defaults to the Ant log.
 void setSrc(java.io.File srcFile)
          Set the name of the file to be run.
 void setStacktrace(boolean stacktrace)
          Enable compiler to report stack trace information if a problem occurs during compilation.
 void setUseGroovyShell(boolean useGroovyShell)
          Should a new GroovyShell be used when forking.
 
Methods inherited from class org.apache.tools.ant.taskdefs.Java
addAssertions, addConfiguredRedirector, addEnv, addSysproperty, addSyspropertyset, checkConfiguration, clearArgs, createBootclasspath, createJvmarg, createPermissions, createWatchdog, executeJava, executeJava, getCommandLine, getSysProperties, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, maybeSetResultPropertyValue, run, setArgs, setClassname, setCloneVm, setDir, setError, setErrorProperty, setFailonerror, setInput, setInputString, setJar, setJvm, setJvmargs, setJVMVersion, setLogError, setMaxmemory, setNewenvironment, setOutputproperty, setResultProperty, setSpawn, setTimeout, setupRedirector
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, 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, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFIX

private static final java.lang.String PREFIX
See Also:
Constant Field Values

SUFFIX

private static final java.lang.String SUFFIX
See Also:
Constant Field Values

log

private final LoggingHelper log

filesets

private java.util.Vector filesets
files to load


srcFile

private java.io.File srcFile
input file


command

private java.lang.String command
input command


output

private java.io.File output
Results Output file.


append

private boolean append
Append to an existing file or overwrite it?


classpath

private org.apache.tools.ant.types.Path classpath

fork

private boolean fork

includeAntRuntime

private boolean includeAntRuntime

useGroovyShell

private boolean useGroovyShell

configuration

private CompilerConfiguration configuration
Compiler configuration.

Used to specify the debug output to print stacktraces in case something fails. TODO: Could probably be reused to specify the encoding of the files to load or other properties.


cmdline

private org.apache.tools.ant.types.Commandline cmdline
Constructor Detail

Groovy

public Groovy()
Method Detail

setFork

public void setFork(boolean fork)
Should the script be executed using a forked process. Defaults to false.

Overrides:
setFork in class org.apache.tools.ant.taskdefs.Java
Parameters:
fork - true if the script should be executed in a forked process

setUseGroovyShell

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

setIncludeAntRuntime

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

setStacktrace

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

setSrc

public void setSrc(java.io.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

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

addText

public void addText(java.lang.String txt)
Set an inline command to execute. NB: Properties are not expanded in this text.

Parameters:
txt - the inline groovy ommands to execute

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet set)
Adds a set of files (nested fileset attribute).

Parameters:
set - the fileset representing source files

setOutput

public void setOutput(java.io.File output)
Set the output file; optional, defaults to the Ant log.

Overrides:
setOutput in class org.apache.tools.ant.taskdefs.Java
Parameters:
output - the output file

setAppend

public void setAppend(boolean append)
Whether output should be appended to or overwrite an existing file. Defaults to false.

Overrides:
setAppend in class org.apache.tools.ant.taskdefs.Java
Parameters:
append - set to true to append

setClasspath

public void setClasspath(org.apache.tools.ant.types.Path classpath)
Sets the classpath for loading.

Overrides:
setClasspath in class org.apache.tools.ant.taskdefs.Java
Parameters:
classpath - The classpath to set

createClasspath

public org.apache.tools.ant.types.Path createClasspath()
Returns a new path element that can be configured. Gets called for instance by Ant when it encounters a nested <classpath> element.

Overrides:
createClasspath in class org.apache.tools.ant.taskdefs.Java
Returns:
the resulting created path

setClasspathRef

public void setClasspathRef(org.apache.tools.ant.types.Reference ref)
Set the classpath for loading using the classpath reference.

Overrides:
setClasspathRef in class org.apache.tools.ant.taskdefs.Java
Parameters:
ref - the refid to use

getClasspath

public org.apache.tools.ant.types.Path getClasspath()
Gets the classpath.

Returns:
Returns a Path

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Load the file and then execute it

Overrides:
execute in class org.apache.tools.ant.taskdefs.Java
Throws:
org.apache.tools.ant.BuildException

getText

private static java.lang.String getText(java.io.BufferedReader reader)
                                 throws java.io.IOException
Throws:
java.io.IOException

createArg

public org.apache.tools.ant.types.Commandline.Argument createArg()
Overrides:
createArg in class org.apache.tools.ant.taskdefs.Java

runStatements

protected void runStatements(java.io.Reader reader,
                             java.io.PrintStream out)
                      throws java.io.IOException
Read in lines and execute them.

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

execGroovy

protected void execGroovy(java.lang.String txt,
                          java.io.PrintStream out)
Exec the statement.

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

parseAndRunScript

private void parseAndRunScript(GroovyShell shell,
                               java.lang.String txt,
                               java.lang.Object mavenPom,
                               java.lang.String scriptName,
                               java.io.File scriptFile,
                               AntBuilder builder)

processError

private void processError(java.lang.Exception e)

main

public static void main(java.lang.String[] args)

createClasspathParts

private void createClasspathParts()

createNewArgs

private void createNewArgs(java.lang.String txt)
                    throws java.io.IOException
Throws:
java.io.IOException

computeScriptName

private java.lang.String computeScriptName()
Try to build a script name for the script of the groovy task to have an helpful value in stack traces in case of exception

Returns:
the name to use when compiling the script

addClassPathes

protected void addClassPathes(GroovyClassLoader classLoader)
Adds the class pathes (if any)

Parameters:
classLoader - the classloader to configure

printResults

protected void printResults(java.io.PrintStream out)
print any results in the statement.

Parameters:
out - the output PrintStream to print to


Copyright © ${year} The Codehaus. All Rights Reserved.