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