View Javadoc

1   package org.apache.maven.index.artifact;
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.text.ParseException;
23  import java.text.SimpleDateFormat;
24  
25  import org.apache.maven.index.artifact.Gav;
26  import org.apache.maven.index.artifact.M1GavCalculator;
27  
28  import junit.framework.TestCase;
29  
30  public class M1GavCalculatorTest
31      extends TestCase
32  {
33      private M1GavCalculator gavCalculator;
34  
35      private SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
36  
37      @Override
38      public void setUp()
39          throws Exception
40      {
41          super.setUp();
42  
43          gavCalculator = new M1GavCalculator();
44      }
45  
46      protected Long parseTimestamp( String timeStamp )
47          throws ParseException
48      {
49          if ( timeStamp == null )
50          {
51              return null;
52          }
53          else
54          {
55              return Long.valueOf( formatter.parse( timeStamp ).getTime() );
56          }
57      }
58  
59      public void testGav()
60          throws Exception
61      {
62          Gav gav = gavCalculator.pathToGav( "/org.jruby/javadocs/jruby-1.0RC1-SNAPSHOT-javadoc.jar" );
63  
64          assertEquals( "org.jruby", gav.getGroupId() );
65          assertEquals( "jruby", gav.getArtifactId() );
66          assertEquals( "1.0RC1-SNAPSHOT", gav.getVersion() );
67          assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
68          assertEquals( "javadoc", gav.getClassifier() );
69          assertEquals( "jar", gav.getExtension() );
70          assertEquals( null, gav.getSnapshotBuildNumber() );
71          assertEquals( null, gav.getSnapshotTimeStamp() );
72          assertEquals( "jruby-1.0RC1-SNAPSHOT-javadoc.jar", gav.getName() );
73          assertEquals( true, gav.isSnapshot() );
74          assertEquals( false, gav.isHash() );
75          assertEquals( null, gav.getHashType() );
76  
77          String path = gavCalculator.gavToPath( gav );
78          assertEquals( "/org.jruby/javadocs/jruby-1.0RC1-SNAPSHOT-javadoc.jar", path );
79  
80          gav = gavCalculator.pathToGav( "/org.jruby/jars/jruby-1.0RC1-SNAPSHOT.jar" );
81  
82          assertEquals( "org.jruby", gav.getGroupId() );
83          assertEquals( "jruby", gav.getArtifactId() );
84          assertEquals( "1.0RC1-SNAPSHOT", gav.getVersion() );
85          assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
86          assertEquals( null, gav.getClassifier() );
87          assertEquals( "jar", gav.getExtension() );
88          assertEquals( null, gav.getSnapshotBuildNumber() );
89          assertEquals( null, gav.getSnapshotTimeStamp() );
90          assertEquals( "jruby-1.0RC1-SNAPSHOT.jar", gav.getName() );
91          assertEquals( true, gav.isSnapshot() );
92          assertEquals( false, gav.isHash() );
93          assertEquals( null, gav.getHashType() );
94  
95          path = gavCalculator.gavToPath( gav );
96          assertEquals( "/org.jruby/jars/jruby-1.0RC1-SNAPSHOT.jar", path );
97  
98          gav = gavCalculator.pathToGav( "/org.jruby/jars/jruby-1.0RC1-SNAPSHOT.jar.md5" );
99  
100         assertEquals( "org.jruby", gav.getGroupId() );
101         assertEquals( "jruby", gav.getArtifactId() );
102         assertEquals( "1.0RC1-SNAPSHOT", gav.getVersion() );
103         assertEquals( "1.0RC1-SNAPSHOT", gav.getBaseVersion() );
104         assertEquals( null, gav.getClassifier() );
105         assertEquals( "jar", gav.getExtension() );
106         assertEquals( null, gav.getSnapshotBuildNumber() );
107         assertEquals( null, gav.getSnapshotTimeStamp() );
108         assertEquals( "jruby-1.0RC1-SNAPSHOT.jar.md5", gav.getName() );
109         assertEquals( true, gav.isSnapshot() );
110         assertEquals( true, gav.isHash() );
111         assertEquals( Gav.HashType.md5, gav.getHashType() );
112 
113         path = gavCalculator.gavToPath( gav );
114         assertEquals( "/org.jruby/jars/jruby-1.0RC1-SNAPSHOT.jar.md5", path );
115 
116         gav = gavCalculator.pathToGav( "/org.jruby/javadocs/jruby-1.0-javadoc.jar" );
117 
118         assertEquals( "org.jruby", gav.getGroupId() );
119         assertEquals( "jruby", gav.getArtifactId() );
120         assertEquals( "1.0", gav.getVersion() );
121         assertEquals( "1.0", gav.getBaseVersion() );
122         assertEquals( "javadoc", gav.getClassifier() );
123         assertEquals( "jar", gav.getExtension() );
124         assertEquals( null, gav.getSnapshotBuildNumber() );
125         assertEquals( null, gav.getSnapshotTimeStamp() );
126         assertEquals( "jruby-1.0-javadoc.jar", gav.getName() );
127         assertEquals( false, gav.isSnapshot() );
128         assertEquals( false, gav.isHash() );
129         assertEquals( null, gav.getHashType() );
130 
131         path = gavCalculator.gavToPath( gav );
132         assertEquals( "/org.jruby/javadocs/jruby-1.0-javadoc.jar", path );
133 
134         gav = gavCalculator.pathToGav( "/org.jruby/javadocs/jruby-1.0-javadoc.jar.sha1" );
135 
136         assertEquals( "org.jruby", gav.getGroupId() );
137         assertEquals( "jruby", gav.getArtifactId() );
138         assertEquals( "1.0", gav.getVersion() );
139         assertEquals( "1.0", gav.getBaseVersion() );
140         assertEquals( "javadoc", gav.getClassifier() );
141         assertEquals( "jar", gav.getExtension() );
142         assertEquals( null, gav.getSnapshotBuildNumber() );
143         assertEquals( null, gav.getSnapshotTimeStamp() );
144         assertEquals( "jruby-1.0-javadoc.jar.sha1", gav.getName() );
145         assertEquals( false, gav.isSnapshot() );
146         assertEquals( true, gav.isHash() );
147         assertEquals( Gav.HashType.sha1, gav.getHashType() );
148 
149         path = gavCalculator.gavToPath( gav );
150         assertEquals( "/org.jruby/javadocs/jruby-1.0-javadoc.jar.sha1", path );
151 
152         gav = gavCalculator.pathToGav( "/org.jruby/jars/jruby-1.0.jar" );
153 
154         assertEquals( "org.jruby", gav.getGroupId() );
155         assertEquals( "jruby", gav.getArtifactId() );
156         assertEquals( "1.0", gav.getVersion() );
157         assertEquals( "1.0", gav.getBaseVersion() );
158         assertEquals( null, gav.getClassifier() );
159         assertEquals( "jar", gav.getExtension() );
160         assertEquals( null, gav.getSnapshotBuildNumber() );
161         assertEquals( null, gav.getSnapshotTimeStamp() );
162         assertEquals( "jruby-1.0.jar", gav.getName() );
163         assertEquals( false, gav.isSnapshot() );
164         assertEquals( false, gav.isHash() );
165         assertEquals( null, gav.getHashType() );
166 
167         path = gavCalculator.gavToPath( gav );
168         assertEquals( "/org.jruby/jars/jruby-1.0.jar", path );
169 
170         gav = gavCalculator.pathToGav( "/maven/jars/dom4j-1.7-20060614.jar" );
171 
172         assertEquals( "maven", gav.getGroupId() );
173         assertEquals( "dom4j", gav.getArtifactId() );
174         assertEquals( "1.7-20060614", gav.getVersion() );
175         assertEquals( "1.7-20060614", gav.getBaseVersion() );
176         assertEquals( null, gav.getClassifier() );
177         assertEquals( "jar", gav.getExtension() );
178         assertEquals( null, gav.getSnapshotBuildNumber() );
179         assertEquals( null, gav.getSnapshotTimeStamp() );
180         assertEquals( "dom4j-1.7-20060614.jar", gav.getName() );
181         assertEquals( false, gav.isSnapshot() );
182         assertEquals( false, gav.isHash() );
183         assertEquals( null, gav.getHashType() );
184 
185         path = gavCalculator.gavToPath( gav );
186         assertEquals( "/maven/jars/dom4j-1.7-20060614.jar", path );
187 
188         gav = gavCalculator.pathToGav( "maven/java-sources/velocity-1.5-SNAPSHOT-sources.jar" );
189 
190         assertEquals( "maven", gav.getGroupId() );
191         assertEquals( "velocity", gav.getArtifactId() );
192         assertEquals( "1.5-SNAPSHOT", gav.getVersion() );
193         assertEquals( "1.5-SNAPSHOT", gav.getBaseVersion() );
194         assertEquals( "sources", gav.getClassifier() );
195         assertEquals( "jar", gav.getExtension() );
196         assertEquals( null, gav.getSnapshotBuildNumber() );
197         assertEquals( null, gav.getSnapshotTimeStamp() );
198         assertEquals( "velocity-1.5-SNAPSHOT-sources.jar", gav.getName() );
199         assertEquals( true, gav.isSnapshot() );
200         assertEquals( false, gav.isHash() );
201         assertEquals( null, gav.getHashType() );
202 
203         path = gavCalculator.gavToPath( gav );
204         assertEquals( "/maven/java-sources/velocity-1.5-SNAPSHOT-sources.jar", path );
205 
206         gav = gavCalculator.pathToGav( "castor/jars/castor-0.9.9-xml.jar" );
207 
208         assertEquals( "castor", gav.getGroupId() );
209         assertEquals( "castor", gav.getArtifactId() );
210         assertEquals( "0.9.9-xml", gav.getVersion() );
211         assertEquals( "0.9.9-xml", gav.getBaseVersion() );
212         assertEquals( null, gav.getClassifier() );
213         assertEquals( "jar", gav.getExtension() );
214         assertEquals( null, gav.getSnapshotBuildNumber() );
215         assertEquals( null, gav.getSnapshotTimeStamp() );
216         assertEquals( "castor-0.9.9-xml.jar", gav.getName() );
217         assertEquals( false, gav.isSnapshot() );
218         assertEquals( false, gav.isHash() );
219         assertEquals( null, gav.getHashType() );
220 
221         path = gavCalculator.gavToPath( gav );
222         assertEquals( "/castor/jars/castor-0.9.9-xml.jar", path );
223 
224         gav = gavCalculator.pathToGav( "/org.slf4j/poms/slf4j-log4j12-1.4.3.pom" );
225 
226         assertEquals( "org.slf4j", gav.getGroupId() );
227         assertEquals( "slf4j-log4j12", gav.getArtifactId() );
228         assertEquals( "1.4.3", gav.getVersion() );
229         assertEquals( "1.4.3", gav.getBaseVersion() );
230         assertEquals( null, gav.getClassifier() );
231         assertEquals( "pom", gav.getExtension() );
232         assertEquals( null, gav.getSnapshotBuildNumber() );
233         assertEquals( null, gav.getSnapshotTimeStamp() );
234         assertEquals( "slf4j-log4j12-1.4.3.pom", gav.getName() );
235         assertEquals( false, gav.isSnapshot() );
236         assertEquals( false, gav.isHash() );
237         assertEquals( null, gav.getHashType() );
238 
239         path = gavCalculator.gavToPath( gav );
240         assertEquals( "/org.slf4j/poms/slf4j-log4j12-1.4.3.pom", path );
241 
242         // TODO: fix this!
243         /* There is an "Oh" letter at the end, not a zero! */
244         gav = gavCalculator.pathToGav( "/xpp3/poms/xpp3_min-1.1.3.4.O.pom" );
245 
246         assertEquals( "xpp3", gav.getGroupId() );
247         assertEquals( "xpp3_min", gav.getArtifactId() );
248         assertEquals( "1.1.3.4.O", gav.getVersion() );
249         assertEquals( "1.1.3.4.O", gav.getBaseVersion() );
250         assertEquals( null, gav.getClassifier() );
251         assertEquals( "pom", gav.getExtension() );
252         assertEquals( null, gav.getSnapshotBuildNumber() );
253         assertEquals( null, gav.getSnapshotTimeStamp() );
254         assertEquals( "xpp3_min-1.1.3.4.O.pom", gav.getName() );
255         assertEquals( false, gav.isSnapshot() );
256         assertEquals( false, gav.isHash() );
257         assertEquals( null, gav.getHashType() );
258 
259         path = gavCalculator.gavToPath( gav );
260         assertEquals( "/xpp3/poms/xpp3_min-1.1.3.4.O.pom", path );
261     }
262 
263     public void testNEXUS1336()
264         throws Exception
265     {
266         Gav gav = gavCalculator.pathToGav( "/castor/ejbs/castor-ejb-1.0.7-SNAPSHOT-client.jar" );
267 
268         assertEquals( "castor", gav.getGroupId() );
269         assertEquals( "castor-ejb", gav.getArtifactId() );
270         assertEquals( "1.0.7-SNAPSHOT", gav.getVersion() );
271         assertEquals( "1.0.7-SNAPSHOT", gav.getBaseVersion() );
272         assertEquals( "client", gav.getClassifier() );
273         assertEquals( "jar", gav.getExtension() );
274         assertEquals( null, gav.getSnapshotBuildNumber() );
275         assertEquals( null, gav.getSnapshotTimeStamp() );
276         assertEquals( "castor-ejb-1.0.7-SNAPSHOT-client.jar", gav.getName() );
277         assertEquals( true, gav.isSnapshot() );
278         assertEquals( false, gav.isHash() );
279         assertEquals( null, gav.getHashType() );
280 
281         String path = gavCalculator.gavToPath( gav );
282         assertEquals( "/castor/ejbs/castor-ejb-1.0.7-SNAPSHOT-client.jar", path );
283 
284         gav = gavCalculator.pathToGav( "/castor/ejbs/castor-ejb-1.0.7.jar" );
285 
286         assertEquals( "castor", gav.getGroupId() );
287         assertEquals( "castor-ejb", gav.getArtifactId() );
288         assertEquals( "1.0.7", gav.getVersion() );
289         assertEquals( "1.0.7", gav.getBaseVersion() );
290         assertEquals( null, gav.getClassifier() );
291         assertEquals( "jar", gav.getExtension() );
292         assertEquals( null, gav.getSnapshotBuildNumber() );
293         assertEquals( null, gav.getSnapshotTimeStamp() );
294         assertEquals( "castor-ejb-1.0.7.jar", gav.getName() );
295         assertEquals( false, gav.isSnapshot() );
296         assertEquals( false, gav.isHash() );
297         assertEquals( null, gav.getHashType() );
298 
299         path = gavCalculator.gavToPath( gav );
300         assertEquals( "/castor/jars/castor-ejb-1.0.7.jar", path );
301 
302         gav = gavCalculator.pathToGav( "/castor/ejbs/castor-ejb-1.0.7-SNAPSHOT-client.jar.sha1" );
303 
304         assertEquals( "castor", gav.getGroupId() );
305         assertEquals( "castor-ejb", gav.getArtifactId() );
306         assertEquals( "1.0.7-SNAPSHOT", gav.getVersion() );
307         assertEquals( "1.0.7-SNAPSHOT", gav.getBaseVersion() );
308         assertEquals( "client", gav.getClassifier() );
309         assertEquals( "jar", gav.getExtension() );
310         assertEquals( null, gav.getSnapshotBuildNumber() );
311         assertEquals( null, gav.getSnapshotTimeStamp() );
312         assertEquals( "castor-ejb-1.0.7-SNAPSHOT-client.jar.sha1", gav.getName() );
313         assertEquals( true, gav.isSnapshot() );
314         assertEquals( true, gav.isHash() );
315         assertEquals( Gav.HashType.sha1, gav.getHashType() );
316 
317         path = gavCalculator.gavToPath( gav );
318         assertEquals( "/castor/ejbs/castor-ejb-1.0.7-SNAPSHOT-client.jar.sha1", path );
319 
320         gav = gavCalculator.pathToGav( "/castor/ejbs/castor-ejb-1.0.7-client.jar" );
321 
322         assertEquals( "castor", gav.getGroupId() );
323         assertEquals( "castor-ejb", gav.getArtifactId() );
324         assertEquals( "1.0.7", gav.getVersion() );
325         assertEquals( "1.0.7", gav.getBaseVersion() );
326         assertEquals( "client", gav.getClassifier() );
327         assertEquals( "jar", gav.getExtension() );
328         assertEquals( null, gav.getSnapshotBuildNumber() );
329         assertEquals( null, gav.getSnapshotTimeStamp() );
330         assertEquals( "castor-ejb-1.0.7-client.jar", gav.getName() );
331         assertEquals( false, gav.isSnapshot() );
332         assertEquals( false, gav.isHash() );
333         assertEquals( null, gav.getHashType() );
334 
335         path = gavCalculator.gavToPath( gav );
336         assertEquals( "/castor/ejbs/castor-ejb-1.0.7-client.jar", path );
337     }
338 
339     public void testGavExtreme()
340         throws Exception
341     {
342         Gav gav = gavCalculator.pathToGav( "/" );
343         assertEquals( null, gav );
344 
345         gav = gavCalculator.pathToGav( "/some/stupid/path" );
346         assertEquals( null, gav );
347 
348         gav = gavCalculator.pathToGav( "/some/stupid/path/more/in/it" );
349         assertEquals( null, gav );
350 
351         gav = gavCalculator.pathToGav( "/something/that/looks/" );
352         assertEquals( null, gav );
353 
354         gav = gavCalculator.pathToGav( "/something/that/like-an-artifact.blah" );
355         assertEquals( null, gav );
356         // assertEquals( false, gav.isChecksum() );
357         // assertEquals( false, gav.isPrimary() );
358         // assertEquals( false, gav.isSnapshot() );
359 
360         gav = gavCalculator.pathToGav( "/something/that/like-an-artifact.pom" );
361         assertEquals( null, gav );
362         // assertEquals( false, gav.isChecksum() );
363         // assertEquals( false, gav.isPrimary() );
364         // assertEquals( false, gav.isSnapshot() );
365 
366         gav = gavCalculator.pathToGav( "/something/that/maven-metadata.xml" );
367         assertEquals( null, gav );
368         // assertEquals( false, gav.isChecksum() );
369         // assertEquals( false, gav.isPrimary() );
370         // assertEquals( false, gav.isSnapshot() );
371 
372         gav = gavCalculator.pathToGav( "/something/that/like-SNAPSHOT/maven-metadata.xml" );
373         assertEquals( null, gav );
374 
375     }
376 }