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