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