PageRenderTime 112ms CodeModel.GetById 15ms app.highlight 87ms RepoModel.GetById 1ms app.codeStats 1ms

/maven-amps-plugin/src/main/java/org/apache/maven/plugins/shade/pom/MavenJDOMWriter.java

https://bitbucket.org/mmeinhold/amps
Java | 2243 lines | 1488 code | 94 blank | 661 comment | 304 complexity | 7fd6f472e95619f5b4d162f2b5e2ad13 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1package org.apache.maven.plugins.shade.pom;
   2
   3/*
   4 * Licensed to the Apache Software Foundation (ASF) under one
   5 * or more contributor license agreements.  See the NOTICE file
   6 * distributed with this work for additional information
   7 * regarding copyright ownership.  The ASF licenses this file
   8 * to you under the Apache License, Version 2.0 (the
   9 * "License"); you may not use this file except in compliance
  10 * with the License.  You may obtain a copy of the License at
  11 *
  12 *   http://www.apache.org/licenses/LICENSE-2.0
  13 *
  14 * Unless required by applicable law or agreed to in writing,
  15 * software distributed under the License is distributed on an
  16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17 * KIND, either express or implied.  See the License for the
  18 * specific language governing permissions and limitations
  19 * under the License.
  20 */
  21
  22//package org.apache.maven.model.io.jdom;
  23
  24//---------------------------------/
  25//- Imported classes and packages -/
  26//---------------------------------/
  27
  28import java.io.OutputStream;
  29import java.io.OutputStreamWriter;
  30import java.io.Writer;
  31import java.util.ArrayList;
  32import java.util.Collection;
  33import java.util.Iterator;
  34import java.util.ListIterator;
  35import java.util.Map;
  36
  37import org.apache.maven.model.ActivationFile;
  38import org.apache.maven.model.ActivationOS;
  39import org.apache.maven.model.ActivationProperty;
  40import org.apache.maven.model.Build;
  41import org.apache.maven.model.BuildBase;
  42import org.apache.maven.model.CiManagement;
  43import org.apache.maven.model.ConfigurationContainer;
  44import org.apache.maven.model.Contributor;
  45import org.apache.maven.model.Dependency;
  46import org.apache.maven.model.DependencyManagement;
  47import org.apache.maven.model.DeploymentRepository;
  48import org.apache.maven.model.Developer;
  49import org.apache.maven.model.DistributionManagement;
  50import org.apache.maven.model.Exclusion;
  51import org.apache.maven.model.Extension;
  52import org.apache.maven.model.FileSet;
  53import org.apache.maven.model.IssueManagement;
  54import org.apache.maven.model.License;
  55import org.apache.maven.model.MailingList;
  56import org.apache.maven.model.Model;
  57import org.apache.maven.model.ModelBase;
  58import org.apache.maven.model.Notifier;
  59import org.apache.maven.model.Organization;
  60import org.apache.maven.model.Parent;
  61import org.apache.maven.model.PatternSet;
  62import org.apache.maven.model.Plugin;
  63import org.apache.maven.model.PluginConfiguration;
  64import org.apache.maven.model.PluginContainer;
  65import org.apache.maven.model.PluginExecution;
  66import org.apache.maven.model.PluginManagement;
  67import org.apache.maven.model.Prerequisites;
  68import org.apache.maven.model.Profile;
  69import org.apache.maven.model.Relocation;
  70import org.apache.maven.model.ReportPlugin;
  71import org.apache.maven.model.ReportSet;
  72import org.apache.maven.model.Reporting;
  73import org.apache.maven.model.Repository;
  74import org.apache.maven.model.RepositoryBase;
  75import org.apache.maven.model.RepositoryPolicy;
  76import org.apache.maven.model.Resource;
  77import org.apache.maven.model.Scm;
  78import org.apache.maven.model.Site;
  79import org.codehaus.plexus.util.xml.Xpp3Dom;
  80import org.jdom.Content;
  81import org.jdom.DefaultJDOMFactory;
  82import org.jdom.Document;
  83import org.jdom.Element;
  84import org.jdom.Text;
  85import org.jdom.output.Format;
  86import org.jdom.output.XMLOutputter;
  87
  88/**
  89 * Class MavenJDOMWriter.
  90 * 
  91 * @since 3.6
  92 */
  93public class MavenJDOMWriter
  94{
  95
  96    // --------------------------/
  97    // - Class/Member Variables -/
  98    // --------------------------/
  99
 100    /**
 101     * Field factory
 102     */
 103    private DefaultJDOMFactory factory;
 104
 105    /**
 106     * Field lineSeparator
 107     */
 108    private String lineSeparator;
 109
 110    // ----------------/
 111    // - Constructors -/
 112    // ----------------/
 113
 114    public MavenJDOMWriter()
 115    {
 116        factory = new DefaultJDOMFactory();
 117        lineSeparator = "\n";
 118    } // -- org.apache.maven.model.io.jdom.MavenJDOMWriter()
 119
 120    // -----------/
 121    // - Methods -/
 122    // -----------/
 123
 124    /**
 125     * Method findAndReplaceProperties
 126     * 
 127     * @param counter
 128     * @param props
 129     * @param name
 130     * @param parent
 131     */
 132    protected Element findAndReplaceProperties( Counter counter, Element parent, String name, Map props )
 133    {
 134        boolean shouldExist = props != null && !props.isEmpty();
 135        Element element = updateElement( counter, parent, name, shouldExist );
 136        if ( shouldExist )
 137        {
 138            Iterator it = props.keySet().iterator();
 139            Counter innerCounter = new Counter( counter.getDepth() + 1 );
 140            while ( it.hasNext() )
 141            {
 142                String key = (String) it.next();
 143                findAndReplaceSimpleElement( innerCounter, element, key, (String) props.get( key ), null );
 144            }
 145            ArrayList lst = new ArrayList( props.keySet() );
 146            it = element.getChildren().iterator();
 147            while ( it.hasNext() )
 148            {
 149                Element elem = (Element) it.next();
 150                String key = elem.getName();
 151                if ( !lst.contains( key ) )
 152                {
 153                    it.remove();
 154                }
 155            }
 156        }
 157        return element;
 158    } // -- Element findAndReplaceProperties(Counter, Element, String, Map)
 159
 160    /**
 161     * Method findAndReplaceSimpleElement
 162     * 
 163     * @param counter
 164     * @param defaultValue
 165     * @param text
 166     * @param name
 167     * @param parent
 168     */
 169    protected Element findAndReplaceSimpleElement( Counter counter, Element parent, String name, String text,
 170                                                   String defaultValue )
 171    {
 172        if ( defaultValue != null && text != null && defaultValue.equals( text ) )
 173        {
 174            Element element = parent.getChild( name, parent.getNamespace() );
 175            // if exist and is default value or if doesn't exist.. just keep the way it is..
 176            if ( ( element != null && defaultValue.equals( element.getText() ) ) || element == null )
 177            {
 178                return element;
 179            }
 180        }
 181        boolean shouldExist = text != null && text.trim().length() > 0;
 182        Element element = updateElement( counter, parent, name, shouldExist );
 183        if ( shouldExist )
 184        {
 185            element.setText( text );
 186        }
 187        return element;
 188    } // -- Element findAndReplaceSimpleElement(Counter, Element, String, String, String)
 189
 190    /**
 191     * Method findAndReplaceSimpleLists
 192     * 
 193     * @param counter
 194     * @param childName
 195     * @param parentName
 196     * @param list
 197     * @param parent
 198     */
 199    protected Element findAndReplaceSimpleLists( Counter counter, Element parent, java.util.Collection list,
 200                                                 String parentName, String childName )
 201    {
 202        boolean shouldExist = list != null && list.size() > 0;
 203        Element element = updateElement( counter, parent, parentName, shouldExist );
 204        if ( shouldExist )
 205        {
 206            Iterator it = list.iterator();
 207            Iterator elIt = element.getChildren( childName, element.getNamespace() ).iterator();
 208            if ( !elIt.hasNext() )
 209                elIt = null;
 210            Counter innerCount = new Counter( counter.getDepth() + 1 );
 211            while ( it.hasNext() )
 212            {
 213                String value = (String) it.next();
 214                Element el;
 215                if ( elIt != null && elIt.hasNext() )
 216                {
 217                    el = (Element) elIt.next();
 218                    if ( !elIt.hasNext() )
 219                        elIt = null;
 220                }
 221                else
 222                {
 223                    el = factory.element( childName, element.getNamespace() );
 224                    insertAtPreferredLocation( element, el, innerCount );
 225                }
 226                el.setText( value );
 227                innerCount.increaseCount();
 228            }
 229            if ( elIt != null )
 230            {
 231                while ( elIt.hasNext() )
 232                {
 233                    elIt.next();
 234                    elIt.remove();
 235                }
 236            }
 237        }
 238        return element;
 239    } // -- Element findAndReplaceSimpleLists(Counter, Element, java.util.Collection, String, String)
 240
 241    /**
 242     * Method findAndReplaceXpp3DOM
 243     * 
 244     * @param counter
 245     * @param dom
 246     * @param name
 247     * @param parent
 248     */
 249    protected Element findAndReplaceXpp3DOM( Counter counter, Element parent, String name, Xpp3Dom dom )
 250    {
 251        boolean shouldExist = dom != null && ( dom.getChildCount() > 0 || dom.getValue() != null );
 252        Element element = updateElement( counter, parent, name, shouldExist );
 253        if ( shouldExist )
 254        {
 255            replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );
 256        }
 257        return element;
 258    } // -- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom)
 259
 260    /**
 261     * Method insertAtPreferredLocation
 262     * 
 263     * @param parent
 264     * @param counter
 265     * @param child
 266     */
 267    protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
 268    {
 269        int contentIndex = 0;
 270        int elementCounter = 0;
 271        Iterator it = parent.getContent().iterator();
 272        Text lastText = null;
 273        int offset = 0;
 274        while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )
 275        {
 276            Object next = it.next();
 277            offset = offset + 1;
 278            if ( next instanceof Element )
 279            {
 280                elementCounter = elementCounter + 1;
 281                contentIndex = contentIndex + offset;
 282                offset = 0;
 283            }
 284            if ( next instanceof Text && it.hasNext() )
 285            {
 286                lastText = (Text) next;
 287            }
 288        }
 289        if ( lastText != null && lastText.getTextTrim().length() == 0 )
 290        {
 291            lastText = (Text) lastText.clone();
 292        }
 293        else
 294        {
 295            String starter = lineSeparator;
 296            for ( int i = 0; i < counter.getDepth(); i++ )
 297            {
 298                starter = starter + "    ";
 299            }
 300            lastText = factory.text( starter );
 301        }
 302        if ( parent.getContentSize() == 0 )
 303        {
 304            Text finalText = (Text) lastText.clone();
 305            finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - "    ".length() ) );
 306            parent.addContent( contentIndex, finalText );
 307        }
 308        parent.addContent( contentIndex, child );
 309        parent.addContent( contentIndex, lastText );
 310    } // -- void insertAtPreferredLocation(Element, Element, Counter)
 311
 312    /**
 313     * Method iterateContributor
 314     * 
 315     * @param counter
 316     * @param childTag
 317     * @param parentTag
 318     * @param list
 319     * @param parent
 320     */
 321    protected void iterateContributor( Counter counter, Element parent, java.util.Collection list,
 322                                       java.lang.String parentTag, java.lang.String childTag )
 323    {
 324        boolean shouldExist = list != null && list.size() > 0;
 325        Element element = updateElement( counter, parent, parentTag, shouldExist );
 326        if ( shouldExist )
 327        {
 328            Iterator it = list.iterator();
 329            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 330            if ( !elIt.hasNext() )
 331                elIt = null;
 332            Counter innerCount = new Counter( counter.getDepth() + 1 );
 333            while ( it.hasNext() )
 334            {
 335                Contributor value = (Contributor) it.next();
 336                Element el;
 337                if ( elIt != null && elIt.hasNext() )
 338                {
 339                    el = (Element) elIt.next();
 340                    if ( !elIt.hasNext() )
 341                        elIt = null;
 342                }
 343                else
 344                {
 345                    el = factory.element( childTag, element.getNamespace() );
 346                    insertAtPreferredLocation( element, el, innerCount );
 347                }
 348                updateContributor( value, childTag, innerCount, el );
 349                innerCount.increaseCount();
 350            }
 351            if ( elIt != null )
 352            {
 353                while ( elIt.hasNext() )
 354                {
 355                    elIt.next();
 356                    elIt.remove();
 357                }
 358            }
 359        }
 360    } // -- void iterateContributor(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 361
 362    /**
 363     * Method iterateDependency
 364     * 
 365     * @param counter
 366     * @param childTag
 367     * @param parentTag
 368     * @param list
 369     * @param parent
 370     */
 371    protected void iterateDependency( Counter counter, Element parent, java.util.Collection list,
 372                                      java.lang.String parentTag, java.lang.String childTag )
 373    {
 374        boolean shouldExist = list != null && list.size() > 0;
 375        Element element = updateElement( counter, parent, parentTag, shouldExist );
 376        if ( shouldExist )
 377        {
 378            Iterator it = list.iterator();
 379            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 380            if ( !elIt.hasNext() )
 381                elIt = null;
 382            Counter innerCount = new Counter( counter.getDepth() + 1 );
 383            while ( it.hasNext() )
 384            {
 385                Dependency value = (Dependency) it.next();
 386                Element el;
 387                if ( elIt != null && elIt.hasNext() )
 388                {
 389                    el = (Element) elIt.next();
 390                    if ( !elIt.hasNext() )
 391                        elIt = null;
 392                }
 393                else
 394                {
 395                    el = factory.element( childTag, element.getNamespace() );
 396                    insertAtPreferredLocation( element, el, innerCount );
 397                }
 398                updateDependency( value, childTag, innerCount, el );
 399                innerCount.increaseCount();
 400            }
 401            if ( elIt != null )
 402            {
 403                while ( elIt.hasNext() )
 404                {
 405                    elIt.next();
 406                    elIt.remove();
 407                }
 408            }
 409        }
 410    } // -- void iterateDependency(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 411
 412    /**
 413     * Method iterateDeveloper
 414     * 
 415     * @param counter
 416     * @param childTag
 417     * @param parentTag
 418     * @param list
 419     * @param parent
 420     */
 421    protected void iterateDeveloper( Counter counter, Element parent, java.util.Collection list,
 422                                     java.lang.String parentTag, java.lang.String childTag )
 423    {
 424        boolean shouldExist = list != null && list.size() > 0;
 425        Element element = updateElement( counter, parent, parentTag, shouldExist );
 426        if ( shouldExist )
 427        {
 428            Iterator it = list.iterator();
 429            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 430            if ( !elIt.hasNext() )
 431                elIt = null;
 432            Counter innerCount = new Counter( counter.getDepth() + 1 );
 433            while ( it.hasNext() )
 434            {
 435                Developer value = (Developer) it.next();
 436                Element el;
 437                if ( elIt != null && elIt.hasNext() )
 438                {
 439                    el = (Element) elIt.next();
 440                    if ( !elIt.hasNext() )
 441                        elIt = null;
 442                }
 443                else
 444                {
 445                    el = factory.element( childTag, element.getNamespace() );
 446                    insertAtPreferredLocation( element, el, innerCount );
 447                }
 448                updateDeveloper( value, childTag, innerCount, el );
 449                innerCount.increaseCount();
 450            }
 451            if ( elIt != null )
 452            {
 453                while ( elIt.hasNext() )
 454                {
 455                    elIt.next();
 456                    elIt.remove();
 457                }
 458            }
 459        }
 460    } // -- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 461
 462    /**
 463     * Method iterateExclusion
 464     * 
 465     * @param counter
 466     * @param childTag
 467     * @param parentTag
 468     * @param list
 469     * @param parent
 470     */
 471    protected void iterateExclusion( Counter counter, Element parent, java.util.Collection list,
 472                                     java.lang.String parentTag, java.lang.String childTag )
 473    {
 474        boolean shouldExist = list != null && list.size() > 0;
 475        Element element = updateElement( counter, parent, parentTag, shouldExist );
 476        if ( shouldExist )
 477        {
 478            Iterator it = list.iterator();
 479            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 480            if ( !elIt.hasNext() )
 481                elIt = null;
 482            Counter innerCount = new Counter( counter.getDepth() + 1 );
 483            while ( it.hasNext() )
 484            {
 485                Exclusion value = (Exclusion) it.next();
 486                Element el;
 487                if ( elIt != null && elIt.hasNext() )
 488                {
 489                    el = (Element) elIt.next();
 490                    if ( !elIt.hasNext() )
 491                        elIt = null;
 492                }
 493                else
 494                {
 495                    el = factory.element( childTag, element.getNamespace() );
 496                    insertAtPreferredLocation( element, el, innerCount );
 497                }
 498                updateExclusion( value, childTag, innerCount, el );
 499                innerCount.increaseCount();
 500            }
 501            if ( elIt != null )
 502            {
 503                while ( elIt.hasNext() )
 504                {
 505                    elIt.next();
 506                    elIt.remove();
 507                }
 508            }
 509        }
 510    } // -- void iterateExclusion(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 511
 512    /**
 513     * Method iterateExtension
 514     * 
 515     * @param counter
 516     * @param childTag
 517     * @param parentTag
 518     * @param list
 519     * @param parent
 520     */
 521    protected void iterateExtension( Counter counter, Element parent, java.util.Collection list,
 522                                     java.lang.String parentTag, java.lang.String childTag )
 523    {
 524        boolean shouldExist = list != null && list.size() > 0;
 525        Element element = updateElement( counter, parent, parentTag, shouldExist );
 526        if ( shouldExist )
 527        {
 528            Iterator it = list.iterator();
 529            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 530            if ( !elIt.hasNext() )
 531                elIt = null;
 532            Counter innerCount = new Counter( counter.getDepth() + 1 );
 533            while ( it.hasNext() )
 534            {
 535                Extension value = (Extension) it.next();
 536                Element el;
 537                if ( elIt != null && elIt.hasNext() )
 538                {
 539                    el = (Element) elIt.next();
 540                    if ( !elIt.hasNext() )
 541                        elIt = null;
 542                }
 543                else
 544                {
 545                    el = factory.element( childTag, element.getNamespace() );
 546                    insertAtPreferredLocation( element, el, innerCount );
 547                }
 548                updateExtension( value, childTag, innerCount, el );
 549                innerCount.increaseCount();
 550            }
 551            if ( elIt != null )
 552            {
 553                while ( elIt.hasNext() )
 554                {
 555                    elIt.next();
 556                    elIt.remove();
 557                }
 558            }
 559        }
 560    } // -- void iterateExtension(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 561
 562    /**
 563     * Method iterateLicense
 564     * 
 565     * @param counter
 566     * @param childTag
 567     * @param parentTag
 568     * @param list
 569     * @param parent
 570     */
 571    protected void iterateLicense( Counter counter, Element parent, java.util.Collection list,
 572                                   java.lang.String parentTag, java.lang.String childTag )
 573    {
 574        boolean shouldExist = list != null && list.size() > 0;
 575        Element element = updateElement( counter, parent, parentTag, shouldExist );
 576        if ( shouldExist )
 577        {
 578            Iterator it = list.iterator();
 579            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 580            if ( !elIt.hasNext() )
 581                elIt = null;
 582            Counter innerCount = new Counter( counter.getDepth() + 1 );
 583            while ( it.hasNext() )
 584            {
 585                License value = (License) it.next();
 586                Element el;
 587                if ( elIt != null && elIt.hasNext() )
 588                {
 589                    el = (Element) elIt.next();
 590                    if ( !elIt.hasNext() )
 591                        elIt = null;
 592                }
 593                else
 594                {
 595                    el = factory.element( childTag, element.getNamespace() );
 596                    insertAtPreferredLocation( element, el, innerCount );
 597                }
 598                updateLicense( value, childTag, innerCount, el );
 599                innerCount.increaseCount();
 600            }
 601            if ( elIt != null )
 602            {
 603                while ( elIt.hasNext() )
 604                {
 605                    elIt.next();
 606                    elIt.remove();
 607                }
 608            }
 609        }
 610    } // -- void iterateLicense(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 611
 612    /**
 613     * Method iterateMailingList
 614     * 
 615     * @param counter
 616     * @param childTag
 617     * @param parentTag
 618     * @param list
 619     * @param parent
 620     */
 621    protected void iterateMailingList( Counter counter, Element parent, java.util.Collection list,
 622                                       java.lang.String parentTag, java.lang.String childTag )
 623    {
 624        boolean shouldExist = list != null && list.size() > 0;
 625        Element element = updateElement( counter, parent, parentTag, shouldExist );
 626        if ( shouldExist )
 627        {
 628            Iterator it = list.iterator();
 629            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 630            if ( !elIt.hasNext() )
 631                elIt = null;
 632            Counter innerCount = new Counter( counter.getDepth() + 1 );
 633            while ( it.hasNext() )
 634            {
 635                MailingList value = (MailingList) it.next();
 636                Element el;
 637                if ( elIt != null && elIt.hasNext() )
 638                {
 639                    el = (Element) elIt.next();
 640                    if ( !elIt.hasNext() )
 641                        elIt = null;
 642                }
 643                else
 644                {
 645                    el = factory.element( childTag, element.getNamespace() );
 646                    insertAtPreferredLocation( element, el, innerCount );
 647                }
 648                updateMailingList( value, childTag, innerCount, el );
 649                innerCount.increaseCount();
 650            }
 651            if ( elIt != null )
 652            {
 653                while ( elIt.hasNext() )
 654                {
 655                    elIt.next();
 656                    elIt.remove();
 657                }
 658            }
 659        }
 660    } // -- void iterateMailingList(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 661
 662    /**
 663     * Method iterateNotifier
 664     * 
 665     * @param counter
 666     * @param childTag
 667     * @param parentTag
 668     * @param list
 669     * @param parent
 670     */
 671    protected void iterateNotifier( Counter counter, Element parent, java.util.Collection list,
 672                                    java.lang.String parentTag, java.lang.String childTag )
 673    {
 674        boolean shouldExist = list != null && list.size() > 0;
 675        Element element = updateElement( counter, parent, parentTag, shouldExist );
 676        if ( shouldExist )
 677        {
 678            Iterator it = list.iterator();
 679            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 680            if ( !elIt.hasNext() )
 681                elIt = null;
 682            Counter innerCount = new Counter( counter.getDepth() + 1 );
 683            while ( it.hasNext() )
 684            {
 685                Notifier value = (Notifier) it.next();
 686                Element el;
 687                if ( elIt != null && elIt.hasNext() )
 688                {
 689                    el = (Element) elIt.next();
 690                    if ( !elIt.hasNext() )
 691                        elIt = null;
 692                }
 693                else
 694                {
 695                    el = factory.element( childTag, element.getNamespace() );
 696                    insertAtPreferredLocation( element, el, innerCount );
 697                }
 698                updateNotifier( value, childTag, innerCount, el );
 699                innerCount.increaseCount();
 700            }
 701            if ( elIt != null )
 702            {
 703                while ( elIt.hasNext() )
 704                {
 705                    elIt.next();
 706                    elIt.remove();
 707                }
 708            }
 709        }
 710    } // -- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 711
 712    /**
 713     * Method iteratePlugin
 714     * 
 715     * @param counter
 716     * @param childTag
 717     * @param parentTag
 718     * @param list
 719     * @param parent
 720     */
 721    protected void iteratePlugin( Counter counter, Element parent, java.util.Collection list,
 722                                  java.lang.String parentTag, java.lang.String childTag )
 723    {
 724        boolean shouldExist = list != null && list.size() > 0;
 725        Element element = updateElement( counter, parent, parentTag, shouldExist );
 726        if ( shouldExist )
 727        {
 728            Iterator it = list.iterator();
 729            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 730            if ( !elIt.hasNext() )
 731                elIt = null;
 732            Counter innerCount = new Counter( counter.getDepth() + 1 );
 733            while ( it.hasNext() )
 734            {
 735                Plugin value = (Plugin) it.next();
 736                Element el;
 737                if ( elIt != null && elIt.hasNext() )
 738                {
 739                    el = (Element) elIt.next();
 740                    if ( !elIt.hasNext() )
 741                        elIt = null;
 742                }
 743                else
 744                {
 745                    el = factory.element( childTag, element.getNamespace() );
 746                    insertAtPreferredLocation( element, el, innerCount );
 747                }
 748                updatePlugin( 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 iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 761
 762    /**
 763     * Method iteratePluginExecution
 764     * 
 765     * @param counter
 766     * @param childTag
 767     * @param parentTag
 768     * @param list
 769     * @param parent
 770     */
 771    protected void iteratePluginExecution( Counter counter, Element parent, java.util.Collection list,
 772                                           java.lang.String parentTag, java.lang.String childTag )
 773    {
 774        boolean shouldExist = list != null && list.size() > 0;
 775        Element element = updateElement( counter, parent, parentTag, shouldExist );
 776        if ( shouldExist )
 777        {
 778            Iterator it = list.iterator();
 779            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 780            if ( !elIt.hasNext() )
 781                elIt = null;
 782            Counter innerCount = new Counter( counter.getDepth() + 1 );
 783            while ( it.hasNext() )
 784            {
 785                PluginExecution value = (PluginExecution) it.next();
 786                Element el;
 787                if ( elIt != null && elIt.hasNext() )
 788                {
 789                    el = (Element) elIt.next();
 790                    if ( !elIt.hasNext() )
 791                        elIt = null;
 792                }
 793                else
 794                {
 795                    el = factory.element( childTag, element.getNamespace() );
 796                    insertAtPreferredLocation( element, el, innerCount );
 797                }
 798                updatePluginExecution( value, childTag, innerCount, el );
 799                innerCount.increaseCount();
 800            }
 801            if ( elIt != null )
 802            {
 803                while ( elIt.hasNext() )
 804                {
 805                    elIt.next();
 806                    elIt.remove();
 807                }
 808            }
 809        }
 810    } // -- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 811
 812    /**
 813     * Method iterateProfile
 814     * 
 815     * @param counter
 816     * @param childTag
 817     * @param parentTag
 818     * @param list
 819     * @param parent
 820     */
 821    protected void iterateProfile( Counter counter, Element parent, java.util.Collection list,
 822                                   java.lang.String parentTag, java.lang.String childTag )
 823    {
 824        boolean shouldExist = list != null && list.size() > 0;
 825        Element element = updateElement( counter, parent, parentTag, shouldExist );
 826        if ( shouldExist )
 827        {
 828            Iterator it = list.iterator();
 829            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 830            if ( !elIt.hasNext() )
 831                elIt = null;
 832            Counter innerCount = new Counter( counter.getDepth() + 1 );
 833            while ( it.hasNext() )
 834            {
 835                Profile value = (Profile) it.next();
 836                Element el;
 837                if ( elIt != null && elIt.hasNext() )
 838                {
 839                    el = (Element) elIt.next();
 840                    if ( !elIt.hasNext() )
 841                        elIt = null;
 842                }
 843                else
 844                {
 845                    el = factory.element( childTag, element.getNamespace() );
 846                    insertAtPreferredLocation( element, el, innerCount );
 847                }
 848                updateProfile( value, childTag, innerCount, el );
 849                innerCount.increaseCount();
 850            }
 851            if ( elIt != null )
 852            {
 853                while ( elIt.hasNext() )
 854                {
 855                    elIt.next();
 856                    elIt.remove();
 857                }
 858            }
 859        }
 860    } // -- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 861
 862    /**
 863     * Method iterateReportPlugin
 864     * 
 865     * @param counter
 866     * @param childTag
 867     * @param parentTag
 868     * @param list
 869     * @param parent
 870     */
 871    protected void iterateReportPlugin( Counter counter, Element parent, java.util.Collection list,
 872                                        java.lang.String parentTag, java.lang.String childTag )
 873    {
 874        boolean shouldExist = list != null && list.size() > 0;
 875        Element element = updateElement( counter, parent, parentTag, shouldExist );
 876        if ( shouldExist )
 877        {
 878            Iterator it = list.iterator();
 879            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 880            if ( !elIt.hasNext() )
 881                elIt = null;
 882            Counter innerCount = new Counter( counter.getDepth() + 1 );
 883            while ( it.hasNext() )
 884            {
 885                ReportPlugin value = (ReportPlugin) it.next();
 886                Element el;
 887                if ( elIt != null && elIt.hasNext() )
 888                {
 889                    el = (Element) elIt.next();
 890                    if ( !elIt.hasNext() )
 891                        elIt = null;
 892                }
 893                else
 894                {
 895                    el = factory.element( childTag, element.getNamespace() );
 896                    insertAtPreferredLocation( element, el, innerCount );
 897                }
 898                updateReportPlugin( value, childTag, innerCount, el );
 899                innerCount.increaseCount();
 900            }
 901            if ( elIt != null )
 902            {
 903                while ( elIt.hasNext() )
 904                {
 905                    elIt.next();
 906                    elIt.remove();
 907                }
 908            }
 909        }
 910    } // -- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 911
 912    /**
 913     * Method iterateReportSet
 914     * 
 915     * @param counter
 916     * @param childTag
 917     * @param parentTag
 918     * @param list
 919     * @param parent
 920     */
 921    protected void iterateReportSet( Counter counter, Element parent, java.util.Collection list,
 922                                     java.lang.String parentTag, java.lang.String childTag )
 923    {
 924        boolean shouldExist = list != null && list.size() > 0;
 925        Element element = updateElement( counter, parent, parentTag, shouldExist );
 926        if ( shouldExist )
 927        {
 928            Iterator it = list.iterator();
 929            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 930            if ( !elIt.hasNext() )
 931                elIt = null;
 932            Counter innerCount = new Counter( counter.getDepth() + 1 );
 933            while ( it.hasNext() )
 934            {
 935                ReportSet value = (ReportSet) it.next();
 936                Element el;
 937                if ( elIt != null && elIt.hasNext() )
 938                {
 939                    el = (Element) elIt.next();
 940                    if ( !elIt.hasNext() )
 941                        elIt = null;
 942                }
 943                else
 944                {
 945                    el = factory.element( childTag, element.getNamespace() );
 946                    insertAtPreferredLocation( element, el, innerCount );
 947                }
 948                updateReportSet( value, childTag, innerCount, el );
 949                innerCount.increaseCount();
 950            }
 951            if ( elIt != null )
 952            {
 953                while ( elIt.hasNext() )
 954                {
 955                    elIt.next();
 956                    elIt.remove();
 957                }
 958            }
 959        }
 960    } // -- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
 961
 962    /**
 963     * Method iterateRepository
 964     * 
 965     * @param counter
 966     * @param childTag
 967     * @param parentTag
 968     * @param list
 969     * @param parent
 970     */
 971    protected void iterateRepository( Counter counter, Element parent, java.util.Collection list,
 972                                      java.lang.String parentTag, java.lang.String childTag )
 973    {
 974        boolean shouldExist = list != null && list.size() > 0;
 975        Element element = updateElement( counter, parent, parentTag, shouldExist );
 976        if ( shouldExist )
 977        {
 978            Iterator it = list.iterator();
 979            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
 980            if ( !elIt.hasNext() )
 981                elIt = null;
 982            Counter innerCount = new Counter( counter.getDepth() + 1 );
 983            while ( it.hasNext() )
 984            {
 985                Repository value = (Repository) it.next();
 986                Element el;
 987                if ( elIt != null && elIt.hasNext() )
 988                {
 989                    el = (Element) elIt.next();
 990                    if ( !elIt.hasNext() )
 991                        elIt = null;
 992                }
 993                else
 994                {
 995                    el = factory.element( childTag, element.getNamespace() );
 996                    insertAtPreferredLocation( element, el, innerCount );
 997                }
 998                updateRepository( value, childTag, innerCount, el );
 999                innerCount.increaseCount();
1000            }
1001            if ( elIt != null )
1002            {
1003                while ( elIt.hasNext() )
1004                {
1005                    elIt.next();
1006                    elIt.remove();
1007                }
1008            }
1009        }
1010    } // -- void iterateRepository(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
1011
1012    /**
1013     * Method iterateResource
1014     * 
1015     * @param counter
1016     * @param childTag
1017     * @param parentTag
1018     * @param list
1019     * @param parent
1020     */
1021    protected void iterateResource( Counter counter, Element parent, java.util.Collection list,
1022                                    java.lang.String parentTag, java.lang.String childTag )
1023    {
1024        boolean shouldExist = list != null && list.size() > 0;
1025        Element element = updateElement( counter, parent, parentTag, shouldExist );
1026        if ( shouldExist )
1027        {
1028            Iterator it = list.iterator();
1029            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
1030            if ( !elIt.hasNext() )
1031                elIt = null;
1032            Counter innerCount = new Counter( counter.getDepth() + 1 );
1033            while ( it.hasNext() )
1034            {
1035                Resource value = (Resource) it.next();
1036                Element el;
1037                if ( elIt != null && elIt.hasNext() )
1038                {
1039                    el = (Element) elIt.next();
1040                    if ( !elIt.hasNext() )
1041                        elIt = null;
1042                }
1043                else
1044                {
1045                    el = factory.element( childTag, element.getNamespace() );
1046                    insertAtPreferredLocation( element, el, innerCount );
1047                }
1048                updateResource( value, childTag, innerCount, el );
1049                innerCount.increaseCount();
1050            }
1051            if ( elIt != null )
1052            {
1053                while ( elIt.hasNext() )
1054                {
1055                    elIt.next();
1056                    elIt.remove();
1057                }
1058            }
1059        }
1060    } // -- void iterateResource(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
1061
1062    /**
1063     * Method replaceXpp3DOM
1064     * 
1065     * @param parent
1066     * @param counter
1067     * @param parentDom
1068     */
1069    protected void replaceXpp3DOM( Element parent, Xpp3Dom parentDom, Counter counter )
1070    {
1071        if ( parentDom.getChildCount() > 0 )
1072        {
1073            Xpp3Dom[] childs = parentDom.getChildren();
1074            Collection domChilds = new ArrayList();
1075            for ( int i = 0; i < childs.length; i++ )
1076            {
1077                domChilds.add( childs[i] );
1078            }
1079            // int domIndex = 0;
1080            ListIterator it = parent.getChildren().listIterator();
1081            while ( it.hasNext() )
1082            {
1083                Element elem = (Element) it.next();
1084                Iterator it2 = domChilds.iterator();
1085                Xpp3Dom corrDom = null;
1086                while ( it2.hasNext() )
1087                {
1088                    Xpp3Dom dm = (Xpp3Dom) it2.next();
1089                    if ( dm.getName().equals( elem.getName() ) )
1090                    {
1091                        corrDom = dm;
1092                        break;
1093                    }
1094                }
1095                if ( corrDom != null )
1096                {
1097                    domChilds.remove( corrDom );
1098                    replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );
1099                    counter.increaseCount();
1100                }
1101                else
1102                {
1103                    parent.removeContent( elem );
1104                }
1105            }
1106            Iterator it2 = domChilds.iterator();
1107            while ( it2.hasNext() )
1108            {
1109                Xpp3Dom dm = (Xpp3Dom) it2.next();
1110                Element elem = factory.element( dm.getName(), parent.getNamespace() );
1111                insertAtPreferredLocation( parent, elem, counter );
1112                counter.increaseCount();
1113                replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );
1114            }
1115        }
1116        else if ( parentDom.getValue() != null )
1117        {
1118            parent.setText( parentDom.getValue() );
1119        }
1120    } // -- void replaceXpp3DOM(Element, Xpp3Dom, Counter)
1121
1122    /**
1123     * Method updateActivation
1124     * 
1125     * @param value
1126     * @param element
1127     * @param counter
1128     * @param xmlTag
1129     */
1130    /*
1131     * protected void updateActivation(Activation value, String xmlTag, Counter counter, Element element) { boolean
1132     * shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
1133     * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceSimpleElement(innerCount,
1134     * root, "activeByDefault", !value.isActiveByDefault() ? null : String.valueOf( value.isActiveByDefault() ),
1135     * "false"); findAndReplaceSimpleElement(innerCount, root, "jdk", value.getJdk(), null); updateActivationOS(
1136     * value.getOs(), "os", innerCount, root); updateActivationProperty( value.getProperty(), "property", innerCount,
1137     * root); updateActivationFile( value.getFile(), "file", innerCount, root); updateActivationCustom(
1138     * value.getCustom(), "custom", innerCount, root); } } //-- void updateActivation(Activation, String, Counter,
1139     * Element)
1140     */
1141
1142    /**
1143     * Method updateActivationCustom
1144     * 
1145     * @param value
1146     * @param element
1147     * @param counter
1148     * @param xmlTag
1149     */
1150    /*
1151     * protected void updateActivationCustom(ActivationCustom value, String xmlTag, Counter counter, Element element) {
1152     * boolean shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
1153     * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceXpp3DOM(innerCount, root,
1154     * "configuration", (Xpp3Dom)value.getConfiguration()); findAndReplaceSimpleElement(innerCount, root, "type",
1155     * value.getType(), null); } } //-- void updateActivationCustom(ActivationCustom, String, Counter, Element)
1156     */
1157
1158    /**
1159     * Method updateActivationFile
1160     * 
1161     * @param value
1162     * @param element
1163     * @param counter
1164     * @param xmlTag
1165     */
1166    protected void updateActivationFile( ActivationFile value, String xmlTag, Counter counter, Element element )
1167    {
1168        boolean shouldExist = value != null;
1169        Element root = updateElement( counter, element, xmlTag, shouldExist );
1170        if ( shouldExist )
1171        {
1172            Counter innerCount = new Counter( counter.getDepth() + 1 );
1173            findAndReplaceSimpleElement( innerCount, root, "missing", value.getMissing(), null );
1174            findAndReplaceSimpleElement( innerCount, root, "exists", value.getExists(), null );
1175        }
1176    } // -- void updateActivationFile(ActivationFile, String, Counter, Element)
1177
1178    /**
1179     * Method updateActivationOS
1180     * 
1181     * @param value
1182     * @param element
1183     * @param counter
1184     * @param xmlTag
1185     */
1186    protected void updateActivationOS( ActivationOS value, String xmlTag, Counter counter, Element element )
1187    {
1188        boolean shouldExist = value != null;
1189        Element root = updateElement( counter, element, xmlTag, shouldExist );
1190        if ( shouldExist )
1191        {
1192            Counter innerCount = new Counter( counter.getDepth() + 1 );
1193            findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1194            findAndReplaceSimpleElement( innerCount, root, "family", value.getFamily(), null );
1195            findAndReplaceSimpleElement( innerCount, root, "arch", value.getArch(), null );
1196            findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
1197        }
1198    } // -- void updateActivationOS(ActivationOS, String, Counter, Element)
1199
1200    /**
1201     * Method updateActivationProperty
1202     * 
1203     * @param value
1204     * @param element
1205     * @param counter
1206     * @param xmlTag
1207     */
1208    protected void updateActivationProperty( ActivationProperty value, String xmlTag, Counter counter, Element element )
1209    {
1210        boolean shouldExist = value != null;
1211        Element root = updateElement( counter, element, xmlTag, shouldExist );
1212        if ( shouldExist )
1213        {
1214            Counter innerCount = new Counter( counter.getDepth() + 1 );
1215            findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
1216            findAndReplaceSimpleElement( innerCount, root, "value", value.getValue(), null );
1217        }
1218    } // -- void updateActivationProperty(ActivationProperty, String, Counter, Element)
1219
1220    /**
1221     * Method updateBuild
1222     * 
1223     * @param value
1224     * @param element
1225     * @param counter
1226     * @param xmlTag
1227     */
1228    protected void updateBuild( Build value, String xmlTag, Counter counter, Element element )
1229    {
1230        boolean shouldExist = value != null;
1231        Element root = updateElement( counter, element, xmlTag, shouldExist );
1232        if ( shouldExist )
1233        {
1234            Counter innerCount = new Counter( counter.getDepth() + 1 );
1235            findAndReplaceSimpleElement( innerCount, root, "sourceDirectory", value.getSourceDirectory(), null );
1236            findAndReplaceSimpleElement( innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
1237                                         null );
1238            findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null );
1239            findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
1240            findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null );
1241            iterateExtension( innerCount, root, value.getExtensions(), "extensions", "extension" );
1242            findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
1243            iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
1244            iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
1245            findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1246            findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
1247            findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
1248            updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1249            iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1250        }
1251    } // -- void updateBuild(Build, String, Counter, Element)
1252
1253    /**
1254     * Method updateBuildBase
1255     * 
1256     * @param value
1257     * @param element
1258     * @param counter
1259     * @param xmlTag
1260     */
1261    protected void updateBuildBase( BuildBase value, String xmlTag, Counter counter, Element element )
1262    {
1263        boolean shouldExist = value != null;
1264        Element root = updateElement( counter, element, xmlTag, shouldExist );
1265        if ( shouldExist )
1266        {
1267            Counter innerCount = new Counter( counter.getDepth() + 1 );
1268            findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
1269            iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
1270            iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
1271            findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
1272            findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
1273            findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
1274            updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
1275            iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
1276        }
1277    } // -- void updateBuildBase(BuildBase, String, Counter, Element)
1278
1279    /**
1280     * Method updateCiManagement
1281     * 
1282     * @param value
1283     * @param element
1284     * @param counter
1285     * @param xmlTag
1286     */
1287    protected void updateCiManagement( CiManagement value, String xmlTag, Counter counter, Element element )
1288    {
1289        boolean shouldExist = value != null;
1290        Element root = updateElement( counter, element, xmlTag, shouldExist );
1291        if ( shouldExist )
1292        {
1293            Counter innerCount = new Counter( counter.getDepth() + 1 );
1294            findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
1295            findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
1296            iterateNotifier( innerCount, root, value.getNotifiers(), "notifiers", "notifier" );
1297        }
1298    } // -- void updateCiManagement(CiManagement, String, Counter, Element)
1299
1300    /**
1301     * Method updateConfigurationContainer
1302     * 
1303     * @param value
1304     * @param element
1305     * @param counter
1306     * @param xmlTag
1307     */
1308    protected void updateConfigurationContainer( ConfigurationContainer value, String xmlTag, Counter counter,
1309                                                 Element element )
1310    {
1311        boolean shouldExist = value != null;
1312        Element root = updateElement( counter, element, xmlTag, shouldExist );
1313        if ( shouldExist )
1314        {
1315            Counter innerCount = new Counter( counter.getDepth() + 1 );
1316            findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
1317            findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
1318        }
1319    } // -- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element)
1320
1321    /**
1322     * Method updateContributor
1323     * 
1324     * @param value
1325     * @param element
1326     * @param counter
1327     * @param xmlTag
1328     */
1329    protected void 

Large files files are truncated, but you can click here to view the full file