Coverage Report - org.apache.maven.plugin.eclipse.LinkedResource
 
Classes in this File Line Coverage Branch Coverage Complexity
LinkedResource
57%
24/42
19%
5/26
1,727
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 
 20  
 package org.apache.maven.plugin.eclipse;
 21  
 
 22  
 import org.codehaus.plexus.util.xml.XMLWriter;
 23  
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 24  
 
 25  
 /**
 26  
  * Represents a LinkedResources section in the <code>.project</code> file.
 27  
  * 
 28  
  * @author <a href="mailto:ashoknanw@gmail.com">Ashokkumar Sankaran</a>
 29  
  */
 30  
 public class LinkedResource
 31  
 {
 32  
     /** Resource name */
 33  
     private String name;
 34  
 
 35  
     /** Type */
 36  
     private String type;
 37  
 
 38  
     /** Resource location */
 39  
     private String location;
 40  
 
 41  
     public String getName()
 42  
     {
 43  0
         return name;
 44  
     }
 45  
 
 46  
     public void setName( String name )
 47  
     {
 48  0
         this.name = name;
 49  0
     }
 50  
 
 51  
     public String getType()
 52  
     {
 53  0
         return type;
 54  
     }
 55  
 
 56  
     public void setType( String type )
 57  
     {
 58  0
         this.type = type;
 59  0
     }
 60  
 
 61  
     public String getLocation()
 62  
     {
 63  0
         return location;
 64  
     }
 65  
 
 66  
     public void setLocation( String location )
 67  
     {
 68  0
         this.location = location;
 69  0
     }
 70  
 
 71  
     /**
 72  
      * Default constructor
 73  
      */
 74  
     public LinkedResource()
 75  
     {
 76  0
         super();
 77  0
     }
 78  
 
 79  
     /**
 80  
      * Creates a LinkedResource from a DOM subtree
 81  
      * <p>
 82  
      * The subtree must represent a &lt;linkedResources&gt; section from an Eclipse .project file
 83  
      * 
 84  
      * @param node DOM node
 85  
      */
 86  
     public LinkedResource( Xpp3Dom node )
 87  6
     {
 88  6
         Xpp3Dom nameNode = node.getChild( "name" );
 89  
 
 90  6
         if ( nameNode == null )
 91  
         {
 92  0
             throw new IllegalArgumentException( "No name node." );
 93  
         }
 94  
 
 95  6
         name = nameNode.getValue();
 96  
 
 97  6
         Xpp3Dom typeNode = node.getChild( "type" );
 98  
 
 99  6
         if ( typeNode == null )
 100  
         {
 101  0
             throw new IllegalArgumentException( "No type node." );
 102  
         }
 103  
 
 104  6
         type = typeNode.getValue();
 105  
 
 106  6
         Xpp3Dom locationNode = node.getChild( "location" );
 107  
 
 108  6
         if ( locationNode == null )
 109  
         {
 110  0
             throw new IllegalArgumentException( "No location node." );
 111  
         }
 112  
 
 113  6
         location = locationNode.getValue();
 114  6
     }
 115  
 
 116  
     public void print( XMLWriter writer )
 117  
     {
 118  6
         writer.startElement( "link" );
 119  
 
 120  6
         writer.startElement( "name" );
 121  6
         writer.writeText( name );
 122  6
         writer.endElement(); // name
 123  
 
 124  6
         writer.startElement( "type" );
 125  6
         writer.writeText( type );
 126  6
         writer.endElement(); // type
 127  
 
 128  6
         writer.startElement( "location" );
 129  6
         writer.writeText( location );
 130  6
         writer.endElement(); // location
 131  6
         writer.endElement();// link
 132  6
     }
 133  
 
 134  
     public boolean equals( Object obj )
 135  
     {
 136  0
         if ( obj instanceof LinkedResource )
 137  
         {
 138  0
             LinkedResource b = (LinkedResource) obj;
 139  
 
 140  0
             return name.equals( b.name ) && ( type == null ? b.type == null : type.equals( b.type ) )
 141  
                 && ( location == null ? b.location == null : location.equals( b.location ) );
 142  
         }
 143  
         else
 144  
         {
 145  0
             return false;
 146  
         }
 147  
     }
 148  
 
 149  
     public int hashCode()
 150  
     {
 151  6
         return name.hashCode() + ( type == null ? 0 : 13 * type.hashCode() )
 152  
             + ( location == null ? 0 : 17 * location.hashCode() );
 153  
     }
 154  
 }