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.nio.file.Path;
22 import java.util.Optional;
23 import java.util.function.BiFunction;
24 import java.util.function.Function;
25
26 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
27
28
29
30
31
32
33
34 public class BuildToRawPomXMLFilterFactory {
35 private final boolean consume;
36
37 public BuildToRawPomXMLFilterFactory() {
38 this(false);
39 }
40
41 public BuildToRawPomXMLFilterFactory(boolean consume) {
42 this.consume = consume;
43 }
44
45
46
47
48
49 public final XmlPullParser get(XmlPullParser orgParser, Path projectFile) {
50
51
52 XmlPullParser parser = orgParser instanceof FastForwardFilter ? orgParser : new FastForwardFilter(orgParser);
53
54 if (getDependencyKeyToVersionMapper() != null) {
55 parser = new ReactorDependencyXMLFilter(parser, getDependencyKeyToVersionMapper());
56 }
57
58 if (getRelativePathMapper() != null) {
59 parser = new ParentXMLFilter(parser, getRelativePathMapper(), projectFile.getParent());
60 }
61
62 CiFriendlyXMLFilter ciFriendlyFilter = new CiFriendlyXMLFilter(parser, consume);
63 getChangelist().ifPresent(ciFriendlyFilter::setChangelist);
64 getRevision().ifPresent(ciFriendlyFilter::setRevision);
65 getSha1().ifPresent(ciFriendlyFilter::setSha1);
66 parser = ciFriendlyFilter;
67
68 parser = new ModelVersionXMLFilter(parser);
69
70 return parser;
71 }
72
73
74
75
76 protected Function<Path, Optional<RelativeProject>> getRelativePathMapper() {
77 return null;
78 }
79
80 protected BiFunction<String, String, String> getDependencyKeyToVersionMapper() {
81 return null;
82 }
83
84
85
86 protected Optional<String> getChangelist() {
87 return Optional.empty();
88 }
89
90 protected Optional<String> getRevision() {
91 return Optional.empty();
92 }
93
94 protected Optional<String> getSha1() {
95 return Optional.empty();
96 }
97 }