Coverage Report - org.apache.maven.plugin.eclipse.LinkedResource
 
Classes in this File Line Coverage Branch Coverage Complexity
LinkedResource
50%
27/53
20%
9/44
2.769
 
 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  
     /** Resource localtionURI */
 42  
     private String locationURI;
 43  
 
 44  
     public String getName()
 45  
     {
 46  0
         return name;
 47  
     }
 48  
 
 49  
     public void setName( String name )
 50  
     {
 51  0
         this.name = name;
 52  0
     }
 53  
 
 54  
     public String getType()
 55  
     {
 56  0
         return type;
 57  
     }
 58  
 
 59  
     public void setType( String type )
 60  
     {
 61  0
         this.type = type;
 62  0
     }
 63  
 
 64  
     public String getLocation()
 65  
     {
 66  0
         return location;
 67  
     }
 68  
 
 69  
     public void setLocation( String location )
 70  
     {
 71  0
         this.location = location;
 72  0
     }
 73  
 
 74  
     public String getLocationURI()
 75  
     {
 76  0
         return locationURI;
 77  
     }
 78  
 
 79  
     public void setLocationURI( String locationURI )
 80  
     {
 81  0
         this.locationURI = locationURI;
 82  0
     }
 83  
 
 84  
     /**
 85  
      * Default constructor
 86  
      */
 87  
     public LinkedResource()
 88  
     {
 89  0
         super();
 90  0
     }
 91  
 
 92  
     /**
 93  
      * Creates a LinkedResource from a DOM subtree
 94  
      * <p>
 95  
      * The subtree must represent a &lt;linkedResources&gt; section from an Eclipse .project file
 96  
      * 
 97  
      * @param node DOM node
 98  
      */
 99  
     public LinkedResource( Xpp3Dom node )
 100  1
     {
 101  1
         Xpp3Dom nameNode = node.getChild( "name" );
 102  
 
 103  1
         if ( nameNode == null )
 104  
         {
 105  0
             throw new IllegalArgumentException( "No name node." );
 106  
         }
 107  
 
 108  1
         name = nameNode.getValue();
 109  
 
 110  1
         Xpp3Dom typeNode = node.getChild( "type" );
 111  
 
 112  1
         if ( typeNode == null )
 113  
         {
 114  0
             throw new IllegalArgumentException( "No type node." );
 115  
         }
 116  
 
 117  1
         type = typeNode.getValue();
 118  
 
 119  1
         Xpp3Dom locationNode = node.getChild( "location" );
 120  1
         Xpp3Dom locationURINode = node.getChild( "locationURI" );
 121  
 
 122  1
         if ( locationNode == null && locationURINode == null )
 123  
         {
 124  0
             throw new IllegalArgumentException( "No location or locationURI node." );
 125  
         }
 126  1
         else if ( locationNode != null && locationURINode != null )
 127  
         {
 128  0
             throw new IllegalArgumentException( "Both location and locationURI nodes are set." );
 129  
         }
 130  
 
 131  1
         location = locationNode.getValue();
 132  1
     }
 133  
 
 134  
     public void print( XMLWriter writer )
 135  
     {
 136  1
         writer.startElement( "link" );
 137  
 
 138  1
         writer.startElement( "name" );
 139  1
         writer.writeText( name );
 140  1
         writer.endElement(); // name
 141  
 
 142  1
         writer.startElement( "type" );
 143  1
         writer.writeText( type );
 144  1
         writer.endElement(); // type
 145  
 
 146  1
         if ( location != null )
 147  
         {
 148  1
             writer.startElement( "location" );
 149  1
             writer.writeText( location );
 150  1
             writer.endElement(); // location
 151  
         }
 152  0
         else if ( locationURI != null )
 153  
         {
 154  0
             writer.startElement( "locationURI" );
 155  0
             writer.writeText( locationURI );
 156  0
             writer.endElement(); // locationURI
 157  
         }
 158  1
         writer.endElement();// link
 159  1
     }
 160  
 
 161  
     public boolean equals( Object obj )
 162  
     {
 163  0
         if ( obj instanceof LinkedResource )
 164  
         {
 165  0
             LinkedResource b = (LinkedResource) obj;
 166  
 
 167  0
             return name.equals( b.name ) && ( type == null ? b.type == null : type.equals( b.type ) )
 168  
                 && ( location == null ? b.location == null : location.equals( b.location ) )
 169  
                 && ( locationURI == null ? b.locationURI == null : locationURI.equals( b.locationURI ) );
 170  
         }
 171  
         else
 172  
         {
 173  0
             return false;
 174  
         }
 175  
     }
 176  
 
 177  
     public int hashCode()
 178  
     {
 179  1
         return name.hashCode() + ( type == null ? 0 : 13 * type.hashCode() )
 180  
             + ( location == null ? 0 : 17 * location.hashCode() )
 181  
             + ( locationURI == null ? 0 : 19 * locationURI.hashCode() );
 182  
     }
 183  
 }