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