Coverage Report - org.apache.maven.shared.runtime.MavenProjectProperties
 
Classes in this File Line Coverage Branch Coverage Complexity
MavenProjectProperties
97%
34/35
93%
15/16
2,714
 
 1  
 package org.apache.maven.shared.runtime;
 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 java.io.Serializable;
 23  
 
 24  
 /**
 25  
  * Encapsulates the unique identifier for a Maven project.
 26  
  * <p>
 27  
  * More specifically, this object holds a project's group id, artifact id and version. This information is typically
 28  
  * generated by Maven and stored within the file
 29  
  * {@code META-INF/maven/<groupId>/<artifactId>/pom.properties} in the packaged project.
 30  
  * </p>
 31  
  * 
 32  
  * @author <a href="mailto:markh@apache.org">Mark Hobson</a>
 33  
  * @version $Id: MavenProjectProperties.java 831910 2009-11-02 15:05:33Z markh $
 34  
  */
 35  
 public class MavenProjectProperties implements Serializable
 36  
 {
 37  
     // constants --------------------------------------------------------------
 38  
 
 39  
     /**
 40  
      * The serial version ID.
 41  
      */
 42  
     private static final long serialVersionUID = 5233832086526764232L;
 43  
 
 44  
     // fields -----------------------------------------------------------------
 45  
 
 46  
     /**
 47  
      * The Maven project group id.
 48  
      */
 49  
     private final String groupId;
 50  
 
 51  
     /**
 52  
      * The Maven project artifact id.
 53  
      */
 54  
     private final String artifactId;
 55  
 
 56  
     /**
 57  
      * The Maven project version.
 58  
      */
 59  
     private final String version;
 60  
 
 61  
     // constructors -----------------------------------------------------------
 62  
 
 63  
     /**
 64  
      * Creates a new {@code MavenProjectProperties} with the specified Maven project group id, artifact id and version 
 65  
      * properties.
 66  
      * 
 67  
      * @param groupId
 68  
      *            the group id, not null
 69  
      * @param artifactId
 70  
      *            the artifact id, not null
 71  
      * @param version
 72  
      *            the version, not null
 73  
      */
 74  
     public MavenProjectProperties( String groupId, String artifactId, String version )
 75  136
     {
 76  136
         if ( groupId == null )
 77  
         {
 78  4
             throw new IllegalArgumentException( "groupId cannot be null" );
 79  
         }
 80  
 
 81  132
         if ( artifactId == null )
 82  
         {
 83  4
             throw new IllegalArgumentException( "artifactId cannot be null" );
 84  
         }
 85  
 
 86  128
         if ( version == null )
 87  
         {
 88  4
             throw new IllegalArgumentException( "version cannot be null" );
 89  
         }
 90  
 
 91  124
         this.groupId = groupId;
 92  124
         this.artifactId = artifactId;
 93  124
         this.version = version;
 94  124
     }
 95  
 
 96  
     // public methods ---------------------------------------------------------
 97  
 
 98  
     /**
 99  
      * Gets the group id for these Maven project properties.
 100  
      * 
 101  
      * @return the group id
 102  
      */
 103  
     public String getGroupId()
 104  
     {
 105  92
         return groupId;
 106  
     }
 107  
 
 108  
     /**
 109  
      * Gets the artifact id for these Maven project properties.
 110  
      * 
 111  
      * @return the artifact id
 112  
      */
 113  
     public String getArtifactId()
 114  
     {
 115  88
         return artifactId;
 116  
     }
 117  
 
 118  
     /**
 119  
      * Gets the version for these Maven project properties.
 120  
      * 
 121  
      * @return the version
 122  
      */
 123  
     public String getVersion()
 124  
     {
 125  84
         return version;
 126  
     }
 127  
 
 128  
     // Object methods ---------------------------------------------------------
 129  
 
 130  
     /**
 131  
      * {@inheritDoc}
 132  
      */
 133  
     @Override
 134  
     public int hashCode()
 135  
     {
 136  8
         int hashCode = 17;
 137  
         
 138  8
         hashCode = ( hashCode * 37 ) + groupId.hashCode();
 139  
 
 140  8
         hashCode = ( hashCode * 37 ) + artifactId.hashCode();
 141  
 
 142  8
         hashCode = ( hashCode * 37 ) + version.hashCode();
 143  
 
 144  8
         return hashCode;
 145  
     }
 146  
 
 147  
     /**
 148  
      * {@inheritDoc}
 149  
      */
 150  
     @Override
 151  
     public boolean equals( Object object )
 152  
     {
 153  20
         if ( object == this )
 154  
         {
 155  0
             return true;
 156  
         }
 157  
         
 158  20
         if ( !( object instanceof MavenProjectProperties ) )
 159  
         {
 160  4
             return false;
 161  
         }
 162  
 
 163  16
         MavenProjectProperties info = (MavenProjectProperties) object;
 164  
 
 165  32
         return groupId.equals( info.getGroupId() )
 166  12
             && artifactId.equals( info.getArtifactId() )
 167  8
             && version.equals( info.getVersion() );
 168  
     }
 169  
 
 170  
     /**
 171  
      * {@inheritDoc}
 172  
      */
 173  
     @Override
 174  
     public String toString()
 175  
     {
 176  4
         StringBuffer buffer = new StringBuffer();
 177  
 
 178  4
         buffer.append( getClass().getName() );
 179  4
         buffer.append( "[" );
 180  4
         buffer.append( "groupId=" ).append( groupId ).append( "," );
 181  4
         buffer.append( "artifactId=" ).append( artifactId ).append( "," );
 182  4
         buffer.append( "version=" ).append( version );
 183  4
         buffer.append( "]" );
 184  
 
 185  4
         return buffer.toString();
 186  
     }
 187  
 }