Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 143 lines (120 sloc) 4.446 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 org.springframework.core.io.FileSystemResource
c3dd521 @graemerocher Fix for GRAILS-4424 "Incorrect display of plugin i18n non-english mes…
graemerocher authored
18 import org.springframework.core.io.Resource
8f57d37 @pledbrook Upgraded from GParallelizer 0.8.3 to GPars 0.9. Two reasons:
pledbrook authored
19
3e17890 1.1 branch is now trunk
graeme authored
20 /**
9a89740 @burtbeckwith reworked stack trace filtering and printing to be user-configurable; …
burtbeckwith authored
21 * Gant script that packages a Grails application (note: does not create WAR).
3e17890 1.1 branch is now trunk
graeme authored
22 *
23 * @author Graeme Rocher
24 *
25 * @since 0.4
26 */
27
d9f2b98 @graemerocher fix for GRAILS-5713 "Package by convention for new artefacts"
graemerocher authored
28 if (getBinding().variables.containsKey("_grails_package_called")) return
29 _grails_package_called = true
30
3e17890 1.1 branch is now trunk
graeme authored
31 includeTargets << grailsScript("_GrailsCompile")
32 includeTargets << grailsScript("_PackagePlugins")
33
835947f @burtbeckwith cleanup
burtbeckwith authored
34 target(createConfig: "Creates the configuration object") {
a68e8e8 fix for issue where config wasn't loaded properly in scripts that dep…
Graeme Rocher authored
35 if (!binding.variables.containsKey("configLoaded")) {
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
36 config = projectPackager.createConfig()
a68e8e8 fix for issue where config wasn't loaded properly in scripts that dep…
Graeme Rocher authored
37 configLoaded = true
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
38 }
3e17890 1.1 branch is now trunk
graeme authored
39 }
40
835947f @burtbeckwith cleanup
burtbeckwith authored
41 target(packageApp : "Implementation of package target") {
4bb14b9 refactored logic from _PackagePlugins.groovy and _GrailsPackage.groov…
Graeme Rocher authored
42 depends(createStructure)
9a89740 @burtbeckwith reworked stack trace filtering and printing to be user-configurable; …
burtbeckwith authored
43 grailsConsole.updateStatus "Packaging Grails application"
4bb14b9 refactored logic from _PackagePlugins.groovy and _GrailsPackage.groov…
Graeme Rocher authored
44 profile("compile") {
45 compile()
3e17890 1.1 branch is now trunk
graeme authored
46 }
47
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
48 projectPackager.classLoader = classLoader
3e17890 1.1 branch is now trunk
graeme authored
49
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
50 try {
51 config = projectPackager.packageApplication()
52 }
53 catch(e) {
54 grailsConsole.error "Error packaging application: $e.message", e
55 exit 1
56 }
3e17890 1.1 branch is now trunk
graeme authored
57
4bb14b9 refactored logic from _PackagePlugins.groovy and _GrailsPackage.groov…
Graeme Rocher authored
58 configureServerContextPath()
3e17890 1.1 branch is now trunk
graeme authored
59
2044229 @jeffbrown GRAILS-8319 - Fix grails.dbconsole.enabled
jeffbrown authored
60 loadPlugins()
61 generateWebXml()
62
3e17890 1.1 branch is now trunk
graeme authored
63 event("PackagingEnd",[])
64 }
65
66 target(configureServerContextPath: "Configuring server context path") {
ce12294 @alkemist GRAILS-7562 - ensure that the config has been read before trying to d…
alkemist authored
67 depends(createConfig)
3e17890 1.1 branch is now trunk
graeme authored
68 // Get the application context path by looking for a property named 'app.context' in the following order of precedence:
835947f @burtbeckwith cleanup
burtbeckwith authored
69 // System properties
70 // application.properties
71 // config
72 // default to grailsAppName if not specified
3e17890 1.1 branch is now trunk
graeme authored
73
74 serverContextPath = System.getProperty("app.context")
75 serverContextPath = serverContextPath ?: metadata.'app.context'
76 serverContextPath = serverContextPath ?: config.grails.app.context
77 serverContextPath = serverContextPath ?: grailsAppName
78
835947f @burtbeckwith cleanup
burtbeckwith authored
79 if (!serverContextPath.startsWith('/')) {
3e17890 1.1 branch is now trunk
graeme authored
80 serverContextPath = "/${serverContextPath}"
81 }
82 }
83
84 target(startLogging:"Bootstraps logging") {
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
85 depends(createConfig)
86 projectPackager.startLogging(config)
3e17890 1.1 branch is now trunk
graeme authored
87 }
88
835947f @burtbeckwith cleanup
burtbeckwith authored
89 target(generateWebXml : "Generates the web.xml file") {
90 depends(classpath)
91
92 if (buildConfig.grails.config.base.webXml) {
93 def customWebXml = resolveResources(buildConfig.grails.config.base.webXml)
94 if (customWebXml) {
95 webXml = customWebXml[0]
96 }
97 else {
98 event("StatusError", [ "Custom web.xml defined in config [${buildConfig.grails.config.base.webXml}] could not be found." ])
99 exit(1)
100 }
101 }
102 else {
103 webXml = new FileSystemResource("${basedir}/src/templates/war/web.xml")
3e17890 1.1 branch is now trunk
graeme authored
104 def tmpWebXml = "${projectWorkDir}/web.xml.tmp"
835947f @burtbeckwith cleanup
burtbeckwith authored
105 if (!webXml.exists()) {
3e17890 1.1 branch is now trunk
graeme authored
106 copyGrailsResource(tmpWebXml, grailsResource("src/war/WEB-INF/web${servletVersion}.template.xml"))
107 }
108 else {
109 ant.copy(file:webXml.file, tofile:tmpWebXml, overwrite:true)
110 }
111 webXml = new FileSystemResource(tmpWebXml)
835947f @burtbeckwith cleanup
burtbeckwith authored
112 ant.replace(file:tmpWebXml, token:"@grails.project.key@",
113 value:"${grailsAppName}-${grailsEnv}-${grailsAppVersion}")
3e17890 1.1 branch is now trunk
graeme authored
114 }
835947f @burtbeckwith cleanup
burtbeckwith authored
115
116 def sw = new StringWriter()
3e17890 1.1 branch is now trunk
graeme authored
117
118 try {
119 profile("generating web.xml from $webXml") {
835947f @burtbeckwith cleanup
burtbeckwith authored
120 event("WebXmlStart", [webXml.filename])
3e17890 1.1 branch is now trunk
graeme authored
121 pluginManager.doWebDescriptor(webXml, sw)
835947f @burtbeckwith cleanup
burtbeckwith authored
122 webXmlFile.withWriter { it << sw.toString() }
123 event("WebXmlEnd", [webXml.filename])
3e17890 1.1 branch is now trunk
graeme authored
124 }
125 }
835947f @burtbeckwith cleanup
burtbeckwith authored
126 catch (Exception e) {
3e17890 1.1 branch is now trunk
graeme authored
127 logError("Error generating web.xml file",e)
128 exit(1)
129 }
130 }
131
132 target(packageTemplates: "Packages templates into the app") {
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
133 projectPackager.packageTemplates(scaffoldDir)
3e17890 1.1 branch is now trunk
graeme authored
134 }
135
136 target(packageTlds:"packages tld definitions for the correct servlet version") {
347b78c @burtbeckwith whitespace, cleanup
burtbeckwith authored
137 projectPackager.packageTlds()
3e17890 1.1 branch is now trunk
graeme authored
138 }
139
140 recompileCheck = { lastModified, callback ->
1aa1cb0 @graemerocher Enhanced terminal output, needed to support redesigned interactive mode
graemerocher authored
141 // do nothing, here for compatibility
3e17890 1.1 branch is now trunk
graeme authored
142 }
Something went wrong with that request. Please try again.