-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathRpmSpec.groovy
105 lines (84 loc) · 2.78 KB
/
RpmSpec.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/groovy
package com.redhat.art
// ===========================================================================
//
// Operations on an RPM Spec File
//
// ===========================================================================
class RpmSpec {
def filename
def lines
def pipeline
def RpmSpec(Map init) {
this.filename = init.filename
this.lines = init.lines
this.pipeline = init.pipeline
}
def load() {
lines = pipeline.readFile(filename).tokenize("\n")
}
def save() {
pipeline.writeFile(file: filename, text: body)
}
String getBody() {
return lines.join('\n')
}
String getVersion() {
// find the line with the Version tag
def v_line = lines.find { it =~ /^Version: / }
if (v_line == null) {
return null
}
// extract the version string and return that
def v_match = v_line =~ /^Version:\s*([.0-9]+)/
return v_match[0][1].trim()
}
void setVersion(String new_version) {
// find the version line
def line_no = lines.findIndexOf{ it =~ /^Version: / }
assert line_no > -1
// replace it with the new version line
lines[line_no] = "Version: ${new_version}"
}
String getRelease() {
// find the line with the Version tag
def v_line = lines.find { it =~ /^Release: / }
if (v_line == null) {
return null
}
// extract the version string and return that
def v_match = v_line =~ /^Release:\s*([.0-9]+)/
return v_match[0][1].trim()
}
void setRelease(String new_release) {
// find the version line
def line_no = lines.findIndexOf{ it =~ /^Release: / }
assert line_no > -1
// replace it with the new version line
lines[line_no] = "Release: ${new_release}"
}
String getChangelog(truncate=true) {
// find the start of the changelog section
def start = lines.findIndexOf{ it =~ /%changelog/ }
// the real changelog starts the next line
if ( start == -1 ) {
error "no changelog section in spec file"
}
// skip the begin tag
start++
def end = lines[start..-1].findIndexOf { it =~ /^%/ }
// the changelog ends with the start of another section or EOF
//def end = lines.size() -1 // lines[start..-1].findIndexOf
if (end == -1) {
end = lines.size()
}
// exclude the end tag
end--
def changelines = lines[start..end]
if (truncate && changelines.size() > 100) {
changelines = changelines[0..99]
changelines << '....Truncated....'
}
return changelines.join('\n')
}
}