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