1
2
3
4
5
6 package org.apache.maven.plugins.assembly.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.plugins.assembly.model.Component;
17 import org.apache.maven.plugins.assembly.model.ContainerDescriptorHandlerConfig;
18 import org.apache.maven.plugins.assembly.model.DependencySet;
19 import org.apache.maven.plugins.assembly.model.FileItem;
20 import org.apache.maven.plugins.assembly.model.FileSet;
21 import org.apache.maven.plugins.assembly.model.ModuleBinaries;
22 import org.apache.maven.plugins.assembly.model.ModuleSet;
23 import org.apache.maven.plugins.assembly.model.ModuleSources;
24 import org.apache.maven.plugins.assembly.model.UnpackOptions;
25 import org.codehaus.plexus.util.ReaderFactory;
26 import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
27 import org.codehaus.plexus.util.xml.pull.MXParser;
28 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
29 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
30
31
32
33
34
35
36 @SuppressWarnings( "all" )
37 public class ComponentXpp3Reader
38 {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 private boolean addDefaultEntities = true;
55
56
57
58
59 public final ContentTransformer contentTransformer;
60
61
62
63
64
65
66 public ComponentXpp3Reader()
67 {
68 this( new ContentTransformer()
69 {
70 public String transform( String source, String fieldName )
71 {
72 return source;
73 }
74 } );
75 }
76
77 public ComponentXpp3Reader(ContentTransformer contentTransformer)
78 {
79 this.contentTransformer = contentTransformer;
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed )
99 throws XmlPullParserException
100 {
101 if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
102 {
103 return false;
104 }
105 if ( !parsed.add( tagName ) )
106 {
107 throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
108 }
109 return true;
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123 private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
124 throws XmlPullParserException, IOException
125 {
126
127 if ( strict )
128 {
129 throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
130 }
131 }
132
133
134
135
136
137
138
139
140
141
142 private void checkUnknownElement( XmlPullParser parser, boolean strict )
143 throws XmlPullParserException, IOException
144 {
145 if ( strict )
146 {
147 throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
148 }
149
150 for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
151 {
152 int eventType = parser.next();
153 if ( eventType == XmlPullParser.START_TAG )
154 {
155 unrecognizedTagCount++;
156 }
157 else if ( eventType == XmlPullParser.END_TAG )
158 {
159 unrecognizedTagCount--;
160 }
161 }
162 }
163
164
165
166
167
168
169 public boolean getAddDefaultEntities()
170 {
171 return addDefaultEntities;
172 }
173
174
175
176
177
178
179
180
181
182
183
184 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
185 throws XmlPullParserException
186 {
187 return getBooleanValue( s, attribute, parser, null );
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201 private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue )
202 throws XmlPullParserException
203 {
204 if ( s != null && s.length() != 0 )
205 {
206 return Boolean.valueOf( s ).booleanValue();
207 }
208 if ( defaultValue != null )
209 {
210 return Boolean.valueOf( defaultValue ).booleanValue();
211 }
212 return false;
213 }
214
215
216
217
218
219
220
221
222
223
224
225
226 private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
227 throws XmlPullParserException
228 {
229 if ( s != null )
230 {
231 try
232 {
233 return Byte.valueOf( s ).byteValue();
234 }
235 catch ( NumberFormatException nfe )
236 {
237 if ( strict )
238 {
239 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
240 }
241 }
242 }
243 return 0;
244 }
245
246
247
248
249
250
251
252
253
254
255
256 private char getCharacterValue( String s, String attribute, XmlPullParser parser )
257 throws XmlPullParserException
258 {
259 if ( s != null )
260 {
261 return s.charAt( 0 );
262 }
263 return 0;
264 }
265
266
267
268
269
270
271
272
273
274
275
276 private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser )
277 throws XmlPullParserException
278 {
279 return getDateValue( s, attribute, null, parser );
280 }
281
282
283
284
285
286
287
288
289
290
291
292
293 private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
294 throws XmlPullParserException
295 {
296 if ( s != null )
297 {
298 String effectiveDateFormat = dateFormat;
299 if ( dateFormat == null )
300 {
301 effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
302 }
303 if ( "long".equals( effectiveDateFormat ) )
304 {
305 try
306 {
307 return new java.util.Date( Long.parseLong( s ) );
308 }
309 catch ( NumberFormatException e )
310 {
311 throw new XmlPullParserException( e.getMessage(), parser, e );
312 }
313 }
314 else
315 {
316 try
317 {
318 DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
319 return dateParser.parse( s );
320 }
321 catch ( java.text.ParseException e )
322 {
323 throw new XmlPullParserException( e.getMessage(), parser, e );
324 }
325 }
326 }
327 return null;
328 }
329
330
331
332
333
334
335
336
337
338
339
340
341 private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
342 throws XmlPullParserException
343 {
344 if ( s != null )
345 {
346 try
347 {
348 return Double.valueOf( s ).doubleValue();
349 }
350 catch ( NumberFormatException nfe )
351 {
352 if ( strict )
353 {
354 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
355 }
356 }
357 }
358 return 0;
359 }
360
361
362
363
364
365
366
367
368
369
370
371
372 private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
373 throws XmlPullParserException
374 {
375 if ( s != null )
376 {
377 try
378 {
379 return Float.valueOf( s ).floatValue();
380 }
381 catch ( NumberFormatException nfe )
382 {
383 if ( strict )
384 {
385 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
386 }
387 }
388 }
389 return 0;
390 }
391
392
393
394
395
396
397
398
399
400
401
402
403 private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
404 throws XmlPullParserException
405 {
406 if ( s != null )
407 {
408 try
409 {
410 return Integer.valueOf( s ).intValue();
411 }
412 catch ( NumberFormatException nfe )
413 {
414 if ( strict )
415 {
416 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
417 }
418 }
419 }
420 return 0;
421 }
422
423
424
425
426
427
428
429
430
431
432
433
434 private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
435 throws XmlPullParserException
436 {
437 if ( s != null )
438 {
439 try
440 {
441 return Long.valueOf( s ).longValue();
442 }
443 catch ( NumberFormatException nfe )
444 {
445 if ( strict )
446 {
447 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
448 }
449 }
450 }
451 return 0;
452 }
453
454
455
456
457
458
459
460
461
462
463
464
465 private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
466 throws XmlPullParserException
467 {
468 if ( s == null )
469 {
470 if ( strict )
471 {
472 throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
473 }
474 }
475 return s;
476 }
477
478
479
480
481
482
483
484
485
486
487
488
489 private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
490 throws XmlPullParserException
491 {
492 if ( s != null )
493 {
494 try
495 {
496 return Short.valueOf( s ).shortValue();
497 }
498 catch ( NumberFormatException nfe )
499 {
500 if ( strict )
501 {
502 throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
503 }
504 }
505 }
506 return 0;
507 }
508
509
510
511
512
513
514
515 private String getTrimmedValue( String s )
516 {
517 if ( s != null )
518 {
519 s = s.trim();
520 }
521 return s;
522 }
523
524
525
526
527
528
529
530
531 private String interpolatedTrimmed( String value, String context )
532 {
533 return getTrimmedValue( contentTransformer.transform( value, context ) );
534 }
535
536
537
538
539
540
541
542
543
544
545 private int nextTag( XmlPullParser parser )
546 throws IOException, XmlPullParserException
547 {
548 int eventType = parser.next();
549 if ( eventType == XmlPullParser.TEXT )
550 {
551 eventType = parser.next();
552 }
553 if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
554 {
555 throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
556 }
557 return eventType;
558 }
559
560
561
562
563
564
565
566
567
568
569
570 public Component read( XmlPullParser parser, boolean strict )
571 throws IOException, XmlPullParserException
572 {
573 Component component = null;
574 int eventType = parser.getEventType();
575 boolean parsed = false;
576 while ( eventType != XmlPullParser.END_DOCUMENT )
577 {
578 if ( eventType == XmlPullParser.START_TAG )
579 {
580 if ( strict && ! "component".equals( parser.getName() ) )
581 {
582 throw new XmlPullParserException( "Expected root element 'component' but found '" + parser.getName() + "'", parser, null );
583 }
584 else if ( parsed )
585 {
586
587 throw new XmlPullParserException( "Duplicated tag: 'component'", parser, null );
588 }
589 component = parseComponent( parser, strict );
590 component.setModelEncoding( parser.getInputEncoding() );
591 parsed = true;
592 }
593 eventType = parser.next();
594 }
595 if ( parsed )
596 {
597 return component;
598 }
599 throw new XmlPullParserException( "Expected root element 'component' but found no element at all: invalid XML document", parser, null );
600 }
601
602
603
604
605
606
607
608
609
610
611
612 public Component read( Reader reader, boolean strict )
613 throws IOException, XmlPullParserException
614 {
615 XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
616
617 parser.setInput( reader );
618
619
620 return read( parser, strict );
621 }
622
623
624
625
626
627
628
629
630
631
632 public Component read( Reader reader )
633 throws IOException, XmlPullParserException
634 {
635 return read( reader, true );
636 }
637
638
639
640
641
642
643
644
645
646
647
648 public Component read( InputStream in, boolean strict )
649 throws IOException, XmlPullParserException
650 {
651 return read( ReaderFactory.newXmlReader( in ), strict );
652 }
653
654
655
656
657
658
659
660
661
662
663 public Component read( InputStream in )
664 throws IOException, XmlPullParserException
665 {
666 return read( ReaderFactory.newXmlReader( in ) );
667 }
668
669
670
671
672
673
674
675
676
677
678
679 private Component parseComponent( XmlPullParser parser, boolean strict )
680 throws IOException, XmlPullParserException
681 {
682 String tagName = parser.getName();
683 Component component = new Component();
684 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
685 {
686 String name = parser.getAttributeName( i );
687 String value = parser.getAttributeValue( i );
688
689 if ( name.indexOf( ':' ) >= 0 )
690 {
691
692 }
693 else if ( "xmlns".equals( name ) )
694 {
695
696 }
697 else
698 {
699 checkUnknownAttribute( parser, name, tagName, strict );
700 }
701 }
702 java.util.Set parsed = new java.util.HashSet();
703 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
704 {
705 if ( checkFieldWithDuplicate( parser, "moduleSets", null, parsed ) )
706 {
707 java.util.List<ModuleSet> moduleSets = new java.util.ArrayList<ModuleSet>();
708 while ( parser.nextTag() == XmlPullParser.START_TAG )
709 {
710 if ( "moduleSet".equals( parser.getName() ) )
711 {
712 moduleSets.add( parseModuleSet( parser, strict ) );
713 }
714 else
715 {
716 checkUnknownElement( parser, strict );
717 }
718 }
719 component.setModuleSets( moduleSets );
720 }
721 else if ( checkFieldWithDuplicate( parser, "fileSets", null, parsed ) )
722 {
723 java.util.List<FileSet> fileSets = new java.util.ArrayList<FileSet>();
724 while ( parser.nextTag() == XmlPullParser.START_TAG )
725 {
726 if ( "fileSet".equals( parser.getName() ) )
727 {
728 fileSets.add( parseFileSet( parser, strict ) );
729 }
730 else
731 {
732 checkUnknownElement( parser, strict );
733 }
734 }
735 component.setFileSets( fileSets );
736 }
737 else if ( checkFieldWithDuplicate( parser, "files", null, parsed ) )
738 {
739 java.util.List<FileItem> files = new java.util.ArrayList<FileItem>();
740 while ( parser.nextTag() == XmlPullParser.START_TAG )
741 {
742 if ( "file".equals( parser.getName() ) )
743 {
744 files.add( parseFileItem( parser, strict ) );
745 }
746 else
747 {
748 checkUnknownElement( parser, strict );
749 }
750 }
751 component.setFiles( files );
752 }
753 else if ( checkFieldWithDuplicate( parser, "dependencySets", null, parsed ) )
754 {
755 java.util.List<DependencySet> dependencySets = new java.util.ArrayList<DependencySet>();
756 while ( parser.nextTag() == XmlPullParser.START_TAG )
757 {
758 if ( "dependencySet".equals( parser.getName() ) )
759 {
760 dependencySets.add( parseDependencySet( parser, strict ) );
761 }
762 else
763 {
764 checkUnknownElement( parser, strict );
765 }
766 }
767 component.setDependencySets( dependencySets );
768 }
769 else if ( checkFieldWithDuplicate( parser, "containerDescriptorHandlers", null, parsed ) )
770 {
771 java.util.List<ContainerDescriptorHandlerConfig> containerDescriptorHandlers = new java.util.ArrayList<ContainerDescriptorHandlerConfig>();
772 while ( parser.nextTag() == XmlPullParser.START_TAG )
773 {
774 if ( "containerDescriptorHandler".equals( parser.getName() ) )
775 {
776 containerDescriptorHandlers.add( parseContainerDescriptorHandlerConfig( parser, strict ) );
777 }
778 else
779 {
780 checkUnknownElement( parser, strict );
781 }
782 }
783 component.setContainerDescriptorHandlers( containerDescriptorHandlers );
784 }
785 else
786 {
787 checkUnknownElement( parser, strict );
788 }
789 }
790 return component;
791 }
792
793
794
795
796
797
798
799
800
801
802
803 private ContainerDescriptorHandlerConfig parseContainerDescriptorHandlerConfig( XmlPullParser parser, boolean strict )
804 throws IOException, XmlPullParserException
805 {
806 String tagName = parser.getName();
807 ContainerDescriptorHandlerConfig containerDescriptorHandlerConfig = new ContainerDescriptorHandlerConfig();
808 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
809 {
810 String name = parser.getAttributeName( i );
811 String value = parser.getAttributeValue( i );
812
813 if ( name.indexOf( ':' ) >= 0 )
814 {
815
816 }
817 else
818 {
819 checkUnknownAttribute( parser, name, tagName, strict );
820 }
821 }
822 java.util.Set parsed = new java.util.HashSet();
823 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
824 {
825 if ( checkFieldWithDuplicate( parser, "handlerName", null, parsed ) )
826 {
827 containerDescriptorHandlerConfig.setHandlerName( interpolatedTrimmed( parser.nextText(), "handlerName" ) );
828 }
829 else if ( checkFieldWithDuplicate( parser, "configuration", null, parsed ) )
830 {
831 containerDescriptorHandlerConfig.setConfiguration( org.codehaus.plexus.util.xml.Xpp3DomBuilder.build( parser, true ) );
832 }
833 else
834 {
835 checkUnknownElement( parser, strict );
836 }
837 }
838 return containerDescriptorHandlerConfig;
839 }
840
841
842
843
844
845
846
847
848
849
850
851 private DependencySet parseDependencySet( XmlPullParser parser, boolean strict )
852 throws IOException, XmlPullParserException
853 {
854 String tagName = parser.getName();
855 DependencySet dependencySet = new DependencySet();
856 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
857 {
858 String name = parser.getAttributeName( i );
859 String value = parser.getAttributeValue( i );
860
861 if ( name.indexOf( ':' ) >= 0 )
862 {
863
864 }
865 else
866 {
867 checkUnknownAttribute( parser, name, tagName, strict );
868 }
869 }
870 java.util.Set parsed = new java.util.HashSet();
871 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
872 {
873 if ( checkFieldWithDuplicate( parser, "outputDirectory", null, parsed ) )
874 {
875 dependencySet.setOutputDirectory( interpolatedTrimmed( parser.nextText(), "outputDirectory" ) );
876 }
877 else if ( checkFieldWithDuplicate( parser, "includes", null, parsed ) )
878 {
879 java.util.List<String> includes = new java.util.ArrayList<String>();
880 while ( parser.nextTag() == XmlPullParser.START_TAG )
881 {
882 if ( "include".equals( parser.getName() ) )
883 {
884 includes.add( interpolatedTrimmed( parser.nextText(), "includes" ) );
885 }
886 else
887 {
888 checkUnknownElement( parser, strict );
889 }
890 }
891 dependencySet.setIncludes( includes );
892 }
893 else if ( checkFieldWithDuplicate( parser, "excludes", null, parsed ) )
894 {
895 java.util.List<String> excludes = new java.util.ArrayList<String>();
896 while ( parser.nextTag() == XmlPullParser.START_TAG )
897 {
898 if ( "exclude".equals( parser.getName() ) )
899 {
900 excludes.add( interpolatedTrimmed( parser.nextText(), "excludes" ) );
901 }
902 else
903 {
904 checkUnknownElement( parser, strict );
905 }
906 }
907 dependencySet.setExcludes( excludes );
908 }
909 else if ( checkFieldWithDuplicate( parser, "fileMode", null, parsed ) )
910 {
911 dependencySet.setFileMode( interpolatedTrimmed( parser.nextText(), "fileMode" ) );
912 }
913 else if ( checkFieldWithDuplicate( parser, "directoryMode", null, parsed ) )
914 {
915 dependencySet.setDirectoryMode( interpolatedTrimmed( parser.nextText(), "directoryMode" ) );
916 }
917 else if ( checkFieldWithDuplicate( parser, "useStrictFiltering", null, parsed ) )
918 {
919 dependencySet.setUseStrictFiltering( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useStrictFiltering" ), "useStrictFiltering", parser, "false" ) );
920 }
921 else if ( checkFieldWithDuplicate( parser, "outputFileNameMapping", null, parsed ) )
922 {
923 dependencySet.setOutputFileNameMapping( interpolatedTrimmed( parser.nextText(), "outputFileNameMapping" ) );
924 }
925 else if ( checkFieldWithDuplicate( parser, "unpack", null, parsed ) )
926 {
927 dependencySet.setUnpack( getBooleanValue( interpolatedTrimmed( parser.nextText(), "unpack" ), "unpack", parser, "false" ) );
928 }
929 else if ( checkFieldWithDuplicate( parser, "unpackOptions", null, parsed ) )
930 {
931 dependencySet.setUnpackOptions( parseUnpackOptions( parser, strict ) );
932 }
933 else if ( checkFieldWithDuplicate( parser, "scope", null, parsed ) )
934 {
935 dependencySet.setScope( interpolatedTrimmed( parser.nextText(), "scope" ) );
936 }
937 else if ( checkFieldWithDuplicate( parser, "useProjectArtifact", null, parsed ) )
938 {
939 dependencySet.setUseProjectArtifact( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useProjectArtifact" ), "useProjectArtifact", parser, "true" ) );
940 }
941 else if ( checkFieldWithDuplicate( parser, "useProjectAttachments", null, parsed ) )
942 {
943 dependencySet.setUseProjectAttachments( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useProjectAttachments" ), "useProjectAttachments", parser, "false" ) );
944 }
945 else if ( checkFieldWithDuplicate( parser, "useTransitiveDependencies", null, parsed ) )
946 {
947 dependencySet.setUseTransitiveDependencies( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useTransitiveDependencies" ), "useTransitiveDependencies", parser, "true" ) );
948 }
949 else if ( checkFieldWithDuplicate( parser, "useTransitiveFiltering", null, parsed ) )
950 {
951 dependencySet.setUseTransitiveFiltering( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useTransitiveFiltering" ), "useTransitiveFiltering", parser, "false" ) );
952 }
953 else
954 {
955 checkUnknownElement( parser, strict );
956 }
957 }
958 return dependencySet;
959 }
960
961
962
963
964
965
966
967
968
969
970
971 private FileItem parseFileItem( XmlPullParser parser, boolean strict )
972 throws IOException, XmlPullParserException
973 {
974 String tagName = parser.getName();
975 FileItem fileItem = new FileItem();
976 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
977 {
978 String name = parser.getAttributeName( i );
979 String value = parser.getAttributeValue( i );
980
981 if ( name.indexOf( ':' ) >= 0 )
982 {
983
984 }
985 else
986 {
987 checkUnknownAttribute( parser, name, tagName, strict );
988 }
989 }
990 java.util.Set parsed = new java.util.HashSet();
991 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
992 {
993 if ( checkFieldWithDuplicate( parser, "source", null, parsed ) )
994 {
995 fileItem.setSource( interpolatedTrimmed( parser.nextText(), "source" ) );
996 }
997 else if ( checkFieldWithDuplicate( parser, "sources", null, parsed ) )
998 {
999 java.util.List<String> sources = new java.util.ArrayList<String>();
1000 while ( parser.nextTag() == XmlPullParser.START_TAG )
1001 {
1002 if ( "source".equals( parser.getName() ) )
1003 {
1004 sources.add( interpolatedTrimmed( parser.nextText(), "sources" ) );
1005 }
1006 else
1007 {
1008 checkUnknownElement( parser, strict );
1009 }
1010 }
1011 fileItem.setSources( sources );
1012 }
1013 else if ( checkFieldWithDuplicate( parser, "outputDirectory", null, parsed ) )
1014 {
1015 fileItem.setOutputDirectory( interpolatedTrimmed( parser.nextText(), "outputDirectory" ) );
1016 }
1017 else if ( checkFieldWithDuplicate( parser, "destName", null, parsed ) )
1018 {
1019 fileItem.setDestName( interpolatedTrimmed( parser.nextText(), "destName" ) );
1020 }
1021 else if ( checkFieldWithDuplicate( parser, "fileMode", null, parsed ) )
1022 {
1023 fileItem.setFileMode( interpolatedTrimmed( parser.nextText(), "fileMode" ) );
1024 }
1025 else if ( checkFieldWithDuplicate( parser, "lineEnding", null, parsed ) )
1026 {
1027 fileItem.setLineEnding( interpolatedTrimmed( parser.nextText(), "lineEnding" ) );
1028 }
1029 else if ( checkFieldWithDuplicate( parser, "filtered", null, parsed ) )
1030 {
1031 fileItem.setFiltered( getBooleanValue( interpolatedTrimmed( parser.nextText(), "filtered" ), "filtered", parser, "false" ) );
1032 }
1033 else
1034 {
1035 checkUnknownElement( parser, strict );
1036 }
1037 }
1038 return fileItem;
1039 }
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051 private FileSet parseFileSet( XmlPullParser parser, boolean strict )
1052 throws IOException, XmlPullParserException
1053 {
1054 String tagName = parser.getName();
1055 FileSet fileSet = new FileSet();
1056 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1057 {
1058 String name = parser.getAttributeName( i );
1059 String value = parser.getAttributeValue( i );
1060
1061 if ( name.indexOf( ':' ) >= 0 )
1062 {
1063
1064 }
1065 else
1066 {
1067 checkUnknownAttribute( parser, name, tagName, strict );
1068 }
1069 }
1070 java.util.Set parsed = new java.util.HashSet();
1071 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1072 {
1073 if ( checkFieldWithDuplicate( parser, "useDefaultExcludes", null, parsed ) )
1074 {
1075 fileSet.setUseDefaultExcludes( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useDefaultExcludes" ), "useDefaultExcludes", parser, "true" ) );
1076 }
1077 else if ( checkFieldWithDuplicate( parser, "outputDirectory", null, parsed ) )
1078 {
1079 fileSet.setOutputDirectory( interpolatedTrimmed( parser.nextText(), "outputDirectory" ) );
1080 }
1081 else if ( checkFieldWithDuplicate( parser, "includes", null, parsed ) )
1082 {
1083 java.util.List<String> includes = new java.util.ArrayList<String>();
1084 while ( parser.nextTag() == XmlPullParser.START_TAG )
1085 {
1086 if ( "include".equals( parser.getName() ) )
1087 {
1088 includes.add( interpolatedTrimmed( parser.nextText(), "includes" ) );
1089 }
1090 else
1091 {
1092 checkUnknownElement( parser, strict );
1093 }
1094 }
1095 fileSet.setIncludes( includes );
1096 }
1097 else if ( checkFieldWithDuplicate( parser, "excludes", null, parsed ) )
1098 {
1099 java.util.List<String> excludes = new java.util.ArrayList<String>();
1100 while ( parser.nextTag() == XmlPullParser.START_TAG )
1101 {
1102 if ( "exclude".equals( parser.getName() ) )
1103 {
1104 excludes.add( interpolatedTrimmed( parser.nextText(), "excludes" ) );
1105 }
1106 else
1107 {
1108 checkUnknownElement( parser, strict );
1109 }
1110 }
1111 fileSet.setExcludes( excludes );
1112 }
1113 else if ( checkFieldWithDuplicate( parser, "fileMode", null, parsed ) )
1114 {
1115 fileSet.setFileMode( interpolatedTrimmed( parser.nextText(), "fileMode" ) );
1116 }
1117 else if ( checkFieldWithDuplicate( parser, "directoryMode", null, parsed ) )
1118 {
1119 fileSet.setDirectoryMode( interpolatedTrimmed( parser.nextText(), "directoryMode" ) );
1120 }
1121 else if ( checkFieldWithDuplicate( parser, "directory", null, parsed ) )
1122 {
1123 fileSet.setDirectory( interpolatedTrimmed( parser.nextText(), "directory" ) );
1124 }
1125 else if ( checkFieldWithDuplicate( parser, "lineEnding", null, parsed ) )
1126 {
1127 fileSet.setLineEnding( interpolatedTrimmed( parser.nextText(), "lineEnding" ) );
1128 }
1129 else if ( checkFieldWithDuplicate( parser, "filtered", null, parsed ) )
1130 {
1131 fileSet.setFiltered( getBooleanValue( interpolatedTrimmed( parser.nextText(), "filtered" ), "filtered", parser, "false" ) );
1132 }
1133 else if ( checkFieldWithDuplicate( parser, "nonFilteredFileExtensions", null, parsed ) )
1134 {
1135 java.util.List<String> nonFilteredFileExtensions = new java.util.ArrayList<String>();
1136 while ( parser.nextTag() == XmlPullParser.START_TAG )
1137 {
1138 if ( "nonFilteredFileExtension".equals( parser.getName() ) )
1139 {
1140 nonFilteredFileExtensions.add( interpolatedTrimmed( parser.nextText(), "nonFilteredFileExtensions" ) );
1141 }
1142 else
1143 {
1144 checkUnknownElement( parser, strict );
1145 }
1146 }
1147 fileSet.setNonFilteredFileExtensions( nonFilteredFileExtensions );
1148 }
1149 else
1150 {
1151 checkUnknownElement( parser, strict );
1152 }
1153 }
1154 return fileSet;
1155 }
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167 private ModuleBinaries parseModuleBinaries( XmlPullParser parser, boolean strict )
1168 throws IOException, XmlPullParserException
1169 {
1170 String tagName = parser.getName();
1171 ModuleBinaries moduleBinaries = new ModuleBinaries();
1172 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1173 {
1174 String name = parser.getAttributeName( i );
1175 String value = parser.getAttributeValue( i );
1176
1177 if ( name.indexOf( ':' ) >= 0 )
1178 {
1179
1180 }
1181 else
1182 {
1183 checkUnknownAttribute( parser, name, tagName, strict );
1184 }
1185 }
1186 java.util.Set parsed = new java.util.HashSet();
1187 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1188 {
1189 if ( checkFieldWithDuplicate( parser, "outputDirectory", null, parsed ) )
1190 {
1191 moduleBinaries.setOutputDirectory( interpolatedTrimmed( parser.nextText(), "outputDirectory" ) );
1192 }
1193 else if ( checkFieldWithDuplicate( parser, "includes", null, parsed ) )
1194 {
1195 java.util.List<String> includes = new java.util.ArrayList<String>();
1196 while ( parser.nextTag() == XmlPullParser.START_TAG )
1197 {
1198 if ( "include".equals( parser.getName() ) )
1199 {
1200 includes.add( interpolatedTrimmed( parser.nextText(), "includes" ) );
1201 }
1202 else
1203 {
1204 checkUnknownElement( parser, strict );
1205 }
1206 }
1207 moduleBinaries.setIncludes( includes );
1208 }
1209 else if ( checkFieldWithDuplicate( parser, "excludes", null, parsed ) )
1210 {
1211 java.util.List<String> excludes = new java.util.ArrayList<String>();
1212 while ( parser.nextTag() == XmlPullParser.START_TAG )
1213 {
1214 if ( "exclude".equals( parser.getName() ) )
1215 {
1216 excludes.add( interpolatedTrimmed( parser.nextText(), "excludes" ) );
1217 }
1218 else
1219 {
1220 checkUnknownElement( parser, strict );
1221 }
1222 }
1223 moduleBinaries.setExcludes( excludes );
1224 }
1225 else if ( checkFieldWithDuplicate( parser, "fileMode", null, parsed ) )
1226 {
1227 moduleBinaries.setFileMode( interpolatedTrimmed( parser.nextText(), "fileMode" ) );
1228 }
1229 else if ( checkFieldWithDuplicate( parser, "directoryMode", null, parsed ) )
1230 {
1231 moduleBinaries.setDirectoryMode( interpolatedTrimmed( parser.nextText(), "directoryMode" ) );
1232 }
1233 else if ( checkFieldWithDuplicate( parser, "attachmentClassifier", null, parsed ) )
1234 {
1235 moduleBinaries.setAttachmentClassifier( interpolatedTrimmed( parser.nextText(), "attachmentClassifier" ) );
1236 }
1237 else if ( checkFieldWithDuplicate( parser, "includeDependencies", null, parsed ) )
1238 {
1239 moduleBinaries.setIncludeDependencies( getBooleanValue( interpolatedTrimmed( parser.nextText(), "includeDependencies" ), "includeDependencies", parser, "true" ) );
1240 }
1241 else if ( checkFieldWithDuplicate( parser, "dependencySets", null, parsed ) )
1242 {
1243 java.util.List<DependencySet> dependencySets = new java.util.ArrayList<DependencySet>();
1244 while ( parser.nextTag() == XmlPullParser.START_TAG )
1245 {
1246 if ( "dependencySet".equals( parser.getName() ) )
1247 {
1248 dependencySets.add( parseDependencySet( parser, strict ) );
1249 }
1250 else
1251 {
1252 checkUnknownElement( parser, strict );
1253 }
1254 }
1255 moduleBinaries.setDependencySets( dependencySets );
1256 }
1257 else if ( checkFieldWithDuplicate( parser, "unpack", null, parsed ) )
1258 {
1259 moduleBinaries.setUnpack( getBooleanValue( interpolatedTrimmed( parser.nextText(), "unpack" ), "unpack", parser, "true" ) );
1260 }
1261 else if ( checkFieldWithDuplicate( parser, "unpackOptions", null, parsed ) )
1262 {
1263 moduleBinaries.setUnpackOptions( parseUnpackOptions( parser, strict ) );
1264 }
1265 else if ( checkFieldWithDuplicate( parser, "outputFileNameMapping", null, parsed ) )
1266 {
1267 moduleBinaries.setOutputFileNameMapping( interpolatedTrimmed( parser.nextText(), "outputFileNameMapping" ) );
1268 }
1269 else
1270 {
1271 checkUnknownElement( parser, strict );
1272 }
1273 }
1274 return moduleBinaries;
1275 }
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287 private ModuleSet parseModuleSet( XmlPullParser parser, boolean strict )
1288 throws IOException, XmlPullParserException
1289 {
1290 String tagName = parser.getName();
1291 ModuleSet moduleSet = new ModuleSet();
1292 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1293 {
1294 String name = parser.getAttributeName( i );
1295 String value = parser.getAttributeValue( i );
1296
1297 if ( name.indexOf( ':' ) >= 0 )
1298 {
1299
1300 }
1301 else
1302 {
1303 checkUnknownAttribute( parser, name, tagName, strict );
1304 }
1305 }
1306 java.util.Set parsed = new java.util.HashSet();
1307 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1308 {
1309 if ( checkFieldWithDuplicate( parser, "useAllReactorProjects", null, parsed ) )
1310 {
1311 moduleSet.setUseAllReactorProjects( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useAllReactorProjects" ), "useAllReactorProjects", parser, "false" ) );
1312 }
1313 else if ( checkFieldWithDuplicate( parser, "includeSubModules", null, parsed ) )
1314 {
1315 moduleSet.setIncludeSubModules( getBooleanValue( interpolatedTrimmed( parser.nextText(), "includeSubModules" ), "includeSubModules", parser, "true" ) );
1316 }
1317 else if ( checkFieldWithDuplicate( parser, "includes", null, parsed ) )
1318 {
1319 java.util.List<String> includes = new java.util.ArrayList<String>();
1320 while ( parser.nextTag() == XmlPullParser.START_TAG )
1321 {
1322 if ( "include".equals( parser.getName() ) )
1323 {
1324 includes.add( interpolatedTrimmed( parser.nextText(), "includes" ) );
1325 }
1326 else
1327 {
1328 checkUnknownElement( parser, strict );
1329 }
1330 }
1331 moduleSet.setIncludes( includes );
1332 }
1333 else if ( checkFieldWithDuplicate( parser, "excludes", null, parsed ) )
1334 {
1335 java.util.List<String> excludes = new java.util.ArrayList<String>();
1336 while ( parser.nextTag() == XmlPullParser.START_TAG )
1337 {
1338 if ( "exclude".equals( parser.getName() ) )
1339 {
1340 excludes.add( interpolatedTrimmed( parser.nextText(), "excludes" ) );
1341 }
1342 else
1343 {
1344 checkUnknownElement( parser, strict );
1345 }
1346 }
1347 moduleSet.setExcludes( excludes );
1348 }
1349 else if ( checkFieldWithDuplicate( parser, "sources", null, parsed ) )
1350 {
1351 moduleSet.setSources( parseModuleSources( parser, strict ) );
1352 }
1353 else if ( checkFieldWithDuplicate( parser, "binaries", null, parsed ) )
1354 {
1355 moduleSet.setBinaries( parseModuleBinaries( parser, strict ) );
1356 }
1357 else
1358 {
1359 checkUnknownElement( parser, strict );
1360 }
1361 }
1362 return moduleSet;
1363 }
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375 private ModuleSources parseModuleSources( XmlPullParser parser, boolean strict )
1376 throws IOException, XmlPullParserException
1377 {
1378 String tagName = parser.getName();
1379 ModuleSources moduleSources = new ModuleSources();
1380 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1381 {
1382 String name = parser.getAttributeName( i );
1383 String value = parser.getAttributeValue( i );
1384
1385 if ( name.indexOf( ':' ) >= 0 )
1386 {
1387
1388 }
1389 else
1390 {
1391 checkUnknownAttribute( parser, name, tagName, strict );
1392 }
1393 }
1394 java.util.Set parsed = new java.util.HashSet();
1395 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1396 {
1397 if ( checkFieldWithDuplicate( parser, "useDefaultExcludes", null, parsed ) )
1398 {
1399 moduleSources.setUseDefaultExcludes( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useDefaultExcludes" ), "useDefaultExcludes", parser, "true" ) );
1400 }
1401 else if ( checkFieldWithDuplicate( parser, "outputDirectory", null, parsed ) )
1402 {
1403 moduleSources.setOutputDirectory( interpolatedTrimmed( parser.nextText(), "outputDirectory" ) );
1404 }
1405 else if ( checkFieldWithDuplicate( parser, "includes", null, parsed ) )
1406 {
1407 java.util.List<String> includes = new java.util.ArrayList<String>();
1408 while ( parser.nextTag() == XmlPullParser.START_TAG )
1409 {
1410 if ( "include".equals( parser.getName() ) )
1411 {
1412 includes.add( interpolatedTrimmed( parser.nextText(), "includes" ) );
1413 }
1414 else
1415 {
1416 checkUnknownElement( parser, strict );
1417 }
1418 }
1419 moduleSources.setIncludes( includes );
1420 }
1421 else if ( checkFieldWithDuplicate( parser, "excludes", null, parsed ) )
1422 {
1423 java.util.List<String> excludes = new java.util.ArrayList<String>();
1424 while ( parser.nextTag() == XmlPullParser.START_TAG )
1425 {
1426 if ( "exclude".equals( parser.getName() ) )
1427 {
1428 excludes.add( interpolatedTrimmed( parser.nextText(), "excludes" ) );
1429 }
1430 else
1431 {
1432 checkUnknownElement( parser, strict );
1433 }
1434 }
1435 moduleSources.setExcludes( excludes );
1436 }
1437 else if ( checkFieldWithDuplicate( parser, "fileMode", null, parsed ) )
1438 {
1439 moduleSources.setFileMode( interpolatedTrimmed( parser.nextText(), "fileMode" ) );
1440 }
1441 else if ( checkFieldWithDuplicate( parser, "directoryMode", null, parsed ) )
1442 {
1443 moduleSources.setDirectoryMode( interpolatedTrimmed( parser.nextText(), "directoryMode" ) );
1444 }
1445 else if ( checkFieldWithDuplicate( parser, "fileSets", null, parsed ) )
1446 {
1447 java.util.List<FileSet> fileSets = new java.util.ArrayList<FileSet>();
1448 while ( parser.nextTag() == XmlPullParser.START_TAG )
1449 {
1450 if ( "fileSet".equals( parser.getName() ) )
1451 {
1452 fileSets.add( parseFileSet( parser, strict ) );
1453 }
1454 else
1455 {
1456 checkUnknownElement( parser, strict );
1457 }
1458 }
1459 moduleSources.setFileSets( fileSets );
1460 }
1461 else if ( checkFieldWithDuplicate( parser, "includeModuleDirectory", null, parsed ) )
1462 {
1463 moduleSources.setIncludeModuleDirectory( getBooleanValue( interpolatedTrimmed( parser.nextText(), "includeModuleDirectory" ), "includeModuleDirectory", parser, "true" ) );
1464 }
1465 else if ( checkFieldWithDuplicate( parser, "excludeSubModuleDirectories", null, parsed ) )
1466 {
1467 moduleSources.setExcludeSubModuleDirectories( getBooleanValue( interpolatedTrimmed( parser.nextText(), "excludeSubModuleDirectories" ), "excludeSubModuleDirectories", parser, "true" ) );
1468 }
1469 else if ( checkFieldWithDuplicate( parser, "outputDirectoryMapping", null, parsed ) )
1470 {
1471 moduleSources.setOutputDirectoryMapping( interpolatedTrimmed( parser.nextText(), "outputDirectoryMapping" ) );
1472 }
1473 else
1474 {
1475 checkUnknownElement( parser, strict );
1476 }
1477 }
1478 return moduleSources;
1479 }
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491 private UnpackOptions parseUnpackOptions( XmlPullParser parser, boolean strict )
1492 throws IOException, XmlPullParserException
1493 {
1494 String tagName = parser.getName();
1495 UnpackOptions unpackOptions = new UnpackOptions();
1496 for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
1497 {
1498 String name = parser.getAttributeName( i );
1499 String value = parser.getAttributeValue( i );
1500
1501 if ( name.indexOf( ':' ) >= 0 )
1502 {
1503
1504 }
1505 else
1506 {
1507 checkUnknownAttribute( parser, name, tagName, strict );
1508 }
1509 }
1510 java.util.Set parsed = new java.util.HashSet();
1511 while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
1512 {
1513 if ( checkFieldWithDuplicate( parser, "includes", null, parsed ) )
1514 {
1515 java.util.List<String> includes = new java.util.ArrayList<String>();
1516 while ( parser.nextTag() == XmlPullParser.START_TAG )
1517 {
1518 if ( "include".equals( parser.getName() ) )
1519 {
1520 includes.add( interpolatedTrimmed( parser.nextText(), "includes" ) );
1521 }
1522 else
1523 {
1524 checkUnknownElement( parser, strict );
1525 }
1526 }
1527 unpackOptions.setIncludes( includes );
1528 }
1529 else if ( checkFieldWithDuplicate( parser, "excludes", null, parsed ) )
1530 {
1531 java.util.List<String> excludes = new java.util.ArrayList<String>();
1532 while ( parser.nextTag() == XmlPullParser.START_TAG )
1533 {
1534 if ( "exclude".equals( parser.getName() ) )
1535 {
1536 excludes.add( interpolatedTrimmed( parser.nextText(), "excludes" ) );
1537 }
1538 else
1539 {
1540 checkUnknownElement( parser, strict );
1541 }
1542 }
1543 unpackOptions.setExcludes( excludes );
1544 }
1545 else if ( checkFieldWithDuplicate( parser, "filtered", null, parsed ) )
1546 {
1547 unpackOptions.setFiltered( getBooleanValue( interpolatedTrimmed( parser.nextText(), "filtered" ), "filtered", parser, "false" ) );
1548 }
1549 else if ( checkFieldWithDuplicate( parser, "nonFilteredFileExtensions", null, parsed ) )
1550 {
1551 java.util.List<String> nonFilteredFileExtensions = new java.util.ArrayList<String>();
1552 while ( parser.nextTag() == XmlPullParser.START_TAG )
1553 {
1554 if ( "nonFilteredFileExtension".equals( parser.getName() ) )
1555 {
1556 nonFilteredFileExtensions.add( interpolatedTrimmed( parser.nextText(), "nonFilteredFileExtensions" ) );
1557 }
1558 else
1559 {
1560 checkUnknownElement( parser, strict );
1561 }
1562 }
1563 unpackOptions.setNonFilteredFileExtensions( nonFilteredFileExtensions );
1564 }
1565 else if ( checkFieldWithDuplicate( parser, "lineEnding", null, parsed ) )
1566 {
1567 unpackOptions.setLineEnding( interpolatedTrimmed( parser.nextText(), "lineEnding" ) );
1568 }
1569 else if ( checkFieldWithDuplicate( parser, "useDefaultExcludes", null, parsed ) )
1570 {
1571 unpackOptions.setUseDefaultExcludes( getBooleanValue( interpolatedTrimmed( parser.nextText(), "useDefaultExcludes" ), "useDefaultExcludes", parser, "true" ) );
1572 }
1573 else if ( checkFieldWithDuplicate( parser, "encoding", null, parsed ) )
1574 {
1575 unpackOptions.setEncoding( interpolatedTrimmed( parser.nextText(), "encoding" ) );
1576 }
1577 else
1578 {
1579 checkUnknownElement( parser, strict );
1580 }
1581 }
1582 return unpackOptions;
1583 }
1584
1585
1586
1587
1588
1589
1590 public void setAddDefaultEntities( boolean addDefaultEntities )
1591 {
1592 this.addDefaultEntities = addDefaultEntities;
1593 }
1594
1595 public static interface ContentTransformer
1596 {
1597
1598
1599
1600
1601
1602
1603
1604 String transform( String source, String fieldName );
1605 }
1606
1607 }