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