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