GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / sandbox / books / build.groovy
blob8dc2f7a5180da3d5b97385744d9e227756f0848a
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
6 ant = new AntBuilder()
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')){
14 startTests()
15 return
18 withJetty { startTests() }
21 warApplication()
22 deploy()
24 withServer {
25 startTests()
31 // method implementations ---------------------------------
33 String initGrailsHome () {
34 def grailsHome = props.grailsHome
35 if (! grailsHome) {
36 grailsHome = props.'env.GRAILS_HOME'
38 println "grailsHome is <$grailsHome>"
39 return grailsHome
42 def startTests(){
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')
54 return grailsHome
57 def deploy () {
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./) {
64 withTomcat5(yield)
65 return
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,
73 searchpath: true ){
74 arg(line: command)
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
82 yield()
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){}
96 tomcat('deploy')
97 ant.echo(message:'tomcat deployment done')
98 yield()
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")
107 server.start()
108 Thread.start { yield() }
109 server.stop()