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 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 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
32 * @version $Id: ClassifierTypeTranslator.java 1081021 2011-03-13 00:17:39Z hboutemy $
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 * (non-Javadoc)
53 *
54 * @see org.apache.mojo.dependency.utils.translators.ArtifactTranslator#translate(java.util.Set,
55 * org.apache.maven.plugin.logging.Log)
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 // this translator must pass both type and classifier here so we
66 // will use the
67 // base artifact value if null comes in
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 // Create a new artifact
89 Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(), artifact
90 .getArtifactId(), artifact.getVersion(), useType, useClassifier );
91
92 // note the new artifacts will always have the scope set to null. We
93 // should
94 // reset it here so that it will pass other filters if needed
95 newArtifact.setScope( artifact.getScope() );
96
97 results.add( newArtifact );
98 }
99
100 return results;
101 }
102
103 /**
104 * @return Returns the type.
105 */
106 public String getType()
107 {
108 return this.type;
109 }
110
111 /**
112 * @param type
113 * The type to set.
114 */
115 public void setType( String theType )
116 {
117 this.type = theType;
118 }
119
120 /**
121 * @return Returns the classifier.
122 */
123 public String getClassifier()
124 {
125 return this.classifier;
126 }
127
128 /**
129 * @param theClassifier
130 * The classifier to set.
131 */
132 public void setClassifier( String theClassifier )
133 {
134 this.classifier = theClassifier;
135 }
136
137 }