Skip to content
Newer
Older
100644 151 lines (126 sloc) 5.01 KB
3e17890 1.1 branch is now trunk
graeme authored
1 /*
2 * Copyright 2004-2005 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
f2f37f1 @burtbeckwith added port tests to avoid long stacktrace when there's already a serv…
burtbeckwith authored
16 import org.codehaus.groovy.grails.cli.interactive.InteractiveMode
4fd2ac3 @burtbeckwith whitespace, cleanup
burtbeckwith authored
17 import org.codehaus.groovy.grails.compiler.GrailsProjectWatcher
24d07b9 @burtbeckwith GRAILS-9949 moved code to new grails-scaffolding plugin
burtbeckwith authored
18 import org.codehaus.groovy.grails.project.container.GrailsProjectRunner
3e17890 1.1 branch is now trunk
graeme authored
19
20 /**
17b252e cleanup, STS warnings
Burt Beckwith authored
21 * Executes Grails using an embedded server.
3e17890 1.1 branch is now trunk
graeme authored
22 *
23 * @author Graeme Rocher
24 *
25 * @since 0.4
26 */
27
b5876f6 @graemerocher more build refactoring. Moved code a lot of code out of _GrailsPackag…
graemerocher authored
28 includeTargets << grailsScript("_GrailsWar")
3e17890 1.1 branch is now trunk
graeme authored
29
b5876f6 @graemerocher more build refactoring. Moved code a lot of code out of _GrailsPackag…
graemerocher authored
30 SCHEME_HTTP = GrailsProjectRunner.SCHEME_HTTP
31 SCHEME_HTTPS = GrailsProjectRunner.SCHEME_HTTPS
32
33 projectRunner = new GrailsProjectRunner(projectPackager, warCreator, classLoader)
3e17890 1.1 branch is now trunk
graeme authored
34
b735e73 @pledbrook Fix for GRAILS-4364: automatic server restarts now remember whether
pledbrook authored
35 // Keep track of whether we're running in HTTPS mode in case we need
36 // to restart the server.
37 usingSecureServer = false
3e17890 1.1 branch is now trunk
graeme authored
38
39 grailsServer = null
40 grailsContext = null
f16f9fa adding support for configurable reload behavior
Dan Woods authored
41 autoRecompile = System.getProperty("disable.auto.recompile") ? !(System.getProperty("disable.auto.recompile").toBoolean()) : true
3e17890 1.1 branch is now trunk
graeme authored
42
43 // How often should recompilation occur while the application is running (in seconds)?
44 // Defaults to 3s.
45 recompileFrequency = System.getProperty("recompile.frequency")
46 recompileFrequency = recompileFrequency ? recompileFrequency.toInteger() : 3
47
f16f9fa adding support for configurable reload behavior
Dan Woods authored
48 // Should the reloading agent be enabled? By default, yes...
ca56900 @graemerocher fixed broken evaluation of grails.reload.enabled system property
graemerocher authored
49 isReloading = System.getProperty("grails.reload.enabled")
50 isReloading = isReloading != null ? isReloading.toBoolean() : true
750524b @danveloper if reloading is disabled, also disable the project watcher
danveloper authored
51
3e17890 1.1 branch is now trunk
graeme authored
52 // This isn't used within this script but may come in handy for scripts
53 // that depend on this one.
54 ant.path(id: "grails.runtime.classpath", runtimeClasspath)
55
56 /**
57 * Runs the application in dev mode, i.e. with class-reloading.
58 */
59 target(runApp: "Main implementation that executes a Grails application") {
b5876f6 @graemerocher more build refactoring. Moved code a lot of code out of _GrailsPackag…
graemerocher authored
60 grailsServer = projectRunner.runApp()
3e17890 1.1 branch is now trunk
graeme authored
61 }
62
63 /**
64 * Runs the application in dev mode over HTTPS.
65 */
27b5b04 whitespace, misc cleanup
Burt Beckwith authored
66 target(runAppHttps: "Main implementation that executes a Grails application with an HTTPS listener") {
b5876f6 @graemerocher more build refactoring. Moved code a lot of code out of _GrailsPackag…
graemerocher authored
67 grailsServer = projectRunner.runAppHttps()
3e17890 1.1 branch is now trunk
graeme authored
68 }
69
70 /**
71 * Runs the application using the WAR file directly.
72 */
17b252e cleanup, STS warnings
Burt Beckwith authored
73 target(runWar: "Main implementation that executes a Grails application WAR") {
b5876f6 @graemerocher more build refactoring. Moved code a lot of code out of _GrailsPackag…
graemerocher authored
74 grailsServer = projectRunner.runWar()
3e17890 1.1 branch is now trunk
graeme authored
75 }
76
77 /**
78 * Runs the application over HTTPS using the WAR file directly.
79 */
17b252e cleanup, STS warnings
Burt Beckwith authored
80 target(runWarHttps: "Main implementation that executes a Grails application WAR") {
b5876f6 @graemerocher more build refactoring. Moved code a lot of code out of _GrailsPackag…
graemerocher authored
81 grailsServer = projectRunner.runWarHttps()
3e17890 1.1 branch is now trunk
graeme authored
82 }
83
84 /**
85 * Starts the plugin scanner. Call this after starting the server if you
86 * want changes to artifacts automatically detected and loaded.
87 */
88 target(startPluginScanner: "Starts the plugin manager's scanner that detects changes to artifacts.") {
17b252e cleanup, STS warnings
Burt Beckwith authored
89 if (!GrailsProjectWatcher.isReloadingAgentPresent() || GrailsProjectWatcher.isActive() || !isReloading) {
651454b whitespace, cleanup, STS warnings
Burt Beckwith authored
90 return
6f9a901 @graemerocher fix for GRAILS-8769 ""No property found for name" exception on unit t…
graemerocher authored
91 }
651454b whitespace, cleanup, STS warnings
Burt Beckwith authored
92
17b252e cleanup, STS warnings
Burt Beckwith authored
93 new GrailsProjectWatcher(projectCompiler, pluginManager).with {
94 reloadExcludes = (config?.grails?.reload?.excludes instanceof List) ? config?.grails?.reload?.excludes : []
95 reloadIncludes = (config?.grails?.reload?.includes instanceof List) ? config?.grails?.reload?.includes : []
96 start()
750524b @danveloper if reloading is disabled, also disable the project watcher
danveloper authored
97 }
3e17890 1.1 branch is now trunk
graeme authored
98 }
99
6779eb9 @alkemist When stopping the running server, also stop the plugin change scanner.
alkemist authored
100 target(stopPluginScanner: "Stops the plugin manager's scanner that detects changes to artifacts.") {
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
101 // do nothing, here for compatibility
6779eb9 @alkemist When stopping the running server, also stop the plugin change scanner.
alkemist authored
102 }
103
3e17890 1.1 branch is now trunk
graeme authored
104 /**
105 * Keeps the server alive and checks for changes in domain classes or
106 * source files under "src". If any changes are detected, the servlet
107 * container is restarted.
108 */
109 target(watchContext: "Watches the WEB-INF/classes directory for changes and restarts the server if necessary") {
110 depends(classpath)
111
db568e4 whitespace
Burt Beckwith authored
112 def im = InteractiveMode.current
113 if (!im) {
17b252e cleanup, STS warnings
Burt Beckwith authored
114 keepServerAlive()
db568e4 whitespace
Burt Beckwith authored
115 return
116 }
117
118 Thread.start {
119 im.grailsServer = grailsServer
120 im.run()
3e17890 1.1 branch is now trunk
graeme authored
121 }
122
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
123 keepServerAlive()
3e17890 1.1 branch is now trunk
graeme authored
124 }
125
126 target(keepServerAlive: "Idles the script, ensuring that the server stays running.") {
17b252e cleanup, STS warnings
Burt Beckwith authored
127 boolean keepRunning = true
128 def killFile = new File(basedir, '.kill-run-app')
1f25b63 @pledbrook Updated keepServerAlive target so that if the kill file already exist…
pledbrook authored
129 if (killFile.exists()) {
130 grailsConsole.warning ".kill-run-app file exists - perhaps a previous server stop didn't work?. Deleting and continuing anyway."
131 killFile.delete()
132 }
133
757fb80 @graemerocher fix for GRAILS-9419 and GRAILS-9424 - only start the Tomcat kill swit…
graemerocher authored
134 while (keepRunning || Boolean.getBoolean("TomcatKillSwitch.active")) {
3e17890 1.1 branch is now trunk
graeme authored
135 sleep(recompileFrequency * 1000)
136
17b252e cleanup, STS warnings
Burt Beckwith authored
137 // Check whether the kill file exists. This is a hack for the functional
138 // tests so that we can stop the servers that are started.
3e17890 1.1 branch is now trunk
graeme authored
139 if (killFile.exists()) {
e3fb07d @burtbeckwith renamed 'console' binding variable to 'grailsConsole' since it confli…
burtbeckwith authored
140 grailsConsole.updateStatus "Stopping server..."
3e17890 1.1 branch is now trunk
graeme authored
141 grailsServer.stop()
142 killFile.delete()
143 keepRunning = false
144 }
145 }
146 }
147
69c8376 @graemerocher Fix for GRAILS-5055 "Server parameter to eventConfigureJetty is null …
graemerocher authored
148 target(stopServer: "Stops the Grails servlet container") {
2f7920b @graemerocher fixed failing functional tests
graemerocher authored
149 projectWatcher?.stopServer()
3e17890 1.1 branch is now trunk
graeme authored
150 }
Something went wrong with that request. Please try again.