1 // General buildfile for the project in that's root this file is located.
2 // Obeys the environment variable 'GRAILS_HOME'.
3 // Adapt build.properties to you personal needs.
4 // Start with argument 'test' to only run the tests without build/deploy/restart
7 ant
.property(file
: 'build.properties')
8 ant
.property(environment
: 'env')
9 props
= ant
.antProject
.properties
11 grailsHome
= initGrailsHome()
13 if (args
.toList().contains('test')){
18 withJetty { startTests() }
31 // method implementations ---------------------------------
33 String
initGrailsHome () {
34 def grailsHome
= props
.grailsHome
36 grailsHome
= props
.'env.GRAILS_HOME'
38 println
"grailsHome is <$grailsHome>"
43 new BooksTest(grailsHome
:grailsHome
, props
:ant
.antProject
.properties
).runTests()
46 // call the general 'war' target and 'init' only if needed
47 String
warApplication () {
48 buildFile
= grailsHome
+ '/src/grails/build.xml'
50 if ( ! new java
.io
.File('tmp').exists()) {
51 ant
.ant(antfile
: buildFile
, target
:'init')
53 ant
.ant(antfile
:buildFile
, target
:'war')
58 targetDir
= "$props.serverDir/$props.serverWebappDir"
59 ant
.copy(file
:'grails-app.war', todir
: targetDir
)
62 def
withServer (Closure yield
) {
63 if (props
.serverDir
=~
/\b5./) {
67 withUnknownServer(yield
)
70 def
unknownServer (String command
, boolean doPrint
) {
71 def filename
= 'server-out.txt'
72 ant
.exec(dir
: props
.serverDir
, executable
: props
.executable
, output
: filename
,
76 if (doPrint
) println
new java
.io
.File(filename
).text
78 def
withUnknownServer (Closure yield
) {
79 unknownServer(props
.serverStopCommand
, false)
80 Thread
.start
{ unknownServer(props
.serverStartCommand
, true) }
81 sleep
10 // wait for server startup
83 unknownServer(props
.serverStopCommand
, true)
86 def
tomcat (String command
) {
87 ant
.ant(antfile
:grailsHome
+ '/tomcat.xml', target
:command
){
88 property(name
:'build', value
:'./')
89 property(name
:'username', value
:props
.serverAdminUsername
)
90 property(name
:'password', value
:props
.serverAdminPassword
)
93 def
withTomcat5 (Closure yield
) {
94 ant
.echo(message
:'*** tomcat is assumed to be running')
95 try { tomcat('undeploy') } catch (Exception mayNotYetBeThere
){}
97 ant
.echo(message
:'tomcat deployment done')
101 def
withJetty (Closure yield
) {
102 def server
= new org
.mortbay
.jetty
.Server()
103 def listener
= new org
.mortbay
.http
.SocketListener()
104 listener
.setPort(8080);
105 server
.addListener(listener
)
106 server
.addWebApplication("/.","books.war")
108 Thread
.start
{ yield() }