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