/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 are truncated click here to view the full file
- package org.apache.maven.plugins.shade.pom;
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- //package org.apache.maven.model.io.jdom;
- //---------------------------------/
- //- Imported classes and packages -/
- //---------------------------------/
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.Writer;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.ListIterator;
- import java.util.Map;
- import org.apache.maven.model.ActivationFile;
- import org.apache.maven.model.ActivationOS;
- import org.apache.maven.model.ActivationProperty;
- import org.apache.maven.model.Build;
- import org.apache.maven.model.BuildBase;
- import org.apache.maven.model.CiManagement;
- import org.apache.maven.model.ConfigurationContainer;
- import org.apache.maven.model.Contributor;
- import org.apache.maven.model.Dependency;
- import org.apache.maven.model.DependencyManagement;
- import org.apache.maven.model.DeploymentRepository;
- import org.apache.maven.model.Developer;
- import org.apache.maven.model.DistributionManagement;
- import org.apache.maven.model.Exclusion;
- import org.apache.maven.model.Extension;
- import org.apache.maven.model.FileSet;
- import org.apache.maven.model.IssueManagement;
- import org.apache.maven.model.License;
- import org.apache.maven.model.MailingList;
- import org.apache.maven.model.Model;
- import org.apache.maven.model.ModelBase;
- import org.apache.maven.model.Notifier;
- import org.apache.maven.model.Organization;
- import org.apache.maven.model.Parent;
- import org.apache.maven.model.PatternSet;
- import org.apache.maven.model.Plugin;
- import org.apache.maven.model.PluginConfiguration;
- import org.apache.maven.model.PluginContainer;
- import org.apache.maven.model.PluginExecution;
- import org.apache.maven.model.PluginManagement;
- import org.apache.maven.model.Prerequisites;
- import org.apache.maven.model.Profile;
- import org.apache.maven.model.Relocation;
- import org.apache.maven.model.ReportPlugin;
- import org.apache.maven.model.ReportSet;
- import org.apache.maven.model.Reporting;
- import org.apache.maven.model.Repository;
- import org.apache.maven.model.RepositoryBase;
- import org.apache.maven.model.RepositoryPolicy;
- import org.apache.maven.model.Resource;
- import org.apache.maven.model.Scm;
- import org.apache.maven.model.Site;
- import org.codehaus.plexus.util.xml.Xpp3Dom;
- import org.jdom.Content;
- import org.jdom.DefaultJDOMFactory;
- import org.jdom.Document;
- import org.jdom.Element;
- import org.jdom.Text;
- import org.jdom.output.Format;
- import org.jdom.output.XMLOutputter;
- /**
- * Class MavenJDOMWriter.
- *
- * @since 3.6
- */
- public class MavenJDOMWriter
- {
- // --------------------------/
- // - Class/Member Variables -/
- // --------------------------/
- /**
- * Field factory
- */
- private DefaultJDOMFactory factory;
- /**
- * Field lineSeparator
- */
- private String lineSeparator;
- // ----------------/
- // - Constructors -/
- // ----------------/
- public MavenJDOMWriter()
- {
- factory = new DefaultJDOMFactory();
- lineSeparator = "\n";
- } // -- org.apache.maven.model.io.jdom.MavenJDOMWriter()
- // -----------/
- // - Methods -/
- // -----------/
- /**
- * Method findAndReplaceProperties
- *
- * @param counter
- * @param props
- * @param name
- * @param parent
- */
- protected Element findAndReplaceProperties( Counter counter, Element parent, String name, Map props )
- {
- boolean shouldExist = props != null && !props.isEmpty();
- Element element = updateElement( counter, parent, name, shouldExist );
- if ( shouldExist )
- {
- Iterator it = props.keySet().iterator();
- Counter innerCounter = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- String key = (String) it.next();
- findAndReplaceSimpleElement( innerCounter, element, key, (String) props.get( key ), null );
- }
- ArrayList lst = new ArrayList( props.keySet() );
- it = element.getChildren().iterator();
- while ( it.hasNext() )
- {
- Element elem = (Element) it.next();
- String key = elem.getName();
- if ( !lst.contains( key ) )
- {
- it.remove();
- }
- }
- }
- return element;
- } // -- Element findAndReplaceProperties(Counter, Element, String, Map)
- /**
- * Method findAndReplaceSimpleElement
- *
- * @param counter
- * @param defaultValue
- * @param text
- * @param name
- * @param parent
- */
- protected Element findAndReplaceSimpleElement( Counter counter, Element parent, String name, String text,
- String defaultValue )
- {
- if ( defaultValue != null && text != null && defaultValue.equals( text ) )
- {
- Element element = parent.getChild( name, parent.getNamespace() );
- // if exist and is default value or if doesn't exist.. just keep the way it is..
- if ( ( element != null && defaultValue.equals( element.getText() ) ) || element == null )
- {
- return element;
- }
- }
- boolean shouldExist = text != null && text.trim().length() > 0;
- Element element = updateElement( counter, parent, name, shouldExist );
- if ( shouldExist )
- {
- element.setText( text );
- }
- return element;
- } // -- Element findAndReplaceSimpleElement(Counter, Element, String, String, String)
- /**
- * Method findAndReplaceSimpleLists
- *
- * @param counter
- * @param childName
- * @param parentName
- * @param list
- * @param parent
- */
- protected Element findAndReplaceSimpleLists( Counter counter, Element parent, java.util.Collection list,
- String parentName, String childName )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentName, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childName, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- String value = (String) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childName, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- el.setText( value );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- return element;
- } // -- Element findAndReplaceSimpleLists(Counter, Element, java.util.Collection, String, String)
- /**
- * Method findAndReplaceXpp3DOM
- *
- * @param counter
- * @param dom
- * @param name
- * @param parent
- */
- protected Element findAndReplaceXpp3DOM( Counter counter, Element parent, String name, Xpp3Dom dom )
- {
- boolean shouldExist = dom != null && ( dom.getChildCount() > 0 || dom.getValue() != null );
- Element element = updateElement( counter, parent, name, shouldExist );
- if ( shouldExist )
- {
- replaceXpp3DOM( element, dom, new Counter( counter.getDepth() + 1 ) );
- }
- return element;
- } // -- Element findAndReplaceXpp3DOM(Counter, Element, String, Xpp3Dom)
- /**
- * Method insertAtPreferredLocation
- *
- * @param parent
- * @param counter
- * @param child
- */
- protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
- {
- int contentIndex = 0;
- int elementCounter = 0;
- Iterator it = parent.getContent().iterator();
- Text lastText = null;
- int offset = 0;
- while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )
- {
- Object next = it.next();
- offset = offset + 1;
- if ( next instanceof Element )
- {
- elementCounter = elementCounter + 1;
- contentIndex = contentIndex + offset;
- offset = 0;
- }
- if ( next instanceof Text && it.hasNext() )
- {
- lastText = (Text) next;
- }
- }
- if ( lastText != null && lastText.getTextTrim().length() == 0 )
- {
- lastText = (Text) lastText.clone();
- }
- else
- {
- String starter = lineSeparator;
- for ( int i = 0; i < counter.getDepth(); i++ )
- {
- starter = starter + " ";
- }
- lastText = factory.text( starter );
- }
- if ( parent.getContentSize() == 0 )
- {
- Text finalText = (Text) lastText.clone();
- finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - " ".length() ) );
- parent.addContent( contentIndex, finalText );
- }
- parent.addContent( contentIndex, child );
- parent.addContent( contentIndex, lastText );
- } // -- void insertAtPreferredLocation(Element, Element, Counter)
- /**
- * Method iterateContributor
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateContributor( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Contributor value = (Contributor) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateContributor( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateContributor(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateDependency
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateDependency( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Dependency value = (Dependency) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateDependency( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateDependency(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateDeveloper
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateDeveloper( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Developer value = (Developer) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateDeveloper( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateExclusion
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateExclusion( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Exclusion value = (Exclusion) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateExclusion( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateExclusion(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateExtension
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateExtension( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Extension value = (Extension) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateExtension( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateExtension(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateLicense
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateLicense( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- License value = (License) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateLicense( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateLicense(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateMailingList
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateMailingList( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- MailingList value = (MailingList) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateMailingList( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateMailingList(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateNotifier
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateNotifier( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Notifier value = (Notifier) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateNotifier( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iteratePlugin
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iteratePlugin( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Plugin value = (Plugin) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updatePlugin( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iteratePlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iteratePluginExecution
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iteratePluginExecution( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- PluginExecution value = (PluginExecution) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updatePluginExecution( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iteratePluginExecution(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateProfile
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateProfile( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Profile value = (Profile) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateProfile( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateProfile(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateReportPlugin
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateReportPlugin( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- ReportPlugin value = (ReportPlugin) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateReportPlugin( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateReportPlugin(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateReportSet
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateReportSet( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- ReportSet value = (ReportSet) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateReportSet( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateReportSet(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateRepository
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateRepository( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Repository value = (Repository) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateRepository( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateRepository(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method iterateResource
- *
- * @param counter
- * @param childTag
- * @param parentTag
- * @param list
- * @param parent
- */
- protected void iterateResource( Counter counter, Element parent, java.util.Collection list,
- java.lang.String parentTag, java.lang.String childTag )
- {
- boolean shouldExist = list != null && list.size() > 0;
- Element element = updateElement( counter, parent, parentTag, shouldExist );
- if ( shouldExist )
- {
- Iterator it = list.iterator();
- Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
- if ( !elIt.hasNext() )
- elIt = null;
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- while ( it.hasNext() )
- {
- Resource value = (Resource) it.next();
- Element el;
- if ( elIt != null && elIt.hasNext() )
- {
- el = (Element) elIt.next();
- if ( !elIt.hasNext() )
- elIt = null;
- }
- else
- {
- el = factory.element( childTag, element.getNamespace() );
- insertAtPreferredLocation( element, el, innerCount );
- }
- updateResource( value, childTag, innerCount, el );
- innerCount.increaseCount();
- }
- if ( elIt != null )
- {
- while ( elIt.hasNext() )
- {
- elIt.next();
- elIt.remove();
- }
- }
- }
- } // -- void iterateResource(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
- /**
- * Method replaceXpp3DOM
- *
- * @param parent
- * @param counter
- * @param parentDom
- */
- protected void replaceXpp3DOM( Element parent, Xpp3Dom parentDom, Counter counter )
- {
- if ( parentDom.getChildCount() > 0 )
- {
- Xpp3Dom[] childs = parentDom.getChildren();
- Collection domChilds = new ArrayList();
- for ( int i = 0; i < childs.length; i++ )
- {
- domChilds.add( childs[i] );
- }
- // int domIndex = 0;
- ListIterator it = parent.getChildren().listIterator();
- while ( it.hasNext() )
- {
- Element elem = (Element) it.next();
- Iterator it2 = domChilds.iterator();
- Xpp3Dom corrDom = null;
- while ( it2.hasNext() )
- {
- Xpp3Dom dm = (Xpp3Dom) it2.next();
- if ( dm.getName().equals( elem.getName() ) )
- {
- corrDom = dm;
- break;
- }
- }
- if ( corrDom != null )
- {
- domChilds.remove( corrDom );
- replaceXpp3DOM( elem, corrDom, new Counter( counter.getDepth() + 1 ) );
- counter.increaseCount();
- }
- else
- {
- parent.removeContent( elem );
- }
- }
- Iterator it2 = domChilds.iterator();
- while ( it2.hasNext() )
- {
- Xpp3Dom dm = (Xpp3Dom) it2.next();
- Element elem = factory.element( dm.getName(), parent.getNamespace() );
- insertAtPreferredLocation( parent, elem, counter );
- counter.increaseCount();
- replaceXpp3DOM( elem, dm, new Counter( counter.getDepth() + 1 ) );
- }
- }
- else if ( parentDom.getValue() != null )
- {
- parent.setText( parentDom.getValue() );
- }
- } // -- void replaceXpp3DOM(Element, Xpp3Dom, Counter)
- /**
- * Method updateActivation
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- /*
- * protected void updateActivation(Activation value, String xmlTag, Counter counter, Element element) { boolean
- * shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
- * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceSimpleElement(innerCount,
- * root, "activeByDefault", !value.isActiveByDefault() ? null : String.valueOf( value.isActiveByDefault() ),
- * "false"); findAndReplaceSimpleElement(innerCount, root, "jdk", value.getJdk(), null); updateActivationOS(
- * value.getOs(), "os", innerCount, root); updateActivationProperty( value.getProperty(), "property", innerCount,
- * root); updateActivationFile( value.getFile(), "file", innerCount, root); updateActivationCustom(
- * value.getCustom(), "custom", innerCount, root); } } //-- void updateActivation(Activation, String, Counter,
- * Element)
- */
- /**
- * Method updateActivationCustom
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- /*
- * protected void updateActivationCustom(ActivationCustom value, String xmlTag, Counter counter, Element element) {
- * boolean shouldExist = value != null; Element root = updateElement(counter, element, xmlTag, shouldExist); if
- * (shouldExist) { Counter innerCount = new Counter(counter.getDepth() + 1); findAndReplaceXpp3DOM(innerCount, root,
- * "configuration", (Xpp3Dom)value.getConfiguration()); findAndReplaceSimpleElement(innerCount, root, "type",
- * value.getType(), null); } } //-- void updateActivationCustom(ActivationCustom, String, Counter, Element)
- */
- /**
- * Method updateActivationFile
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateActivationFile( ActivationFile value, String xmlTag, Counter counter, Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "missing", value.getMissing(), null );
- findAndReplaceSimpleElement( innerCount, root, "exists", value.getExists(), null );
- }
- } // -- void updateActivationFile(ActivationFile, String, Counter, Element)
- /**
- * Method updateActivationOS
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateActivationOS( ActivationOS value, String xmlTag, Counter counter, Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
- findAndReplaceSimpleElement( innerCount, root, "family", value.getFamily(), null );
- findAndReplaceSimpleElement( innerCount, root, "arch", value.getArch(), null );
- findAndReplaceSimpleElement( innerCount, root, "version", value.getVersion(), null );
- }
- } // -- void updateActivationOS(ActivationOS, String, Counter, Element)
- /**
- * Method updateActivationProperty
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateActivationProperty( ActivationProperty value, String xmlTag, Counter counter, Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
- findAndReplaceSimpleElement( innerCount, root, "value", value.getValue(), null );
- }
- } // -- void updateActivationProperty(ActivationProperty, String, Counter, Element)
- /**
- * Method updateBuild
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateBuild( Build value, String xmlTag, Counter counter, Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "sourceDirectory", value.getSourceDirectory(), null );
- findAndReplaceSimpleElement( innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
- null );
- findAndReplaceSimpleElement( innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null );
- findAndReplaceSimpleElement( innerCount, root, "outputDirectory", value.getOutputDirectory(), null );
- findAndReplaceSimpleElement( innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null );
- iterateExtension( innerCount, root, value.getExtensions(), "extensions", "extension" );
- findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
- iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
- iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
- findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
- findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
- findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
- updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
- iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
- }
- } // -- void updateBuild(Build, String, Counter, Element)
- /**
- * Method updateBuildBase
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateBuildBase( BuildBase value, String xmlTag, Counter counter, Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
- iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
- iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
- findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
- findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
- findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
- updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
- iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
- }
- } // -- void updateBuildBase(BuildBase, String, Counter, Element)
- /**
- * Method updateCiManagement
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateCiManagement( CiManagement value, String xmlTag, Counter counter, Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "system", value.getSystem(), null );
- findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
- iterateNotifier( innerCount, root, value.getNotifiers(), "notifiers", "notifier" );
- }
- } // -- void updateCiManagement(CiManagement, String, Counter, Element)
- /**
- * Method updateConfigurationContainer
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void updateConfigurationContainer( ConfigurationContainer value, String xmlTag, Counter counter,
- Element element )
- {
- boolean shouldExist = value != null;
- Element root = updateElement( counter, element, xmlTag, shouldExist );
- if ( shouldExist )
- {
- Counter innerCount = new Counter( counter.getDepth() + 1 );
- findAndReplaceSimpleElement( innerCount, root, "inherited", value.getInherited(), null );
- findAndReplaceXpp3DOM( innerCount, root, "configuration", (Xpp3Dom) value.getConfiguration() );
- }
- } // -- void updateConfigurationContainer(ConfigurationContainer, String, Counter, Element)
- /**
- * Method updateContributor
- *
- * @param value
- * @param element
- * @param counter
- * @param xmlTag
- */
- protected void…