1 package org.apache.maven.archetype.common;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 import org.apache.maven.archetype.common.util.Format;
31 import org.apache.maven.archetype.common.util.XMLOutputter;
32 import org.apache.maven.model.Activation;
33 import org.apache.maven.model.ActivationFile;
34 import org.apache.maven.model.ActivationOS;
35 import org.apache.maven.model.ActivationProperty;
36 import org.apache.maven.model.Build;
37 import org.apache.maven.model.BuildBase;
38 import org.apache.maven.model.CiManagement;
39 import org.apache.maven.model.ConfigurationContainer;
40 import org.apache.maven.model.Contributor;
41 import org.apache.maven.model.Dependency;
42 import org.apache.maven.model.DependencyManagement;
43 import org.apache.maven.model.DeploymentRepository;
44 import org.apache.maven.model.Developer;
45 import org.apache.maven.model.DistributionManagement;
46 import org.apache.maven.model.Exclusion;
47 import org.apache.maven.model.Extension;
48 import org.apache.maven.model.FileSet;
49 import org.apache.maven.model.IssueManagement;
50 import org.apache.maven.model.License;
51 import org.apache.maven.model.MailingList;
52 import org.apache.maven.model.Model;
53 import org.apache.maven.model.ModelBase;
54 import org.apache.maven.model.Notifier;
55 import org.apache.maven.model.Organization;
56 import org.apache.maven.model.Parent;
57 import org.apache.maven.model.PatternSet;
58 import org.apache.maven.model.Plugin;
59 import org.apache.maven.model.PluginConfiguration;
60 import org.apache.maven.model.PluginContainer;
61 import org.apache.maven.model.PluginExecution;
62 import org.apache.maven.model.PluginManagement;
63 import org.apache.maven.model.Prerequisites;
64 import org.apache.maven.model.Profile;
65 import org.apache.maven.model.Relocation;
66 import org.apache.maven.model.ReportPlugin;
67 import org.apache.maven.model.ReportSet;
68 import org.apache.maven.model.Reporting;
69 import org.apache.maven.model.Repository;
70 import org.apache.maven.model.RepositoryBase;
71 import org.apache.maven.model.RepositoryPolicy;
72 import org.apache.maven.model.Resource;
73 import org.apache.maven.model.Scm;
74 import org.apache.maven.model.Site;
75 import org.codehaus.plexus.util.xml.Xpp3Dom;
76 import org.jdom2.Content;
77 import org.jdom2.DefaultJDOMFactory;
78 import org.jdom2.Document;
79 import org.jdom2.Element;
80 import org.jdom2.Text;
81
82 import java.io.OutputStream;
83 import java.io.OutputStreamWriter;
84 import java.io.Writer;
85 import java.util.ArrayList;
86 import java.util.Collection;
87 import java.util.Iterator;
88 import java.util.List;
89 import java.util.ListIterator;
90 import java.util.Map;
91
92
93
94
95 public class MavenJDOMWriter
96 {
97
98
99
100
101
102
103
104 private DefaultJDOMFactory factory;
105
106
107
108
109 private String lineSeparator;
110
111 private static final String LS = System.getProperty( "line.separator" );
112
113
114
115
116
117 public MavenJDOMWriter()
118 {
119 factory = new DefaultJDOMFactory();
120 lineSeparator = "\n";
121 }
122
123
124
125
126
127
128
129
130
131 @Deprecated
132 public void write( Model project, Document document, OutputStream stream )
133 throws java.io.IOException
134 {
135 updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
136
137 XMLOutputter outputter = new XMLOutputter();
138 outputter.setFormat( Format.getPrettyFormat().setIndent( " " ).setLineSeparator( LS ) );
139 outputter.output( document, stream );
140 }
141
142
143
144
145
146
147
148
149 public void write( Model project, Document document, OutputStreamWriter writer )
150 throws java.io.IOException
151 {
152 Format format = Format.getRawFormat().setEncoding( writer.getEncoding() ).setLineSeparator( LS );
153 write( project, document, writer, format );
154 }
155
156
157
158
159
160
161
162
163
164 public void write( Model project, Document document, Writer writer, Format jdomFormat )
165 throws java.io.IOException
166 {
167 updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
168
169 XMLOutputter outputter = new XMLOutputter();
170 outputter.setFormat( jdomFormat );
171 outputter.output( document, writer );
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185
186 protected Element findAndReplaceProperties( Counter counter, Element parent, String name, Map props )
187 {
188 boolean shouldExist = ( props != null ) && !props.isEmpty();
189 Element element = updateElement( counter, parent, name, shouldExist );
190 if ( shouldExist )
191 {
192 Iterator it = props.keySet().iterator();
193 Counter innerCounter = new Counter( counter.getDepth() + 1 );
194 while ( it.hasNext() )
195 {
196 String key = (String) it.next();
197 findAndReplaceSimpleElement( innerCounter, element, key, (String) props.get( key ), null );
198 }
199
200 List<String> lst = new ArrayList<>( props.keySet() );
201 it = element.getChildren().iterator();
202 while ( it.hasNext() )
203 {
204 Element elem = (Element) it.next();
205 String key = elem.getName();
206 if ( !lst.contains( key ) )
207 {
208 it.remove();
209 }
210 }
211 }
212 return element;
213 }
214
215
216
217
218
219
220
221
222
223
224 protected Element findAndReplaceSimpleElement( Counter counter, Element parent, String name, String text,
225 String defaultValue )
226 {
227 if ( ( defaultValue != null ) && ( text != null ) && defaultValue.equals( text ) )
228 {
229 Element element = parent.getChild( name, parent.getNamespace() );
230
231 if ( ( ( element != null ) && defaultValue.equals( element.getText() ) ) || ( element == null ) )
232 {
233 return element;
234 }
235 }
236
237 boolean shouldExist = ( text != null ) && ( text.trim().length() > 0 );
238 Element element = updateElement( counter, parent, name, shouldExist );
239 if ( shouldExist )
240 {
241 element.setText( text );
242 }
243 return element;
244 }
245
246
247
248
249
250
251
252
253
254
255 protected Element findAndReplaceSimpleLists( Counter counter, Element parent, Collection list,
256 String parentName, String childName )
257 {
258 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
259 Element element = updateElement( counter, parent, parentName, shouldExist );
260 if ( shouldExist )
261 {
262 Iterator it = list.iterator();
263 Iterator elIt = element.getChildren( childName, element.getNamespace() ).iterator();
264 if ( !elIt.hasNext() )
265 {
266 elIt = null;
267 }
268
269 Counter innerCount = new Counter( counter.getDepth() + 1 );
270 while ( it.hasNext() )
271 {
272 String value = (String) it.next();
273 Element el;
274 if ( ( elIt != null ) && elIt.hasNext() )
275 {
276 el = (Element) elIt.next();
277 if ( !elIt.hasNext() )
278 {
279 elIt = null;
280 }
281 }
282 else
283 {
284 el = factory.element( childName, element.getNamespace() );
285 insertAtPreferredLocation( element, el, innerCount );
286 }
287 el.setText( value );
288 innerCount.increaseCount();
289 }
290 if ( elIt != null )
291 {
292 while ( elIt.hasNext() )
293 {
294 elIt.next();
295 elIt.remove();
296 }
297 }
298 }
299 return element;
300 }
301
302
303
304
305
306
307
308
309
310 protected Element findAndReplaceXpp3DOM( Counter counter, Element parent, String name, Xpp3Dom dom )
311 {
312 boolean shouldExist = ( dom != null ) && ( ( dom.getChildCount() > 0 ) || ( dom.getValue() != null ) );
313 Element element = updateElement( counter, parent, name, shouldExist );
314 if ( shouldExist )
315 {
316 replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );
317 }
318 return element;
319 }
320
321
322
323
324
325
326
327
328 protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
329 {
330 int contentIndex = 0;
331 int elementCounter = 0;
332 Iterator it = parent.getContent().iterator();
333 Text lastText = null;
334 int offset = 0;
335 while ( it.hasNext() && ( elementCounter <= counter.getCurrentIndex() ) )
336 {
337 Object next = it.next();
338 offset = offset + 1;
339 if ( next instanceof Element )
340 {
341 elementCounter = elementCounter + 1;
342 contentIndex = contentIndex + offset;
343 offset = 0;
344 }
345 if ( ( next instanceof Text ) && it.hasNext() )
346 {
347 lastText = (Text) next;
348 }
349 }
350 if ( ( lastText != null ) && ( lastText.getTextTrim().length() == 0 ) )
351 {
352 lastText = (Text) lastText.clone();
353 }
354 else
355 {
356 StringBuilder starter = new StringBuilder( lineSeparator );
357 for ( int i = 0; i < counter.getDepth(); i++ )
358 {
359 starter.append( " " );
360 }
361 lastText = factory.text( starter.toString() );
362 }
363 if ( parent.getContentSize() == 0 )
364 {
365 Text finalText = (Text) lastText.clone();
366 finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - " ".length() ) );
367 parent.addContent( contentIndex, finalText );
368 }
369 parent.addContent( contentIndex, child );
370 parent.addContent( contentIndex, lastText );
371 }
372
373
374
375
376
377
378
379
380
381
382 protected void iterateContributor( Counter counter, Element parent, Collection list,
383 String parentTag, String childTag )
384 {
385 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
386 Element element = updateElement( counter, parent, parentTag, shouldExist );
387 if ( shouldExist )
388 {
389 Iterator it = list.iterator();
390 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
391 if ( !elIt.hasNext() )
392 {
393 elIt = null;
394 }
395
396 Counter innerCount = new Counter( counter.getDepth() + 1 );
397 while ( it.hasNext() )
398 {
399 Contributor value = (Contributor) it.next();
400 Element el;
401 if ( ( elIt != null ) && elIt.hasNext() )
402 {
403 el = (Element) elIt.next();
404 if ( !elIt.hasNext() )
405 {
406 elIt = null;
407 }
408 }
409 else
410 {
411 el = factory.element( childTag, element.getNamespace() );
412 insertAtPreferredLocation( element, el, innerCount );
413 }
414 updateContributor( value, childTag, innerCount, el );
415 innerCount.increaseCount();
416 }
417 if ( elIt != null )
418 {
419 while ( elIt.hasNext() )
420 {
421 elIt.next();
422 elIt.remove();
423 }
424 }
425 }
426 }
427
428
429
430
431
432
433
434
435
436
437
438 protected void iterateDependency( Counter counter, Element parent, Collection list,
439 String parentTag, String childTag )
440 {
441 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
442 Element element = updateElement( counter, parent, parentTag, shouldExist );
443 if ( shouldExist )
444 {
445 Iterator it = list.iterator();
446 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
447 if ( !elIt.hasNext() )
448 {
449 elIt = null;
450 }
451
452 Counter innerCount = new Counter( counter.getDepth() + 1 );
453 while ( it.hasNext() )
454 {
455 Dependency value = (Dependency) it.next();
456 Element el;
457 if ( ( elIt != null ) && elIt.hasNext() )
458 {
459 el = (Element) elIt.next();
460 if ( !elIt.hasNext() )
461 {
462 elIt = null;
463 }
464 }
465 else
466 {
467 el = factory.element( childTag, element.getNamespace() );
468 insertAtPreferredLocation( element, el, innerCount );
469 }
470 updateDependency( value, childTag, innerCount, el );
471 innerCount.increaseCount();
472 }
473 if ( elIt != null )
474 {
475 while ( elIt.hasNext() )
476 {
477 elIt.next();
478 elIt.remove();
479 }
480 }
481 }
482 }
483
484
485
486
487
488
489
490
491
492
493
494 protected void iterateDeveloper( Counter counter, Element parent, Collection list,
495 String parentTag, String childTag )
496 {
497 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
498 Element element = updateElement( counter, parent, parentTag, shouldExist );
499 if ( shouldExist )
500 {
501 Iterator it = list.iterator();
502 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
503 if ( !elIt.hasNext() )
504 {
505 elIt = null;
506 }
507
508 Counter innerCount = new Counter( counter.getDepth() + 1 );
509 while ( it.hasNext() )
510 {
511 Developer value = (Developer) it.next();
512 Element el;
513 if ( ( elIt != null ) && elIt.hasNext() )
514 {
515 el = (Element) elIt.next();
516 if ( !elIt.hasNext() )
517 {
518 elIt = null;
519 }
520 }
521 else
522 {
523 el = factory.element( childTag, element.getNamespace() );
524 insertAtPreferredLocation( element, el, innerCount );
525 }
526 updateDeveloper( value, childTag, innerCount, el );
527 innerCount.increaseCount();
528 }
529 if ( elIt != null )
530 {
531 while ( elIt.hasNext() )
532 {
533 elIt.next();
534 elIt.remove();
535 }
536 }
537 }
538 }
539
540
541
542
543
544
545
546
547
548
549
550 protected void iterateExclusion( Counter counter, Element parent, Collection list,
551 String parentTag, String childTag )
552 {
553 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
554 Element element = updateElement( counter, parent, parentTag, shouldExist );
555 if ( shouldExist )
556 {
557 Iterator it = list.iterator();
558 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
559 if ( !elIt.hasNext() )
560 {
561 elIt = null;
562 }
563
564 Counter innerCount = new Counter( counter.getDepth() + 1 );
565 while ( it.hasNext() )
566 {
567 Exclusion value = (Exclusion) it.next();
568 Element el;
569 if ( ( elIt != null ) && elIt.hasNext() )
570 {
571 el = (Element) elIt.next();
572 if ( !elIt.hasNext() )
573 {
574 elIt = null;
575 }
576 }
577 else
578 {
579 el = factory.element( childTag, element.getNamespace() );
580 insertAtPreferredLocation( element, el, innerCount );
581 }
582 updateExclusion( value, childTag, innerCount, el );
583 innerCount.increaseCount();
584 }
585 if ( elIt != null )
586 {
587 while ( elIt.hasNext() )
588 {
589 elIt.next();
590 elIt.remove();
591 }
592 }
593 }
594 }
595
596
597
598
599
600
601
602
603
604
605 protected void iterateExtension( Counter counter, Element parent, Collection list,
606 String parentTag, String childTag )
607 {
608 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
609 Element element = updateElement( counter, parent, parentTag, shouldExist );
610 if ( shouldExist )
611 {
612 Iterator it = list.iterator();
613 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
614 if ( !elIt.hasNext() )
615 {
616 elIt = null;
617 }
618
619 Counter innerCount = new Counter( counter.getDepth() + 1 );
620 while ( it.hasNext() )
621 {
622 Extension value = (Extension) it.next();
623 Element el;
624 if ( ( elIt != null ) && elIt.hasNext() )
625 {
626 el = (Element) elIt.next();
627 if ( !elIt.hasNext() )
628 {
629 elIt = null;
630 }
631 }
632 else
633 {
634 el = factory.element( childTag, element.getNamespace() );
635 insertAtPreferredLocation( element, el, innerCount );
636 }
637 updateExtension( value, childTag, innerCount, el );
638 innerCount.increaseCount();
639 }
640 if ( elIt != null )
641 {
642 while ( elIt.hasNext() )
643 {
644 elIt.next();
645 elIt.remove();
646 }
647 }
648 }
649 }
650
651
652
653
654
655
656
657
658
659
660 protected void iterateLicense( Counter counter, Element parent, Collection list,
661 String parentTag, String childTag )
662 {
663 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
664 Element element = updateElement( counter, parent, parentTag, shouldExist );
665 if ( shouldExist )
666 {
667 Iterator it = list.iterator();
668 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
669 if ( !elIt.hasNext() )
670 {
671 elIt = null;
672 }
673
674 Counter innerCount = new Counter( counter.getDepth() + 1 );
675 while ( it.hasNext() )
676 {
677 License value = (License) it.next();
678 Element el;
679 if ( ( elIt != null ) && elIt.hasNext() )
680 {
681 el = (Element) elIt.next();
682 if ( !elIt.hasNext() )
683 {
684 elIt = null;
685 }
686 }
687 else
688 {
689 el = factory.element( childTag, element.getNamespace() );
690 insertAtPreferredLocation( element, el, innerCount );
691 }
692 updateLicense( value, childTag, innerCount, el );
693 innerCount.increaseCount();
694 }
695 if ( elIt != null )
696 {
697 while ( elIt.hasNext() )
698 {
699 elIt.next();
700 elIt.remove();
701 }
702 }
703 }
704 }
705
706
707
708
709
710
711
712
713
714
715
716 protected void iterateMailingList( Counter counter, Element parent, java.util.Collection list,
717 String parentTag, String childTag )
718 {
719 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
720 Element element = updateElement( counter, parent, parentTag, shouldExist );
721 if ( shouldExist )
722 {
723 Iterator it = list.iterator();
724 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
725 if ( !elIt.hasNext() )
726 {
727 elIt = null;
728 }
729
730 Counter innerCount = new Counter( counter.getDepth() + 1 );
731 while ( it.hasNext() )
732 {
733 MailingList value = (MailingList) it.next();
734 Element el;
735 if ( ( elIt != null ) && elIt.hasNext() )
736 {
737 el = (Element) elIt.next();
738 if ( !elIt.hasNext() )
739 {
740 elIt = null;
741 }
742 }
743 else
744 {
745 el = factory.element( childTag, element.getNamespace() );
746 insertAtPreferredLocation( element, el, innerCount );
747 }
748 updateMailingList( value, childTag, innerCount, el );
749 innerCount.increaseCount();
750 }
751 if ( elIt != null )
752 {
753 while ( elIt.hasNext() )
754 {
755 elIt.next();
756 elIt.remove();
757 }
758 }
759 }
760 }
761
762
763
764
765
766
767
768
769
770
771
772 protected void iterateNotifier( Counter counter, Element parent, java.util.Collection list,
773 String parentTag, String childTag )
774 {
775 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
776 Element element = updateElement( counter, parent, parentTag, shouldExist );
777 if ( shouldExist )
778 {
779 Iterator it = list.iterator();
780 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
781 if ( !elIt.hasNext() )
782 {
783 elIt = null;
784 }
785
786 Counter innerCount = new Counter( counter.getDepth() + 1 );
787 while ( it.hasNext() )
788 {
789 Notifier value = (Notifier) it.next();
790 Element el;
791 if ( ( elIt != null ) && elIt.hasNext() )
792 {
793 el = (Element) elIt.next();
794 if ( !elIt.hasNext() )
795 {
796 elIt = null;
797 }
798 }
799 else
800 {
801 el = factory.element( childTag, element.getNamespace() );
802 insertAtPreferredLocation( element, el, innerCount );
803 }
804 updateNotifier( value, childTag, innerCount, el );
805 innerCount.increaseCount();
806 }
807 if ( elIt != null )
808 {
809 while ( elIt.hasNext() )
810 {
811 elIt.next();
812 elIt.remove();
813 }
814 }
815 }
816 }
817
818
819
820
821
822
823
824
825
826
827
828 protected void iteratePlugin( Counter counter, Element parent, java.util.Collection list,
829 String parentTag, String childTag )
830 {
831 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
832 Element element = updateElement( counter, parent, parentTag, shouldExist );
833 if ( shouldExist )
834 {
835 Iterator it = list.iterator();
836 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
837 if ( !elIt.hasNext() )
838 {
839 elIt = null;
840 }
841
842 Counter innerCount = new Counter( counter.getDepth() + 1 );
843 while ( it.hasNext() )
844 {
845 Plugin value = (Plugin) it.next();
846 Element el;
847 if ( ( elIt != null ) && elIt.hasNext() )
848 {
849 el = (Element) elIt.next();
850 if ( !elIt.hasNext() )
851 {
852 elIt = null;
853 }
854 }
855 else
856 {
857 el = factory.element( childTag, element.getNamespace() );
858 insertAtPreferredLocation( element, el, innerCount );
859 }
860 updatePlugin( value, childTag, innerCount, el );
861 innerCount.increaseCount();
862 }
863 if ( elIt != null )
864 {
865 while ( elIt.hasNext() )
866 {
867 elIt.next();
868 elIt.remove();
869 }
870 }
871 }
872 }
873
874
875
876
877
878
879
880
881
882
883
884 protected void iteratePluginExecution( Counter counter, Element parent, java.util.Collection list,
885 String parentTag, String childTag )
886 {
887 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
888 Element element = updateElement( counter, parent, parentTag, shouldExist );
889 if ( shouldExist )
890 {
891 Iterator it = list.iterator();
892 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
893 if ( !elIt.hasNext() )
894 {
895 elIt = null;
896 }
897
898 Counter innerCount = new Counter( counter.getDepth() + 1 );
899 while ( it.hasNext() )
900 {
901 PluginExecution value = (PluginExecution) it.next();
902 Element el;
903 if ( ( elIt != null ) && elIt.hasNext() )
904 {
905 el = (Element) elIt.next();
906 if ( !elIt.hasNext() )
907 {
908 elIt = null;
909 }
910 }
911 else
912 {
913 el = factory.element( childTag, element.getNamespace() );
914 insertAtPreferredLocation( element, el, innerCount );
915 }
916 updatePluginExecution( value, childTag, innerCount, el );
917 innerCount.increaseCount();
918 }
919 if ( elIt != null )
920 {
921 while ( elIt.hasNext() )
922 {
923 elIt.next();
924 elIt.remove();
925 }
926 }
927 }
928 }
929
930
931
932
933
934
935
936
937
938
939
940 protected void iterateProfile( Counter counter, Element parent, java.util.Collection list,
941 String parentTag, String childTag )
942 {
943 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
944 Element element = updateElement( counter, parent, parentTag, shouldExist );
945 if ( shouldExist )
946 {
947 Iterator it = list.iterator();
948 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
949 if ( !elIt.hasNext() )
950 {
951 elIt = null;
952 }
953
954 Counter innerCount = new Counter( counter.getDepth() + 1 );
955 while ( it.hasNext() )
956 {
957 Profile value = (Profile) it.next();
958 Element el;
959 if ( ( elIt != null ) && elIt.hasNext() )
960 {
961 el = (Element) elIt.next();
962 if ( !elIt.hasNext() )
963 {
964 elIt = null;
965 }
966 }
967 else
968 {
969 el = factory.element( childTag, element.getNamespace() );
970 insertAtPreferredLocation( element, el, innerCount );
971 }
972 updateProfile( value, childTag, innerCount, el );
973 innerCount.increaseCount();
974 }
975 if ( elIt != null )
976 {
977 while ( elIt.hasNext() )
978 {
979 elIt.next();
980 elIt.remove();
981 }
982 }
983 }
984 }
985
986
987
988
989
990
991
992
993
994
995
996 protected void iterateReportPlugin( Counter counter, Element parent, java.util.Collection list,
997 String parentTag, String childTag )
998 {
999 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
1000 Element element = updateElement( counter, parent, parentTag, shouldExist );
1001 if ( shouldExist )
1002 {
1003 Iterator it = list.iterator();
1004 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1005 if ( !elIt.hasNext() )
1006 {
1007 elIt = null;
1008 }
1009
1010 Counter innerCount = new Counter( counter.getDepth() + 1 );
1011 while ( it.hasNext() )
1012 {
1013 ReportPlugin value = (ReportPlugin) it.next();
1014 Element el;
1015 if ( ( elIt != null ) && elIt.hasNext() )
1016 {
1017 el = (Element) elIt.next();
1018 if ( !elIt.hasNext() )
1019 {
1020 elIt = null;
1021 }
1022 }
1023 else
1024 {
1025 el = factory.element( childTag, element.getNamespace() );
1026 insertAtPreferredLocation( element, el, innerCount );
1027 }
1028 updateReportPlugin( value, childTag, innerCount, el );
1029 innerCount.increaseCount();
1030 }
1031 if ( elIt != null )
1032 {
1033 while ( elIt.hasNext() )
1034 {
1035 elIt.next();
1036 elIt.remove();
1037 }
1038 }
1039 }
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052 protected void iterateReportSet( Counter counter, Element parent, java.util.Collection list,
1053 String parentTag, String childTag )
1054 {
1055 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
1056 Element element = updateElement( counter, parent, parentTag, shouldExist );
1057 if ( shouldExist )
1058 {
1059 Iterator it = list.iterator();
1060 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1061 if ( !elIt.hasNext() )
1062 {
1063 elIt = null;
1064 }
1065
1066 Counter innerCount = new Counter( counter.getDepth() + 1 );
1067 while ( it.hasNext() )
1068 {
1069 ReportSet value = (ReportSet) it.next();
1070 Element el;
1071 if ( ( elIt != null ) && elIt.hasNext() )
1072 {
1073 el = (Element) elIt.next();
1074 if ( !elIt.hasNext() )
1075 {
1076 elIt = null;
1077 }
1078 }
1079 else
1080 {
1081 el = factory.element( childTag, element.getNamespace() );
1082 insertAtPreferredLocation( element, el, innerCount );
1083 }
1084 updateReportSet( value, childTag, innerCount, el );
1085 innerCount.increaseCount();
1086 }
1087 if ( elIt != null )
1088 {
1089 while ( elIt.hasNext() )
1090 {
1091 elIt.next();
1092 elIt.remove();
1093 }
1094 }
1095 }
1096 }
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108 protected void iterateRepository( Counter counter, Element parent, java.util.Collection list,
1109 String parentTag, String childTag )
1110 {
1111 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
1112 Element element = updateElement( counter, parent, parentTag, shouldExist );
1113 if ( shouldExist )
1114 {
1115 Iterator it = list.iterator();
1116 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1117 if ( !elIt.hasNext() )
1118 {
1119 elIt = null;
1120 }
1121
1122 Counter innerCount = new Counter( counter.getDepth() + 1 );
1123 while ( it.hasNext() )
1124 {
1125 Repository value = (Repository) it.next();
1126 Element el;
1127 if ( ( elIt != null ) && elIt.hasNext() )
1128 {
1129 el = (Element) elIt.next();
1130 if ( !elIt.hasNext() )
1131 {
1132 elIt = null;
1133 }
1134 }
1135 else
1136 {
1137 el = factory.element( childTag, element.getNamespace() );
1138 insertAtPreferredLocation( element, el, innerCount );
1139 }
1140 updateRepository( value, childTag, innerCount, el );
1141 innerCount.increaseCount();
1142 }
1143 if ( elIt != null )
1144 {
1145 while ( elIt.hasNext() )
1146 {
1147 elIt.next();
1148 elIt.remove();
1149 }
1150 }
1151 }
1152 }
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164 protected void iterateResource( Counter counter, Element parent, java.util.Collection list,
1165 String parentTag, String childTag )
1166 {
1167 boolean shouldExist = ( list != null ) && ( list.size() > 0 );
1168 Element element = updateElement( counter, parent, parentTag, shouldExist );
1169 if ( shouldExist )
1170 {
1171 Iterator it = list.iterator();
1172 Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1173 if ( !elIt.hasNext() )
1174 {
1175 elIt = null;
1176 }
1177
1178 Counter innerCount = new Counter( counter.getDepth() + 1 );
1179 while ( it.hasNext() )
1180 {
1181 Resource value = (Resource) it.next();
1182 Element el;
1183 if ( ( elIt != null ) && elIt.hasNext() )
1184 {
1185 el = (Element) elIt.next();
1186 if ( !elIt.hasNext() )
1187 {
1188 elIt = null;
1189 }
1190 }
1191 else
1192 {
1193 el = factory.element( childTag, element.getNamespace() );
1194 insertAtPreferredLocation( element, el, innerCount );
1195 }
1196 updateResource( value, childTag, innerCount, el );
1197 innerCount.increaseCount();
1198 }
1199 if ( elIt != null )
1200 {
1201 while ( elIt.hasNext() )
1202 {
1203 elIt.next();
1204 elIt.remove();
1205 }
1206 }
1207 }
1208 }
1209
1210
1211
1212
1213
1214
1215
1216
1217 protected void replaceXpp3DOM( Element parent, Xpp3Dom parentDom, Counter counter )
1218 {
1219 if ( parentDom.getChildCount() > 0 )
1220 {
1221 Xpp3Dom[] childs = parentDom.getChildren();
1222 Collection domChilds = new ArrayList();
1223 for ( int i = 0; i < childs.length; i++ )
1224 {
1225 domChilds.add( childs[i] );
1226 }
1227
1228 ListIterator it = parent.getChildren().listIterator();
1229 while ( it.hasNext() )
1230 {
1231 Element elem = (Element) it.next();
1232 Iterator it2 = domChilds.iterator();
1233 Xpp3Dom corrDom = null;
1234 while ( it2.hasNext() )
1235 {
1236 Xpp3Dom dm = (Xpp3Dom) it2.next();
1237 if ( dm.getName().equals( elem.getName() ) )
1238 {
1239 corrDom = dm;
1240 break;
1241 }
1242 }
1243 if ( corrDom != null )
1244 {
1245 domChilds.remove( corrDom );
1246 replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );
1247 counter.increaseCount();
1248 }
1249 else
1250 {
1251 parent.removeContent( elem );
1252 }
1253 }
1254
1255 Iterator it2 = domChilds.iterator();
1256 while ( it2.hasNext() )
1257 {
1258 Xpp3Dom dm = (Xpp3Dom) it2.next();
1259 Element elem = factory.element( dm.getName(), parent.getNamespace() );
1260 insertAtPreferredLocation( parent, elem, counter );
1261 counter.increaseCount();
1262 replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );
1263 }
1264 }
1265 else if ( parentDom.getValue() != null )
1266 {
1267 parent.setText( parentDom.getValue() );
1268 }
1269 }
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279 protected void updateActivation( Activation value, String xmlTag, Counter counter, Element element )
1280 {
1281 boolean shouldExist = value != null;
1282 Element root = updateElement( counter, element, xmlTag, shouldExist );
1283 if ( shouldExist )
1284 {
1285 Counter innerCount = new Counter( counter.getDepth() + 1 );
1286 findAndReplaceSimpleElement( innerCount, root, "activeByDefault", ( value.isActiveByDefault() == false )
1287 ? null
1288 : String.valueOf( value.isActiveByDefault() ), "false" );
1289 findAndReplaceSimpleElement( innerCount, root, "jdk", value.getJdk(), null );
1290 updateActivationOS( value.getOs(), "os", innerCount, root );
1291 updateActivationProperty( value.getProperty(), "property", innerCount, root );
1292 updateActivationFile( value.getFile(), "file", innerCount, root );
1293 }
1294 }
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304 protected void updateActivationFile( ActivationFile value, String xmlTag, Counter counter, Element element )
1305 {
1306 boolean shouldExist = value != null;
1307 Element root = updateElement( counter, element, xmlTag, shouldExist );
1308 if ( shouldExist )
1309 {
1310 Counter innerCount = new Counter( counter.getDepth() + 1 );
1311 findAndReplaceSimpleElement( innerCount, root, "missing", value.getMissing(), null );
1312 findAndReplaceSimpleElement( innerCount, root, "exists", value.getExists(), null );
1313 }
1314 }
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324 protected void updateActivationOS( ActivationOS value, String xmlTag, Counter counter, Element element )
1325 {
1326 boolean shouldExist = value != null;
1327 Element root = updateElement( counter, element, xmlTag, shouldExist );
1328 if ( shouldExist )
1329 {
1330 Counter innerCount = new Counter( counter.getDepth() + 1 );
1331 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1332 findAndReplaceSimpleElement( innerCount, root, "family", value.getFamily(), null );
1333 findAndReplaceSimpleElement( innerCount, root, "arch", value.getArch(), null );
1334 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1335 }
1336 }
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346 protected void updateActivationProperty( ActivationProperty value, String xmlTag, Counter counter, Element element )
1347 {
1348 boolean shouldExist = value != null;
1349 Element root = updateElement( counter, element, xmlTag, shouldExist );
1350 if ( shouldExist )
1351 {
1352 Counter innerCount = new Counter( counter.getDepth() + 1 );
1353 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1354 findAndReplaceSimpleElement( innerCount, root, "value", value.getValue(), null );
1355 }
1356 }
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366 protected void updateBuild( Build value, String xmlTag, Counter counter, Element element )
1367 {
1368 boolean shouldExist = value != null;
1369 Element root = updateElement( counter, element, xmlTag, shouldExist );
1370 if ( shouldExist )
1371 {
1372 Counter innerCount = new Counter( counter.getDepth() + 1 );
1373 findAndReplaceSimpleElement( innerCount, root, "sourceDirectory", value.getSourceDirectory(), null );
1374 findAndReplaceSimpleElement( innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
1375 null );
1376 findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(),
1377 null );
1378 findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
1379 findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(),
1380 null );
1381 iterateExtension( innerCount, root, value.getExtensions(), "extensions", "extension" );
1382 findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
1383 iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
1384 iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
1385 findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1386 findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
1387 findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
1388 updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1389 iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1390 }
1391 }
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401 protected void updateBuildBase( BuildBase value, String xmlTag, Counter counter, Element element )
1402 {
1403 boolean shouldExist = value != null;
1404 Element root = updateElement( counter, element, xmlTag, shouldExist );
1405 if ( shouldExist )
1406 {
1407 Counter innerCount = new Counter( counter.getDepth() + 1 );
1408 findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
1409 iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
1410 iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
1411 findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1412 findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
1413 findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
1414 updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1415 iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1416 }
1417 }
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427 protected void updateCiManagement( CiManagement value, String xmlTag, Counter counter, Element element )
1428 {
1429 boolean shouldExist = value != null;
1430 Element root = updateElement( counter, element, xmlTag, shouldExist );
1431 if ( shouldExist )
1432 {
1433 Counter innerCount = new Counter( counter.getDepth() + 1 );
1434 findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
1435 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1436 iterateNotifier( innerCount, root, value.getNotifiers(), "notifiers", "notifier" );
1437 }
1438 }
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448 protected void updateConfigurationContainer( ConfigurationContainer value, String xmlTag, Counter counter,
1449 Element element )
1450 {
1451 boolean shouldExist = value != null;
1452 Element root = updateElement( counter, element, xmlTag, shouldExist );
1453 if ( shouldExist )
1454 {
1455 Counter innerCount = new Counter( counter.getDepth() + 1 );
1456 findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
1457 findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
1458 }
1459 }
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469 protected void updateContributor( Contributor value, String xmlTag, Counter counter, Element element )
1470 {
1471 Element root = element;
1472 Counter innerCount = new Counter( counter.getDepth() + 1 );
1473 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1474 findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
1475 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1476 findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
1477 findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
1478 findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
1479 findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
1480 findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1481 }
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491 protected void updateDependency( Dependency value, String xmlTag, Counter counter, Element element )
1492 {
1493 Element root = element;
1494 Counter innerCount = new Counter( counter.getDepth() + 1 );
1495 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1496 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1497 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1498 findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "jar" );
1499 findAndReplaceSimpleElement( innerCount, root, "classifier", value.getClassifier(), null );
1500 findAndReplaceSimpleElement( innerCount, root, "scope", value.getScope(), null );
1501 findAndReplaceSimpleElement( innerCount, root, "systemPath", value.getSystemPath(), null );
1502 iterateExclusion( innerCount, root, value.getExclusions(), "exclusions", "exclusion" );
1503 findAndReplaceSimpleElement( innerCount, root, "optional",
1504 ( value.isOptional() == false ) ? null : String.valueOf( value.isOptional() ),
1505 "false" );
1506 }
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516 protected void updateDependencyManagement( DependencyManagement value, String xmlTag, Counter counter,
1517 Element element )
1518 {
1519 boolean shouldExist = value != null;
1520 Element root = updateElement( counter, element, xmlTag, shouldExist );
1521 if ( shouldExist )
1522 {
1523 Counter innerCount = new Counter( counter.getDepth() + 1 );
1524 iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1525 }
1526 }
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536 protected void updateDeploymentRepository( DeploymentRepository value, String xmlTag, Counter counter,
1537 Element element )
1538 {
1539 boolean shouldExist = value != null;
1540 Element root = updateElement( counter, element, xmlTag, shouldExist );
1541 if ( shouldExist )
1542 {
1543 Counter innerCount = new Counter( counter.getDepth() + 1 );
1544 findAndReplaceSimpleElement( innerCount, root, "uniqueVersion", ( value.isUniqueVersion() == true )
1545 ? null
1546 : String.valueOf( value.isUniqueVersion() ), "true" );
1547 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
1548 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1549 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1550 findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
1551 }
1552 }
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562 protected void updateDeveloper( Developer value, String xmlTag, Counter counter, Element element )
1563 {
1564 Element root = element;
1565 Counter innerCount = new Counter( counter.getDepth() + 1 );
1566 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
1567 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1568 findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
1569 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1570 findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
1571 findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
1572 findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
1573 findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
1574 findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1575 }
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585 protected void updateDistributionManagement( DistributionManagement value, String xmlTag, Counter counter,
1586 Element element )
1587 {
1588 boolean shouldExist = value != null;
1589 Element root = updateElement( counter, element, xmlTag, shouldExist );
1590 if ( shouldExist )
1591 {
1592 Counter innerCount = new Counter( counter.getDepth() + 1 );
1593 updateDeploymentRepository( value.getRepository(), "repository", innerCount, root );
1594 updateDeploymentRepository( value.getSnapshotRepository(), "snapshotRepository", innerCount, root );
1595 updateSite( value.getSite(), "site", innerCount, root );
1596 findAndReplaceSimpleElement( innerCount, root, "downloadUrl", value.getDownloadUrl(), null );
1597 updateRelocation( value.getRelocation(), "relocation", innerCount, root );
1598 findAndReplaceSimpleElement( innerCount, root, "status", value.getStatus(), null );
1599 }
1600 }
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610 protected Element updateElement( Counter counter, Element parent, String name, boolean shouldExist )
1611 {
1612 Element element = parent.getChild( name, parent.getNamespace() );
1613 if ( ( element != null ) && shouldExist )
1614 {
1615 counter.increaseCount();
1616 }
1617 if ( ( element == null ) && shouldExist )
1618 {
1619 element = factory.element( name, parent.getNamespace() );
1620 insertAtPreferredLocation( parent, element, counter );
1621 counter.increaseCount();
1622 }
1623 if ( !shouldExist && ( element != null ) )
1624 {
1625 int index = parent.indexOf( element );
1626 if ( index > 0 )
1627 {
1628 Content previous = parent.getContent( index - 1 );
1629 if ( previous instanceof Text )
1630 {
1631 Text txt = (Text) previous;
1632 if ( txt.getTextTrim().length() == 0 )
1633 {
1634 parent.removeContent( txt );
1635 }
1636 }
1637 }
1638 parent.removeContent( element );
1639 }
1640 return element;
1641 }
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651 protected void updateExclusion( Exclusion value, String xmlTag, Counter counter, Element element )
1652 {
1653 Element root = element;
1654 Counter innerCount = new Counter( counter.getDepth() + 1 );
1655 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1656 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1657 }
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667 protected void updateExtension( Extension value, String xmlTag, Counter counter, Element element )
1668 {
1669 Element root = element;
1670 Counter innerCount = new Counter( counter.getDepth() + 1 );
1671 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1672 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1673 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1674 }
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684 protected void updateFileSet( FileSet value, String xmlTag, Counter counter, Element element )
1685 {
1686 boolean shouldExist = value != null;
1687 Element root = updateElement( counter, element, xmlTag, shouldExist );
1688 if ( shouldExist )
1689 {
1690 Counter innerCount = new Counter( counter.getDepth() + 1 );
1691 findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1692 findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
1693 findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
1694 }
1695 }
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705 protected void updateIssueManagement( IssueManagement value, String xmlTag, Counter counter, Element element )
1706 {
1707 boolean shouldExist = value != null;
1708 Element root = updateElement( counter, element, xmlTag, shouldExist );
1709 if ( shouldExist )
1710 {
1711 Counter innerCount = new Counter( counter.getDepth() + 1 );
1712 findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
1713 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1714 }
1715 }
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725 protected void updateLicense( License value, String xmlTag, Counter counter, Element element )
1726 {
1727 Element root = element;
1728 Counter innerCount = new Counter( counter.getDepth() + 1 );
1729 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1730 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1731 findAndReplaceSimpleElement( innerCount, root, "distribution", value.getDistribution(), null );
1732 findAndReplaceSimpleElement( innerCount, root, "comments", value.getComments(), null );
1733 }
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743 protected void updateMailingList( MailingList value, String xmlTag, Counter counter, Element element )
1744 {
1745 Element root = element;
1746 Counter innerCount = new Counter( counter.getDepth() + 1 );
1747 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1748 findAndReplaceSimpleElement( innerCount, root, "subscribe", value.getSubscribe(), null );
1749 findAndReplaceSimpleElement( innerCount, root, "unsubscribe", value.getUnsubscribe(), null );
1750 findAndReplaceSimpleElement( innerCount, root, "post", value.getPost(), null );
1751 findAndReplaceSimpleElement( innerCount, root, "archive", value.getArchive(), null );
1752 findAndReplaceSimpleLists( innerCount, root, value.getOtherArchives(), "otherArchives", "otherArchive" );
1753 }
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763 protected void updateModel( Model value, String xmlTag, Counter counter, Element element )
1764 {
1765 Element root = element;
1766 Counter innerCount = new Counter( counter.getDepth() + 1 );
1767 updateParent( value.getParent(), "parent", innerCount, root );
1768 findAndReplaceSimpleElement( innerCount, root, "modelVersion", value.getModelVersion(), null );
1769 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1770 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1771 findAndReplaceSimpleElement( innerCount, root, "packaging", value.getPackaging(), "jar" );
1772 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1773 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1774 findAndReplaceSimpleElement( innerCount, root, "description", value.getDescription(), null );
1775 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1776 updatePrerequisites( value.getPrerequisites(), "prerequisites", innerCount, root );
1777 updateIssueManagement( value.getIssueManagement(), "issueManagement", innerCount, root );
1778 updateCiManagement( value.getCiManagement(), "ciManagement", innerCount, root );
1779 findAndReplaceSimpleElement( innerCount, root, "inceptionYear", value.getInceptionYear(), null );
1780 iterateMailingList( innerCount, root, value.getMailingLists(), "mailingLists", "mailingList" );
1781 iterateDeveloper( innerCount, root, value.getDevelopers(), "developers", "developer" );
1782 iterateContributor( innerCount, root, value.getContributors(), "contributors", "contributor" );
1783 iterateLicense( innerCount, root, value.getLicenses(), "licenses", "license" );
1784 updateScm( value.getScm(), "scm", innerCount, root );
1785 updateOrganization( value.getOrganization(), "organization", innerCount, root );
1786 updateBuild( value.getBuild(), "build", innerCount, root );
1787 iterateProfile( innerCount, root, value.getProfiles(), "profiles", "profile" );
1788 findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
1789 iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
1790 iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
1791 iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1792 findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
1793 updateReporting( value.getReporting(), "reporting", innerCount, root );
1794 updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
1795 updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
1796 findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1797 }
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807 protected void updateModelBase( ModelBase value, String xmlTag, Counter counter, Element element )
1808 {
1809 boolean shouldExist = value != null;
1810 Element root = updateElement( counter, element, xmlTag, shouldExist );
1811 if ( shouldExist )
1812 {
1813 Counter innerCount = new Counter( counter.getDepth() + 1 );
1814 findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
1815 iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
1816 iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories",
1817 "pluginRepository" );
1818 iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1819 findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
1820 updateReporting( value.getReporting(), "reporting", innerCount, root );
1821 updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
1822 updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount,
1823 root );
1824 findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
1825 }
1826 }
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836 protected void updateNotifier( Notifier value, String xmlTag, Counter counter, Element element )
1837 {
1838 Element root = element;
1839 Counter innerCount = new Counter( counter.getDepth() + 1 );
1840 findAndReplaceSimpleElement( innerCount, root, "type", value.getType(), "mail" );
1841 findAndReplaceSimpleElement( innerCount, root, "sendOnError",
1842 ( value.isSendOnError() == true ) ? null : String.valueOf( value.isSendOnError() ),
1843 "true" );
1844 findAndReplaceSimpleElement( innerCount, root, "sendOnFailure", ( value.isSendOnFailure() == true )
1845 ? null
1846 : String.valueOf( value.isSendOnFailure() ), "true" );
1847 findAndReplaceSimpleElement( innerCount, root, "sendOnSuccess", ( value.isSendOnSuccess() == true )
1848 ? null
1849 : String.valueOf( value.isSendOnSuccess() ), "true" );
1850 findAndReplaceSimpleElement( innerCount, root, "sendOnWarning", ( value.isSendOnWarning() == true )
1851 ? null
1852 : String.valueOf( value.isSendOnWarning() ), "true" );
1853 findAndReplaceSimpleElement( innerCount, root, "address", value.getAddress(), null );
1854 findAndReplaceProperties( innerCount, root, "configuration", value.getConfiguration() );
1855 }
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865 protected void updateOrganization( Organization value, String xmlTag, Counter counter, Element element )
1866 {
1867 boolean shouldExist = value != null;
1868 Element root = updateElement( counter, element, xmlTag, shouldExist );
1869 if ( shouldExist )
1870 {
1871 Counter innerCount = new Counter( counter.getDepth() + 1 );
1872 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1873 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1874 }
1875 }
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885 protected void updateParent( Parent value, String xmlTag, Counter counter, Element element )
1886 {
1887 boolean shouldExist = value != null;
1888 Element root = updateElement( counter, element, xmlTag, shouldExist );
1889 if ( shouldExist )
1890 {
1891 Counter innerCount = new Counter( counter.getDepth() + 1 );
1892 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1893 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
1894 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1895 findAndReplaceSimpleElement( innerCount, root, "relativePath", value.getRelativePath(), "../pom.xml" );
1896 }
1897 }
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907 protected void updatePatternSet( PatternSet value, String xmlTag, Counter counter, Element element )
1908 {
1909 boolean shouldExist = value != null;
1910 Element root = updateElement( counter, element, xmlTag, shouldExist );
1911 if ( shouldExist )
1912 {
1913 Counter innerCount = new Counter( counter.getDepth() + 1 );
1914 findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
1915 findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
1916 }
1917 }
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927 protected void updatePlugin( Plugin value, String xmlTag, Counter counter, Element element )
1928 {
1929 Element root = element;
1930 Counter innerCount = new Counter( counter.getDepth() + 1 );
1931 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" );
1932 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
1933 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1934 findAndReplaceSimpleElement( innerCount, root, "extensions",
1935 ( value.isExtensions() == false ) ? null : String.valueOf( value.isExtensions() ),
1936 "false" );
1937 iteratePluginExecution( innerCount, root, value.getExecutions(), "executions", "execution" );
1938 iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
1939 findAndReplaceXpp3DOM( innerCount, root, "goals", (Xpp3Dom) value.getGoals() );
1940 findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
1941 findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
1942 }
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952 protected void updatePluginConfiguration( PluginConfiguration value, String xmlTag, Counter counter,
1953 Element element )
1954 {
1955 boolean shouldExist = value != null;
1956 Element root = updateElement( counter, element, xmlTag, shouldExist );
1957 if ( shouldExist )
1958 {
1959 Counter innerCount = new Counter( counter.getDepth() + 1 );
1960 updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1961 iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1962 }
1963 }
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973 protected void updatePluginContainer( PluginContainer value, String xmlTag, Counter counter, Element element )
1974 {
1975 boolean shouldExist = value != null;
1976 Element root = updateElement( counter, element, xmlTag, shouldExist );
1977 if ( shouldExist )
1978 {
1979 Counter innerCount = new Counter( counter.getDepth() + 1 );
1980 iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1981 }
1982 }
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992 protected void updatePluginExecution( PluginExecution value, String xmlTag, Counter counter, Element element )
1993 {
1994 Element root = element;
1995 Counter innerCount = new Counter( counter.getDepth() + 1 );
1996 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
1997 findAndReplaceSimpleElement( innerCount, root, "phase", value.getPhase(), null );
1998 findAndReplaceSimpleLists( innerCount, root, value.getGoals(), "goals", "goal" );
1999 findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
2000 findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
2001 }
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011 protected void updatePluginManagement( PluginManagement value, String xmlTag, Counter counter, Element element )
2012 {
2013 boolean shouldExist = value != null;
2014 Element root = updateElement( counter, element, xmlTag, shouldExist );
2015 if ( shouldExist )
2016 {
2017 Counter innerCount = new Counter( counter.getDepth() + 1 );
2018 iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
2019 }
2020 }
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030 protected void updatePrerequisites( Prerequisites value, String xmlTag, Counter counter, Element element )
2031 {
2032 boolean shouldExist = value != null;
2033 Element root = updateElement( counter, element, xmlTag, shouldExist );
2034 if ( shouldExist )
2035 {
2036 Counter innerCount = new Counter( counter.getDepth() + 1 );
2037 findAndReplaceSimpleElement( innerCount, root, "maven", value.getMaven(), "2.0" );
2038 }
2039 }
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049 protected void updateProfile( Profile value, String xmlTag, Counter counter, Element element )
2050 {
2051 Element root = element;
2052 Counter innerCount = new Counter( counter.getDepth() + 1 );
2053 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2054 updateActivation( value.getActivation(), "activation", innerCount, root );
2055 updateBuildBase( value.getBuild(), "build", innerCount, root );
2056 findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
2057 iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
2058 iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
2059 iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
2060 findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
2061 updateReporting( value.getReporting(), "reporting", innerCount, root );
2062 updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
2063 updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
2064 findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
2065 }
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075 protected void updateRelocation( Relocation value, String xmlTag, Counter counter, Element element )
2076 {
2077 boolean shouldExist = value != null;
2078 Element root = updateElement( counter, element, xmlTag, shouldExist );
2079 if ( shouldExist )
2080 {
2081 Counter innerCount = new Counter( counter.getDepth() + 1 );
2082 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), null );
2083 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
2084 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
2085 findAndReplaceSimpleElement( innerCount, root, "message", value.getMessage(), null );
2086 }
2087 }
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097 protected void updateReporting( Reporting value, String xmlTag, Counter counter, Element element )
2098 {
2099 boolean shouldExist = value != null;
2100 Element root = updateElement( counter, element, xmlTag, shouldExist );
2101 if ( shouldExist )
2102 {
2103 Counter innerCount = new Counter( counter.getDepth() + 1 );
2104 findAndReplaceSimpleElement( innerCount, root, "excludeDefaults", ( value.isExcludeDefaults() == false )
2105 ? null
2106 : String.valueOf( value.isExcludeDefaults() ), "false" );
2107 findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
2108 iterateReportPlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
2109 }
2110 }
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120 protected void updateReportPlugin( ReportPlugin value, String xmlTag, Counter counter, Element element )
2121 {
2122 Element root = element;
2123 Counter innerCount = new Counter( counter.getDepth() + 1 );
2124 findAndReplaceSimpleElement( innerCount, root, "groupId", value.getGroupId(), "org.apache.maven.plugins" );
2125 findAndReplaceSimpleElement( innerCount, root, "artifactId", value.getArtifactId(), null );
2126 findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
2127 findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
2128 findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
2129 iterateReportSet( innerCount, root, value.getReportSets(), "reportSets", "reportSet" );
2130 }
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140 protected void updateReportSet( ReportSet value, String xmlTag, Counter counter, Element element )
2141 {
2142 Element root = element;
2143 Counter innerCount = new Counter( counter.getDepth() + 1 );
2144 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), "default" );
2145 findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
2146 findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
2147 findAndReplaceSimpleLists( innerCount, root, value.getReports(), "reports", "report" );
2148 }
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158 protected void updateRepository( Repository value, String xmlTag, Counter counter, Element element )
2159 {
2160 Element root = element;
2161 Counter innerCount = new Counter( counter.getDepth() + 1 );
2162 updateRepositoryPolicy( value.getReleases(), "releases", innerCount, root );
2163 updateRepositoryPolicy( value.getSnapshots(), "snapshots", innerCount, root );
2164 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2165 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
2166 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2167 findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
2168 }
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178 protected void updateRepositoryBase( RepositoryBase value, String xmlTag, Counter counter, Element element )
2179 {
2180 boolean shouldExist = value != null;
2181 Element root = updateElement( counter, element, xmlTag, shouldExist );
2182 if ( shouldExist )
2183 {
2184 Counter innerCount = new Counter( counter.getDepth() + 1 );
2185 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2186 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
2187 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2188 findAndReplaceSimpleElement( innerCount, root, "layout", value.getLayout(), "default" );
2189 }
2190 }
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200 protected void updateRepositoryPolicy( RepositoryPolicy value, String xmlTag, Counter counter, Element element )
2201 {
2202 boolean shouldExist = value != null;
2203 Element root = updateElement( counter, element, xmlTag, shouldExist );
2204 if ( shouldExist )
2205 {
2206 Counter innerCount = new Counter( counter.getDepth() + 1 );
2207 findAndReplaceSimpleElement( innerCount, root, "enabled",
2208 ( value.isEnabled() == true ) ? null : String.valueOf( value.isEnabled() ),
2209 "true" );
2210 findAndReplaceSimpleElement( innerCount, root, "updatePolicy", value.getUpdatePolicy(), null );
2211 findAndReplaceSimpleElement( innerCount, root, "checksumPolicy", value.getChecksumPolicy(), null );
2212 }
2213 }
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223 protected void updateResource( Resource value, String xmlTag, Counter counter, Element element )
2224 {
2225 Element root = element;
2226 Counter innerCount = new Counter( counter.getDepth() + 1 );
2227 findAndReplaceSimpleElement( innerCount, root, "targetPath", value.getTargetPath(), null );
2228 findAndReplaceSimpleElement( innerCount, root, "filtering",
2229 ( value.isFiltering() == false ) ? null : String.valueOf( value.isFiltering() ),
2230 "false" );
2231 findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
2232 findAndReplaceSimpleLists( innerCount, root, value.getIncludes(), "includes", "include" );
2233 findAndReplaceSimpleLists( innerCount, root, value.getExcludes(), "excludes", "exclude" );
2234 }
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244 protected void updateScm( Scm value, String xmlTag, Counter counter, Element element )
2245 {
2246 boolean shouldExist = value != null;
2247 Element root = updateElement( counter, element, xmlTag, shouldExist );
2248 if ( shouldExist )
2249 {
2250 Counter innerCount = new Counter( counter.getDepth() + 1 );
2251 findAndReplaceSimpleElement( innerCount, root, "connection", value.getConnection(), null );
2252 findAndReplaceSimpleElement( innerCount, root, "developerConnection", value.getDeveloperConnection(),
2253 null );
2254 findAndReplaceSimpleElement( innerCount, root, "tag", value.getTag(), "HEAD" );
2255 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2256 }
2257 }
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267 protected void updateSite( Site value, String xmlTag, Counter counter, Element element )
2268 {
2269 boolean shouldExist = value != null;
2270 Element root = updateElement( counter, element, xmlTag, shouldExist );
2271 if ( shouldExist )
2272 {
2273 Counter innerCount = new Counter( counter.getDepth() + 1 );
2274 findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
2275 findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
2276 findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
2277 }
2278 }
2279
2280
2281
2282
2283
2284
2285
2286
2287 public class Counter
2288 {
2289
2290
2291
2292
2293
2294
2295
2296 private int currentIndex = 0;
2297
2298
2299
2300
2301 private int level;
2302
2303
2304
2305
2306
2307 public Counter( int depthLevel )
2308 {
2309 level = depthLevel;
2310 }
2311
2312
2313
2314
2315
2316
2317
2318
2319 public int getCurrentIndex()
2320 {
2321 return currentIndex;
2322 }
2323
2324
2325
2326
2327 public int getDepth()
2328 {
2329 return level;
2330 }
2331
2332
2333
2334
2335 public void increaseCount()
2336 {
2337 currentIndex = currentIndex + 1;
2338 }
2339 }
2340 }