Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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