Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 146 lines (127 sloc) 5.8 kb
3e17890 1.1 branch is now trunk
graeme authored
1 /*
835947f @burtbeckwith cleanup
burtbeckwith authored
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 */
3e17890 1.1 branch is now trunk
graeme authored
16
17 import grails.spring.WebBeanBuilder
18 import org.codehaus.groovy.grails.support.CommandLineResourceLoader
835947f @burtbeckwith cleanup
burtbeckwith authored
19 import org.codehaus.groovy.grails.cli.support.JndiBindingSupport
3e17890 1.1 branch is now trunk
graeme authored
20 import org.codehaus.groovy.grails.commons.ApplicationAttributes
21 import org.codehaus.groovy.grails.commons.ApplicationHolder
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
22 import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
23 import org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean
24 import org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder
25 import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator
3e17890 1.1 branch is now trunk
graeme authored
26 import org.codehaus.groovy.grails.plugins.PluginManagerHolder
8c32005 fixes the resources plugin failing to load resources in integration t…
Graeme Rocher authored
27 import org.codehaus.groovy.grails.core.io.PluginPathAwareFileSystemResourceLoader
3e17890 1.1 branch is now trunk
graeme authored
28 import org.springframework.mock.web.MockServletContext
29 import org.springframework.web.context.WebApplicationContext
bd265a1 @alkemist GRAILS-6855 - make the pluginManager bean in the app context for inte…
alkemist authored
30 import org.springframework.beans.factory.config.MethodInvokingFactoryBean
3e17890 1.1 branch is now trunk
graeme authored
31
32 /**
33 * Gant script that bootstraps a running Grails instance without a
34 * servlet container.
35 *
36 * @author Graeme Rocher
37 */
38
39 includeTargets << grailsScript("_GrailsPackage")
40
41 parentContext = null // default parent context is null
42
43 target(loadApp:"Loads the Grails application object") {
835947f @burtbeckwith cleanup
burtbeckwith authored
44 event("AppLoadStart", ["Loading Grails Application"])
45 profile("Loading parent ApplicationContext") {
46 def builder = parentContext ? new WebBeanBuilder(parentContext) : new WebBeanBuilder()
47 beanDefinitions = builder.beans {
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
48 resourceHolder(GrailsResourceHolder) {
835947f @burtbeckwith cleanup
burtbeckwith authored
49 resources = pluginSettings.artefactResources
50 }
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
51 grailsResourceLoader(GrailsResourceLoaderFactoryBean) {
835947f @burtbeckwith cleanup
burtbeckwith authored
52 grailsResourceHolder = resourceHolder
53 }
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
54 grailsApplication(DefaultGrailsApplication, ref("grailsResourceLoader"))
835947f @burtbeckwith cleanup
burtbeckwith authored
55 }
56 }
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
57
835947f @burtbeckwith cleanup
burtbeckwith authored
58 appCtx = beanDefinitions.createApplicationContext()
59 def ctx = appCtx
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
60
3e17890 1.1 branch is now trunk
graeme authored
61 // The mock servlet context needs to resolve resources relative to the 'web-app'
62 // directory. We also need to use a FileSystemResourceLoader, otherwise paths are
63 // evaluated against the classpath - not what we want!
8c32005 fixes the resources plugin failing to load resources in integration t…
Graeme Rocher authored
64 def resourceLoader = new PluginPathAwareFileSystemResourceLoader()
65 def locations = new ArrayList(grailsSettings.pluginDirectories.collect { it.absolutePath })
a4ebf48 @burtbeckwith whitespace/cleanup
burtbeckwith authored
66 locations << grailsSettings.baseDir.absolutePath
8c32005 fixes the resources plugin failing to load resources in integration t…
Graeme Rocher authored
67 resourceLoader.searchLocations = locations
68 servletContext = new MockServletContext('web-app', resourceLoader)
3e17890 1.1 branch is now trunk
graeme authored
69 ctx.servletContext = servletContext
835947f @burtbeckwith cleanup
burtbeckwith authored
70 grailsApp = ctx.grailsApplication
71 ApplicationHolder.application = grailsApp
72 classLoader = grailsApp.classLoader
73 packageApp()
3e17890 1.1 branch is now trunk
graeme authored
74 PluginManagerHolder.pluginManager = null
75 loadPlugins()
76 pluginManager = PluginManagerHolder.pluginManager
77 pluginManager.application = grailsApp
78 pluginManager.doArtefactConfiguration()
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
79
bd265a1 @alkemist GRAILS-6855 - make the pluginManager bean in the app context for inte…
alkemist authored
80 def builder = new WebBeanBuilder(ctx)
81 newBeans = builder.beans {
82 delegate."pluginManager"(MethodInvokingFactoryBean) {
83 targetClass = PluginManagerHolder
84 targetMethod = "getPluginManager"
85 }
86 }
87 newBeans.beanDefinitions.each { name, definition ->
88 ctx.registerBeanDefinition(name, definition)
89 }
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
90
3e17890 1.1 branch is now trunk
graeme authored
91 grailsApp.initialise()
835947f @burtbeckwith cleanup
burtbeckwith authored
92 event("AppLoadEnd", ["Loading Grails Application"])
3e17890 1.1 branch is now trunk
graeme authored
93 }
94
95 target(configureApp:"Configures the Grails application and builds an ApplicationContext") {
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
96 event("AppCfgStart", ["Configuring Grails Application"])
3e17890 1.1 branch is now trunk
graeme authored
97 appCtx.resourceLoader = new CommandLineResourceLoader()
835947f @burtbeckwith cleanup
burtbeckwith authored
98 profile("Performing runtime Spring configuration") {
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
99 def configurer = new GrailsRuntimeConfigurator(grailsApp, appCtx)
5c9b37e @graemerocher Support for JNDI entries registered via grails.naming.entries inside …
graemerocher authored
100 def jndiEntries = config?.grails?.naming?.entries
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
101
835947f @burtbeckwith cleanup
burtbeckwith authored
102 if (jndiEntries instanceof Map) {
103 def jndiBindingSupport = new JndiBindingSupport(jndiEntries)
104 jndiBindingSupport.bind()
5c9b37e @graemerocher Support for JNDI entries registered via grails.naming.entries inside …
graemerocher authored
105 }
106 appCtx = configurer.configure(servletContext)
835947f @burtbeckwith cleanup
burtbeckwith authored
107 servletContext.setAttribute(ApplicationAttributes.APPLICATION_CONTEXT,appCtx)
108 servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx)
109 }
b0fe781 @burtbeckwith whitespace, warnings, deprecation fixes, switched from StringBuffer t…
burtbeckwith authored
110 applicationLoaded = true
33b7ddb @burtbeckwith GRAILS-6182 added extra events
burtbeckwith authored
111 event("AppCfgEnd", ["Configuring Grails Application"])
3e17890 1.1 branch is now trunk
graeme authored
112 }
113
114 // Flag that determines whether the monitor loop should keep running.
115 keepMonitoring = true
116
117 // Callback invoked by the monitor each time it has checked for changes.
118 monitorCheckCallback = {}
119
120 // Callback invoked by the monitor each time it recompiles the app and
121 // restarts it.
122 monitorRecompileCallback = {}
123
124 target(monitorApp:"Monitors an application for changes using the PluginManager and reloads changes") {
125 depends(classpath)
b0fe781 @burtbeckwith whitespace, warnings, deprecation fixes, switched from StringBuffer t…
burtbeckwith authored
126 // do nothing. Deprecated, purely here for compatibility
3e17890 1.1 branch is now trunk
graeme authored
127 }
128
129 target(bootstrap: "Loads and configures a Grails instance") {
b0fe781 @burtbeckwith whitespace, warnings, deprecation fixes, switched from StringBuffer t…
burtbeckwith authored
130 packageApp()
3e17890 1.1 branch is now trunk
graeme authored
131 loadApp()
132 configureApp()
133 }
3d543df @graemerocher application/applicationContext only loaded once for integration tests…
graemerocher authored
134
135 target(bootstrapOnce:"Loads and configures a Grails instance only if it is not already loaded and configured") {
78892f5 @burtbeckwith ensuring that ExpandoMetaClass.enableGlobally() gets called when runn…
burtbeckwith authored
136 depends(enableExpandoMetaClass)
b47116a @alkemist whitespace cleanup
alkemist authored
137 if (!binding.variables.applicationLoaded) {
b0fe781 @burtbeckwith whitespace, warnings, deprecation fixes, switched from StringBuffer t…
burtbeckwith authored
138 loadApp()
139 configureApp()
140 }
78892f5 @burtbeckwith ensuring that ExpandoMetaClass.enableGlobally() gets called when runn…
burtbeckwith authored
141 }
142
143 target(enableExpandoMetaClass: "Calls ExpandoMetaClass.enableGlobally()") {
144 ExpandoMetaClass.enableGlobally()
145 }
Something went wrong with that request. Please try again.