Coverage Report - org.apache.maven.plugin.antrun.AntrunXmlPlexusConfigurationWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
AntrunXmlPlexusConfigurationWriter
0%
0/26
0%
0/8
2
 
 1  
 package org.apache.maven.plugin.antrun;
 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.configuration.PlexusConfiguration;
 23  
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 24  
 import org.codehaus.plexus.util.xml.XMLWriter;
 25  
 
 26  
 import java.io.IOException;
 27  
 import java.io.Writer;
 28  
 
 29  
 /**
 30  
  * Write a plexus configuration to a stream
 31  
  * Note: This class was originally copied from plexus-container-default.  It is duplicated here
 32  
  * to maintain compatibility with both Maven 2.x and Maven 3.x.
 33  
  *
 34  
  */
 35  0
 public class AntrunXmlPlexusConfigurationWriter
 36  
 {
 37  
 
 38  
     public void write( PlexusConfiguration configuration, Writer writer )
 39  
         throws IOException
 40  
     {
 41  0
         int depth = 0;
 42  
 
 43  0
         PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );
 44  0
         write( configuration, xmlWriter, depth );
 45  0
     }
 46  
 
 47  
     private void write( PlexusConfiguration c, XMLWriter w, int depth )
 48  
         throws IOException
 49  
     {
 50  0
         int count = c.getChildCount();
 51  
 
 52  0
         if ( count == 0 )
 53  
         {
 54  0
             writeTag( c, w, depth );
 55  
         }
 56  
         else
 57  
         {
 58  0
             w.startElement( c.getName() );
 59  0
             writeAttributes( c, w );
 60  
 
 61  0
             for ( int i = 0; i < count; i++ )
 62  
             {
 63  0
                 PlexusConfiguration child = c.getChild( i );
 64  
 
 65  0
                 write( child, w, depth + 1 );
 66  
             }
 67  
             
 68  0
             w.endElement();
 69  
         }
 70  0
     }
 71  
 
 72  
     private void writeTag( PlexusConfiguration c, XMLWriter w, int depth )
 73  
         throws IOException
 74  
     {
 75  0
         w.startElement( c.getName() );
 76  
         
 77  0
         writeAttributes( c, w );
 78  
         
 79  0
         String value = c.getValue( null );
 80  0
         if ( value != null )
 81  
         {
 82  0
             w.writeText( value );
 83  
         }
 84  
 
 85  0
         w.endElement();
 86  0
     }
 87  
 
 88  
     private void writeAttributes( PlexusConfiguration c, XMLWriter w )
 89  
         throws IOException
 90  
     {
 91  0
         String[] names = c.getAttributeNames();
 92  
 
 93  0
         for ( int i = 0; i < names.length; i++ )
 94  
         {
 95  0
             w.addAttribute( names[i], c.getAttribute( names[i], null ) );
 96  
         }
 97  0
     }
 98  
 
 99  
 }
 100