View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.archetype.common;
20  
21  /*
22   * $Id$
23   */
24  
25  // ---------------------------------/
26  // - Imported classes and packages -/
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   * Class MavenJDOMWriter.
92   */
93  public class MavenJDOMWriter {
94      // --------------------------/
95      // - Class/Member Variables -/
96      // --------------------------/
97  
98      /**
99       * Field factory.
100      */
101     private DefaultJDOMFactory factory;
102 
103     /**
104      * Field lineSeparator.
105      */
106     private String lineSeparator;
107 
108     private static final String LS = System.getProperty("line.separator");
109 
110     // ----------------/
111     // - Constructors -/
112     // ----------------/
113 
114     public MavenJDOMWriter() {
115         factory = new DefaultJDOMFactory();
116         lineSeparator = "\n";
117     } // -- org.apache.maven.model.io.jdom.MavenJDOMWriter()
118 
119     /**
120      * Method write.
121      *
122      * @param project
123      * @param stream
124      * @param document
125      * @deprecated
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     } // -- void write(Model, Document, OutputStream)
135 
136     /**
137      * Method write.
138      *
139      * @param project
140      * @param writer
141      * @param document
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     } // -- void write(Model, Document, OutputStreamWriter)
147 
148     /**
149      * Method write.
150      *
151      * @param project
152      * @param jdomFormat
153      * @param writer
154      * @param document
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     } // -- void write(Model, Document, Writer, Format)
163 
164     // -----------/
165     // - Methods -/
166     // -----------/
167 
168     /**
169      * Method findAndReplaceProperties.
170      *
171      * @param counter
172      * @param props
173      * @param name
174      * @param parent
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     } // -- Element findAndReplaceProperties(Counter, Element, String, Map)
198 
199     /**
200      * Method findAndReplaceSimpleElement.
201      *
202      * @param counter
203      * @param defaultValue
204      * @param text
205      * @param name
206      * @param parent
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             // if exist and is default value or if doesn't exist.. just keep the way it is..
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     } // -- Element findAndReplaceSimpleElement(Counter, Element, String, String, String)
224 
225     /**
226      * Method findAndReplaceSimpleLists.
227      *
228      * @param counter
229      * @param childName
230      * @param parentName
231      * @param list
232      * @param parent
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     } // -- Element findAndReplaceSimpleLists(Counter, Element, Collection, String, String)
270 
271     /**
272      * Method findAndReplaceXpp3DOM.
273      *
274      * @param counter
275      * @param dom
276      * @param name
277      * @param parent
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     } // -- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom)
286 
287     /**
288      * Method insertAtPreferredLocation.
289      *
290      * @param parent
291      * @param counter
292      * @param child
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("  "); // TODO make settable?
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     } // -- void insertAtPreferredLocation(Element, Element, Counter)
330 
331     /**
332      * Method iterateContributor.
333      *
334      * @param counter
335      * @param childTag
336      * @param parentTag
337      * @param list
338      * @param parent
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     } // -- void iterateContributor(Counter, Element, Collection, String,
376     // String)
377 
378     /**
379      * Method iterateDependency.
380      *
381      * @param counter
382      * @param childTag
383      * @param parentTag
384      * @param list
385      * @param parent
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     } // -- void iterateDependency(Counter, Element, java.util.Collection, String,
423     // String)
424 
425     /**
426      * Method iterateDeveloper.
427      *
428      * @param counter
429      * @param childTag
430      * @param parentTag
431      * @param list
432      * @param parent
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     } // -- void iterateDeveloper(Counter, Element, java.util.Collection, String,
470     // String)
471 
472     /**
473      * Method iterateExclusion.
474      *
475      * @param counter
476      * @param childTag
477      * @param parentTag
478      * @param list
479      * @param parent
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     } // -- void iterateExclusion(Counter, Element, Collection, String, String)
517 
518     /**
519      * Method iterateExtension.
520      *
521      * @param counter
522      * @param childTag
523      * @param parentTag
524      * @param list
525      * @param parent
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     } // -- void iterateExtension(Counter, Element, Collection, String, String)
563 
564     /**
565      * Method iterateLicense.
566      *
567      * @param counter
568      * @param childTag
569      * @param parentTag
570      * @param list
571      * @param parent
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     } // -- void iterateLicense(Counter, Element, java.util.Collection, String,
608     // String)
609 
610     /**
611      * Method iterateMailingList.
612      *
613      * @param counter
614      * @param childTag
615      * @param parentTag
616      * @param list
617      * @param parent
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     } // -- void iterateMailingList(Counter, Element, java.util.Collection, String,
655     // String)
656 
657     /**
658      * Method iterateNotifier.
659      *
660      * @param counter
661      * @param childTag
662      * @param parentTag
663      * @param list
664      * @param parent
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     } // -- void iterateNotifier(Counter, Element, java.util.Collection, String,
702     // String)
703 
704     /**
705      * Method iteratePlugin.
706      *
707      * @param counter
708      * @param childTag
709      * @param parentTag
710      * @param list
711      * @param parent
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     } // -- void iteratePlugin(Counter, Element, java.util.Collection, String,
749     // String)
750 
751     /**
752      * Method iteratePluginExecution.
753      *
754      * @param counter
755      * @param childTag
756      * @param parentTag
757      * @param list
758      * @param parent
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     } // -- void iteratePluginExecution(Counter, Element, java.util.Collection, String,
796     // String)
797 
798     /**
799      * Method iterateProfile.
800      *
801      * @param counter
802      * @param childTag
803      * @param parentTag
804      * @param list
805      * @param parent
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     } // -- void iterateProfile(Counter, Element, java.util.Collection, String,
843     // String)
844 
845     /**
846      * Method iterateReportPlugin.
847      *
848      * @param counter
849      * @param childTag
850      * @param parentTag
851      * @param list
852      * @param parent
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     } // -- void iterateReportPlugin(Counter, Element, java.util.Collection, String,
890     // String)
891 
892     /**
893      * Method iterateReportSet.
894      *
895      * @param counter
896      * @param childTag
897      * @param parentTag
898      * @param list
899      * @param parent
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     } // -- void iterateReportSet(Counter, Element, java.util.Collection, String,
937     // String)
938 
939     /**
940      * Method iterateRepository.
941      *
942      * @param counter
943      * @param childTag
944      * @param parentTag
945      * @param list
946      * @param parent
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     } // -- void iterateRepository(Counter, Element, java.util.Collection, String,
984     // String)
985 
986     /**
987      * Method iterateResource.
988      *
989      * @param counter
990      * @param childTag
991      * @param parentTag
992      * @param list
993      * @param parent
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     } // -- void iterateResource(Counter, Element, Collection, String, String)
1031 
1032     /**
1033      * Method replaceXpp3DOM.
1034      *
1035      * @param parent
1036      * @param counter
1037      * @param parentDom
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     } // -- void replaceXpp3DOM(Element, Xpp3Dom, Counter)
1080 
1081     /**
1082      * Method updateActivation.
1083      *
1084      * @param value
1085      * @param element
1086      * @param counter
1087      * @param xmlTag
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     } // -- void updateActivation(Activation, String, Counter, Element)
1106 
1107     /**
1108      * Method updateActivationFile.
1109      *
1110      * @param value
1111      * @param element
1112      * @param counter
1113      * @param xmlTag
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     } // -- void updateActivationFile(ActivationFile, String, Counter, Element)
1124 
1125     /**
1126      * Method updateActivationOS.
1127      *
1128      * @param value
1129      * @param element
1130      * @param counter
1131      * @param xmlTag
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     } // -- void updateActivationOS(ActivationOS, String, Counter, Element)
1144 
1145     /**
1146      * Method updateActivationProperty.
1147      *
1148      * @param value
1149      * @param element
1150      * @param counter
1151      * @param xmlTag
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     } // -- void updateActivationProperty(ActivationProperty, String, Counter, Element)
1162 
1163     /**
1164      * Method updateBuild.
1165      *
1166      * @param value
1167      * @param element
1168      * @param counter
1169      * @param xmlTag
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         } // end if
1192     } // -- void updateBuild(Build, String, Counter, Element)
1193 
1194     /**
1195      * Method updateBuildBase.
1196      *
1197      * @param value
1198      * @param element
1199      * @param counter
1200      * @param xmlTag
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     } // -- void updateBuildBase(BuildBase, String, Counter, Element)
1217 
1218     /**
1219      * Method updateCiManagement.
1220      *
1221      * @param value
1222      * @param element
1223      * @param counter
1224      * @param xmlTag
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     } // -- void updateCiManagement(CiManagement, String, Counter, Element)
1236 
1237     /**
1238      * Method updateConfigurationContainer.
1239      *
1240      * @param value
1241      * @param element
1242      * @param counter
1243      * @param xmlTag
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     } // -- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element)
1255 
1256     /**
1257      * Method updateContributor.
1258      *
1259      * @param value
1260      * @param element
1261      * @param counter
1262      * @param xmlTag
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     } // -- void updateContributor(Contributor, String, Counter, Element)
1276 
1277     /**
1278      * Method updateDependency.
1279      *
1280      * @param value
1281      * @param element
1282      * @param counter
1283      * @param xmlTag
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     } // -- void updateDependency(Dependency, String, Counter, Element)
1303 
1304     /**
1305      * Method updateDependencyManagement.
1306      *
1307      * @param value
1308      * @param element
1309      * @param counter
1310      * @param xmlTag
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     } // -- void updateDependencyManagement(DependencyManagement, String, Counter, Element)
1321 
1322     /**
1323      * Method updateDeploymentRepository.
1324      *
1325      * @param value
1326      * @param element
1327      * @param counter
1328      * @param xmlTag
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     } // -- void updateDeploymentRepository(DeploymentRepository, String, Counter, Element)
1348 
1349     /**
1350      * Method updateDeveloper.
1351      *
1352      * @param value
1353      * @param element
1354      * @param counter
1355      * @param xmlTag
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     } // -- void updateDeveloper(Developer, String, Counter, Element)
1370 
1371     /**
1372      * Method updateDistributionManagement.
1373      *
1374      * @param value
1375      * @param element
1376      * @param counter
1377      * @param xmlTag
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     } // -- void updateDistributionManagement(DistributionManagement, String, Counter, Element)
1393 
1394     /**
1395      * Method updateElement.
1396      *
1397      * @param counter
1398      * @param shouldExist
1399      * @param name
1400      * @param parent
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     } // -- Element updateElement(Counter, Element, String, boolean)
1427 
1428     /**
1429      * Method updateExclusion.
1430      *
1431      * @param value
1432      * @param element
1433      * @param counter
1434      * @param xmlTag
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     } // -- void updateExclusion(Exclusion, String, Counter, Element)
1442 
1443     /**
1444      * Method updateExtension.
1445      *
1446      * @param value
1447      * @param element
1448      * @param counter
1449      * @param xmlTag
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     } // -- void updateExtension(Extension, String, Counter, Element)
1458 
1459     /**
1460      * Method updateFileSet.
1461      *
1462      * @param value
1463      * @param element
1464      * @param counter
1465      * @param xmlTag
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     } // -- void updateFileSet(FileSet, String, Counter, Element)
1477 
1478     /**
1479      * Method updateIssueManagement.
1480      *
1481      * @param value
1482      * @param element
1483      * @param counter
1484      * @param xmlTag
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     } // -- void updateIssueManagement(IssueManagement, String, Counter, Element)
1495 
1496     /**
1497      * Method updateLicense.
1498      *
1499      * @param value
1500      * @param element
1501      * @param counter
1502      * @param xmlTag
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     } // -- void updateLicense(License, String, Counter, Element)
1512 
1513     /**
1514      * Method updateMailingList.
1515      *
1516      * @param value
1517      * @param element
1518      * @param counter
1519      * @param xmlTag
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     } // -- void updateMailingList(MailingList, String, Counter, Element)
1531 
1532     /**
1533      * Method updateModel.
1534      *
1535      * @param value
1536      * @param element
1537      * @param counter
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     } // -- void updateModel(Model, String, Counter, Element)
1573 
1574     /**
1575      * Method updateNotifier.
1576      *
1577      * @param value
1578      * @param element
1579      * @param counter
1580      * @param xmlTag
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     } // -- void updateNotifier(Notifier, String, Counter, Element)
1613 
1614     /**
1615      * Method updateOrganization.
1616      *
1617      * @param value
1618      * @param element
1619      * @param counter
1620      * @param xmlTag
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     } // -- void updateOrganization(Organization, String, Counter, Element)
1631 
1632     /**
1633      * Method updateParent.
1634      *
1635      * @param value
1636      * @param element
1637      * @param counter
1638      * @param xmlTag
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     } // -- void updateParent(Parent, String, Counter, Element)
1651 
1652     /**
1653      * Method updatePatternSet.
1654      *
1655      * @param value
1656      * @param element
1657      * @param counter
1658      * @param xmlTag
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     } // -- void updatePatternSet(PatternSet, String, Counter, Element)
1669 
1670     /**
1671      * Method updatePlugin.
1672      *
1673      * @param value
1674      * @param element
1675      * @param counter
1676      * @param xmlTag
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     } // -- void updatePlugin(Plugin, String, Counter, Element)
1696 
1697     // Workaround for Maven 4 dropped methods
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      * Method updatePluginConfiguration.
1717      *
1718      * @param value
1719      * @param element
1720      * @param counter
1721      * @param xmlTag
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     } // -- void updatePluginConfiguration(PluginConfiguration, String, Counter, Element)
1733 
1734     /**
1735      * Method updatePluginContainer.
1736      *
1737      * @param value
1738      * @param element
1739      * @param counter
1740      * @param xmlTag
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     } // -- void updatePluginContainer(PluginContainer, String, Counter, Element)
1750 
1751     /**
1752      * Method updatePluginExecution.
1753      *
1754      * @param value
1755      * @param element
1756      * @param counter
1757      * @param xmlTag
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     } // -- void updatePluginExecution(PluginExecution, String, Counter, Element)
1768 
1769     /**
1770      * Method updatePluginManagement.
1771      *
1772      * @param value
1773      * @param element
1774      * @param counter
1775      * @param xmlTag
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     } // -- void updatePluginManagement(PluginManagement, String, Counter, Element)
1785 
1786     /**
1787      * Method updatePrerequisites.
1788      *
1789      * @param value
1790      * @param element
1791      * @param counter
1792      * @param xmlTag
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     } // -- void updatePrerequisites(Prerequisites, String, Counter, Element)
1802 
1803     /**
1804      * Method updateProfile.
1805      *
1806      * @param value
1807      * @param element
1808      * @param counter
1809      * @param xmlTag
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     } // -- void updateProfile(Profile, String, Counter, Element)
1827 
1828     /**
1829      * Method updateRelocation.
1830      *
1831      * @param value
1832      * @param element
1833      * @param counter
1834      * @param xmlTag
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     } // -- void updateRelocation(Relocation, String, Counter, Element)
1847 
1848     /**
1849      * Method updateReporting.
1850      *
1851      * @param value
1852      * @param element
1853      * @param counter
1854      * @param xmlTag
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     } // -- void updateReporting(Reporting, String, Counter, Element)
1871 
1872     /**
1873      * Method updateReportPlugin.
1874      *
1875      * @param value
1876      * @param element
1877      * @param counter
1878      * @param xmlTag
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     } // -- void updateReportPlugin(ReportPlugin, String, Counter, Element)
1890 
1891     /**
1892      * Method updateReportSet.
1893      *
1894      * @param value
1895      * @param element
1896      * @param counter
1897      * @param xmlTag
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     } // -- void updateReportSet(ReportSet, String, Counter, Element)
1907 
1908     /**
1909      * Method updateRepository.
1910      *
1911      * @param value
1912      * @param element
1913      * @param counter
1914      * @param xmlTag
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     } // -- void updateRepository(Repository, String, Counter, Element)
1926 
1927     /**
1928      * Method updateRepositoryBase.
1929      *
1930      * @param value
1931      * @param element
1932      * @param counter
1933      * @param xmlTag
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     } // -- void updateRepositoryBase(RepositoryBase, String, Counter, Element)
1946 
1947     /**
1948      * Method updateRepositoryPolicy.
1949      *
1950      * @param value
1951      * @param element
1952      * @param counter
1953      * @param xmlTag
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     } // -- void updateRepositoryPolicy(RepositoryPolicy, String, Counter, Element)
1970 
1971     /**
1972      * Method updateResource.
1973      *
1974      * @param value
1975      * @param element
1976      * @param counter
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     } // -- void updateResource(Resource, String, Counter, Element)
1992 
1993     /**
1994      * Method updateScm.
1995      *
1996      * @param value
1997      * @param element
1998      * @param counter
1999      * @param xmlTag
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     } // -- void updateScm(Scm, String, Counter, Element)
2012 
2013     /**
2014      * Method updateSite.
2015      *
2016      * @param value
2017      * @param element
2018      * @param counter
2019      * @param xmlTag
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     } // -- void updateSite(Site, String, Counter, Element)
2031 
2032     // -----------------/
2033     // - Inner Classes -/
2034     // -----------------/
2035 
2036     /**
2037      * Class Counter.
2038      */
2039     public class Counter {
2040         // --------------------------/
2041         // - Class/Member Variables -/
2042         // --------------------------/
2043 
2044         /**
2045          * Field currentIndex.
2046          */
2047         private int currentIndex = 0;
2048 
2049         /**
2050          * Field level.
2051          */
2052         private int level;
2053 
2054         // ----------------/
2055         // - Constructors -/
2056         // ----------------/
2057 
2058         public Counter(int depthLevel) {
2059             level = depthLevel;
2060         } // -- org.apache.maven.model.io.jdom.Counter(int)
2061 
2062         // -----------/
2063         // - Methods -/
2064         // -----------/
2065 
2066         /**
2067          * Method getCurrentIndex.
2068          */
2069         public int getCurrentIndex() {
2070             return currentIndex;
2071         } // -- int getCurrentIndex()
2072 
2073         /**
2074          * Method getDepth.
2075          */
2076         public int getDepth() {
2077             return level;
2078         } // -- int getDepth()
2079 
2080         /**
2081          * Method increaseCount.
2082          */
2083         public void increaseCount() {
2084             currentIndex = currentIndex + 1;
2085         } // -- void increaseCount()
2086     }
2087 }