Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (73 sloc) 2.921 kb
3e17890 1.1 branch is now trunk
graeme 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 manages the application version
19 *
20 * @author Marc Palmer
21 * @author Sergey Nebolsin (nebolsin@gmail.com)
22 * @author Graeme Rocher
23 *
24 * @since 0.5
25 */
26
27 includeTargets << grailsScript("_GrailsEvents")
28
29 target ('default': "Sets the current application version") {
4a69917 @burtbeckwith whitespace, STS warnings, etc.
burtbeckwith authored
30
2c8a7ab @pledbrook Modified the set-version command so that it prints a warning and exits
pledbrook authored
31 if (isPluginProject) {
698d561 @burtbeckwith GRAILS-6565 applied patch (with modifications) to set a plugin's version
burtbeckwith authored
32 if (!pluginSettings.basePluginDescriptor.filename) {
e3fb07d @burtbeckwith renamed 'console' binding variable to 'grailsConsole' since it conflicte...
burtbeckwith authored
33 grailsConsole.error "PluginDescripter not found to set version"
698d561 @burtbeckwith GRAILS-6565 applied patch (with modifications) to set a plugin's version
burtbeckwith authored
34 exit 1
35 }
36
37 File file = new File(pluginSettings.basePluginDescriptor.filename)
38 String descriptorContent = file.text
39
40 def pattern = ~/def\s*version\s*=\s*"(.*)"/
41 def matcher = (descriptorContent =~ pattern)
42
43 String oldVersion = ''
44 if (matcher.size() > 0) {
45 oldVersion = matcher[0][0]
46 }
47
48 String newVersion
49 if (!args) {
50 ant.input addProperty: "app.version.new", message: "Enter the new version",
51 defaultvalue: oldVersion - 'def version = '
52 newVersion = ant.antProject.properties.'app.version.new'
53 }
54 else {
55 newVersion = args
56 }
57 newVersion = newVersion?.trim()
2c8a7ab @pledbrook Modified the set-version command so that it prints a warning and exits
pledbrook authored
58
698d561 @burtbeckwith GRAILS-6565 applied patch (with modifications) to set a plugin's version
burtbeckwith authored
59 String newVersionString = "def version = \"${newVersion}\""
60
61 if (matcher.size() > 0) {
9c15d2b @burtbeckwith GRAILS-6565 changed to replaceFirst to avoid changing more than just plu...
burtbeckwith authored
62 descriptorContent = descriptorContent.replaceFirst(/def\s*version\s*=\s*".*"/, newVersionString)
698d561 @burtbeckwith GRAILS-6565 applied patch (with modifications) to set a plugin's version
burtbeckwith authored
63 }
64 else {
65 descriptorContent = descriptorContent.replaceFirst(/\{/,"{\n\t$newVersionString // added by set-version")
66 }
67
68 file.withWriter { it.write descriptorContent }
69 event("StatusFinal", [ "Plugin version updated to $newVersion"])
835947f @burtbeckwith cleanup
burtbeckwith authored
70 }
71 else {
698d561 @burtbeckwith GRAILS-6565 applied patch (with modifications) to set a plugin's version
burtbeckwith authored
72 if (args) {
73 ant.property(name:"app.version.new", value: args)
74 }
75 else {
76 def oldVersion = metadata.'app.version'
77 ant.input addProperty: "app.version.new", message: "Enter the new version", defaultvalue: oldVersion
78 }
3e17890 1.1 branch is now trunk
graeme authored
79
698d561 @burtbeckwith GRAILS-6565 applied patch (with modifications) to set a plugin's version
burtbeckwith authored
80 def newVersion = ant.antProject.properties.'app.version.new'
81 metadata.'app.version' = newVersion
82 metadata.persist()
83 event("StatusFinal", [ "Application version updated to $newVersion"])
84 }
3e17890 1.1 branch is now trunk
graeme authored
85 }
Something went wrong with that request. Please try again.