1 package org.apache.maven.plugins.shade.mojo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }