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 | 14 | { |
51 | 14 | this.classifier = theClassifier; |
52 | 14 | this.type = theType; |
53 | 14 | this.factory = theFactory; |
54 | 14 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public Set translate( Set artifacts, Log log ) |
63 | |
{ |
64 | 13 | Set results = artifacts; |
65 | |
|
66 | 13 | log.debug( "Translating Artifacts using Classifier: " + this.classifier + " and Type: " + this.type ); |
67 | 13 | results = new HashSet(); |
68 | 13 | for ( Iterator i = artifacts.iterator(); i.hasNext(); ) |
69 | |
{ |
70 | 116 | Artifact artifact = (Artifact) i.next(); |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 116 | String useType = null; |
76 | 116 | if ( StringUtils.isNotEmpty( this.type ) ) |
77 | |
{ |
78 | 78 | useType = this.type; |
79 | |
} |
80 | |
else |
81 | |
{ |
82 | 38 | useType = artifact.getType(); |
83 | |
} |
84 | |
|
85 | 116 | String useClassifier = null; |
86 | 116 | if ( StringUtils.isNotEmpty( this.classifier ) ) |
87 | |
{ |
88 | 92 | useClassifier = this.classifier; |
89 | |
} |
90 | |
else |
91 | |
{ |
92 | 24 | useClassifier = artifact.getClassifier(); |
93 | |
} |
94 | |
|
95 | |
|
96 | 116 | Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(), artifact |
97 | |
.getArtifactId(), artifact.getVersion(), useType, useClassifier ); |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | 116 | newArtifact.setScope( artifact.getScope() ); |
103 | |
|
104 | 116 | results.add( newArtifact ); |
105 | 116 | } |
106 | |
|
107 | 13 | return results; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public String getType() |
114 | |
{ |
115 | 2 | return this.type; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
public void setType( String theType ) |
123 | |
{ |
124 | 1 | this.type = theType; |
125 | 1 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public String getClassifier() |
131 | |
{ |
132 | 2 | return this.classifier; |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public void setClassifier( String theClassifier ) |
140 | |
{ |
141 | 1 | this.classifier = theClassifier; |
142 | 1 | } |
143 | |
|
144 | |
} |