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