Coverage Report - org.apache.maven.index.artifact.Gav
 
Classes in this File Line Coverage Branch Coverage Complexity
Gav
31 %
40/129
7 %
8/114
5,4
Gav$1
0 %
0/1
N/A
5,4
Gav$HashType
100 %
2/2
N/A
5,4
Gav$SignatureType
40 %
2/5
0 %
0/2
5,4
 
 1  
 package org.apache.maven.index.artifact;
 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  
 /**
 23  
  * An immutable value class representing unique artifact coordinates.
 24  
  * 
 25  
  * @author cstamas
 26  
  * @author jvanzyl
 27  
  */
 28  
 public class Gav
 29  
 {
 30  
     /**
 31  
      * Enumeration representing Maven artifact hash types
 32  
      */
 33  3
     public enum HashType
 34  
     {
 35  1
         sha1, md5
 36  
     }
 37  
 
 38  
     /**
 39  
      * Enumeration representing Maven artifact signature types
 40  
      */
 41  2
     public enum SignatureType
 42  
     {
 43  1
         gpg;
 44  
 
 45  
         @Override
 46  
         public String toString()
 47  
         {
 48  0
             switch ( this )
 49  
             {
 50  
                 case gpg:
 51  
                 {
 52  0
                     return "asc";
 53  
                 }
 54  
 
 55  
                 default:
 56  
                 {
 57  0
                     return "unknown-signature-type";
 58  
                 }
 59  
             }
 60  
         }
 61  
     }
 62  
 
 63  
     private final String groupId;
 64  
 
 65  
     private final String artifactId;
 66  
 
 67  
     private final String version;
 68  
 
 69  
     private final String baseVersion;
 70  
 
 71  
     private final String classifier;
 72  
 
 73  
     private final String extension;
 74  
 
 75  
     private final Integer snapshotBuildNumber;
 76  
 
 77  
     private final Long snapshotTimeStamp;
 78  
 
 79  
     private final String name;
 80  
 
 81  
     private final boolean snapshot;
 82  
 
 83  
     private final boolean hash;
 84  
 
 85  
     private final HashType hashType;
 86  
 
 87  
     private final boolean signature;
 88  
 
 89  
     private final SignatureType signatureType;
 90  
 
 91  
     public Gav( String groupId, String artifactId, String version )
 92  
     {
 93  0
         this( groupId, artifactId, version, null, null, null, null, null, false, null, false, null );
 94  0
     }
 95  
 
 96  
     /**
 97  
      * Deprecated constructor, left here for backward compatibility. It simply delegates to other constructor and
 98  
      * neglects the snapshot redundant parameter.
 99  
      * 
 100  
      * @deprecated The <code>boolean snapshot</code> parameter is simply neglected. Use the constructor without it.
 101  
      * @param groupId
 102  
      * @param artifactId
 103  
      * @param version
 104  
      * @param classifier
 105  
      * @param extension
 106  
      * @param snapshotBuildNumber
 107  
      * @param snapshotTimeStamp
 108  
      * @param name
 109  
      * @param snapshot
 110  
      * @param hash
 111  
      * @param hashType
 112  
      * @param signature
 113  
      * @param signatureType
 114  
      */
 115  
     public Gav( String groupId, String artifactId, String version, String classifier, String extension,
 116  
                 Integer snapshotBuildNumber, Long snapshotTimeStamp, String name, boolean snapshot, boolean hash,
 117  
                 HashType hashType, boolean signature, SignatureType signatureType )
 118  
     {
 119  0
         this( groupId, artifactId, version, classifier, extension, snapshotBuildNumber, snapshotTimeStamp, name, hash,
 120  
             hashType, signature, signatureType );
 121  0
     }
 122  
 
 123  
     public Gav( String groupId, String artifactId, String version, String classifier, String extension,
 124  
                 Integer snapshotBuildNumber, Long snapshotTimeStamp, String name, boolean hash, HashType hashType,
 125  
                 boolean signature, SignatureType signatureType )
 126  55
     {
 127  55
         this.groupId = groupId;
 128  55
         this.artifactId = artifactId;
 129  55
         this.version = version;
 130  55
         this.snapshot = VersionUtils.isSnapshot( version );
 131  
 
 132  55
         if ( !snapshot )
 133  
         {
 134  21
             this.baseVersion = null;
 135  
         }
 136  
         else
 137  
         {
 138  34
             if ( version.contains( "SNAPSHOT" ) )
 139  
             {
 140  
                 // this is not a timestamped version
 141  18
                 this.baseVersion = null;
 142  
             }
 143  
             else
 144  
             {
 145  
                 // this is a timestamped version (verified against pattern, see above)
 146  
                 // we have XXXXXX-YYYYMMDD.HHMMSS-B
 147  
                 // but XXXXXX may contain "-" too!
 148  
 
 149  
                 // if ( new DefaultNexusEnforcer().isStrict() )
 150  
                 // {
 151  
                 // this.baseVersion = version.substring( 0, version.lastIndexOf( '-' ) );
 152  
                 // this.baseVersion = baseVersion.substring( 0, baseVersion.lastIndexOf( '-' ) ) + "-SNAPSHOT";
 153  
                 // }
 154  
                 // also there may be no XXXXXX (i.e. when version is strictly named SNAPSHOT
 155  
                 // BUT this is not the proper scheme, we will simply loosen up here if requested
 156  
                 // else
 157  
                 // {
 158  
                 // trim the part of 'YYYYMMDD.HHMMSS-BN
 159  16
                 String tempBaseVersion = version.substring( 0, version.lastIndexOf( '-' ) );
 160  16
                 tempBaseVersion = tempBaseVersion.substring( 0, tempBaseVersion.length() - 15 );
 161  
 
 162  16
                 if ( tempBaseVersion.length() > 0 )
 163  
                 {
 164  15
                     this.baseVersion = tempBaseVersion + "SNAPSHOT";
 165  
                 }
 166  
                 else
 167  
                 {
 168  1
                     this.baseVersion = "SNAPSHOT";
 169  
                 }
 170  
                 // }
 171  
             }
 172  
         }
 173  
 
 174  55
         this.classifier = classifier;
 175  55
         this.extension = extension;
 176  55
         this.snapshotBuildNumber = snapshotBuildNumber;
 177  55
         this.snapshotTimeStamp = snapshotTimeStamp;
 178  55
         this.name = name;
 179  55
         this.hash = hash;
 180  55
         this.hashType = hashType;
 181  55
         this.signature = signature;
 182  55
         this.signatureType = signatureType;
 183  55
     }
 184  
 
 185  
     public String getGroupId()
 186  
     {
 187  84
         return groupId;
 188  
     }
 189  
 
 190  
     public String getArtifactId()
 191  
     {
 192  84
         return artifactId;
 193  
     }
 194  
 
 195  
     public String getVersion()
 196  
     {
 197  114
         return version;
 198  
     }
 199  
 
 200  
     public String getBaseVersion()
 201  
     {
 202  69
         if ( baseVersion == null )
 203  
         {
 204  44
             return getVersion();
 205  
         }
 206  
         else
 207  
         {
 208  25
             return baseVersion;
 209  
         }
 210  
     }
 211  
 
 212  
     public String getClassifier()
 213  
     {
 214  108
         return classifier;
 215  
     }
 216  
 
 217  
     public String getExtension()
 218  
     {
 219  79
         return extension;
 220  
     }
 221  
 
 222  
     public String getName()
 223  
     {
 224  121
         return name;
 225  
     }
 226  
 
 227  
     public boolean isSnapshot()
 228  
     {
 229  47
         return snapshot;
 230  
     }
 231  
 
 232  
     public Integer getSnapshotBuildNumber()
 233  
     {
 234  43
         return snapshotBuildNumber;
 235  
     }
 236  
 
 237  
     public Long getSnapshotTimeStamp()
 238  
     {
 239  43
         return snapshotTimeStamp;
 240  
     }
 241  
 
 242  
     public boolean isHash()
 243  
     {
 244  58
         return hash;
 245  
     }
 246  
 
 247  
     public HashType getHashType()
 248  
     {
 249  46
         return hashType;
 250  
     }
 251  
 
 252  
     public boolean isSignature()
 253  
     {
 254  5
         return signature;
 255  
     }
 256  
 
 257  
     public SignatureType getSignatureType()
 258  
     {
 259  2
         return signatureType;
 260  
     }
 261  
 
 262  
     @Override
 263  
     public int hashCode()
 264  
     {
 265  0
         int result = 1;
 266  0
         result = 31 * result + ( groupId == null ? 0 : groupId.hashCode() );
 267  0
         result = 31 * result + ( artifactId == null ? 0 : artifactId.hashCode() );
 268  0
         result = 31 * result + ( version == null ? 0 : version.hashCode() );
 269  0
         result = 31 * result + ( baseVersion == null ? 0 : baseVersion.hashCode() );
 270  0
         result = 31 * result + ( classifier == null ? 0 : classifier.hashCode() );
 271  0
         result = 31 * result + ( extension == null ? 0 : extension.hashCode() );
 272  0
         result = 31 * result + ( name == null ? 0 : name.hashCode() );
 273  0
         result = 31 * result + ( snapshot ? 1231 : 1237 );
 274  0
         result = 31 * result + ( snapshotBuildNumber == null ? 0 : snapshotBuildNumber.hashCode() );
 275  0
         result = 31 * result + ( snapshotTimeStamp == null ? 0 : snapshotTimeStamp.hashCode() );
 276  0
         result = 31 * result + ( hash ? 1231 : 1237 );
 277  0
         result = 31 * result + ( hashType == null ? 0 : hashType.hashCode() );
 278  0
         result = 31 * result + ( signature ? 1231 : 1237 );
 279  0
         result = 31 * result + ( signatureType == null ? 0 : signatureType.hashCode() );
 280  0
         return result;
 281  
     }
 282  
 
 283  
     @Override
 284  
     public boolean equals( Object obj )
 285  
     {
 286  0
         if ( this == obj )
 287  
         {
 288  0
             return true;
 289  
         }
 290  0
         if ( obj == null )
 291  
         {
 292  0
             return false;
 293  
         }
 294  0
         if ( getClass() != obj.getClass() )
 295  
         {
 296  0
             return false;
 297  
         }
 298  
 
 299  0
         Gav other = (Gav) obj;
 300  
 
 301  0
         if ( groupId == null )
 302  
         {
 303  0
             if ( other.groupId != null )
 304  
             {
 305  0
                 return false;
 306  
             }
 307  
         }
 308  0
         else if ( !groupId.equals( other.groupId ) )
 309  
         {
 310  0
             return false;
 311  
         }
 312  
 
 313  0
         if ( artifactId == null )
 314  
         {
 315  0
             if ( other.artifactId != null )
 316  
             {
 317  0
                 return false;
 318  
             }
 319  
         }
 320  0
         else if ( !artifactId.equals( other.artifactId ) )
 321  
         {
 322  0
             return false;
 323  
         }
 324  
 
 325  0
         if ( version == null )
 326  
         {
 327  0
             if ( other.version != null )
 328  
             {
 329  0
                 return false;
 330  
             }
 331  
         }
 332  0
         else if ( !version.equals( other.version ) )
 333  
         {
 334  0
             return false;
 335  
         }
 336  
 
 337  0
         if ( baseVersion == null )
 338  
         {
 339  0
             if ( other.baseVersion != null )
 340  
             {
 341  0
                 return false;
 342  
             }
 343  
         }
 344  0
         else if ( !baseVersion.equals( other.baseVersion ) )
 345  
         {
 346  0
             return false;
 347  
         }
 348  
 
 349  0
         if ( classifier == null )
 350  
         {
 351  0
             if ( other.classifier != null )
 352  
             {
 353  0
                 return false;
 354  
             }
 355  
         }
 356  0
         else if ( !classifier.equals( other.classifier ) )
 357  
         {
 358  0
             return false;
 359  
         }
 360  
 
 361  0
         if ( extension == null )
 362  
         {
 363  0
             if ( other.extension != null )
 364  
             {
 365  0
                 return false;
 366  
             }
 367  
         }
 368  0
         else if ( !extension.equals( other.extension ) )
 369  
         {
 370  0
             return false;
 371  
         }
 372  
 
 373  0
         if ( name == null )
 374  
         {
 375  0
             if ( other.name != null )
 376  
             {
 377  0
                 return false;
 378  
             }
 379  
         }
 380  0
         else if ( !name.equals( other.name ) )
 381  
         {
 382  0
             return false;
 383  
         }
 384  
 
 385  0
         if ( snapshot != other.snapshot )
 386  
         {
 387  0
             return false;
 388  
         }
 389  
 
 390  0
         if ( snapshotBuildNumber == null )
 391  
         {
 392  0
             if ( other.snapshotBuildNumber != null )
 393  
             {
 394  0
                 return false;
 395  
             }
 396  
         }
 397  0
         else if ( !snapshotBuildNumber.equals( other.snapshotBuildNumber ) )
 398  
         {
 399  0
             return false;
 400  
         }
 401  
 
 402  0
         if ( snapshotTimeStamp == null )
 403  
         {
 404  0
             if ( other.snapshotTimeStamp != null )
 405  
             {
 406  0
                 return false;
 407  
             }
 408  
         }
 409  0
         else if ( !snapshotTimeStamp.equals( other.snapshotTimeStamp ) )
 410  
         {
 411  0
             return false;
 412  
         }
 413  
 
 414  0
         if ( hash != other.hash )
 415  
         {
 416  0
             return false;
 417  
         }
 418  
 
 419  0
         if ( hashType == null )
 420  
         {
 421  0
             if ( other.hashType != null )
 422  
             {
 423  0
                 return false;
 424  
             }
 425  
         }
 426  0
         else if ( !hashType.equals( other.hashType ) )
 427  
         {
 428  0
             return false;
 429  
         }
 430  
 
 431  0
         if ( signature != other.signature )
 432  
         {
 433  0
             return false;
 434  
         }
 435  
 
 436  0
         if ( signatureType == null )
 437  
         {
 438  0
             if ( other.signatureType != null )
 439  
             {
 440  0
                 return false;
 441  
             }
 442  
         }
 443  0
         else if ( !signatureType.equals( other.signatureType ) )
 444  
         {
 445  0
             return false;
 446  
         }
 447  
 
 448  0
         return true;
 449  
     }
 450  
 }