Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 237 lines (201 sloc) 10.988 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
7d6ceb1 add flag to optionally update ds settings to upgrade
Graeme Rocher authored
30 UNMODIFIED_CHECKSUMS = [indexgsp:['e9f4d3450ba02fe92d55f4ae4b53dee8', 'e9f4d3450ba02fe92d55f4ae4b53dee8', '77f5ed5c2fca586a9ff1dc8e7beeb85b', '5313f072b2ed10129a446d5f648d8b41'],
31 errorgsp:['473b673fb3f04a60412ace1b7bc12a8c', '473b673fb3f04a60412ace1b7bc12a8c', '473b673fb3f04a60412ace1b7bc12a8c', '473b673fb3f04a60412ace1b7bc12a8c'],
32 maincss:['612301d27b1d5d6f670cc98905376f59','612301d27b1d5d6f670cc98905376f59', '820b415fc6e53b156b68e5a01fa5677e', '820b415fc6e53b156b68e5a01fa5677e']]
33
3e17890 1.1 branch is now trunk
graeme authored
34 target(upgrade: "main upgrade target") {
35
36 depends(createStructure, parseArguments)
37
a2be4f9 @jeffbrown GRAILS-8107 - Don't abort an upgrade if dependency resolution fails
jeffbrown authored
38 System.properties.put('runningGrailsUpgrade', 'true')
3e17890 1.1 branch is now trunk
graeme authored
39 boolean force = argsMap.force || !isInteractive ?: false
40
41 if (appGrailsVersion != grailsVersion) {
42 def gv = appGrailsVersion == null ? "pre-0.5" : appGrailsVersion
43 event("StatusUpdate", ["NOTE: Your application currently expects grails version [$gv], " +
835947f @burtbeckwith cleanup
burtbeckwith authored
44 "this target will upgrade it to Grails ${grailsVersion}"])
3e17890 1.1 branch is now trunk
graeme authored
45 }
46
47 if (!force) {
48 ant.input(message: """
835947f @burtbeckwith cleanup
burtbeckwith authored
49 WARNING: This target will upgrade an older Grails application to ${grailsVersion}.
50 Are you sure you want to continue?
51 """,
52 validargs: "y,n",
53 addproperty: "grails.upgrade.warning")
3e17890 1.1 branch is now trunk
graeme authored
54
55 def answer = ant.antProject.properties."grails.upgrade.warning"
56
57 if (answer == "n") exit(0)
58
59 if ((grailsVersion.startsWith("1.0")) &&
60 !(['utf-8', 'us-ascii'].contains(System.getProperty('file.encoding')?.toLowerCase()))) {
61 ant.input(message: """
835947f @burtbeckwith cleanup
burtbeckwith authored
62 WARNING: This version of Grails requires all source code to be encoded in UTF-8.
63 Your system file encoding indicates that your source code may not be saved in UTF-8.
64 You can re-encode your source code manually after upgrading, but if you have used any
65 non-ASCII chars in your source or GSPs your application may not operate correctly until
66 you re-encode the files as UTF-8.
67
68 Are you sure you want to upgrade your project now?
69 """,
70 validargs: "y,n",
71 addproperty: "grails.src.encoding.warning")
3e17890 1.1 branch is now trunk
graeme authored
72 answer = ant.antProject.properties."grails.src.encoding.warning"
73 if (answer == "n") exit(0)
74 }
75 }
76
77 clean()
78
79 def coreTaglibs = new File("${basedir}/plugins/core")
80
81 ant.delete(dir: "${coreTaglibs}", failonerror: false)
82
83 ant.sequential {
84 def testDir = "${basedir}/grails-tests"
85 if (new File("${testDir}/CVS").exists()) {
86 println """
87 WARNING: Your Grails tests directory '${testDir}' is currently under CVS control so the upgrade script cannot
88 move it to the new location of '${basedir}/test/integration'. Please move the directory using the relevant CVS commands."""
89 }
90 else if (new File("${testDir}/.svn").exists()) {
91 println """
92 WARNING: Your Grails tests directory '${testDir}' is currently under SVN control so the upgrade script cannot
93 move it to the new location of '${basedir}/test/integration'. Please move the directory using the relevant SVN commands."""
94 }
95 else {
96 if (new File(testDir).exists()) {
97 move(todir: "${basedir}/test/integration") {
98 fileset(dir: testDir, includes: "**")
99 }
100 delete(dir: testDir)
101 }
102 }
103 delete(dir: "${basedir}/tmp", failonerror: false)
104
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
105 if (!new File("$grailsHome/src/war").exists()) {
106 if (new File("${grailsHome}/grails-resources").exists()) {
107 grailsHome = new File("${grailsHome}/grails-resources")
108 }
109 }
1ab803f @graemerocher fix for broken upgrade script
graemerocher authored
110
3e17890 1.1 branch is now trunk
graeme authored
111 copy(todir: "${basedir}/web-app") {
112 fileset(dir: "${grailsHome}/src/war") {
113 include(name: "**/**")
114 exclude(name: "WEB-INF/**")
115 present(present: "srconly", targetdir: "${basedir}/web-app")
116 }
117 }
118 copy(file: "${grailsHome}/src/war/WEB-INF/sitemesh.xml",
835947f @burtbeckwith cleanup
burtbeckwith authored
119 tofile: "${basedir}/web-app/WEB-INF/sitemesh.xml", overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
120 copy(file: "${grailsHome}/src/war/WEB-INF/applicationContext.xml",
835947f @burtbeckwith cleanup
burtbeckwith authored
121 tofile: "${basedir}/web-app/WEB-INF/applicationContext.xml", overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
122
123 if (!isPluginProject) {
124 // Install application-only files if needed, exact "one file only" matches
125 ['Config.groovy'].each() {template ->
126 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.equals(template) }) {
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
127 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
3e17890 1.1 branch is now trunk
graeme authored
128 }
129 }
130
8162d12 @burtbeckwith updated to also create a BuildConfig.groovy if it doesn't exist
burtbeckwith authored
131 ['BuildConfig.groovy'].each() {template ->
132 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.equals(template) }) {
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
133 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
8162d12 @burtbeckwith updated to also create a BuildConfig.groovy if it doesn't exist
burtbeckwith authored
134 }
135 }
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
136
3e17890 1.1 branch is now trunk
graeme authored
137 // Install application-only files if needed, with suffix matching
138 ['DataSource.groovy'].each() {template ->
139 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.startsWith(template) }) {
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
140 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
3e17890 1.1 branch is now trunk
graeme authored
141 }
142 }
143 }
144
145 // Both applications and plugins can have UrlMappings, but only install default if there is nothing already
146 ['UrlMappings.groovy'].each() {template ->
147 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.endsWith(template) }) {
91375d8 fixed bug in upgrade script that failed upgrade
Graeme Rocher authored
148 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
3e17890 1.1 branch is now trunk
graeme authored
149 }
150 }
151
092ffe8 update the DataSource settings from hsqldb to h2 if possible
Graeme Rocher authored
152 def dsFile = new File(baseFile, "grails-app/conf/DataSource.groovy")
94733fb @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
153 if (dsFile.exists() && argsMap.'update-data-source') {
69b918c @lhotari Fix for GRAILS-8433 using H2 database: increase H2 lock timeout from …
lhotari authored
154 replace file:dsFile, token:"jdbc:hsqldb:mem:devDB", value:"jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
155 replace file:dsFile, token:"jdbc:hsqldb:mem:testDb",value: "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
94733fb @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
156 replace file:dsFile, token:"org.hsqldb.jdbcDriver", value:"org.h2.Driver"
092ffe8 update the DataSource settings from hsqldb to h2 if possible
Graeme Rocher authored
157 }
3e17890 1.1 branch is now trunk
graeme authored
158 // if Config.groovy exists and it does not contain values for
159 // grails.views.default.codec or grails.views.gsp.encoding then
160 // add reasonable defaults for them
161 def configFile = new File(baseFile, '/grails-app/conf/Config.groovy')
162 if (configFile.exists()) {
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
163 def configText = configFile.text
164 configFile.withWriterAppend {
165 if (!configText.contains("grails.views.default.codec")) {
6abd749 @graemerocher fix for GRAILS-6970 "Cannot use 'import' statement in Grails Config"
graemerocher authored
166 it.writeLine 'grails.views.default.codec="none" // none, html, base64'
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
167 }
168 if (!configText.contains("grails.views.gsp.encoding")) {
169 it.writeLine 'grails.views.gsp.encoding="UTF-8"'
170 }
171 }
3e17890 1.1 branch is now trunk
graeme authored
172 }
173
174 if (new File("${basedir}/spring").exists()) {
175 move(file: "${basedir}/spring", todir: "${basedir}/grails-app/conf")
176 }
177 if (new File("${basedir}/hibernate").exists()) {
178 move(file: "${basedir}/hibernate", todir: "${basedir}/grails-app/conf")
179 }
180
181 def appKey = baseName.replaceAll(/\s/, '.').toLowerCase()
182
183 replace(dir: "${basedir}/web-app/WEB-INF", includes: "**/*.*",
184 token: "@grails.project.key@", value: "${appKey}")
185
186 copy(todir: "${basedir}/web-app/WEB-INF/tld", overwrite: true) {
187 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld/${servletVersion}")
188 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld", includes: "spring.tld")
189 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld", includes: "grails.tld")
190 }
191 touch(file: "${basedir}/grails-app/i18n/messages.properties")
192 }
193
194 // Add the app name and Grails version to the metadata.
3523178 @graemerocher fixed issue updating default plugin versions with the upgrade command
graemerocher authored
195 def newMetadata = ["app.name": "$grailsAppName", "app.grails.version": "$grailsVersion"]
96df8cc @burtbeckwith whitespace
burtbeckwith authored
196 for (pluginEntry in grailsSettings.defaultPluginMap) {
3523178 @graemerocher fixed issue updating default plugin versions with the upgrade command
graemerocher authored
197 def pluginName = pluginEntry.key
198 def pluginKey = "plugins.$pluginName".toString()
96df8cc @burtbeckwith whitespace
burtbeckwith authored
199 if (metadata.containsKey(pluginKey)) {
3523178 @graemerocher fixed issue updating default plugin versions with the upgrade command
graemerocher authored
200 newMetadata[pluginKey] = pluginEntry.value
96df8cc @burtbeckwith whitespace
burtbeckwith authored
201 }
3523178 @graemerocher fixed issue updating default plugin versions with the upgrade command
graemerocher authored
202 }
203 updateMetadata(metadata, newMetadata)
3e17890 1.1 branch is now trunk
graeme authored
204
205 // 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
206 def plugins = pluginSettings.pluginBaseDirectories
3e17890 1.1 branch is now trunk
graeme authored
207 if (plugins) {
208 for (pluginDir in plugins) {
209 def f = new File(pluginDir)
210 if (f.isDirectory() && f.name != 'core') {
211 // fix for Windows-style path with backslashes
212
213 def pluginBase = "${basedir}/plugins/${f.name}".toString().replaceAll("\\\\", "/")
214 // proceed _Upgrade.groovy plugin script if exists
215 def upgradeScript = new File("${pluginBase}/scripts/_Upgrade.groovy")
216 if (upgradeScript.exists()) {
217 event("StatusUpdate", ["Executing ${f.name} plugin upgrade script"])
218 // instrumenting plugin scripts adding 'pluginBasedir' variable
219 def instrumentedUpgradeScript = "def pluginBasedir = '${pluginBase}'\n" + upgradeScript.text
220 // we are using text form of script here to prevent Gant caching
221 includeTargets << instrumentedUpgradeScript
222 }
223 }
224 }
225 }
226
227 installDefaultPluginSet()
228
229 event("StatusUpdate", ["Please make sure you view the README for important information about changes to your source code."])
230
231 event("StatusFinal", ["Project upgraded"])
232 }
233
234 target("default": "Upgrades a Grails application from a previous version of Grails") {
235 depends(upgrade)
835947f @burtbeckwith cleanup
burtbeckwith authored
236 }
Something went wrong with that request. Please try again.