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