View Javadoc
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      ArtifactId( Dependency dependency )
41      {
42          this( dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), dependency.getClassifier() );
43      }
44  
45      ArtifactId( Artifact artifact )
46      {
47          this( artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier() );
48      }
49  
50      ArtifactId( String groupId, String artifactId, String type, String classifier )
51      {
52          this.groupId = ( groupId != null ) ? groupId : "";
53          this.artifactId = ( artifactId != null ) ? artifactId : "";
54          this.type = ( type != null ) ? type : "";
55          this.classifier = ( classifier != null ) ? classifier : "";
56      }
57  
58      ArtifactId( String id )
59      {
60          String[] tokens = new String[0];
61          if ( id != null && id.length() > 0 )
62          {
63              tokens = id.split( ":", -1 );
64          }
65          groupId = ( tokens.length > 0 ) ? tokens[0] : "";
66          artifactId = ( tokens.length > 1 ) ? tokens[1] : "*";
67          type = ( tokens.length > 3 ) ? tokens[2] : "*";
68          classifier = ( tokens.length > 3 ) ? tokens[3] : ( ( tokens.length > 2 ) ? tokens[2] : "*" );
69      }
70  
71      public String getGroupId()
72      {
73          return groupId;
74      }
75  
76      public String getArtifactId()
77      {
78          return artifactId;
79      }
80  
81      public String getType()
82      {
83          return type;
84      }
85  
86      public String getClassifier()
87      {
88          return classifier;
89      }
90  
91      public boolean matches( ArtifactId pattern )
92      {
93          if ( pattern == null )
94          {
95              return false;
96          }
97          if ( !match( getGroupId(), pattern.getGroupId() ) )
98          {
99              return false;
100         }
101         if ( !match( getArtifactId(), pattern.getArtifactId() ) )
102         {
103             return false;
104         }
105         if ( !match( getType(), pattern.getType() ) )
106         {
107             return false;
108         }
109         return match( getClassifier(), pattern.getClassifier() );
110     }
111 
112     private boolean match( String str, String pattern )
113     {
114         return SelectorUtils.match( pattern, str );
115     }
116 
117 }