Skip to content

Commit 698d561

Browse files
committed
GRAILS-6565 applied patch (with modifications) to set a plugin's version
1 parent 9fae0ad commit 698d561

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

scripts/SetVersion.groovy

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,59 @@
2727
includeTargets << grailsScript("_GrailsEvents")
2828

2929
target ('default': "Sets the current application version") {
30+
3031
if (isPluginProject) {
31-
println "The set-version command cannot update the version of a plugin project. Change the value of the 'version' property in ${pluginSettings.basePluginDescriptor.filename} instead."
32-
exit(1)
33-
}
32+
if (!pluginSettings.basePluginDescriptor.filename) {
33+
println "PluginDescripter not found to set version"
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()
3458

35-
if (args != null) {
36-
ant.property(name:"app.version.new", value: args)
59+
String newVersionString = "def version = \"${newVersion}\""
60+
61+
if (matcher.size() > 0) {
62+
descriptorContent = descriptorContent.replaceAll(/def\s*version\s*=\s*".*"/, newVersionString)
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"])
3770
}
3871
else {
39-
def oldVersion = metadata.'app.version'
40-
ant.input(addProperty:"app.version.new", message:"Enter the new version", defaultvalue:oldVersion)
41-
}
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+
}
4279

43-
def newVersion = ant.antProject.properties.'app.version.new'
44-
metadata.'app.version' = newVersion
45-
metadata.persist()
46-
event("StatusFinal", [ "Application version updated to $newVersion"])
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+
}
4785
}

0 commit comments

Comments
 (0)