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