Package org.codehaus.groovy.ant
Class Groovy
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.Java
org.codehaus.groovy.ant.Groovy
- All Implemented Interfaces:
- 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.
- 
Field SummaryFields inherited from class org.apache.tools.ant.taskdefs.Javaredirector, redirectorElementFields inherited from class org.apache.tools.ant.Tasktarget, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidaddClassPathes(GroovyClassLoader classLoader) Adds the class paths (if any)voidaddConfigured(org.apache.tools.ant.types.ResourceCollection a) Set the source resource.voidaddFileset(org.apache.tools.ant.types.FileSet set) Adds a fileset (nested fileset attribute) which should represent a single source file.final voidaddFilterChain(org.apache.tools.ant.types.FilterChain filter) Add the FilterChain element.voidSet an inline command to execute.org.apache.tools.ant.types.Commandline.Argumentorg.apache.tools.ant.types.PathReturns a new path element that can be configured.protected voidexecGroovy(String txt, PrintStream out) Exec the statement.voidexecute()Load the file and then execute itorg.apache.tools.ant.types.PathGets the classpath.booleanReturns true if parameter metadata generation has been enabled.static voidprotected voidprintResults(PrintStream out) print any results in the statement.protected voidrunStatements(Reader reader, PrintStream out) Read in lines and execute them.voidsetAppend(boolean append) Whether output should be appended to or overwrite an existing file.voidsetClasspath(org.apache.tools.ant.types.Path classpath) Sets the classpath for loading.voidsetClasspathRef(org.apache.tools.ant.types.Reference ref) Set the classpath for loading using the classpath reference.voidsetConfigscript(String configscript) Sets the configuration script for the groovy compiler configuration.voidsetContextClassLoader(boolean contextClassLoader) Setting to true will cause the contextClassLoader to be set with the classLoader of the shell used to run the script.voidsetEncoding(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.voidsetFork(boolean fork) Should the script be executed using a forked process.voidsetIncludeAntRuntime(boolean includeAntRuntime) Should the system classpath be included on the classpath when forking.voidsetIndy(boolean indy) Deprecated.voidSet the output file; optional, defaults to the Ant log.voidsetOutputEncoding(String encoding) Declare the encoding to use when outputting to a file; Leave unspecified or use "" for the platform's default encoding.voidsetParameters(boolean parameters) If true, generates metadata for reflection on method parameter names (jdk8+ only).voidsetScriptBaseClass(String scriptBaseClass) Set the script base class namevoidSet the name of the file to be run.voidsetStacktrace(boolean stacktrace) Enable compiler to report stack trace information if a problem occurs during compilation.voidsetUseGroovyShell(boolean useGroovyShell) Should a new GroovyShell be used when forking.Methods inherited from class org.apache.tools.ant.taskdefs.JavaaddAssertions, addConfiguredRedirector, addEnv, addSysproperty, addSyspropertyset, checkConfiguration, clearArgs, createBootclasspath, createJvmarg, createModulepath, createPermissions, createUpgrademodulepath, createWatchdog, executeJava, executeJava, getCommandLine, getSysProperties, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, maybeSetResultPropertyValue, run, setArgs, setClassname, setCloneVm, setDir, setDiscardError, setDiscardOutput, setError, setErrorProperty, setFailonerror, setInput, setInputString, setJar, setJvm, setJvmargs, setJVMVersion, setLogError, setMaxmemory, setModule, setModulepath, setModulepathRef, setNewenvironment, setOutputproperty, setResultProperty, setSourceFile, setSpawn, setTimeout, setupRedirectorMethods inherited from class org.apache.tools.ant.TaskbindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
- 
Constructor Details- 
Groovypublic Groovy()
 
- 
- 
Method Details- 
setForkpublic void setFork(boolean fork) Should the script be executed using a forked process. Defaults to false.- Overrides:
- setForkin class- org.apache.tools.ant.taskdefs.Java
- Parameters:
- fork- true if the script should be executed in a forked process
 
- 
setOutputEncodingDeclare 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
 
- 
setEncodingDeclare 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
 
- 
setUseGroovyShellpublic 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
 
- 
setIncludeAntRuntimepublic 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
 
- 
setStacktracepublic 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
 
- 
setSrcSet 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
 
- 
addTextSet an inline command to execute. NB: Properties are not expanded in this text.- Parameters:
- txt- the inline groovy commands to execute
 
- 
addFilesetpublic void addFileset(org.apache.tools.ant.types.FileSet set) Adds a fileset (nested fileset attribute) which should represent a single source file.- Parameters:
- set- the fileset representing a source file
 
- 
setOutputSet the output file; optional, defaults to the Ant log.- Overrides:
- setOutputin class- org.apache.tools.ant.taskdefs.Java
- Parameters:
- output- the output file
 
- 
setAppendpublic void setAppend(boolean append) Whether output should be appended to or overwrite an existing file. Defaults to false.- Overrides:
- setAppendin class- org.apache.tools.ant.taskdefs.Java
- Parameters:
- append- set to true to append
 
- 
setClasspathpublic void setClasspath(org.apache.tools.ant.types.Path classpath) Sets the classpath for loading.- Overrides:
- setClasspathin class- org.apache.tools.ant.taskdefs.Java
- Parameters:
- classpath- The classpath to set
 
- 
createClasspathpublic 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:
- createClasspathin class- org.apache.tools.ant.taskdefs.Java
- Returns:
- the resulting created path
 
- 
setClasspathRefpublic void setClasspathRef(org.apache.tools.ant.types.Reference ref) Set the classpath for loading using the classpath reference.- Overrides:
- setClasspathRefin class- org.apache.tools.ant.taskdefs.Java
- Parameters:
- ref- the refid to use
 
- 
getClasspathpublic org.apache.tools.ant.types.Path getClasspath()Gets the classpath.- Returns:
- Returns a Path
 
- 
setConfigscriptSets the configuration script for the groovy compiler configuration.- Parameters:
- configscript- path to the configuration script
 
- 
setIndyDeprecated.Legacy method to set the indy flag (only true is allowed)- Parameters:
- indy- true means invokedynamic support is active
 
- 
setScriptBaseClassSet the script base class name- Parameters:
- scriptBaseClass- the name of the base class for scripts
 
- 
setParameterspublic 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.
 
- 
getParameterspublic boolean getParameters()Returns true if parameter metadata generation has been enabled.
- 
executepublic void execute() throws org.apache.tools.ant.BuildExceptionLoad the file and then execute it- Overrides:
- executein class- org.apache.tools.ant.taskdefs.Java
- Throws:
- org.apache.tools.ant.BuildException
 
- 
createArgpublic org.apache.tools.ant.types.Commandline.Argument createArg()- Overrides:
- createArgin class- org.apache.tools.ant.taskdefs.Java
 
- 
addFilterChainpublic final void addFilterChain(org.apache.tools.ant.types.FilterChain filter) Add the FilterChain element.- Parameters:
- filter- the filter to add
 
- 
addConfiguredpublic void addConfigured(org.apache.tools.ant.types.ResourceCollection a) Set the source resource.- Parameters:
- a- the resource to load as a single element Resource collection.
 
- 
runStatementsRead in lines and execute them.- Parameters:
- reader- the reader from which to get the groovy source to exec
- out- the outputstream to use
- Throws:
- IOException- if something goes wrong
 
- 
execGroovyExec the statement.- Parameters:
- txt- the groovy source to exec
- out- not used?
 
- 
main
- 
addClassPathesAdds the class paths (if any)- Parameters:
- classLoader- the classloader to configure
 
- 
printResultsprint any results in the statement.- Parameters:
- out- the output PrintStream to print to
 
- 
setContextClassLoaderpublic 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
 
 
-