...
| Code Block |
|---|
def ant = new AntBuilder()
// lets just call one task
ant.echo("hello")
// here is an example of a block of Ant inside GroovyMarkup
ant.sequential {
echo("inside sequential")
myDir = "target/AntTest/"
mkdir(dir:myDir)
copy(todir:myDir) {
fileset(dir:"src/test") {
include(name:"**/*.groovy")
}
}
echo("done")
}
// now lets do some normal Groovy again
file = new File("target/AntTest/groovy/util/AntTest.groovy")
assert file.exists()
|
| Code Block |
|---|
def ant = new AntBuilder()
// lets create a scanner of filesets
scanner = ant.fileScanner {
fileset(dir:"src/test") {
include(name:"**/Ant*.groovy")
}
}
// now lets iterate over
def found = false
for (f in scanner) {
println("Found file $f")
found = true
assert f instanceof File
assert f.name.endsWith(".groovy")
}
assert found
|
| Code Block |
|---|
def ant = new AntBuilder()
ant.junit {
test(name:'groovy.util.SomethingThatDoesNotExist')
}
|
| Code Block |
|---|
def ant = new AntBuilder()
value = ant.path {
fileset(dir:"xdocs") {
include(name:"*.wiki")
}
}
assert value != null
println "Found path of type ${value.class.name}"
println value
|
...
| Code Block |
|---|
def ant = new AntBuilder()
SpoofTaskContainer.spoof.length = 0
def PATH = 'task.path'
ant.path(id:PATH){ant.pathelement(location:'classes')}
['spoofcontainer':'SpoofTaskContainer', 'spoof':'SpoofTask'].each{ pair ->
ant.taskdef(name:pair.key, classname:'groovy.util.'+pair.value, classpathref:PATH)
}
ant.spoofcontainer(){
ant.spoof()
}
expectedSpoof =
"SpoofTaskContainer ctor\n"+
"SpoofTask ctor\n"+
"in addTask\n"+
"begin SpoofTaskContainer execute\n"+
"begin SpoofTask execute\n"+
"end SpoofTask execute\n"+
"end SpoofTaskContainer execute\n"
assertEquals expectedSpoof, SpoofTaskContainer.spoof.toString()
|
Using the joint compiler
Here is a small build file which uses the joint compiler to compile Groovy and Java source files together, and put them in WEB-INF/classes:
| Code Block |
|---|
def ant = new AntBuilder().sequential {
webinf = "deploy/WEB-INF"
taskdef name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc"
groovyc srcdir: "src", destdir: "${webinf}/classes", {
classpath {
fileset dir: "${webinf}/lib", {
include name: "*.jar"
}
pathelement path: "${webinf}/classes"
}
javac source: "1.5", target: "1.5", debug: "on"
}
}
|