1
2
3
4
5
6 package org.apache.maven.plugin.descriptor.model.io.xpp3;
7
8
9
10
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.io.Reader;
15 import java.text.DateFormat;
16 import org.apache.maven.plugin.descriptor.model.Configuration;
17 import org.apache.maven.plugin.descriptor.model.Dependency;
18 import org.apache.maven.plugin.descriptor.model.MojoDescriptor;
19 import org.apache.maven.plugin.descriptor.model.Parameter;
20 import org.apache.maven.plugin.descriptor.model.PluginDescriptor;
21 import org.apache.maven.plugin.descriptor.model.Requirement;
22 import org.codehaus.plexus.util.ReaderFactory;
23 import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
24 import org.codehaus.plexus.util.xml.pull.MXParser;
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 @SuppressWarnings( "all" )
34 public class PluginDescriptorXpp3Reader
35 {
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 private boolean addDefaultEntities = true;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
69 throws XmlPullParserException
70 {
71 if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
72 {
73 return false;
74 }
75 if ( !parsed.add( tagName ) )
76 {
77 throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
78 }
79 return true;
80 }
81
82
83
84
85
86
87
88
89
90
91
92 private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
93 throws XmlPullParserException, IOException
94 {
95
96 if ( strict )
97 {
98 throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
99 }
100 }
101
102
103
104
105
106
107
108
109
110 private void checkUnknownElement( XmlPullParser parser, boolean strict )
111 throws XmlPullParserException, IOException
112 {
113 if ( strict )
114 {
115 throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
116 }
117
118 for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
119 {
120 int eventType = parser.next();
121 if ( eventType == XmlPullParser.START_TAG )
122 {
123 unrecognizedTagCount++;
124 }
125 else if ( eventType == XmlPullParser.END_TAG )
126 {
127 unrecognizedTagCount--;
128 }
129 }
130 }
131
132
133
134
135
136
137 public boolean getAddDefaultEntities()
138 {
139 return addDefaultEntities;
140 }
141
142
143
144
145
146
147
148
149
150
151 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
152 throws XmlPullParserException
153 {
154 return getBooleanValue( s, attribute, parser, null );
155 }
156
157
158
159
160
161
162
163
164
165
166
167 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
168 throws XmlPullParserException
169 {
170 if ( s != null && s.length() != 0 )
171 {
172 return Boolean.valueOf( s ).booleanValue();
173 }
174 if ( defaultValue != null )
175 {
176 return Boolean.valueOf( defaultValue ).booleanValue();
177 }
178 return false;
179 }
180
181
182
183
184
185
186
187
188
189
190
191 private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
192 throws XmlPullParserException
193 {
194 if ( s != null )
195 {
196 try
197 {
198 return Byte.valueOf( s ).byteValue();
199 }
200 catch ( NumberFormatException nfe )
201 {
202 if ( strict )
203 {
204 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
205 }
206 }
207 }
208 return 0;
209 }
210
211
212
213
214
215
216
217
218
219
220 private char getCharacterValue( String s, String attribute, XmlPullParser parser )
221 throws XmlPullParserException
222 {
223 if ( s != null )
224 {
225 return s.charAt( 0 );
226 }
227 return 0;
228 }
229
230
231
232
233
234
235
236
237
238
239 private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
240 throws XmlPullParserException
241 {
242 return getDateValue( s, attribute, null, parser );
243 }
244
245
246
247
248
249
250
251
252
253
254
255 private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
256 throws XmlPullParserException
257 {
258 if ( s != null )
259 {
260 String effectiveDateFormat = dateFormat;
261 if ( dateFormat == null )
262 {
263 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
264 }
265 if ( "long".equals( effectiveDateFormat ) )
266 {
267 try
268 {
269 return new java.util.Date( Long.parseLong( s ) );
270 }
271 catch ( NumberFormatException e )
272 {
273 throw new XmlPullParserException( e.getMessage(), parser, e );
274 }
275 }
276 else
277 {
278 try
279 {
280 DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
281 return dateParser.parse( s );
282 }
283 catch ( java.text.ParseException e )
284 {
285 throw new XmlPullParserException( e.getMessage(), parser, e );
286 }
287 }
288 }
289 return null;
290 }
291
292
293
294
295
296
297
298
299
300
301
302 private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
303 throws XmlPullParserException
304 {
305 if ( s != null )
306 {
307 try
308 {
309 return Double.valueOf( s ).doubleValue();
310 }
311 catch ( NumberFormatException nfe )
312 {
313 if ( strict )
314 {
315 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
316 }
317 }
318 }
319 return 0;
320 }
321
322
323
324
325
326
327
328
329
330
331
332 private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
333 throws XmlPullParserException
334 {
335 if ( s != null )
336 {
337 try
338 {
339 return Float.valueOf( s ).floatValue();
340 }
341 catch ( NumberFormatException nfe )
342 {
343 if ( strict )
344 {
345 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
346 }
347 }
348 }
349 return 0;
350 }
351
352
353
354
355
356
357
358
359
360
361
362 private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
363 throws XmlPullParserException
364 {
365 if ( s != null )
366 {
367 try
368 {
369 return Integer.valueOf( s ).intValue();
370 }
371 catch ( NumberFormatException nfe )
372 {
373 if ( strict )
374 {
375 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
376 }
377 }
378 }
379 return 0;
380 }
381
382
383
384
385
386
387
388
389
390
391
392 private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
393 throws XmlPullParserException
394 {
395 if ( s != null )
396 {
397 try
398 {
399 return Long.valueOf( s ).longValue();
400 }
401 catch ( NumberFormatException nfe )
402 {
403 if ( strict )
404 {
405 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
406 }
407 }
408 }
409 return 0;
410 }
411
412
413
414
415
416
417
418
419
420
421
422 private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
423 throws XmlPullParserException
424 {
425 if ( s == null )
426 {
427 if ( strict )
428 {
429 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
430 }
431 }
432 return s;
433 }
434
435
436
437
438
439
440
441
442
443
444
445 private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
446 throws XmlPullParserException
447 {
448 if ( s != null )
449 {
450 try
451 {
452 return Short.valueOf( s ).shortValue();
453 }
454 catch ( NumberFormatException nfe )
455 {
456 if ( strict )
457 {
458 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
459 }
460 }
461 }
462 return 0;
463 }
464
465
466
467
468
469
470
471 private String getTrimmedValue( String s )
472 {
473 if ( s != null )
474 {
475 s = s.trim();
476 }
477 return s;
478 }
479
480
481
482
483
484
485
486
487
488 private int nextTag( XmlPullParser parser )
489 throws IOException, XmlPullParserException
490 {
491 int eventType = parser.next();
492 if ( eventType == XmlPullParser.TEXT )
493 {
494 eventType = parser.next();
495 }
496 if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
497 {
498 throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
499 }
500 return eventType;
501 }
502
503
504
505
506
507
508
509
510
511
512 public PluginDescriptor read( Reader reader, boolean strict )
513 throws IOException, XmlPullParserException
514 {
515 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
516
517 parser.setInput( reader );
518
519
520 return read( parser, strict );
521 }
522
523
524
525
526
527
528
529
530
531 public PluginDescriptor read( Reader reader )
532 throws IOException, XmlPullParserException
533 {
534 return read( reader, true );
535 }
536
537
538
539
540
541
542
543
544
545
546 public PluginDescriptor read( InputStream in, boolean strict )
547 throws IOException, XmlPullParserException
548 {
549 return read( ReaderFactory.newXmlReader( in ), strict );
550 }
551
552
553
554
555
556
557
558
559
560 public PluginDescriptor read( InputStream in )
561 throws IOException, XmlPullParserException
562 {
563 return read( ReaderFactory.newXmlReader( in ) );
564 }
565
566
567
568
569
570
571
572
573
574
575 private Configuration parseConfiguration( XmlPullParser parser, boolean strict )
576 throws IOException, XmlPullParserException
577 {
578 String tagName = parser.getName();
579 Configuration configuration = new Configuration();
580 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
581 {
582 String name = parser.getAttributeName( i );
583 String value = parser.getAttributeValue( i );
584
585 if ( name.indexOf( ':' ) >= 0 )
586 {
587
588 }
589 else if ( "implementation".equals( name ) )
590 {
591 configuration.setImplementation( getTrimmedValue( value ) );
592 }
593 else if ( "default-value".equals( name ) )
594 {
595 configuration.setDefaultValue( getTrimmedValue( value ) );
596 }
597 else
598 {
599 checkUnknownAttribute( parser, name, tagName, strict );
600 }
601 }
602 configuration.setExpression( getTrimmedValue( parser.nextText() ) );
603 return configuration;
604 }
605
606
607
608
609
610
611
612
613
614
615 private Dependency parseDependency( XmlPullParser parser, boolean strict )
616 throws IOException, XmlPullParserException
617 {
618 String tagName = parser.getName();
619 Dependency dependency = new Dependency();
620 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
621 {
622 String name = parser.getAttributeName( i );
623 String value = parser.getAttributeValue( i );
624
625 if ( name.indexOf( ':' ) >= 0 )
626 {
627
628 }
629 else
630 {
631 checkUnknownAttribute( parser, name, tagName, strict );
632 }
633 }
634 java.util.Set parsed = new java.util.HashSet();
635 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
636 {
637 if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) )
638 {
639 dependency.setGroupId( getTrimmedValue( parser.nextText() ) );
640 }
641 else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
642 {
643 dependency.setArtifactId( getTrimmedValue( parser.nextText() ) );
644 }
645 else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
646 {
647 dependency.setVersion( getTrimmedValue( parser.nextText() ) );
648 }
649 else if ( checkFieldWithDuplicate( parser, "type", null, parsed ) )
650 {
651 dependency.setType( getTrimmedValue( parser.nextText() ) );
652 }
653 else
654 {
655 checkUnknownElement( parser, strict );
656 }
657 }
658 return dependency;
659 }
660
661
662
663
664
665
666
667
668
669
670 private MojoDescriptor parseMojoDescriptor( XmlPullParser parser, boolean strict )
671 throws IOException, XmlPullParserException
672 {
673 String tagName = parser.getName();
674 MojoDescriptor mojoDescriptor = new MojoDescriptor();
675 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
676 {
677 String name = parser.getAttributeName( i );
678 String value = parser.getAttributeValue( i );
679
680 if ( name.indexOf( ':' ) >= 0 )
681 {
682
683 }
684 else
685 {
686 checkUnknownAttribute( parser, name, tagName, strict );
687 }
688 }
689 java.util.Set parsed = new java.util.HashSet();
690 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
691 {
692 if ( checkFieldWithDuplicate( parser, "goal", null, parsed ) )
693 {
694 mojoDescriptor.setGoal( getTrimmedValue( parser.nextText() ) );
695 }
696 else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
697 {
698 mojoDescriptor.setDescription( getTrimmedValue( parser.nextText() ) );
699 }
700 else if ( checkFieldWithDuplicate( parser, "implementation", null, parsed ) )
701 {
702 mojoDescriptor.setImplementation( getTrimmedValue( parser.nextText() ) );
703 }
704 else if ( checkFieldWithDuplicate( parser, "language", null, parsed ) )
705 {
706 mojoDescriptor.setLanguage( getTrimmedValue( parser.nextText() ) );
707 }
708 else if ( checkFieldWithDuplicate( parser, "phase", null, parsed ) )
709 {
710 mojoDescriptor.setPhase( getTrimmedValue( parser.nextText() ) );
711 }
712 else if ( checkFieldWithDuplicate( parser, "executePhase", null, parsed ) )
713 {
714 mojoDescriptor.setExecutePhase( getTrimmedValue( parser.nextText() ) );
715 }
716 else if ( checkFieldWithDuplicate( parser, "executeGoal", null, parsed ) )
717 {
718 mojoDescriptor.setExecuteGoal( getTrimmedValue( parser.nextText() ) );
719 }
720 else if ( checkFieldWithDuplicate( parser, "executeLifecycle", null, parsed ) )
721 {
722 mojoDescriptor.setExecuteLifecycle( getTrimmedValue( parser.nextText() ) );
723 }
724 else if ( checkFieldWithDuplicate( parser, "requiresDependencyResolution", null, parsed ) )
725 {
726 mojoDescriptor.setRequiresDependencyResolution( getTrimmedValue( parser.nextText() ) );
727 }
728 else if ( checkFieldWithDuplicate( parser, "requiresDependencyCollection", null, parsed ) )
729 {
730 mojoDescriptor.setRequiresDependencyCollection( getTrimmedValue( parser.nextText() ) );
731 }
732 else if ( checkFieldWithDuplicate( parser, "requiresDirectInvocation", null, parsed ) )
733 {
734 mojoDescriptor.setRequiresDirectInvocation( getBooleanValue( getTrimmedValue( parser.nextText() ), "requiresDirectInvocation", parser, "false" ) );
735 }
736 else if ( checkFieldWithDuplicate( parser, "requiresProject", null, parsed ) )
737 {
738 mojoDescriptor.setRequiresProject( getBooleanValue( getTrimmedValue( parser.nextText() ), "requiresProject", parser, "true" ) );
739 }
740 else if ( checkFieldWithDuplicate( parser, "requiresReports", null, parsed ) )
741 {
742 mojoDescriptor.setRequiresReports( getBooleanValue( getTrimmedValue( parser.nextText() ), "requiresReports", parser, "false" ) );
743 }
744 else if ( checkFieldWithDuplicate( parser, "requiresOnline", null, parsed ) )
745 {
746 mojoDescriptor.setRequiresOnline( getBooleanValue( getTrimmedValue( parser.nextText() ), "requiresOnline", parser, "false" ) );
747 }
748 else if ( checkFieldWithDuplicate( parser, "aggregator", null, parsed ) )
749 {
750 mojoDescriptor.setAggregator( getBooleanValue( getTrimmedValue( parser.nextText() ), "aggregator", parser, "false" ) );
751 }
752 else if ( checkFieldWithDuplicate( parser, "inheritedByDefault", null, parsed ) )
753 {
754 mojoDescriptor.setInheritedByDefault( getBooleanValue( getTrimmedValue( parser.nextText() ), "inheritedByDefault", parser, "true" ) );
755 }
756 else if ( checkFieldWithDuplicate( parser, "threadSafe", null, parsed ) )
757 {
758 mojoDescriptor.setThreadSafe( getBooleanValue( getTrimmedValue( parser.nextText() ), "threadSafe", parser, "false" ) );
759 }
760 else if ( checkFieldWithDuplicate( parser, "instantiationStrategy", null, parsed ) )
761 {
762 mojoDescriptor.setInstantiationStrategy( getTrimmedValue( parser.nextText() ) );
763 }
764 else if ( checkFieldWithDuplicate( parser, "executionStrategy", null, parsed ) )
765 {
766 mojoDescriptor.setExecutionStrategy( getTrimmedValue( parser.nextText() ) );
767 }
768 else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) )
769 {
770 mojoDescriptor.setSince( getTrimmedValue( parser.nextText() ) );
771 }
772 else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) )
773 {
774 mojoDescriptor.setDeprecated( getTrimmedValue( parser.nextText() ) );
775 }
776 else if ( checkFieldWithDuplicate( parser, "configurator", null, parsed ) )
777 {
778 mojoDescriptor.setConfigurator( getTrimmedValue( parser.nextText() ) );
779 }
780 else if ( checkFieldWithDuplicate( parser, "composer", null, parsed ) )
781 {
782 mojoDescriptor.setComposer( getTrimmedValue( parser.nextText() ) );
783 }
784 else if ( checkFieldWithDuplicate( parser, "parameters", null, parsed ) )
785 {
786 java.util.List parameters = new java.util.ArrayList();
787 mojoDescriptor.setParameters( parameters );
788 while ( parser.nextTag() == XmlPullParser.START_TAG )
789 {
790 if ( "parameter".equals( parser.getName() ) )
791 {
792 parameters.add( parseParameter( parser, strict ) );
793 }
794 else
795 {
796 checkUnknownElement( parser, strict );
797 }
798 }
799 }
800 else if ( checkFieldWithDuplicate( parser, "configuration", null, parsed ) )
801 {
802 java.util.List configuration = new java.util.ArrayList();
803 mojoDescriptor.setConfiguration( configuration );
804 while ( parser.nextTag() == XmlPullParser.START_TAG )
805 {
806 if ( "paramName".equals( parser.getName() ) )
807 {
808 configuration.add( parseConfiguration( parser, strict ) );
809 }
810 else
811 {
812 checkUnknownElement( parser, strict );
813 }
814 }
815 }
816 else if ( checkFieldWithDuplicate( parser, "requirements", null, parsed ) )
817 {
818 java.util.List requirements = new java.util.ArrayList();
819 mojoDescriptor.setRequirements( requirements );
820 while ( parser.nextTag() == XmlPullParser.START_TAG )
821 {
822 if ( "requirement".equals( parser.getName() ) )
823 {
824 requirements.add( parseRequirement( parser, strict ) );
825 }
826 else
827 {
828 checkUnknownElement( parser, strict );
829 }
830 }
831 }
832 else
833 {
834 checkUnknownElement( parser, strict );
835 }
836 }
837 return mojoDescriptor;
838 }
839
840
841
842
843
844
845
846
847
848
849 private Parameter parseParameter( XmlPullParser parser, boolean strict )
850 throws IOException, XmlPullParserException
851 {
852 String tagName = parser.getName();
853 Parameter parameter = new Parameter();
854 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
855 {
856 String name = parser.getAttributeName( i );
857 String value = parser.getAttributeValue( i );
858
859 if ( name.indexOf( ':' ) >= 0 )
860 {
861
862 }
863 else
864 {
865 checkUnknownAttribute( parser, name, tagName, strict );
866 }
867 }
868 java.util.Set parsed = new java.util.HashSet();
869 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
870 {
871 if ( checkFieldWithDuplicate( parser, "name", null, parsed ) )
872 {
873 parameter.setName( getTrimmedValue( parser.nextText() ) );
874 }
875 else if ( checkFieldWithDuplicate( parser, "alias", null, parsed ) )
876 {
877 parameter.setAlias( getTrimmedValue( parser.nextText() ) );
878 }
879 else if ( checkFieldWithDuplicate( parser, "type", null, parsed ) )
880 {
881 parameter.setType( getTrimmedValue( parser.nextText() ) );
882 }
883 else if ( checkFieldWithDuplicate( parser, "required", null, parsed ) )
884 {
885 parameter.setRequired( getBooleanValue( getTrimmedValue( parser.nextText() ), "required", parser, "false" ) );
886 }
887 else if ( checkFieldWithDuplicate( parser, "editable", null, parsed ) )
888 {
889 parameter.setEditable( getBooleanValue( getTrimmedValue( parser.nextText() ), "editable", parser, "true" ) );
890 }
891 else if ( checkFieldWithDuplicate( parser, "implementation", null, parsed ) )
892 {
893 parameter.setImplementation( getTrimmedValue( parser.nextText() ) );
894 }
895 else if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
896 {
897 parameter.setDescription( getTrimmedValue( parser.nextText() ) );
898 }
899 else if ( checkFieldWithDuplicate( parser, "since", null, parsed ) )
900 {
901 parameter.setSince( getTrimmedValue( parser.nextText() ) );
902 }
903 else if ( checkFieldWithDuplicate( parser, "deprecated", null, parsed ) )
904 {
905 parameter.setDeprecated( getTrimmedValue( parser.nextText() ) );
906 }
907 else
908 {
909 checkUnknownElement( parser, strict );
910 }
911 }
912 return parameter;
913 }
914
915
916
917
918
919
920
921
922
923
924 private PluginDescriptor parsePluginDescriptor( XmlPullParser parser, boolean strict )
925 throws IOException, XmlPullParserException
926 {
927 String tagName = parser.getName();
928 PluginDescriptor pluginDescriptor = new PluginDescriptor();
929 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
930 {
931 String name = parser.getAttributeName( i );
932 String value = parser.getAttributeValue( i );
933
934 if ( name.indexOf( ':' ) >= 0 )
935 {
936
937 }
938 else if ( "xmlns".equals( name ) )
939 {
940
941 }
942 else
943 {
944 checkUnknownAttribute( parser, name, tagName, strict );
945 }
946 }
947 java.util.Set parsed = new java.util.HashSet();
948 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
949 {
950 if ( checkFieldWithDuplicate( parser, "description", null, parsed ) )
951 {
952 pluginDescriptor.setDescription( getTrimmedValue( parser.nextText() ) );
953 }
954 else if ( checkFieldWithDuplicate( parser, "groupId", null, parsed ) )
955 {
956 pluginDescriptor.setGroupId( getTrimmedValue( parser.nextText() ) );
957 }
958 else if ( checkFieldWithDuplicate( parser, "artifactId", null, parsed ) )
959 {
960 pluginDescriptor.setArtifactId( getTrimmedValue( parser.nextText() ) );
961 }
962 else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) )
963 {
964 pluginDescriptor.setVersion( getTrimmedValue( parser.nextText() ) );
965 }
966 else if ( checkFieldWithDuplicate( parser, "goalPrefix", null, parsed ) )
967 {
968 pluginDescriptor.setGoalPrefix( getTrimmedValue( parser.nextText() ) );
969 }
970 else if ( checkFieldWithDuplicate( parser, "isolatedRealm", null, parsed ) )
971 {
972 pluginDescriptor.setIsolatedRealm( getBooleanValue( getTrimmedValue( parser.nextText() ), "isolatedRealm", parser, "false" ) );
973 }
974 else if ( checkFieldWithDuplicate( parser, "inheritedByDefault", null, parsed ) )
975 {
976 pluginDescriptor.setInheritedByDefault( getBooleanValue( getTrimmedValue( parser.nextText() ), "inheritedByDefault", parser, "true" ) );
977 }
978 else if ( checkFieldWithDuplicate( parser, "mojos", null, parsed ) )
979 {
980 java.util.List mojos = new java.util.ArrayList();
981 pluginDescriptor.setMojos( mojos );
982 while ( parser.nextTag() == XmlPullParser.START_TAG )
983 {
984 if ( "mojo".equals( parser.getName() ) )
985 {
986 mojos.add( parseMojoDescriptor( parser, strict ) );
987 }
988 else
989 {
990 checkUnknownElement( parser, strict );
991 }
992 }
993 }
994 else if ( checkFieldWithDuplicate( parser, "dependencies", null, parsed ) )
995 {
996 java.util.List dependencies = new java.util.ArrayList();
997 pluginDescriptor.setDependencies( dependencies );
998 while ( parser.nextTag() == XmlPullParser.START_TAG )
999 {
1000 if ( "dependency".equals( parser.getName() ) )
1001 {
1002 dependencies.add( parseDependency( parser, strict ) );
1003 }
1004 else
1005 {
1006 checkUnknownElement( parser, strict );
1007 }
1008 }
1009 }
1010 else
1011 {
1012 checkUnknownElement( parser, strict );
1013 }
1014 }
1015 return pluginDescriptor;
1016 }
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027 private Requirement parseRequirement( XmlPullParser parser, boolean strict )
1028 throws IOException, XmlPullParserException
1029 {
1030 String tagName = parser.getName();
1031 Requirement requirement = new Requirement();
1032 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1033 {
1034 String name = parser.getAttributeName( i );
1035 String value = parser.getAttributeValue( i );
1036
1037 if ( name.indexOf( ':' ) >= 0 )
1038 {
1039
1040 }
1041 else
1042 {
1043 checkUnknownAttribute( parser, name, tagName, strict );
1044 }
1045 }
1046 java.util.Set parsed = new java.util.HashSet();
1047 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1048 {
1049 if ( checkFieldWithDuplicate( parser, "role", null, parsed ) )
1050 {
1051 requirement.setRole( getTrimmedValue( parser.nextText() ) );
1052 }
1053 else if ( checkFieldWithDuplicate( parser, "role-hint", null, parsed ) )
1054 {
1055 requirement.setRoleHint( getTrimmedValue( parser.nextText() ) );
1056 }
1057 else if ( checkFieldWithDuplicate( parser, "field-name", null, parsed ) )
1058 {
1059 requirement.setFieldName( getTrimmedValue( parser.nextText() ) );
1060 }
1061 else
1062 {
1063 checkUnknownElement( parser, strict );
1064 }
1065 }
1066 return requirement;
1067 }
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078 private PluginDescriptor read( XmlPullParser parser, boolean strict )
1079 throws IOException, XmlPullParserException
1080 {
1081 int eventType = parser.getEventType();
1082 while ( eventType != XmlPullParser.END_DOCUMENT )
1083 {
1084 if ( eventType == XmlPullParser.START_TAG )
1085 {
1086 if ( strict && ! "plugin".equals( parser.getName() ) )
1087 {
1088 throw new XmlPullParserException( "Expected root element 'plugin' but found '" + parser.getName() + "'", parser, null );
1089 }
1090 PluginDescriptor pluginDescriptor = parsePluginDescriptor( parser, strict );
1091 pluginDescriptor.setModelEncoding( parser.getInputEncoding() );
1092 return pluginDescriptor;
1093 }
1094 eventType = parser.next();
1095 }
1096 throw new XmlPullParserException( "Expected root element 'plugin' but found no element at all: invalid XML document", parser, null );
1097 }
1098
1099
1100
1101
1102
1103
1104 public void setAddDefaultEntities( boolean addDefaultEntities )
1105 {
1106 this.addDefaultEntities = addDefaultEntities;
1107 }
1108
1109 }