Coverage Report - org.apache.maven.plugins.shade.mojo.ArtifactId
 
Classes in this File Line Coverage Branch Coverage Complexity
ArtifactId
86%
30/35
84%
27/32
2,1
 
 1  
 package org.apache.maven.plugins.shade.mojo;
 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.apache.maven.artifact.Artifact;
 23  
 import org.apache.maven.model.Dependency;
 24  
 import org.codehaus.plexus.util.SelectorUtils;
 25  
 
 26  
 /**
 27  
  * @author Benjamin Bentmann
 28  
  */
 29  
 class ArtifactId
 30  
 {
 31  
 
 32  
     private final String groupId;
 33  
 
 34  
     private final String artifactId;
 35  
 
 36  
     private final String type;
 37  
 
 38  
     private final String classifier;
 39  
 
 40  
     public ArtifactId( Dependency dependency )
 41  
     {
 42  0
         this( dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), dependency.getClassifier() );
 43  0
     }
 44  
 
 45  
     public ArtifactId( Artifact artifact )
 46  
     {
 47  0
         this( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier() );
 48  0
     }
 49  
 
 50  
     public ArtifactId( String groupId, String artifactId, String type, String classifier )
 51  50
     {
 52  50
         this.groupId = ( groupId != null ) ? groupId : "";
 53  50
         this.artifactId = ( artifactId != null ) ? artifactId : "";
 54  50
         this.type = ( type != null ) ? type : "";
 55  50
         this.classifier = ( classifier != null ) ? classifier : "";
 56  50
     }
 57  
 
 58  
     public ArtifactId( String id )
 59  55
     {
 60  55
         String[] tokens = new String[0];
 61  55
         if ( id != null && id.length() > 0 )
 62  
         {
 63  53
             tokens = id.split( ":", -1 );
 64  
         }
 65  55
         groupId = ( tokens.length > 0 ) ? tokens[0] : "";
 66  55
         artifactId = ( tokens.length > 1 ) ? tokens[1] : "*";
 67  55
         type = ( tokens.length > 3 ) ? tokens[2] : "*";
 68  55
         classifier = ( tokens.length > 3 ) ? tokens[3] : ( ( tokens.length > 2 ) ? tokens[2] : "*" );
 69  55
     }
 70  
 
 71  
     public String getGroupId()
 72  
     {
 73  111
         return groupId;
 74  
     }
 75  
 
 76  
     public String getArtifactId()
 77  
     {
 78  91
         return artifactId;
 79  
     }
 80  
 
 81  
     public String getType()
 82  
     {
 83  71
         return type;
 84  
     }
 85  
 
 86  
     public String getClassifier()
 87  
     {
 88  69
         return classifier;
 89  
     }
 90  
 
 91  
     public boolean matches( ArtifactId pattern )
 92  
     {
 93  48
         if ( pattern == null )
 94  
         {
 95  0
             return false;
 96  
         }
 97  48
         if ( !match( getGroupId(), pattern.getGroupId() ) )
 98  
         {
 99  9
             return false;
 100  
         }
 101  39
         if ( !match( getArtifactId(), pattern.getArtifactId() ) )
 102  
         {
 103  10
             return false;
 104  
         }
 105  29
         if ( !match( getType(), pattern.getType() ) )
 106  
         {
 107  1
             return false;
 108  
         }
 109  28
         if ( !match( getClassifier(), pattern.getClassifier() ) )
 110  
         {
 111  1
             return false;
 112  
         }
 113  
 
 114  27
         return true;
 115  
     }
 116  
 
 117  
     private boolean match( String str, String pattern )
 118  
     {
 119  144
         return SelectorUtils.match( pattern, str );
 120  
     }
 121  
 
 122  
 }