This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformPOMs.groovy
86 lines (78 loc) · 2.8 KB
/
transformPOMs.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the GNU Lesser General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author stanley.shyiko@gmail.com
* @version 2010-11-06
*/
private String getVersion() {
String buildNumber = (new File("pom.xml").getText() =~ /<build.number>.*?<\/build.number>/)[0]
"${buildNumber[14..-16]}"
}
private String replaceVersionInformation(String source, String version) {
source.replaceAll(/\$\{build.number\}/, {return version})
}
private String prepareForSonatypeOSS(String source) {
def root = new XmlParser().parseText(source)
def relativePaths = root.get("parent")?.relativePath
if (relativePaths) {
Node relativePath = relativePaths[0]
removeNodeIfExist relativePath.parent(), relativePath.name().getLocalPart()
}
removeNodeIfExist root, "properties"
removeNodeIfExist root, "build"
removeNodeIfExist root, "profiles"
toString(root)
}
private void removeNodeIfExist(Node parent, String child) {
def children = parent.get(child)
if (children)
parent.remove((Node) children[0])
}
private String toString(Node root) {
def writer = new StringWriter()
def printer = new XmlNodePrinter(new PrintWriter(writer));
printer.setPreserveWhitespace true
printer.print root
writer.toString()
}
private String moveModulesFromDefaultProfile(String source) {
def root = new XmlParser().parseText(source)
def defaultProfile = root.profiles.profile.find {it.id.get(0).value().get(0) == "default"}
root.append(defaultProfile.modules.get(0))
toString(root)
}
def version = getVersion()
def root = new File("build/oss-release")
root.mkdirs()
root.eachFile {
it.delete()
}
def transform = {String source ->
prepareForSonatypeOSS(replaceVersionInformation(source, version))
}
def save = {File file, String content ->
print "Saving ${file.getAbsolutePath()}"
file.write content
println ". Done"
}
[
"jsst-antlib", "jsst-core", "jsst-junit", "jsst-testng", "jsst-war"
].each {artifact ->
def sourcePom = new File(artifact, "pom.xml")
def targetPom = new File(root, "${artifact}-1.0.${version}.pom")
save targetPom, transform(sourcePom.getText())
}
save new File(root, "jsst-1.0.${version}.pom"), transform(moveModulesFromDefaultProfile(new File("pom.xml").getText()))