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