1 package org.apache.maven.plugin.dependency.utils.translators;
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 /**
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 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
37 * @version $Id: ClassifierTypeTranslator.java 728546 2008-12-21 22:56:51Z bentmann $
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 * (non-Javadoc)
58 *
59 * @see org.apache.mojo.dependency.utils.translators.ArtifactTranslator#translate(java.util.Set,
60 * org.apache.maven.plugin.logging.Log)
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 // this translator must pass both type and classifier here so we
73 // will use the
74 // base artifact value if null comes in
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 // Create a new artifact
96 Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(), artifact
97 .getArtifactId(), artifact.getVersion(), useType, useClassifier );
98
99 // note the new artifacts will always have the scope set to null. We
100 // should
101 // reset it here so that it will pass other filters if needed
102 newArtifact.setScope( artifact.getScope() );
103
104 results.add( newArtifact );
105 }
106
107 return results;
108 }
109
110 /**
111 * @return Returns the type.
112 */
113 public String getType()
114 {
115 return this.type;
116 }
117
118 /**
119 * @param type
120 * The type to set.
121 */
122 public void setType( String theType )
123 {
124 this.type = theType;
125 }
126
127 /**
128 * @return Returns the classifier.
129 */
130 public String getClassifier()
131 {
132 return this.classifier;
133 }
134
135 /**
136 * @param theClassifier
137 * The classifier to set.
138 */
139 public void setClassifier( String theClassifier )
140 {
141 this.classifier = theClassifier;
142 }
143
144 }