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.io.IOException;
22 import java.util.ArrayDeque;
23 import java.util.Deque;
24 import org.apache.maven.model.transform.pull.BufferingParser;
25 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
26 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
27
28
29
30
31
32
33
34
35
36
37 class FastForwardFilter extends BufferingParser {
38
39
40
41
42
43
44
45
46
47
48
49
50 private final Deque<String> state = new ArrayDeque<>();
51
52 private int domDepth = 0;
53
54 FastForwardFilter(XmlPullParser xmlPullParser) {
55 super(xmlPullParser);
56 }
57
58 @Override
59 public int next() throws XmlPullParserException, IOException {
60 int event = super.next();
61 filter();
62 return event;
63 }
64
65 @Override
66 public int nextToken() throws XmlPullParserException, IOException {
67 int event = super.nextToken();
68 filter();
69 return event;
70 }
71
72 protected void filter() throws XmlPullParserException, IOException {
73 if (xmlPullParser.getEventType() == START_TAG) {
74 String localName = xmlPullParser.getName();
75 if (domDepth > 0) {
76 domDepth++;
77 } else {
78 final String key = state.peekLast() + '/' + localName;
79 switch (key) {
80 case "execution/configuration":
81 case "plugin/configuration":
82 case "plugin/goals":
83 case "profile/reports":
84 case "project/reports":
85 case "reportSet/configuration":
86 if (domDepth == 0) {
87 bypass(true);
88 }
89 domDepth++;
90 break;
91 default:
92 break;
93 }
94 }
95 state.add(localName);
96 } else if (xmlPullParser.getEventType() == END_TAG) {
97 if (domDepth > 0) {
98 if (--domDepth == 0) {
99 bypass(false);
100 }
101 }
102 state.removeLast();
103 }
104 }
105
106 @Override
107 public void bypass(boolean bypass) {
108 this.bypass = bypass;
109 }
110 }