|
27 | 27 | includeTargets << grailsScript("_GrailsEvents") |
28 | 28 |
|
29 | 29 | target ('default': "Sets the current application version") { |
| 30 | + |
30 | 31 | 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() |
34 | 58 |
|
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"]) |
37 | 70 | } |
38 | 71 | 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 | + } |
42 | 79 |
|
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 | + } |
47 | 85 | } |
0 commit comments