Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 224 lines (189 sloc) 10.018 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
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
100 if (!new File("$grailsHome/src/war").exists()) {
101 if (new File("${grailsHome}/grails-resources").exists()) {
102 grailsHome = new File("${grailsHome}/grails-resources")
103 }
104 }
1ab803f @graemerocher fix for broken upgrade script
graemerocher authored
105
3e17890 1.1 branch is now trunk
graeme authored
106 copy(todir: "${basedir}/web-app") {
107 fileset(dir: "${grailsHome}/src/war") {
108 include(name: "**/**")
109 exclude(name: "WEB-INF/**")
110 present(present: "srconly", targetdir: "${basedir}/web-app")
111 }
112 }
113 copy(file: "${grailsHome}/src/war/WEB-INF/sitemesh.xml",
835947f @burtbeckwith cleanup
burtbeckwith authored
114 tofile: "${basedir}/web-app/WEB-INF/sitemesh.xml", overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
115 copy(file: "${grailsHome}/src/war/WEB-INF/applicationContext.xml",
835947f @burtbeckwith cleanup
burtbeckwith authored
116 tofile: "${basedir}/web-app/WEB-INF/applicationContext.xml", overwrite: true)
3e17890 1.1 branch is now trunk
graeme authored
117
118 if (!isPluginProject) {
119 // Install application-only files if needed, exact "one file only" matches
120 ['Config.groovy'].each() {template ->
121 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.equals(template) }) {
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
122 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
3e17890 1.1 branch is now trunk
graeme authored
123 }
124 }
125
8162d12 @burtbeckwith updated to also create a BuildConfig.groovy if it doesn't exist
burtbeckwith authored
126 ['BuildConfig.groovy'].each() {template ->
127 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.equals(template) }) {
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
128 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
129 }
130 }
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
131
3e17890 1.1 branch is now trunk
graeme authored
132 // Install application-only files if needed, with suffix matching
133 ['DataSource.groovy'].each() {template ->
134 if (!new File(baseFile, '/grails-app/conf').listFiles().find { it.name.startsWith(template) }) {
f06bc67 @burtbeckwith whitespace, cleanup
burtbeckwith authored
135 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
3e17890 1.1 branch is now trunk
graeme authored
136 }
137 }
138 }
139
140 // Both applications and plugins can have UrlMappings, but only install default if there is nothing already
141 ['UrlMappings.groovy'].each() {template ->
142 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
143 copyGrailsResource("${basedir}/grails-app/conf/${template}", grailsResource("src/grails/grails-app/conf/${template}"))
3e17890 1.1 branch is now trunk
graeme authored
144 }
145 }
146
092ffe8 update the DataSource settings from hsqldb to h2 if possible
Graeme Rocher authored
147 def dsFile = new File(baseFile, "grails-app/conf/DataSource.groovy")
148 if(dsFile.exists()) {
149 replace file:dsFile, token:"jdbc:hsqldb:mem:devDB", value:"jdbc:h2:mem:devDb"
150 replace file:dsFile, token:"jdbc:hsqldb:mem:testDb",value: "jdbc:h2:mem:testDb"
151 replace file:dsFile, token:"org.hsqldb.jdbcDriver", value:"org.h2.Driver"
152 }
3e17890 1.1 branch is now trunk
graeme authored
153 // if Config.groovy exists and it does not contain values for
154 // grails.views.default.codec or grails.views.gsp.encoding then
155 // add reasonable defaults for them
156 def configFile = new File(baseFile, '/grails-app/conf/Config.groovy')
157 if (configFile.exists()) {
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
158 def configText = configFile.text
159 configFile.withWriterAppend {
160 if (!configText.contains("grails.views.default.codec")) {
6abd749 @graemerocher fix for GRAILS-6970 "Cannot use 'import' statement in Grails Config"
graemerocher authored
161 it.writeLine 'grails.views.default.codec="none" // none, html, base64'
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
162 }
163 if (!configText.contains("grails.views.gsp.encoding")) {
164 it.writeLine 'grails.views.gsp.encoding="UTF-8"'
165 }
166 }
3e17890 1.1 branch is now trunk
graeme authored
167 }
168
169 if (new File("${basedir}/spring").exists()) {
170 move(file: "${basedir}/spring", todir: "${basedir}/grails-app/conf")
171 }
172 if (new File("${basedir}/hibernate").exists()) {
173 move(file: "${basedir}/hibernate", todir: "${basedir}/grails-app/conf")
174 }
175
176 def appKey = baseName.replaceAll(/\s/, '.').toLowerCase()
177
178 replace(dir: "${basedir}/web-app/WEB-INF", includes: "**/*.*",
179 token: "@grails.project.key@", value: "${appKey}")
180
181 copy(todir: "${basedir}/web-app/WEB-INF/tld", overwrite: true) {
182 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld/${servletVersion}")
183 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld", includes: "spring.tld")
184 fileset(dir: "${grailsHome}/src/war/WEB-INF/tld", includes: "grails.tld")
185 }
186 touch(file: "${basedir}/grails-app/i18n/messages.properties")
187 }
188
189 // Add the app name and Grails version to the metadata.
085382c @jeffbrown GRAILS-7695 - fix upgrade command so it updates app.grails.version in…
jeffbrown authored
190 updateMetadata(metadata, ["app.name": "$grailsAppName", "app.grails.version": "$grailsVersion"])
3e17890 1.1 branch is now trunk
graeme authored
191
192 // 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
193 def plugins = pluginSettings.pluginBaseDirectories
3e17890 1.1 branch is now trunk
graeme authored
194 if (plugins) {
195 for (pluginDir in plugins) {
196 def f = new File(pluginDir)
197 if (f.isDirectory() && f.name != 'core') {
198 // fix for Windows-style path with backslashes
199
200 def pluginBase = "${basedir}/plugins/${f.name}".toString().replaceAll("\\\\", "/")
201 // proceed _Upgrade.groovy plugin script if exists
202 def upgradeScript = new File("${pluginBase}/scripts/_Upgrade.groovy")
203 if (upgradeScript.exists()) {
204 event("StatusUpdate", ["Executing ${f.name} plugin upgrade script"])
205 // instrumenting plugin scripts adding 'pluginBasedir' variable
206 def instrumentedUpgradeScript = "def pluginBasedir = '${pluginBase}'\n" + upgradeScript.text
207 // we are using text form of script here to prevent Gant caching
208 includeTargets << instrumentedUpgradeScript
209 }
210 }
211 }
212 }
213
214 installDefaultPluginSet()
215
216 event("StatusUpdate", ["Please make sure you view the README for important information about changes to your source code."])
217
218 event("StatusFinal", ["Project upgraded"])
219 }
220
221 target("default": "Upgrades a Grails application from a previous version of Grails") {
222 depends(upgrade)
835947f @burtbeckwith cleanup
burtbeckwith authored
223 }
Something went wrong with that request. Please try again.