1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.transform;
20
21 import java.util.List;
22 import java.util.function.Function;
23
24 import org.apache.maven.model.transform.pull.NodeBufferingParser;
25 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
26
27
28
29
30
31
32
33
34 class CiFriendlyXMLFilter extends NodeBufferingParser {
35 private final boolean replace;
36
37 private Function<String, String> replaceChain = Function.identity();
38
39 CiFriendlyXMLFilter(XmlPullParser xmlPullParser, boolean replace) {
40 super(xmlPullParser, "version");
41 this.replace = replace;
42 }
43
44 public CiFriendlyXMLFilter setChangelist(String changelist) {
45 replaceChain = replaceChain.andThen(t -> t.replace("${changelist}", changelist));
46 return this;
47 }
48
49 public CiFriendlyXMLFilter setRevision(String revision) {
50 replaceChain = replaceChain.andThen(t -> t.replace("${revision}", revision));
51 return this;
52 }
53
54 public CiFriendlyXMLFilter setSha1(String sha1) {
55 replaceChain = replaceChain.andThen(t -> t.replace("${sha1}", sha1));
56 return this;
57 }
58
59
60
61
62 public boolean isSet() {
63 return !replaceChain.equals(Function.identity());
64 }
65
66 @Override
67 protected void process(List<Event> buffer) {
68 for (Event event : buffer) {
69 if (event.event == TEXT && replace && event.text.contains("${")) {
70 event.text = replaceChain.apply(event.text);
71 }
72 pushEvent(event);
73 }
74 }
75 }