Coverage Report - org.apache.maven.archetype.creator.olddescriptor.OldArchetypeDescriptorXpp3Writer
 
Classes in this File Line Coverage Branch Coverage Complexity
OldArchetypeDescriptorXpp3Writer
88 %
44/50
71 %
24/34
7
 
 1  
 package org.apache.maven.archetype.creator.olddescriptor;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.codehaus.plexus.util.xml.pull.MXSerializer;
 23  
 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
 24  
 
 25  
 import java.io.Writer;
 26  
 import java.util.Iterator;
 27  
 
 28  
 /** @author rafale */
 29  4
 public class OldArchetypeDescriptorXpp3Writer
 30  
 {
 31  
     private String NAMESPACE;
 32  
 
 33  
     public void write( Writer writer,
 34  
                        OldArchetypeDescriptor descriptor )
 35  
         throws
 36  
         java.io.IOException
 37  
     {
 38  4
         XmlSerializer serializer = new MXSerializer();
 39  4
         serializer.setProperty(
 40  
             "http://xmlpull.org/v1/doc/properties.html#serializer-indentation",
 41  
             "  "
 42  
         );
 43  4
         serializer.setProperty(
 44  
             "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator",
 45  
             "\n"
 46  
         );
 47  4
         serializer.setOutput( writer );
 48  4
         serializer.startDocument( "UTF-8", null );
 49  4
         writeArchetypeDescriptor( descriptor, "archetype", serializer );
 50  4
         serializer.endDocument();
 51  4
     }
 52  
 
 53  
     private void writeArchetypeDescriptor(
 54  
         OldArchetypeDescriptor descriptor,
 55  
         String tagName,
 56  
         XmlSerializer serializer
 57  
     )
 58  
         throws
 59  
         java.io.IOException
 60  
     {
 61  4
         if ( descriptor != null )
 62  
         {
 63  4
             serializer.startTag( NAMESPACE, tagName );
 64  4
             if ( descriptor.getId() != null )
 65  
             {
 66  4
                 serializer.startTag( NAMESPACE, "id" ).text( descriptor.getId() ).endTag(
 67  
                     NAMESPACE,
 68  
                     "id"
 69  
                 );
 70  
             }
 71  4
             if ( ( descriptor.getSources() != null ) && ( descriptor.getSources().size() > 0 ) )
 72  
             {
 73  2
                 serializer.startTag( NAMESPACE, "sources" );
 74  2
                 for ( Iterator iter = descriptor.getSources().iterator(); iter.hasNext(); )
 75  
                 {
 76  2
                     String source = (String) iter.next();
 77  2
                     serializer.startTag( NAMESPACE, "source" ).text( source ).endTag(
 78  
                         NAMESPACE,
 79  
                         "source"
 80  
                     );
 81  2
                 }
 82  2
                 serializer.endTag( NAMESPACE, "sources" );
 83  
             }
 84  4
             if ( ( descriptor.getTestSources() != null )
 85  
                 && ( descriptor.getTestSources().size() > 0 )
 86  
                 )
 87  
             {
 88  2
                 serializer.startTag( NAMESPACE, "testSources" );
 89  2
                 for ( Iterator iter = descriptor.getTestSources().iterator(); iter.hasNext(); )
 90  
                 {
 91  2
                     String source = (String) iter.next();
 92  2
                     serializer.startTag( NAMESPACE, "source" ).text( source ).endTag(
 93  
                         NAMESPACE,
 94  
                         "source"
 95  
                     );
 96  2
                 }
 97  2
                 serializer.endTag( NAMESPACE, "testSources" );
 98  
             }
 99  4
             if ( ( descriptor.getResources() != null )
 100  
                 && ( descriptor.getResources().size() > 0 )
 101  
                 )
 102  
             {
 103  2
                 serializer.startTag( NAMESPACE, "resources" );
 104  2
                 for ( Iterator iter = descriptor.getResources().iterator(); iter.hasNext(); )
 105  
                 {
 106  51
                     String source = (String) iter.next();
 107  51
                     serializer.startTag( NAMESPACE, "resource" ).text( source ).endTag(
 108  
                         NAMESPACE,
 109  
                         "resource"
 110  
                     );
 111  51
                 }
 112  2
                 serializer.endTag( NAMESPACE, "resources" );
 113  
             }
 114  4
             if ( ( descriptor.getTestResources() != null )
 115  
                 && ( descriptor.getTestResources().size() > 0 )
 116  
                 )
 117  
             {
 118  0
                 serializer.startTag( NAMESPACE, "testResources" );
 119  0
                 for ( Iterator iter = descriptor.getTestResources().iterator(); iter.hasNext(); )
 120  
                 {
 121  0
                     String source = (String) iter.next();
 122  0
                     serializer.startTag( NAMESPACE, "resource" ).text( source ).endTag(
 123  
                         NAMESPACE,
 124  
                         "resource"
 125  
                     );
 126  0
                 }
 127  0
                 serializer.endTag( NAMESPACE, "testResources" );
 128  
             }
 129  4
             if ( ( descriptor.getSiteResources() != null )
 130  
                 && ( descriptor.getSiteResources().size() > 0 )
 131  
                 )
 132  
             {
 133  2
                 serializer.startTag( NAMESPACE, "siteResources" );
 134  2
                 for ( Iterator iter = descriptor.getSiteResources().iterator(); iter.hasNext(); )
 135  
                 {
 136  4
                     String source = (String) iter.next();
 137  4
                     serializer.startTag( NAMESPACE, "resource" ).text( source ).endTag(
 138  
                         NAMESPACE,
 139  
                         "resource"
 140  
                     );
 141  4
                 }
 142  2
                 serializer.endTag( NAMESPACE, "siteResources" );
 143  
             }
 144  4
             serializer.endTag( NAMESPACE, tagName );
 145  
         } // end if
 146  4
     }
 147  
 }