View Javadoc
1   package org.apache.maven.plugins.ear.stub;
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 org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.handler.ArtifactHandler;
24  import org.apache.maven.artifact.metadata.ArtifactMetadata;
25  import org.apache.maven.artifact.repository.ArtifactRepository;
26  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
27  import org.apache.maven.artifact.versioning.ArtifactVersion;
28  import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
29  import org.apache.maven.artifact.versioning.VersionRange;
30  
31  import java.io.File;
32  import java.util.Collection;
33  import java.util.List;
34  
35  /**
36   * A fake {@link Artifact} test stub.
37   * 
38   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
39   */
40  public class ArtifactTestStub
41      implements Artifact
42  
43  {
44      public static final String DEFAULT_VERSION = "1.0";
45  
46      private final String groupId;
47  
48      private final String artifactId;
49  
50      private final String type;
51  
52      private final String classifier;
53  
54      private String version;
55  
56      public ArtifactTestStub( String groupId, String artifactId, String type, String classifier, String version )
57      {
58          this.groupId = groupId;
59          this.artifactId = artifactId;
60          this.type = type;
61          this.classifier = classifier;
62          this.version = version;
63      }
64  
65      public ArtifactTestStub( String groupId, String artifactId, String type, String classifier )
66      {
67          this( groupId, artifactId, type, classifier, DEFAULT_VERSION );
68      }
69  
70      public String getGroupId()
71      {
72          return groupId;
73      }
74  
75      public String getArtifactId()
76      {
77          return artifactId;
78      }
79  
80      public String getVersion()
81      {
82          return version;
83      }
84  
85      public void setVersion( String version )
86      {
87          this.version = version;
88      }
89  
90      public String getScope()
91      {
92          throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
93      }
94  
95      public String getType()
96      {
97          return type;
98      }
99  
100     public String getClassifier()
101     {
102         return classifier;
103     }
104 
105     public boolean hasClassifier()
106     {
107         return classifier != null;
108     }
109 
110     public File getFile()
111     {
112         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
113     }
114 
115     public void setFile( File file )
116     {
117         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
118     }
119 
120     public String getBaseVersion()
121     {
122         return version;
123     }
124 
125     public void setBaseVersion( String string )
126     {
127         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
128     }
129 
130     public String getId()
131     {
132         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
133     }
134 
135     public String getDependencyConflictId()
136     {
137         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
138     }
139 
140     public void addMetadata( ArtifactMetadata artifactMetadata )
141     {
142         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
143     }
144 
145     public Collection<ArtifactMetadata> getMetadataList()
146     {
147         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
148     }
149 
150     public void setRepository( ArtifactRepository artifactRepository )
151     {
152         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
153     }
154 
155     public ArtifactRepository getRepository()
156     {
157         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
158     }
159 
160     public void updateVersion( String string, ArtifactRepository artifactRepository )
161     {
162         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
163     }
164 
165     public String getDownloadUrl()
166     {
167         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
168     }
169 
170     public void setDownloadUrl( String string )
171     {
172         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
173     }
174 
175     public ArtifactFilter getDependencyFilter()
176     {
177         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
178     }
179 
180     public void setDependencyFilter( ArtifactFilter artifactFilter )
181     {
182         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
183     }
184 
185     public ArtifactHandler getArtifactHandler()
186     {
187         return new ArtifactHandlerTestStub( "jar" );
188     }
189 
190     public List<String> getDependencyTrail()
191     {
192         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
193     }
194 
195     public void setDependencyTrail( List<String> list )
196     {
197         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
198     }
199 
200     public void setScope( String string )
201     {
202         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
203     }
204 
205     public VersionRange getVersionRange()
206     {
207         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
208     }
209 
210     public void setVersionRange( VersionRange versionRange )
211     {
212         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
213     }
214 
215     public void selectVersion( String string )
216     {
217         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
218     }
219 
220     public void setGroupId( String string )
221     {
222         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
223     }
224 
225     public void setArtifactId( String string )
226     {
227         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
228     }
229 
230     public boolean isSnapshot()
231     {
232         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
233     }
234 
235     public void setResolved( boolean b )
236     {
237         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
238     }
239 
240     public boolean isResolved()
241     {
242         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
243     }
244 
245     public void setResolvedVersion( String string )
246     {
247         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
248     }
249 
250     public void setArtifactHandler( ArtifactHandler artifactHandler )
251     {
252         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
253     }
254 
255     public boolean isRelease()
256     {
257         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
258     }
259 
260     public void setRelease( boolean b )
261     {
262         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
263     }
264 
265     public List<ArtifactVersion> getAvailableVersions()
266     {
267         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
268     }
269 
270     public void setAvailableVersions( List<ArtifactVersion> list )
271     {
272         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
273     }
274 
275     public boolean isOptional()
276     {
277         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
278     }
279 
280     public void setOptional( boolean b )
281     {
282         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
283     }
284 
285     public ArtifactVersion getSelectedVersion()
286         throws OverConstrainedVersionException
287     {
288         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
289     }
290 
291     public boolean isSelectedVersionKnown()
292         throws OverConstrainedVersionException
293     {
294         throw new UnsupportedOperationException( "not implemented ; fake artifact stub" );
295     }
296 
297     public boolean equals( Object o )
298     {
299         if ( this == o )
300         {
301             return true;
302         }
303         if ( o == null || getClass() != o.getClass() )
304         {
305             return false;
306         }
307 
308         ArtifactTestStub that = (ArtifactTestStub) o;
309 
310         if ( artifactId != null ? !artifactId.equals( that.artifactId ) : that.artifactId != null )
311         {
312             return false;
313         }
314         if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null )
315         {
316             return false;
317         }
318         if ( groupId != null ? !groupId.equals( that.groupId ) : that.groupId != null )
319         {
320             return false;
321         }
322         if ( type != null ? !type.equals( that.type ) : that.type != null )
323         {
324             return false;
325         }
326 
327         return true;
328     }
329 
330     public int hashCode()
331     {
332         int result;
333         result = ( groupId != null ? groupId.hashCode() : 0 );
334         result = 31 * result + ( artifactId != null ? artifactId.hashCode() : 0 );
335         result = 31 * result + ( type != null ? type.hashCode() : 0 );
336         result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
337         return result;
338     }
339 
340     public int compareTo( Artifact o )
341     {
342         if ( this.equals( o ) )
343         {
344             return 0;
345         }
346         else
347         {
348             return 1;
349         }
350     }
351 
352     public ArtifactMetadata getMetadata( Class<?> metadataClass )
353     {
354         // TODO Auto-generated method stub
355         return null;
356     }
357 }