1 package org.apache.maven.archiva.discoverer;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter;
23 import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter;
24 import org.apache.maven.artifact.Artifact;
25 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
28 import java.net.MalformedURLException;
29 import java.util.Collections;
30 import java.util.Iterator;
31 import java.util.List;
34 * Test the legacy artifact discoverer.
36 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37 * @version $Id:LegacyArtifactDiscovererTest.java 437105 2006-08-26 17:22:22 +1000 (Sat, 26 Aug 2006) brett $
39 public class LegacyArtifactDiscovererTest
40 extends AbstractArtifactDiscovererTest
42 private static final List JAVAX_SQL_BLACKLIST = Collections.singletonList( "javax.sql/**" );
44 protected String getLayout()
49 protected File getRepositoryFile()
51 return getTestFile( "src/test/legacy-repository" );
54 public void testDefaultExcludes()
55 throws DiscovererException
57 List artifacts = discoverArtifacts();
58 assertNotNull( "Check artifacts not null", artifacts );
59 boolean found = false;
60 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
62 DiscovererPath dPath = (DiscovererPath) i.next();
64 String path = dPath.getPath();
66 if ( path.indexOf( "CVS" ) >= 0 )
69 assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() );
72 assertTrue( "Check exclusion was found", found );
74 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
76 Artifact a = (Artifact) i.next();
77 assertFalse( "Check not CVS", a.getFile().getPath().indexOf( "CVS" ) >= 0 );
78 assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
82 public void testStandardExcludes()
83 throws DiscovererException
85 List artifacts = discoverArtifacts();
86 assertNotNull( "Check artifacts not null", artifacts );
87 boolean found = false;
88 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
90 DiscovererPath dPath = (DiscovererPath) i.next();
92 String path = dPath.getPath();
94 if ( "KEYS".equals( path ) )
97 assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() );
100 assertTrue( "Check exclusion was found", found );
102 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
104 Artifact a = (Artifact) i.next();
105 assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) );
109 public void testBlacklistedExclude()
110 throws DiscovererException
112 List artifacts = discoverArtifactsWithBlacklist();
113 assertNotNull( "Check artifacts not null", artifacts );
114 boolean found = false;
115 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
117 DiscovererPath dPath = (DiscovererPath) i.next();
119 String path = dPath.getPath();
121 if ( "javax.sql/jars/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) )
124 assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions",
125 dPath.getComment() );
128 assertTrue( "Check exclusion was found", found );
130 assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
133 public void testKickoutWithShortPath()
134 throws DiscovererException
136 List artifacts = discoverArtifacts();
137 assertNotNull( "Check artifacts not null", artifacts );
138 boolean found = false;
139 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
141 DiscovererPath dPath = (DiscovererPath) i.next();
143 String path = dPath.getPath();
145 if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) )
148 assertEquals( "Check reason for kickout",
149 "Path does not match a legacy repository path for an artifact", dPath.getComment() );
152 assertTrue( "Check kickout was found", found );
154 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
156 Artifact a = (Artifact) i.next();
157 assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) );
161 public void testKickoutWithLongPath()
162 throws DiscovererException
164 List artifacts = discoverArtifacts();
165 assertNotNull( "Check artifacts not null", artifacts );
166 boolean found = false;
167 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
169 DiscovererPath dPath = (DiscovererPath) i.next();
171 String path = dPath.getPath();
173 if ( "invalid/jars/1.0/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) )
176 assertEquals( "Check reason for kickout",
177 "Path does not match a legacy repository path for an artifact", dPath.getComment() );
180 assertTrue( "Check kickout was found", found );
182 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
184 Artifact a = (Artifact) i.next();
185 assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) );
189 public void testKickoutWithInvalidType()
190 throws DiscovererException
192 List artifacts = discoverArtifacts();
193 assertNotNull( "Check artifacts not null", artifacts );
194 boolean found = false;
195 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
197 DiscovererPath dPath = (DiscovererPath) i.next();
199 String path = dPath.getPath();
201 if ( "invalid/foo/invalid-1.0.foo".equals( path.replace( '\\', '/' ) ) )
204 assertEquals( "Check reason for kickout", "Path artifact type does not corresspond to an artifact type",
205 dPath.getComment() );
208 assertTrue( "Check kickout was found", found );
210 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
212 Artifact a = (Artifact) i.next();
213 assertFalse( "Check not invalid-1.0.foo", "invalid-1.0.foo".equals( a.getFile().getName() ) );
217 public void testKickoutWithNoExtension()
218 throws DiscovererException
220 List artifacts = discoverArtifacts();
221 assertNotNull( "Check artifacts not null", artifacts );
222 boolean found = false;
223 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
225 DiscovererPath dPath = (DiscovererPath) i.next();
227 String path = dPath.getPath();
229 if ( "invalid/jars/no-extension".equals( path.replace( '\\', '/' ) ) )
232 assertEquals( "Check reason for kickout", "Path filename does not have an extension",
233 dPath.getComment() );
236 assertTrue( "Check kickout was found", found );
238 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
240 Artifact a = (Artifact) i.next();
241 assertFalse( "Check not 'no-extension'", "no-extension".equals( a.getFile().getName() ) );
245 public void testKickoutWithWrongExtension()
246 throws DiscovererException
248 List artifacts = discoverArtifacts();
249 assertNotNull( "Check artifacts not null", artifacts );
250 boolean found = false;
251 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
253 DiscovererPath dPath = (DiscovererPath) i.next();
255 String path = dPath.getPath();
257 if ( "invalid/jars/invalid-1.0.rar".equals( path.replace( '\\', '/' ) ) )
260 assertEquals( "Check reason for kickout", "Path type does not match the extension",
261 dPath.getComment() );
264 assertTrue( "Check kickout was found", found );
266 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
268 Artifact a = (Artifact) i.next();
269 assertFalse( "Check not 'invalid-1.0.rar'", "invalid-1.0.rar".equals( a.getFile().getName() ) );
273 public void testKickoutWithNoVersion()
274 throws DiscovererException
276 List artifacts = discoverArtifacts();
277 assertNotNull( "Check artifacts not null", artifacts );
278 boolean found = false;
279 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
281 DiscovererPath dPath = (DiscovererPath) i.next();
283 String path = dPath.getPath();
285 if ( "invalid/jars/invalid.jar".equals( path.replace( '\\', '/' ) ) )
288 assertEquals( "Check reason for kickout", "Path filename version is empty", dPath.getComment() );
291 assertTrue( "Check kickout was found", found );
293 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
295 Artifact a = (Artifact) i.next();
296 assertFalse( "Check not 'invalid.jar'", "invalid.jar".equals( a.getFile().getName() ) );
300 public void testInclusion()
301 throws DiscovererException
303 List artifacts = discoverArtifactsWithSnapshots();
304 assertNotNull( "Check artifacts not null", artifacts );
306 assertTrue( "Check normal included",
307 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
310 public void testTextualVersion()
311 throws DiscovererException
313 List artifacts = discoverArtifactsWithSnapshots();
314 assertNotNull( "Check artifacts not null", artifacts );
316 assertTrue( "Check normal included",
317 artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) );
320 public void testArtifactWithClassifier()
321 throws DiscovererException
323 List artifacts = discoverArtifactsWithSnapshots();
324 assertNotNull( "Check artifacts not null", artifacts );
326 assertTrue( "Check normal included",
327 artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
330 public void testJavaSourcesInclusion()
331 throws DiscovererException
333 List artifacts = discoverArtifactsWithSnapshots();
334 assertNotNull( "Check artifacts not null", artifacts );
336 assertTrue( "Check normal included", artifacts.contains(
337 createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) );
340 public void testDistributionInclusion()
341 throws DiscovererException
343 List artifacts = discoverArtifactsWithSnapshots();
344 assertNotNull( "Check artifacts not null", artifacts );
346 assertTrue( "Check zip included",
347 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
349 assertTrue( "Check tar.gz included",
350 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
353 public void testSnapshotInclusion()
354 throws DiscovererException
356 List artifacts = discoverArtifactsWithSnapshots();
357 assertNotNull( "Check artifacts not null", artifacts );
359 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
360 assertTrue( "Check snapshot included",
361 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
364 public void testSnapshotExclusion()
365 throws DiscovererException
367 List artifacts = discoverArtifacts();
368 assertNotNull( "Check artifacts not null", artifacts );
370 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
371 assertFalse( "Check snapshot included",
372 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
375 public void testFileSet()
376 throws DiscovererException
378 List artifacts = discoverArtifactsWithSnapshots();
379 assertNotNull( "Check artifacts not null", artifacts );
381 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
383 Artifact artifact = (Artifact) i.next();
384 assertNotNull( "Check file is set", artifact.getFile() );
388 public void testRepositorySet()
389 throws MalformedURLException, DiscovererException
391 List artifacts = discoverArtifactsWithSnapshots();
392 assertNotNull( "Check artifacts not null", artifacts );
394 String url = repository.getUrl();
395 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
397 Artifact artifact = (Artifact) i.next();
398 assertNotNull( "Check repository set", artifact.getRepository() );
399 assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() );
403 public void testWrongArtifactPackaging()
404 throws ComponentLookupException, DiscovererException
408 discoverer.buildArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" );
410 fail( "Artifact should be null for wrong package extension" );
412 catch ( DiscovererException e )
418 public void testNoArtifactId()
419 throws DiscovererException
423 discoverer.buildArtifact( "groupId/jars/-1.0.jar" );
425 fail( "Artifact should be null when artifactId is missing" );
427 catch ( DiscovererException e )
434 discoverer.buildArtifact( "groupId/jars/1.0.jar" );
436 fail( "Artifact should be null when artifactId is missing" );
438 catch ( DiscovererException e )
444 public void testNoType()
445 throws ComponentLookupException, DiscovererException
449 discoverer.buildArtifact( "invalid/invalid/1/invalid-1" );
451 fail( "Artifact should be null for no type" );
453 catch ( DiscovererException e )
459 public void testSnapshot()
460 throws ComponentLookupException, DiscovererException
462 String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
464 Artifact artifact = discoverer.buildArtifact( testPath );
466 assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact );
469 public void testFinal()
470 throws ComponentLookupException, DiscovererException
472 String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
474 Artifact artifact = discoverer.buildArtifact( testPath );
476 assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact );
479 public void testNormal()
480 throws ComponentLookupException, DiscovererException
482 String testPath = "javax.sql/jars/jdbc-2.0.jar";
484 Artifact artifact = discoverer.buildArtifact( testPath );
486 assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );
489 public void testJavadoc()
490 throws ComponentLookupException, DiscovererException
492 String testPath = "javax.sql/javadoc.jars/jdbc-2.0-javadoc.jar";
494 Artifact artifact = discoverer.buildArtifact( testPath );
496 assertEquals( createArtifact( "javax.sql", "jdbc", "2.0", "javadoc.jar", "javadoc" ), artifact );
499 public void testSources()
500 throws ComponentLookupException, DiscovererException
502 String testPath = "javax.sql/java-sources/jdbc-2.0-sources.jar";
504 Artifact artifact = discoverer.buildArtifact( testPath );
506 assertEquals( createArtifact( "javax.sql", "jdbc", "2.0", "java-source", "sources" ), artifact );
509 public void testPlugin()
510 throws ComponentLookupException, DiscovererException
512 String testPath = "maven/plugins/maven-test-plugin-1.8.jar";
514 Artifact artifact = discoverer.buildArtifact( testPath );
516 assertEquals( createArtifact( "maven", "maven-test-plugin", "1.8", "plugin" ), artifact );
520 private List discoverArtifacts()
521 throws DiscovererException
523 return discoverer.discoverArtifacts( repository, null, new SnapshotArtifactFilter() );
526 private List discoverArtifactsWithBlacklist()
527 throws DiscovererException
529 return discoverer.discoverArtifacts( repository, JAVAX_SQL_BLACKLIST, new SnapshotArtifactFilter() );
532 private List discoverArtifactsWithSnapshots()
533 throws DiscovererException
535 return discoverer.discoverArtifacts( repository, null, new AcceptAllArtifactFilter() );