1 package org.apache.maven.plugin.dependency.utils.translators;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashSet;
23 import java.util.Set;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.factory.ArtifactFactory;
27 import org.apache.maven.plugin.logging.Log;
28 import org.codehaus.plexus.util.StringUtils;
29
30
31
32
33
34 public class ClassifierTypeTranslator
35 implements ArtifactTranslator
36 {
37
38 private String classifier;
39
40 private String type;
41
42 private ArtifactFactory factory;
43
44 public ClassifierTypeTranslator( String theClassifier, String theType, ArtifactFactory theFactory )
45 {
46 this.classifier = theClassifier;
47 this.type = theType;
48 this.factory = theFactory;
49 }
50
51
52
53
54
55
56
57 public Set<Artifact> translate( Set<Artifact> artifacts, Log log )
58 {
59 Set<Artifact> results = artifacts;
60
61 log.debug( "Translating Artifacts using Classifier: " + this.classifier + " and Type: " + this.type );
62 results = new HashSet<Artifact>();
63 for ( Artifact artifact : artifacts )
64 {
65
66
67
68 String useType = null;
69 if ( StringUtils.isNotEmpty( this.type ) )
70 {
71 useType = this.type;
72 }
73 else
74 {
75 useType = artifact.getType();
76 }
77
78 String useClassifier = null;
79 if ( StringUtils.isNotEmpty( this.classifier ) )
80 {
81 useClassifier = this.classifier;
82 }
83 else
84 {
85 useClassifier = artifact.getClassifier();
86 }
87
88
89 Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(), artifact
90 .getArtifactId(), artifact.getVersion(), useType, useClassifier );
91
92
93
94
95 newArtifact.setScope( artifact.getScope() );
96
97 results.add( newArtifact );
98 }
99
100 return results;
101 }
102
103
104
105
106 public String getType()
107 {
108 return this.type;
109 }
110
111
112
113
114
115 public void setType( String theType )
116 {
117 this.type = theType;
118 }
119
120
121
122
123 public String getClassifier()
124 {
125 return this.classifier;
126 }
127
128
129
130
131
132 public void setClassifier( String theClassifier )
133 {
134 this.classifier = theClassifier;
135 }
136
137 }