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