Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 237 lines (201 sloc) 10.988 kB
7995c9f @graemerocher ignoring test temporarily, as due to infrastructure issues it is not …
graemerocher authored
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 /**
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 UNMODIFIED_CHECKSUMS = [indexgsp:['e9f4d3450ba02fe92d55f4ae4b53dee8', 'e9f4d3450ba02fe92d55f4ae4b53dee8', '77f5ed5c2fca586a9ff1dc8e7beeb85b', '5313f072b2ed10129a446d5f648d8b41'],
31 errorgsp:['473b673fb3f04a60412ace1b7bc12a8c', '473b673fb3f04a60412ace1b7bc12a8c', '473b673fb3f04a60412ace1b7bc12a8c', '473b673fb3f04a60412ace1b7bc12a8c'],
32 maincss:['612301d27b1d5d6f670cc98905376f59','612301d27b1d5d6f670cc98905376f59', '820b415fc6e53b156b68e5a01fa5677e', '820b415fc6e53b156b68e5a01fa5677e']]
33
34 target(upgrade: "main upgrade target") {
35
36 depends(createStructure, parseArguments)
37
38 System.properties.put('runningGrailsUpgrade', 'true')
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], " +
44 "this target will upgrade it to Grails ${grailsVersion}"])
45 }
46
47 if (!force) {
48 ant.input(message: """
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")
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: """
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")
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
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 }
110
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",
119 tofile: "${basedir}/web-app/WEB-INF/sitemesh.xml", overwrite: true)
120 copy(file: "${grailsHome}/src/war/WEB-INF/applicationContext.xml",
121 tofile: "${basedir}/web-app/WEB-INF/applicationContext.xml", overwrite: true)
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) }) {
127 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
128 }
129 }
130
131 ['BuildConfig.groovy'].each() {template ->
132 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.equals(template) }) {
133 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
134 }
135 }
136
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) }) {
140 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
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) }) {
148 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
149 }
150 }
151
152 def dsFile = new File(baseFile, "grails-app/conf/DataSource.groovy")
153 if (dsFile.exists() && argsMap.'update-data-source') {
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"
156 replace file:dsFile, token:"org.hsqldb.jdbcDriver", value:"org.h2.Driver"
157 }
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()) {
163 def configText = configFile.text
164 configFile.withWriterAppend {
165 if (!configText.contains("grails.views.default.codec")) {
166 it.writeLine 'grails.views.default.codec="none" // none, html, base64'
167 }
168 if (!configText.contains("grails.views.gsp.encoding")) {
169 it.writeLine 'grails.views.gsp.encoding="UTF-8"'
170 }
171 }
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.
195 def newMetadata = ["app.name": "$grailsAppName", "app.grails.version": "$grailsVersion"]
196 for (pluginEntry in grailsSettings.defaultPluginMap) {
197 def pluginName = pluginEntry.key
198 def pluginKey = "plugins.$pluginName".toString()
199 if (metadata.containsKey(pluginKey)) {
200 newMetadata[pluginKey] = pluginEntry.value
201 }
202 }
203 updateMetadata(metadata, newMetadata)
204
205 // proceed plugin-specific upgrade logic contained in 'scripts/_Upgrade.groovy' under plugin's root
206 def plugins = pluginSettings.pluginBaseDirectories
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)
236 }
Something went wrong with that request. Please try again.