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