Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 218 lines (185 sloc) 9.517 kb
3e17890 1.1 branch is now trunk
graeme authored
1 /*
2 * Copyright 2004-2005 the original author or authors.
835947f @burtbeckwith cleanup
burtbeckwith authored
3 *
3e17890 1.1 branch is now trunk
graeme authored
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
835947f @burtbeckwith cleanup
burtbeckwith authored
7 *
3e17890 1.1 branch is now trunk
graeme authored
8 * http://www.apache.org/licenses/LICENSE-2.0
835947f @burtbeckwith cleanup
burtbeckwith authored
9 *
3e17890 1.1 branch is now trunk
graeme authored
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 /**
18 * Gant script that handles upgrading of a Grails applications
19 *
20 * @author Graeme Rocher
21 * @author Sergey Nebolsin
22 *
23 * @since 0.4
24 */
25
26 import grails.util.Metadata
27
28 includeTargets << grailsScript("_GrailsPlugins")
29
30 target(upgrade: "main upgrade target") {
31
32 depends(createStructure, parseArguments)
33
34 boolean force = argsMap.force || !isInteractive ?: false
35
36 if (appGrailsVersion != grailsVersion) {
37 def gv = appGrailsVersion == null ? "pre-0.5" : appGrailsVersion
38 event("StatusUpdate", ["NOTE: Your application currently expects grails version [$gv], " +
835947f @burtbeckwith cleanup
burtbeckwith authored
39 "this target will upgrade it to Grails ${grailsVersion}"])
3e17890 1.1 branch is now trunk
graeme authored
40 }
41
42 if (!force) {
43 ant.input(message: """
835947f @burtbeckwith cleanup
burtbeckwith authored
44 WARNING: This target will upgrade an older Grails application to ${grailsVersion}.
45 Are you sure you want to continue?
46 """,
47 validargs: "y,n",
48 addproperty: "grails.upgrade.warning")
3e17890 1.1 branch is now trunk
graeme authored
49
50 def answer = ant.antProject.properties."grails.upgrade.warning"
51
52 if (answer == "n") exit(0)
53
54 if ((grailsVersion.startsWith("1.0")) &&
55 !(['utf-8', 'us-ascii'].contains(System.getProperty('file.encoding')?.toLowerCase()))) {
56 ant.input(message: """
835947f @burtbeckwith cleanup
burtbeckwith authored
57 WARNING: This version of Grails requires all source code to be encoded in UTF-8.
58 Your system file encoding indicates that your source code may not be saved in UTF-8.
59 You can re-encode your source code manually after upgrading, but if you have used any
60 non-ASCII chars in your source or GSPs your application may not operate correctly until
61 you re-encode the files as UTF-8.
62
63 Are you sure you want to upgrade your project now?
64 """,
65 validargs: "y,n",
66 addproperty: "grails.src.encoding.warning")
3e17890 1.1 branch is now trunk
graeme authored
67 answer = ant.antProject.properties."grails.src.encoding.warning"
68 if (answer == "n") exit(0)
69 }
70 }
71
72 clean()
73
74 def coreTaglibs = new File("${basedir}/plugins/core")
75
76 ant.delete(dir: "${coreTaglibs}", failonerror: false)
77
78 ant.sequential {
79 def testDir = "${basedir}/grails-tests"
80 if (new File("${testDir}/CVS").exists()) {
81 println """
82 WARNING: Your Grails tests directory '${testDir}' is currently under CVS control so the upgrade script cannot
83 move it to the new location of '${basedir}/test/integration'. Please move the directory using the relevant CVS commands."""
84 }
85 else if (new File("${testDir}/.svn").exists()) {
86 println """
87 WARNING: Your Grails tests directory '${testDir}' is currently under SVN control so the upgrade script cannot
88 move it to the new location of '${basedir}/test/integration'. Please move the directory using the relevant SVN commands."""
89 }
90 else {
91 if (new File(testDir).exists()) {
92 move(todir: "${basedir}/test/integration") {
93 fileset(dir: testDir, includes: "**")
94 }
95 delete(dir: testDir)
96 }
97 }
98 delete(dir: "${basedir}/tmp", failonerror: false)
99
100 copy(todir: "${basedir}/web-app") {
101 fileset(dir: "${grailsHome}/src/war") {
102 include(name: "**/**")
103 exclude(name: "WEB-INF/**")
104 present(present: "srconly", targetdir: "${basedir}/web-app")
105 }
106 }
107 copy(file: "${grailsHome}/src/war/WEB-INF/sitemesh.xml",
835947f @burtbeckwith cleanup
burtbeckwith authored
108 tofile: "${basedir}/web-app/WEB-INF/sitemesh.xml", overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
109 copy(file: "${grailsHome}/src/war/WEB-INF/applicationContext.xml",
835947f @burtbeckwith cleanup
burtbeckwith authored
110 tofile: "${basedir}/web-app/WEB-INF/applicationContext.xml", overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
111
112 if (!isPluginProject) {
113 // Install application-only files if needed, exact "one file only" matches
114 ['Config.groovy'].each() {template ->
115 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.equals(template) }) {
116 copy(tofile: "${basedir}/grails-app/conf/${template}") {
117 fileset(file: "${grailsHome}/src/grails/grails-app/conf/${template}") {
118 present(present: "srconly", targetdir: "${basedir}/grails-app/conf")
119 }
120 }
121 }
122 }
123
124 // Install application-only files if needed, with suffix matching
125 ['DataSource.groovy'].each() {template ->
126 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.startsWith(template) }) {
127 copy(tofile: "${basedir}/grails-app/conf/${template}") {
128 fileset(file: "${grailsHome}/src/grails/grails-app/conf/${template}") {
129 present(present: "srconly", targetdir: "${basedir}/grails-app/conf")
130 }
131 }
132 }
133 }
134 }
135
136 // Both applications and plugins can have UrlMappings, but only install default if there is nothing already
137 ['UrlMappings.groovy'].each() {template ->
138 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.endsWith(template) }) {
139 copy(tofile: "${basedir}/grails-app/conf/${template}") {
140 fileset(file: "${grailsHome}/src/grails/grails-app/conf/${template}") {
141 present(present: "srconly", targetdir: "${basedir}/grails-app/conf")
142 }
143 }
144 }
145 }
146
147 // if Config.groovy exists and it does not contain values for
148 // grails.views.default.codec or grails.views.gsp.encoding then
149 // add reasonable defaults for them
150 def configFile = new File(baseFile, '/grails-app/conf/Config.groovy')
151 if (configFile.exists()) {
549164e @graemerocher fix for GRAILS-6970 "Cannot use 'import' statement in Grails Config"
graemerocher authored
152 def configText = configFile.text
153 configFile.withWriterAppend {
154 if(!configText.contains("grails.views.default.codec") ) {
155 it.writeLine 'grails.views.default.codec="none" // none, html, base64'
156 }
157 if(!configText.contains("grails.views.gsp.encoding") ) {
158 it.writeLine 'grails.views.gsp.encoding="UTF-8"'
159 }
160 }
3e17890 1.1 branch is now trunk
graeme authored
161 }
162
163 if (new File("${basedir}/spring").exists()) {
164 move(file: "${basedir}/spring", todir: "${basedir}/grails-app/conf")
165 }
166 if (new File("${basedir}/hibernate").exists()) {
167 move(file: "${basedir}/hibernate", todir: "${basedir}/grails-app/conf")
168 }
169
170 def appKey = baseName.replaceAll(/\s/, '.').toLowerCase()
171
172 replace(dir: "${basedir}/web-app/WEB-INF", includes: "**/*.*",
173 token: "@grails.project.key@", value: "${appKey}")
174
175 copy(todir: "${basedir}/web-app/WEB-INF/tld", overwrite: true) {
176 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld/${servletVersion}")
177 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld", includes: "spring.tld")
178 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld", includes: "grails.tld")
179 }
180 touch(file: "${basedir}/grails-app/i18n/messages.properties")
181 }
182
183 // Add the app name and Grails version to the metadata.
184 updateMetadata("app.name": "$grailsAppName", "app.grails.version": "$grailsVersion")
185
186 // proceed plugin-specific upgrade logic contained in 'scripts/_Upgrade.groovy' under plugin's root
881a417 @pledbrook This ostensibly fixes a problem with the _GrailsWar script which was
pledbrook authored
187 def plugins = pluginSettings.pluginBaseDirectories
3e17890 1.1 branch is now trunk
graeme authored
188 if (plugins) {
189 for (pluginDir in plugins) {
190 def f = new File(pluginDir)
191 if (f.isDirectory() && f.name != 'core') {
192 // fix for Windows-style path with backslashes
193
194 def pluginBase = "${basedir}/plugins/${f.name}".toString().replaceAll("\\\\", "/")
195 // proceed _Upgrade.groovy plugin script if exists
196 def upgradeScript = new File("${pluginBase}/scripts/_Upgrade.groovy")
197 if (upgradeScript.exists()) {
198 event("StatusUpdate", ["Executing ${f.name} plugin upgrade script"])
199 // instrumenting plugin scripts adding 'pluginBasedir' variable
200 def instrumentedUpgradeScript = "def pluginBasedir = '${pluginBase}'\n" + upgradeScript.text
201 // we are using text form of script here to prevent Gant caching
202 includeTargets << instrumentedUpgradeScript
203 }
204 }
205 }
206 }
207
208 installDefaultPluginSet()
209
210 event("StatusUpdate", ["Please make sure you view the README for important information about changes to your source code."])
211
212 event("StatusFinal", ["Project upgraded"])
213 }
214
215 target("default": "Upgrades a Grails application from a previous version of Grails") {
216 depends(upgrade)
835947f @burtbeckwith cleanup
burtbeckwith authored
217 }
Something went wrong with that request. Please try again.