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