View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from reader-stax.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.plugin.descriptor.io;
6   
7   import java.io.IOException;
8   import java.io.InputStream;
9   import java.io.Reader;
10  import java.text.DateFormat;
11  import java.util.ArrayDeque;
12  import java.util.ArrayList;
13  import java.util.Collections;
14  import java.util.Date;
15  import java.util.Deque;
16  import java.util.HashMap;
17  import java.util.HashSet;
18  import java.util.LinkedHashMap;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Set;
22  import org.apache.maven.api.annotations.Generated;
23  import org.apache.maven.api.plugin.descriptor.PluginDescriptor;
24  import org.apache.maven.api.plugin.descriptor.MojoDescriptor;
25  import org.apache.maven.api.plugin.descriptor.Parameter;
26  import org.apache.maven.api.plugin.descriptor.Requirement;
27  import org.apache.maven.api.plugin.descriptor.Dependency;
28  import org.apache.maven.api.plugin.descriptor.Resolution;
29  import org.apache.maven.internal.xml.XmlNodeStaxBuilder;
30  import org.apache.maven.api.xml.XmlNode;
31  import javax.xml.stream.XMLInputFactory;
32  import javax.xml.stream.XMLStreamException;
33  import javax.xml.stream.XMLStreamReader;
34  import javax.xml.transform.stream.StreamSource;
35  
36  import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
37  import static javax.xml.XMLConstants.XML_NS_URI;
38  
39  @Generated
40  public class PluginDescriptorStaxReader {
41  
42      private static final Map<String, String> DEFAULT_ENTITIES;
43      static {
44          Map<String, String> entities = new HashMap<>();
45          entities.put("nbsp", "\u00a0");
46          entities.put("iexcl", "\u00a1");
47          entities.put("cent", "\u00a2");
48          entities.put("pound", "\u00a3");
49          entities.put("curren", "\u00a4");
50          entities.put("yen", "\u00a5");
51          entities.put("brvbar", "\u00a6");
52          entities.put("sect", "\u00a7");
53          entities.put("uml", "\u00a8");
54          entities.put("copy", "\u00a9");
55          entities.put("ordf", "\u00aa");
56          entities.put("laquo", "\u00ab");
57          entities.put("not", "\u00ac");
58          entities.put("shy", "\u00ad");
59          entities.put("reg", "\u00ae");
60          entities.put("macr", "\u00af");
61          entities.put("deg", "\u00b0");
62          entities.put("plusmn", "\u00b1");
63          entities.put("sup2", "\u00b2");
64          entities.put("sup3", "\u00b3");
65          entities.put("acute", "\u00b4");
66          entities.put("micro", "\u00b5");
67          entities.put("para", "\u00b6");
68          entities.put("middot", "\u00b7");
69          entities.put("cedil", "\u00b8");
70          entities.put("sup1", "\u00b9");
71          entities.put("ordm", "\u00ba");
72          entities.put("raquo", "\u00bb");
73          entities.put("frac14", "\u00bc");
74          entities.put("frac12", "\u00bd");
75          entities.put("frac34", "\u00be");
76          entities.put("iquest", "\u00bf");
77          entities.put("Agrave", "\u00c0");
78          entities.put("Aacute", "\u00c1");
79          entities.put("Acirc", "\u00c2");
80          entities.put("Atilde", "\u00c3");
81          entities.put("Auml", "\u00c4");
82          entities.put("Aring", "\u00c5");
83          entities.put("AElig", "\u00c6");
84          entities.put("Ccedil", "\u00c7");
85          entities.put("Egrave", "\u00c8");
86          entities.put("Eacute", "\u00c9");
87          entities.put("Ecirc", "\u00ca");
88          entities.put("Euml", "\u00cb");
89          entities.put("Igrave", "\u00cc");
90          entities.put("Iacute", "\u00cd");
91          entities.put("Icirc", "\u00ce");
92          entities.put("Iuml", "\u00cf");
93          entities.put("ETH", "\u00d0");
94          entities.put("Ntilde", "\u00d1");
95          entities.put("Ograve", "\u00d2");
96          entities.put("Oacute", "\u00d3");
97          entities.put("Ocirc", "\u00d4");
98          entities.put("Otilde", "\u00d5");
99          entities.put("Ouml", "\u00d6");
100         entities.put("times", "\u00d7");
101         entities.put("Oslash", "\u00d8");
102         entities.put("Ugrave", "\u00d9");
103         entities.put("Uacute", "\u00da");
104         entities.put("Ucirc", "\u00db");
105         entities.put("Uuml", "\u00dc");
106         entities.put("Yacute", "\u00dd");
107         entities.put("THORN", "\u00de");
108         entities.put("szlig", "\u00df");
109         entities.put("agrave", "\u00e0");
110         entities.put("aacute", "\u00e1");
111         entities.put("acirc", "\u00e2");
112         entities.put("atilde", "\u00e3");
113         entities.put("auml", "\u00e4");
114         entities.put("aring", "\u00e5");
115         entities.put("aelig", "\u00e6");
116         entities.put("ccedil", "\u00e7");
117         entities.put("egrave", "\u00e8");
118         entities.put("eacute", "\u00e9");
119         entities.put("ecirc", "\u00ea");
120         entities.put("euml", "\u00eb");
121         entities.put("igrave", "\u00ec");
122         entities.put("iacute", "\u00ed");
123         entities.put("icirc", "\u00ee");
124         entities.put("iuml", "\u00ef");
125         entities.put("eth", "\u00f0");
126         entities.put("ntilde", "\u00f1");
127         entities.put("ograve", "\u00f2");
128         entities.put("oacute", "\u00f3");
129         entities.put("ocirc", "\u00f4");
130         entities.put("otilde", "\u00f5");
131         entities.put("ouml", "\u00f6");
132         entities.put("divide", "\u00f7");
133         entities.put("oslash", "\u00f8");
134         entities.put("ugrave", "\u00f9");
135         entities.put("uacute", "\u00fa");
136         entities.put("ucirc", "\u00fb");
137         entities.put("uuml", "\u00fc");
138         entities.put("yacute", "\u00fd");
139         entities.put("thorn", "\u00fe");
140         entities.put("yuml", "\u00ff");
141 
142         // ----------------------------------------------------------------------
143         // Special entities
144         // ----------------------------------------------------------------------
145 
146         entities.put("OElig", "\u0152");
147         entities.put("oelig", "\u0153");
148         entities.put("Scaron", "\u0160");
149         entities.put("scaron", "\u0161");
150         entities.put("Yuml", "\u0178");
151         entities.put("circ", "\u02c6");
152         entities.put("tilde", "\u02dc");
153         entities.put("ensp", "\u2002");
154         entities.put("emsp", "\u2003");
155         entities.put("thinsp", "\u2009");
156         entities.put("zwnj", "\u200c");
157         entities.put("zwj", "\u200d");
158         entities.put("lrm", "\u200e");
159         entities.put("rlm", "\u200f");
160         entities.put("ndash", "\u2013");
161         entities.put("mdash", "\u2014");
162         entities.put("lsquo", "\u2018");
163         entities.put("rsquo", "\u2019");
164         entities.put("sbquo", "\u201a");
165         entities.put("ldquo", "\u201c");
166         entities.put("rdquo", "\u201d");
167         entities.put("bdquo", "\u201e");
168         entities.put("dagger", "\u2020");
169         entities.put("Dagger", "\u2021");
170         entities.put("permil", "\u2030");
171         entities.put("lsaquo", "\u2039");
172         entities.put("rsaquo", "\u203a");
173         entities.put("euro", "\u20ac");
174 
175         // ----------------------------------------------------------------------
176         // Symbol entities
177         // ----------------------------------------------------------------------
178 
179         entities.put("fnof", "\u0192");
180         entities.put("Alpha", "\u0391");
181         entities.put("Beta", "\u0392");
182         entities.put("Gamma", "\u0393");
183         entities.put("Delta", "\u0394");
184         entities.put("Epsilon", "\u0395");
185         entities.put("Zeta", "\u0396");
186         entities.put("Eta", "\u0397");
187         entities.put("Theta", "\u0398");
188         entities.put("Iota", "\u0399");
189         entities.put("Kappa", "\u039a");
190         entities.put("Lambda", "\u039b");
191         entities.put("Mu", "\u039c");
192         entities.put("Nu", "\u039d");
193         entities.put("Xi", "\u039e");
194         entities.put("Omicron", "\u039f");
195         entities.put("Pi", "\u03a0");
196         entities.put("Rho", "\u03a1");
197         entities.put("Sigma", "\u03a3");
198         entities.put("Tau", "\u03a4");
199         entities.put("Upsilon", "\u03a5");
200         entities.put("Phi", "\u03a6");
201         entities.put("Chi", "\u03a7");
202         entities.put("Psi", "\u03a8");
203         entities.put("Omega", "\u03a9");
204         entities.put("alpha", "\u03b1");
205         entities.put("beta", "\u03b2");
206         entities.put("gamma", "\u03b3");
207         entities.put("delta", "\u03b4");
208         entities.put("epsilon", "\u03b5");
209         entities.put("zeta", "\u03b6");
210         entities.put("eta", "\u03b7");
211         entities.put("theta", "\u03b8");
212         entities.put("iota", "\u03b9");
213         entities.put("kappa", "\u03ba");
214         entities.put("lambda", "\u03bb");
215         entities.put("mu", "\u03bc");
216         entities.put("nu", "\u03bd");
217         entities.put("xi", "\u03be");
218         entities.put("omicron", "\u03bf");
219         entities.put("pi", "\u03c0");
220         entities.put("rho", "\u03c1");
221         entities.put("sigmaf", "\u03c2");
222         entities.put("sigma", "\u03c3");
223         entities.put("tau", "\u03c4");
224         entities.put("upsilon", "\u03c5");
225         entities.put("phi", "\u03c6");
226         entities.put("chi", "\u03c7");
227         entities.put("psi", "\u03c8");
228         entities.put("omega", "\u03c9");
229         entities.put("thetasym", "\u03d1");
230         entities.put("upsih", "\u03d2");
231         entities.put("piv", "\u03d6");
232         entities.put("bull", "\u2022");
233         entities.put("hellip", "\u2026");
234         entities.put("prime", "\u2032");
235         entities.put("Prime", "\u2033");
236         entities.put("oline", "\u203e");
237         entities.put("frasl", "\u2044");
238         entities.put("weierp", "\u2118");
239         entities.put("image", "\u2111");
240         entities.put("real", "\u211c");
241         entities.put("trade", "\u2122");
242         entities.put("alefsym", "\u2135");
243         entities.put("larr", "\u2190");
244         entities.put("uarr", "\u2191");
245         entities.put("rarr", "\u2192");
246         entities.put("darr", "\u2193");
247         entities.put("harr", "\u2194");
248         entities.put("crarr", "\u21b5");
249         entities.put("lArr", "\u21d0");
250         entities.put("uArr", "\u21d1");
251         entities.put("rArr", "\u21d2");
252         entities.put("dArr", "\u21d3");
253         entities.put("hArr", "\u21d4");
254         entities.put("forall", "\u2200");
255         entities.put("part", "\u2202");
256         entities.put("exist", "\u2203");
257         entities.put("empty", "\u2205");
258         entities.put("nabla", "\u2207");
259         entities.put("isin", "\u2208");
260         entities.put("notin", "\u2209");
261         entities.put("ni", "\u220b");
262         entities.put("prod", "\u220f");
263         entities.put("sum", "\u2211");
264         entities.put("minus", "\u2212");
265         entities.put("lowast", "\u2217");
266         entities.put("radic", "\u221a");
267         entities.put("prop", "\u221d");
268         entities.put("infin", "\u221e");
269         entities.put("ang", "\u2220");
270         entities.put("and", "\u2227");
271         entities.put("or", "\u2228");
272         entities.put("cap", "\u2229");
273         entities.put("cup", "\u222a");
274         entities.put("int", "\u222b");
275         entities.put("there4", "\u2234");
276         entities.put("sim", "\u223c");
277         entities.put("cong", "\u2245");
278         entities.put("asymp", "\u2248");
279         entities.put("ne", "\u2260");
280         entities.put("equiv", "\u2261");
281         entities.put("le", "\u2264");
282         entities.put("ge", "\u2265");
283         entities.put("sub", "\u2282");
284         entities.put("sup", "\u2283");
285         entities.put("nsub", "\u2284");
286         entities.put("sube", "\u2286");
287         entities.put("supe", "\u2287");
288         entities.put("oplus", "\u2295");
289         entities.put("otimes", "\u2297");
290         entities.put("perp", "\u22a5");
291         entities.put("sdot", "\u22c5");
292         entities.put("lceil", "\u2308");
293         entities.put("rceil", "\u2309");
294         entities.put("lfloor", "\u230a");
295         entities.put("rfloor", "\u230b");
296         entities.put("lang", "\u2329");
297         entities.put("rang", "\u232a");
298         entities.put("loz", "\u25ca");
299         entities.put("spades", "\u2660");
300         entities.put("clubs", "\u2663");
301         entities.put("hearts", "\u2665");
302         entities.put("diams", "\u2666");
303         DEFAULT_ENTITIES = Collections.unmodifiableMap(entities);
304     }
305 
306     private boolean addDefaultEntities = true;
307 
308     private final ContentTransformer contentTransformer;
309 
310     public PluginDescriptorStaxReader() {
311         this((s, f) -> s);
312     }
313 
314     public PluginDescriptorStaxReader(ContentTransformer contentTransformer) {
315         this.contentTransformer = contentTransformer;
316     }
317 
318     /**
319      * Returns the state of the "add default entities" flag.
320      *
321      * @return boolean
322      */
323     public boolean getAddDefaultEntities() {
324         return addDefaultEntities;
325     } //-- boolean getAddDefaultEntities()
326 
327     /**
328      * Sets the state of the "add default entities" flag.
329      *
330      * @param addDefaultEntities a addDefaultEntities object.
331      */
332     public void setAddDefaultEntities(boolean addDefaultEntities) {
333         this.addDefaultEntities = addDefaultEntities;
334     } //-- void setAddDefaultEntities(boolean)
335 
336 
337     public PluginDescriptor read(Reader reader) throws XMLStreamException {
338         return read(reader, true);
339     }
340 
341     /**
342      * @param reader a reader object.
343      * @param strict a strict object.
344      * @throws XMLStreamException XMLStreamException if
345      * any.
346      * @return PluginDescriptor
347      */
348     public PluginDescriptor read(Reader reader, boolean strict) throws XMLStreamException {
349         XMLInputFactory factory = XMLInputFactory.newFactory();
350         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
351         StreamSource streamSource = new StreamSource(reader);
352         XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
353     return read(parser, strict);
354     } //-- PluginDescriptor read(Reader, boolean)
355 
356     public PluginDescriptor read(InputStream in) throws XMLStreamException {
357         return read(in, true);
358     }
359 
360     /**
361      * Method read.
362      *
363      * @param in a in object.
364      * @param strict a strict object.
365      * @throws XMLStreamException XMLStreamException if
366      * any.
367      * @return PluginDescriptor
368      */
369     public PluginDescriptor read(InputStream in, boolean strict) throws XMLStreamException {
370         XMLInputFactory factory = XMLInputFactory.newFactory();
371         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
372         StreamSource streamSource = new StreamSource(in);
373         XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
374         return read(parser, strict);
375     } //-- PluginDescriptor read(InputStream, boolean)
376 
377     /**
378      * Method read.
379      *
380      * @param parser a parser object.
381      * @param strict a strict object.
382      * @throws XMLStreamException XMLStreamException if
383      * any.
384      * @return PluginDescriptor
385      */
386     public PluginDescriptor read(XMLStreamReader parser, boolean strict) throws XMLStreamException {
387         Deque<Object> context = new ArrayDeque<>();
388         PluginDescriptor pluginDescriptor = null;
389         int eventType = parser.getEventType();
390         boolean parsed = false;
391         while (eventType != XMLStreamReader.END_DOCUMENT) {
392             if (eventType == XMLStreamReader.START_ELEMENT) {
393                 if (strict && ! "plugin".equals(parser.getLocalName())) {
394                     throw new XMLStreamException("Expected root element 'plugin' but found '" + parser.getName() + "'", parser.getLocation(), null);
395                 } else if (parsed) {
396                     // fallback, already expected a XMLStreamException due to invalid XML
397                     throw new XMLStreamException("Duplicated tag: 'plugin'", parser.getLocation(), null);
398                 }
399                 pluginDescriptor = parsePluginDescriptor(parser, strict, context);
400                 parsed = true;
401             }
402             eventType = parser.next();
403         }
404         if (parsed) {
405             return pluginDescriptor;
406         }
407         throw new XMLStreamException("Expected root element 'plugin' but found no element at all: invalid XML document", parser.getLocation(), null);
408     } //-- PluginDescriptor read(XMLStreamReader, boolean)
409 
410     private PluginDescriptor parsePluginDescriptor(XMLStreamReader parser, boolean strict, Deque<Object> context) throws XMLStreamException {
411         String tagName = parser.getLocalName();
412         PluginDescriptor.Builder pluginDescriptor = PluginDescriptor.newBuilder(true);
413         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
414             String name = parser.getAttributeLocalName(i);
415             String ns = parser.getAttributeNamespace(i);
416             String value = parser.getAttributeValue(i);
417             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
418                 // just ignore attributes with non-default namespace (for example: xsi and xml)
419             } else if ("xmlns".equals(name)) {
420                 // ignore xmlns attribute in root class, which is a reserved attribute name
421             } else {
422                 checkUnknownAttribute(parser, name, tagName, strict);
423             }
424         }
425         Set<String> parsed = new HashSet<>();
426         context.addLast( pluginDescriptor );
427         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
428             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
429             switch (childName) {
430                 case "name": {
431                     pluginDescriptor.name(interpolatedTrimmed(nextText(parser, strict), "name"));
432                     break;
433                 }
434                 case "description": {
435                     pluginDescriptor.description(interpolatedTrimmed(nextText(parser, strict), "description"));
436                     break;
437                 }
438                 case "groupId": {
439                     pluginDescriptor.groupId(interpolatedTrimmed(nextText(parser, strict), "groupId"));
440                     break;
441                 }
442                 case "artifactId": {
443                     pluginDescriptor.artifactId(interpolatedTrimmed(nextText(parser, strict), "artifactId"));
444                     break;
445                 }
446                 case "version": {
447                     pluginDescriptor.version(interpolatedTrimmed(nextText(parser, strict), "version"));
448                     break;
449                 }
450                 case "goalPrefix": {
451                     pluginDescriptor.goalPrefix(interpolatedTrimmed(nextText(parser, strict), "goalPrefix"));
452                     break;
453                 }
454                 case "isolatedRealm": {
455                     pluginDescriptor.isolatedRealm(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "isolatedRealm"), "isolatedRealm", parser, false));
456                     break;
457                 }
458                 case "inheritedByDefault": {
459                     pluginDescriptor.inheritedByDefault(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "inheritedByDefault"), "inheritedByDefault", parser, true));
460                     break;
461                 }
462                 case "requiredJavaVersion": {
463                     pluginDescriptor.requiredJavaVersion(interpolatedTrimmed(nextText(parser, strict), "requiredJavaVersion"));
464                     break;
465                 }
466                 case "requiredMavenVersion": {
467                     pluginDescriptor.requiredMavenVersion(interpolatedTrimmed(nextText(parser, strict), "requiredMavenVersion"));
468                     break;
469                 }
470                 case "mojos": {
471                     List<MojoDescriptor> mojos = new ArrayList<>();
472                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
473                         if ("mojo".equals(parser.getLocalName())) {
474                             mojos.add(parseMojoDescriptor(parser, strict, context));
475                         } else {
476                             checkUnknownElement(parser, strict);
477                         }
478                     }
479                     pluginDescriptor.mojos(mojos);
480                     break;
481                 }
482                 default: {
483                     checkUnknownElement(parser, strict);
484                     break;
485                 }
486             }
487         }
488         context.removeLast();
489         pluginDescriptor.namespaceUri(parser.getNamespaceURI());
490         pluginDescriptor.modelEncoding(parser.getEncoding());
491         return pluginDescriptor.build();
492     }
493 
494     private MojoDescriptor parseMojoDescriptor(XMLStreamReader parser, boolean strict, Deque<Object> context) throws XMLStreamException {
495         String tagName = parser.getLocalName();
496         MojoDescriptor.Builder mojoDescriptor = MojoDescriptor.newBuilder(true);
497         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
498             String name = parser.getAttributeLocalName(i);
499             String ns = parser.getAttributeNamespace(i);
500             String value = parser.getAttributeValue(i);
501             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
502                 // just ignore attributes with non-default namespace (for example: xsi and xml)
503             } else {
504                 checkUnknownAttribute(parser, name, tagName, strict);
505             }
506         }
507         Set<String> parsed = new HashSet<>();
508         context.addLast( mojoDescriptor );
509         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
510             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
511             switch (childName) {
512                 case "goal": {
513                     mojoDescriptor.goal(interpolatedTrimmed(nextText(parser, strict), "goal"));
514                     break;
515                 }
516                 case "description": {
517                     mojoDescriptor.description(interpolatedTrimmed(nextText(parser, strict), "description"));
518                     break;
519                 }
520                 case "implementation": {
521                     mojoDescriptor.implementation(interpolatedTrimmed(nextText(parser, strict), "implementation"));
522                     break;
523                 }
524                 case "language": {
525                     mojoDescriptor.language(interpolatedTrimmed(nextText(parser, strict), "language"));
526                     break;
527                 }
528                 case "phase": {
529                     mojoDescriptor.phase(interpolatedTrimmed(nextText(parser, strict), "phase"));
530                     break;
531                 }
532                 case "executePhase": {
533                     mojoDescriptor.executePhase(interpolatedTrimmed(nextText(parser, strict), "executePhase"));
534                     break;
535                 }
536                 case "executeGoal": {
537                     mojoDescriptor.executeGoal(interpolatedTrimmed(nextText(parser, strict), "executeGoal"));
538                     break;
539                 }
540                 case "executeLifecycle": {
541                     mojoDescriptor.executeLifecycle(interpolatedTrimmed(nextText(parser, strict), "executeLifecycle"));
542                     break;
543                 }
544                 case "dependencyResolution": {
545                     mojoDescriptor.dependencyResolution(interpolatedTrimmed(nextText(parser, strict), "dependencyResolution"));
546                     break;
547                 }
548                 case "dependencyCollection": {
549                     mojoDescriptor.dependencyCollection(interpolatedTrimmed(nextText(parser, strict), "dependencyCollection"));
550                     break;
551                 }
552                 case "directInvocationOnly": {
553                     mojoDescriptor.directInvocationOnly(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "directInvocationOnly"), "directInvocationOnly", parser, false));
554                     break;
555                 }
556                 case "projectRequired": {
557                     mojoDescriptor.projectRequired(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "projectRequired"), "projectRequired", parser, true));
558                     break;
559                 }
560                 case "onlineRequired": {
561                     mojoDescriptor.onlineRequired(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "onlineRequired"), "onlineRequired", parser, false));
562                     break;
563                 }
564                 case "aggregator": {
565                     mojoDescriptor.aggregator(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "aggregator"), "aggregator", parser, false));
566                     break;
567                 }
568                 case "inheritedByDefault": {
569                     mojoDescriptor.inheritedByDefault(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "inheritedByDefault"), "inheritedByDefault", parser, true));
570                     break;
571                 }
572                 case "since": {
573                     mojoDescriptor.since(interpolatedTrimmed(nextText(parser, strict), "since"));
574                     break;
575                 }
576                 case "deprecated": {
577                     mojoDescriptor.deprecated(interpolatedTrimmed(nextText(parser, strict), "deprecated"));
578                     break;
579                 }
580                 case "configurator": {
581                     mojoDescriptor.configurator(interpolatedTrimmed(nextText(parser, strict), "configurator"));
582                     break;
583                 }
584                 case "parameters": {
585                     List<Parameter> parameters = new ArrayList<>();
586                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
587                         if ("parameter".equals(parser.getLocalName())) {
588                             parameters.add(parseParameter(parser, strict, context));
589                         } else {
590                             checkUnknownElement(parser, strict);
591                         }
592                     }
593                     mojoDescriptor.parameters(parameters);
594                     break;
595                 }
596                 case "resolutions": {
597                     List<Resolution> resolutions = new ArrayList<>();
598                     while (parser.nextTag() == XMLStreamReader.START_ELEMENT) {
599                         if ("resolution".equals(parser.getLocalName())) {
600                             resolutions.add(parseResolution(parser, strict, context));
601                         } else {
602                             checkUnknownElement(parser, strict);
603                         }
604                     }
605                     mojoDescriptor.resolutions(resolutions);
606                     break;
607                 }
608                 default: {
609                     checkUnknownElement(parser, strict);
610                     break;
611                 }
612             }
613         }
614         context.removeLast();
615         mojoDescriptor.id(((PluginDescriptor.Builder) context.peekLast()).build().getId() + ":" + mojoDescriptor.build().getGoal());
616         mojoDescriptor.fullGoalName(((PluginDescriptor.Builder) context.peekLast()).build().getGoalPrefix() + ":" + mojoDescriptor.build().getGoal());
617         return mojoDescriptor.build();
618     }
619 
620     private Parameter parseParameter(XMLStreamReader parser, boolean strict, Deque<Object> context) throws XMLStreamException {
621         String tagName = parser.getLocalName();
622         Parameter.Builder parameter = Parameter.newBuilder(true);
623         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
624             String name = parser.getAttributeLocalName(i);
625             String ns = parser.getAttributeNamespace(i);
626             String value = parser.getAttributeValue(i);
627             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
628                 // just ignore attributes with non-default namespace (for example: xsi and xml)
629             } else {
630                 checkUnknownAttribute(parser, name, tagName, strict);
631             }
632         }
633         Set<String> parsed = new HashSet<>();
634         context.addLast( parameter );
635         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
636             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
637             switch (childName) {
638                 case "name": {
639                     parameter.name(interpolatedTrimmed(nextText(parser, strict), "name"));
640                     break;
641                 }
642                 case "alias": {
643                     parameter.alias(interpolatedTrimmed(nextText(parser, strict), "alias"));
644                     break;
645                 }
646                 case "type": {
647                     parameter.type(interpolatedTrimmed(nextText(parser, strict), "type"));
648                     break;
649                 }
650                 case "required": {
651                     parameter.required(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "required"), "required", parser, false));
652                     break;
653                 }
654                 case "editable": {
655                     parameter.editable(getBooleanValue(interpolatedTrimmed(nextText(parser, strict), "editable"), "editable", parser, true));
656                     break;
657                 }
658                 case "description": {
659                     parameter.description(interpolatedTrimmed(nextText(parser, strict), "description"));
660                     break;
661                 }
662                 case "since": {
663                     parameter.since(interpolatedTrimmed(nextText(parser, strict), "since"));
664                     break;
665                 }
666                 case "deprecated": {
667                     parameter.deprecated(interpolatedTrimmed(nextText(parser, strict), "deprecated"));
668                     break;
669                 }
670                 case "expression": {
671                     parameter.expression(interpolatedTrimmed(nextText(parser, strict), "expression"));
672                     break;
673                 }
674                 case "defaultValue": {
675                     parameter.defaultValue(interpolatedTrimmed(nextText(parser, strict), "defaultValue"));
676                     break;
677                 }
678                 default: {
679                     checkUnknownElement(parser, strict);
680                     break;
681                 }
682             }
683         }
684         context.removeLast();
685         return parameter.build();
686     }
687 
688     private Requirement parseRequirement(XMLStreamReader parser, boolean strict, Deque<Object> context) throws XMLStreamException {
689         String tagName = parser.getLocalName();
690         Requirement.Builder requirement = Requirement.newBuilder(true);
691         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
692             String name = parser.getAttributeLocalName(i);
693             String ns = parser.getAttributeNamespace(i);
694             String value = parser.getAttributeValue(i);
695             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
696                 // just ignore attributes with non-default namespace (for example: xsi and xml)
697             } else {
698                 checkUnknownAttribute(parser, name, tagName, strict);
699             }
700         }
701         Set<String> parsed = new HashSet<>();
702         context.addLast( requirement );
703         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
704             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
705             switch (childName) {
706                 case "role": {
707                     requirement.role(interpolatedTrimmed(nextText(parser, strict), "role"));
708                     break;
709                 }
710                 case "role-hint": {
711                     requirement.roleHint(interpolatedTrimmed(nextText(parser, strict), "role-hint"));
712                     break;
713                 }
714                 case "field-name": {
715                     requirement.fieldName(interpolatedTrimmed(nextText(parser, strict), "field-name"));
716                     break;
717                 }
718                 default: {
719                     checkUnknownElement(parser, strict);
720                     break;
721                 }
722             }
723         }
724         context.removeLast();
725         return requirement.build();
726     }
727 
728     private Dependency parseDependency(XMLStreamReader parser, boolean strict, Deque<Object> context) throws XMLStreamException {
729         String tagName = parser.getLocalName();
730         Dependency.Builder dependency = Dependency.newBuilder(true);
731         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
732             String name = parser.getAttributeLocalName(i);
733             String ns = parser.getAttributeNamespace(i);
734             String value = parser.getAttributeValue(i);
735             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
736                 // just ignore attributes with non-default namespace (for example: xsi and xml)
737             } else {
738                 checkUnknownAttribute(parser, name, tagName, strict);
739             }
740         }
741         Set<String> parsed = new HashSet<>();
742         context.addLast( dependency );
743         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
744             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
745             switch (childName) {
746                 case "groupId": {
747                     dependency.groupId(interpolatedTrimmed(nextText(parser, strict), "groupId"));
748                     break;
749                 }
750                 case "artifactId": {
751                     dependency.artifactId(interpolatedTrimmed(nextText(parser, strict), "artifactId"));
752                     break;
753                 }
754                 case "version": {
755                     dependency.version(interpolatedTrimmed(nextText(parser, strict), "version"));
756                     break;
757                 }
758                 case "type": {
759                     dependency.type(interpolatedTrimmed(nextText(parser, strict), "type"));
760                     break;
761                 }
762                 default: {
763                     checkUnknownElement(parser, strict);
764                     break;
765                 }
766             }
767         }
768         context.removeLast();
769         return dependency.build();
770     }
771 
772     private Resolution parseResolution(XMLStreamReader parser, boolean strict, Deque<Object> context) throws XMLStreamException {
773         String tagName = parser.getLocalName();
774         Resolution.Builder resolution = Resolution.newBuilder(true);
775         for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
776             String name = parser.getAttributeLocalName(i);
777             String ns = parser.getAttributeNamespace(i);
778             String value = parser.getAttributeValue(i);
779             if (W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(ns) || XML_NS_URI.equals(ns)) {
780                 // just ignore attributes with non-default namespace (for example: xsi and xml)
781             } else {
782                 checkUnknownAttribute(parser, name, tagName, strict);
783             }
784         }
785         Set<String> parsed = new HashSet<>();
786         context.addLast( resolution );
787         while ((strict ? parser.nextTag() : nextTag(parser)) == XMLStreamReader.START_ELEMENT) {
788             String childName = checkDuplicate(parser.getLocalName(), parser, parsed);
789             switch (childName) {
790                 case "field": {
791                     resolution.field(interpolatedTrimmed(nextText(parser, strict), "field"));
792                     break;
793                 }
794                 case "pathScope": {
795                     resolution.pathScope(interpolatedTrimmed(nextText(parser, strict), "pathScope"));
796                     break;
797                 }
798                 case "requestType": {
799                     resolution.requestType(interpolatedTrimmed(nextText(parser, strict), "requestType"));
800                     break;
801                 }
802                 default: {
803                     checkUnknownElement(parser, strict);
804                     break;
805                 }
806             }
807         }
808         context.removeLast();
809         return resolution.build();
810     }
811 
812 
813     private String checkDuplicate(String tagName, XMLStreamReader parser, Set<String> parsed) throws XMLStreamException {
814         if (!parsed.add(tagName)) {
815             throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
816         }
817         return tagName;
818     }
819 
820     /**
821      * Method checkUnknownAttribute.
822      *
823      * @param parser a parser object.
824      * @param strict a strict object.
825      * @param tagName a tagName object.
826      * @param attribute a attribute object.
827      * @throws XMLStreamException XMLStreamException if
828      * any.
829      * @throws IOException IOException if any.
830      */
831     private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {
832         // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
833         if (strict) {
834             throw new XMLStreamException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser.getLocation(), null);
835         }
836     } //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)
837 
838     /**
839      * Method checkUnknownElement.
840      *
841      * @param parser a parser object.
842      * @param strict a strict object.
843      * @throws XMLStreamException XMLStreamException if
844      * any.
845      * @throws IOException IOException if any.
846      */
847     private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {
848         if (strict) {
849             throw new XMLStreamException("Unrecognised tag: '" + parser.getName() + "'", parser.getLocation(), null);
850         }
851 
852         for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
853             int eventType = nextTag(parser);
854             if (eventType == XMLStreamReader.START_ELEMENT) {
855                 unrecognizedTagCount++;
856             } else if (eventType == XMLStreamReader.END_ELEMENT) {
857                 unrecognizedTagCount--;
858             }
859         }
860     } //-- void checkUnknownElement(XMLStreamReader, boolean)
861 
862     /**
863      * Method getTrimmedValue.
864      *
865      * @param s a s object.
866      * @return String
867      */
868     private String getTrimmedValue(String s) {
869         if (s != null) {
870             s = s.trim();
871         }
872         return s;
873     } //-- String getTrimmedValue(String)
874 
875     /**
876      * Method interpolatedTrimmed.
877      *
878      * @param value a value object.
879      * @param context a context object.
880      * @return String
881      */
882     private String interpolatedTrimmed(String value, String context) {
883         return getTrimmedValue(contentTransformer.transform(value, context));
884     } //-- String interpolatedTrimmed(String, String)
885 
886     /**
887      * Method nextTag.
888      *
889      * @param parser a parser object.
890      * @throws IOException IOException if any.
891      * @throws XMLStreamException XMLStreamException if
892      * any.
893      * @return int
894      */
895     private int nextTag(XMLStreamReader parser) throws XMLStreamException {
896         while (true) {
897             int next = parser.next();
898             switch (next) {
899                 case XMLStreamReader.SPACE:
900                 case XMLStreamReader.COMMENT:
901                 case XMLStreamReader.PROCESSING_INSTRUCTION:
902                 case XMLStreamReader.CDATA:
903                 case XMLStreamReader.CHARACTERS:
904                     continue;
905                 case XMLStreamReader.START_ELEMENT:
906                 case XMLStreamReader.END_ELEMENT:
907                     return next;
908             }
909         }
910     } //-- int nextTag(XMLStreamReader)
911 
912     private String nextText(XMLStreamReader parser, boolean strict) throws XMLStreamException {
913         int eventType = parser.getEventType();
914         if (eventType != XMLStreamReader.START_ELEMENT) {
915             throw new XMLStreamException("parser must be on START_ELEMENT to read next text", parser.getLocation(), null);
916         }
917         eventType = parser.next();
918         StringBuilder result = new StringBuilder();
919         while (true) {
920             if (eventType == XMLStreamReader.CHARACTERS || eventType == XMLStreamReader.CDATA) {
921                 result.append(parser.getText());
922             } else if (eventType == XMLStreamReader.ENTITY_REFERENCE) {
923                 String val = null;
924                 if (strict) {
925                     throw new XMLStreamException("Entities are not supported in strict mode", parser.getLocation(), null);
926                 } else if (addDefaultEntities) {
927                     val = DEFAULT_ENTITIES.get(parser.getLocalName());
928                 }
929                 if (val != null) {
930                     result.append(val);
931                 } else {
932                     result.append("&").append(parser.getLocalName()).append(";");
933                 }
934             } else if (eventType != XMLStreamReader.COMMENT) {
935                 break;
936             }
937             eventType = parser.next();
938         }
939         if (eventType != XMLStreamReader.END_ELEMENT) {
940             throw new XMLStreamException(
941                 "TEXT must be immediately followed by END_ELEMENT and not " + eventType /*TODO: TYPES[eventType]*/, parser.getLocation(), null);
942         }
943         return result.toString();
944     }
945 
946     private XmlNode buildXmlNode(XMLStreamReader parser) throws XMLStreamException {
947         return XmlNodeStaxBuilder.build(parser);
948     }
949 
950     /**
951      * Method getBooleanValue.
952      *
953      * @param s a s object.
954      * @param defaultValue a defaultValue object.
955      * @param parser a parser object.
956      * @param attribute a attribute object.
957      * @throws XMLStreamException XMLStreamException if
958      * any.
959      * @return boolean
960      */
961     private boolean getBooleanValue(String s, String attribute, XMLStreamReader parser, boolean defaultValue) throws XMLStreamException {
962         if (s != null && s.length() != 0) {
963             return Boolean.valueOf(s).booleanValue();
964         }
965         return defaultValue;
966     } //-- boolean getBooleanValue(String, String, XMLStreamReader, String)
967 
968     public static interface ContentTransformer {
969         /**
970          * Interpolate the value read from the xpp3 document
971          * @param source The source value
972          * @param fieldName A description of the field being interpolated. The implementation may use this to
973          *                           log stuff.
974          * @return The interpolated value.
975          */
976         String transform(String source, String fieldName);
977     }
978 
979 }