Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 145 lines (126 sloc) 5.777 kb
7995c9f2 »
2012-06-19 ignoring test temporarily, as due to infrastructure issues it is not …
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 */
16
17 import grails.spring.WebBeanBuilder
18 import org.codehaus.groovy.grails.support.CommandLineResourceLoader
19 import org.codehaus.groovy.grails.cli.support.JndiBindingSupport
20 import org.codehaus.groovy.grails.commons.ApplicationAttributes
21 import org.codehaus.groovy.grails.commons.ApplicationHolder
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
26 import org.codehaus.groovy.grails.plugins.PluginManagerHolder
27 import org.codehaus.groovy.grails.core.io.PluginPathAwareFileSystemResourceLoader
28 import org.springframework.mock.web.MockServletContext
29 import org.springframework.web.context.WebApplicationContext
30 import org.springframework.beans.factory.config.MethodInvokingFactoryBean
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") {
44 event("AppLoadStart", ["Loading Grails Application"])
45 profile("Loading parent ApplicationContext") {
46 def builder = parentContext ? new WebBeanBuilder(parentContext) : new WebBeanBuilder()
47 beanDefinitions = builder.beans {
48 resourceHolder(GrailsResourceHolder) {
49 resources = pluginSettings.artefactResources
50 }
51 grailsResourceLoader(GrailsResourceLoaderFactoryBean) {
52 grailsResourceHolder = resourceHolder
53 }
54 grailsApplication(DefaultGrailsApplication, ref("grailsResourceLoader"))
55 }
56 }
57
58 appCtx = beanDefinitions.createApplicationContext()
59 def ctx = appCtx
60
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!
64 def resourceLoader = new PluginPathAwareFileSystemResourceLoader()
65 def locations = new ArrayList(grailsSettings.pluginDirectories.collect { it.absolutePath })
66 locations << grailsSettings.baseDir.absolutePath
67 resourceLoader.searchLocations = locations
68 servletContext = new MockServletContext('web-app', resourceLoader)
69 ctx.servletContext = servletContext
70 grailsApp = ctx.grailsApplication
71 ApplicationHolder.application = grailsApp
72 packageApp()
73 PluginManagerHolder.pluginManager = null
74 loadPlugins()
75 pluginManager = PluginManagerHolder.pluginManager
76 pluginManager.application = grailsApp
77 pluginManager.doArtefactConfiguration()
78
79 def builder = new WebBeanBuilder(ctx)
80 newBeans = builder.beans {
81 delegate."pluginManager"(MethodInvokingFactoryBean) {
82 targetClass = PluginManagerHolder
83 targetMethod = "getPluginManager"
84 }
85 }
86 newBeans.beanDefinitions.each { name, definition ->
87 ctx.registerBeanDefinition(name, definition)
88 }
89
90 grailsApp.initialise()
91 event("AppLoadEnd", ["Loading Grails Application"])
92 }
93
94 target(configureApp:"Configures the Grails application and builds an ApplicationContext") {
95 event("AppCfgStart", ["Configuring Grails Application"])
96 appCtx.resourceLoader = new CommandLineResourceLoader()
97 profile("Performing runtime Spring configuration") {
98 def configurer = new GrailsRuntimeConfigurator(grailsApp, appCtx)
99 def jndiEntries = config?.grails?.naming?.entries
100
101 if ((jndiEntries instanceof Map) && jndiEntries) {
102 def jndiBindingSupport = new JndiBindingSupport(jndiEntries)
103 jndiBindingSupport.bind()
104 }
105 appCtx = configurer.configure(servletContext)
106 servletContext.setAttribute(ApplicationAttributes.APPLICATION_CONTEXT,appCtx)
107 servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx)
108 }
109 applicationLoaded = true
110 event("AppCfgEnd", ["Configuring Grails Application"])
111 }
112
113 // Flag that determines whether the monitor loop should keep running.
114 keepMonitoring = true
115
116 // Callback invoked by the monitor each time it has checked for changes.
117 monitorCheckCallback = {}
118
119 // Callback invoked by the monitor each time it recompiles the app and
120 // restarts it.
121 monitorRecompileCallback = {}
122
123 target(monitorApp:"Monitors an application for changes using the PluginManager and reloads changes") {
124 depends(classpath)
125 // do nothing. Deprecated, purely here for compatibility
126 }
127
128 target(bootstrap: "Loads and configures a Grails instance") {
129 packageApp()
130 loadApp()
131 configureApp()
132 }
133
134 target(bootstrapOnce:"Loads and configures a Grails instance only if it is not already loaded and configured") {
135 depends(enableExpandoMetaClass)
136 if (!binding.variables.applicationLoaded) {
137 loadApp()
138 configureApp()
139 }
140 }
141
142 target(enableExpandoMetaClass: "Calls ExpandoMetaClass.enableGlobally()") {
143 ExpandoMetaClass.enableGlobally()
144 }
Something went wrong with that request. Please try again.