This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
forked from pngowda/xtext-build-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pom_changes.groovy
67 lines (56 loc) · 2.21 KB
/
pom_changes.groovy
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
56
57
58
59
60
61
62
63
64
65
66
67
import jenkins.model.*
import hudson.model.*
import groovy.xml.XmlUtil
def changePomDependencyVersion(xtext_version, pomFile, snapshot_version) {
def pom = readXML(pomFile)
pom.dependencies.dependency.each { dependency ->
pom.dependencies.dependency.version="${dependency.version}".replace(snapshot_version, xtext_version)
}
pom.dependencyManagement.dependencies.dependency.findAll{it.artifactId.text() == 'xtext-dev-bom' }.each { dependency ->
pom.dependencyManagement.dependencies.dependency.version="${dependency.version}".replace(snapshot_version, xtext_version)
}
writeXML (pom, pomFile)
}
// TODO Move to some XML Utility file
def readXML (String xmlFile) {
curdir = new File('.')
println "XML file to process: ${curdir.absolutePath} ${xmlFile}"
def xml = new XmlSlurper( false, false ).parseText(new File(xmlFile).getText())
return xml
}
// TODO Move to some XML Utility file
def writeXML (xml, xmlFile) {
def file = new File(xmlFile)
XmlUtil xmlUtil = new XmlUtil()
xmlUtil.serialize(xml, new FileWriter(file))
// xml is serialized with space indentation, but we want to indent with tabs => postprocess and change that
def content = file.getText()
content = content.replaceAll(' ','\t')
file.setText(content)
}
def pomVersionUpdate(pomFile, xtext_version) {
def pom = readXML(pomFile)
pom.version = xtext_version
if (pom.parent != null) {
pom.parent.version = xtext_version
}
writeXML (pom, pomFile)
}
def setProperty (String pomFile, propertyName, propertyValue) {
println ("Set property $propertyName")
def pom = readXML (pomFile)
pom.properties.'*'.find { node -> node.name() == propertyName }.replaceBody(propertyValue)
writeXML (pom, pomFile)
}
// just for debugging with groovysh
def setProperty2 (pom, propertyName, propertyValue) {
println ("Set property $propertyName")
pom.properties.'*'.find { node -> node.name() == propertyName }.replaceBody(propertyValue)
println(XmlUtil.serialize(pom))
}
def pomZipVersionUpdate(xtext_version, pomFile,snapshot_version) {
def file = new File(pomFile)
def newContent = file.text.replaceFirst("tofile=(.*)repository-.+\\.zip", "tofile=\$1repository-${xtext_version}.zip")
file.write(newContent)
}
return this