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