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