-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetVersion.groovy
More file actions
executable file
·55 lines (50 loc) · 2.54 KB
/
setVersion.groovy
File metadata and controls
executable file
·55 lines (50 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env groovy
import java.util.regex.Matcher
import java.util.regex.Pattern
start(args)
def start(String[] args) {
if (args.length != 2) {
usage()
} else {
setVersion(args[0], args[1])
}
}
def usage() {
println "Usage: ./setVersion.groovy from-version to-version"
}
def setVersion(String fromVersion, String toVersion) {
replaceInFile('jreleaser.yml', "(.*version: )(${fromVersion})", toVersion)
replaceInFile('build.gradle', "( version = ')(${fromVersion})(')", toVersion)
replaceInFile('README.md', "(documentationGeneratorVersion = )(${fromVersion})", toVersion)
replaceInFile('demos/demo-data-dictionary/gradle.properties', "(documentationGeneratorVersion = )(${fromVersion})", toVersion)
replaceInFile('demos/demo-data-lineage/gradle.properties', "(documentationGeneratorVersion = )(${fromVersion})", toVersion)
replaceInFile('demos/demo-erdiagram/gradle.properties', "(documentationGeneratorVersion = )(${fromVersion})", toVersion)
replaceInFile('demos/demo-erdiagram/pom.xml', "(.*<documentation-generator.version>)(${fromVersion})(</documentation-generator.version>)", toVersion)
replaceInFile('demos/demo-erdiagram/pom.xml', "(.*<version>)(${fromVersion})(</version>)", toVersion)
replaceInFile('demos/demo-sqlscript/gradle.properties', "(documentationGeneratorVersion = )(${fromVersion})", toVersion)
replaceInFile('documentation-generator-maven-plugin/pom.xml', "(.*<version>)(${fromVersion})(</version>)", toVersion)
replaceInFile('documentation-generator-maven-plugin/jreleaser.yml', "(.*version: )(${fromVersion})", toVersion)
replaceInFile('documentation-generator-maven-plugin/README.md', "(.*<version>)(${fromVersion})(</version>)", toVersion)
replaceInFile('documentation-generator-gradle/README.md', "(documentationGeneratorVersion = )(${fromVersion})", toVersion)
}
def replaceInFile(String filename, String regex, String toVersion) {
File file = new File(filename)
File tmpFile = new File(filename + ".tmp")
if (tmpFile.exists()) {
tmpFile.delete()
}
Pattern pattern = Pattern.compile(regex)
file.text.eachLine { line ->
Matcher lineMatcher = pattern.matcher(line)
if (lineMatcher.matches()) {
if (lineMatcher.groupCount() < 3) {
line = line.replaceAll(pattern, "\$1${toVersion}".toString())
} else {
line = line.replaceAll(pattern, "\$1${toVersion}\$3".toString())
}
}
tmpFile.append("$line\n");
}
file.delete()
tmpFile.renameTo(file)
}