123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- package org.apache.maven.repository.discovery;
-
- /*
- * Copyright 2001-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- import org.apache.maven.artifact.Artifact;
- import org.apache.maven.artifact.factory.ArtifactFactory;
- import org.codehaus.plexus.PlexusTestCase;
-
- import java.io.File;
- import java.util.Iterator;
- import java.util.List;
-
- /**
- * Test the default artifact discoverer.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @version $Id$
- * @todo other tests for kickouts to do here, along the lines of wrong artifactId, parse classifiers, locate poms
- */
- public class DefaultArtifactDiscovererTest
- extends PlexusTestCase
- {
- private ArtifactDiscoverer discoverer;
-
- private ArtifactFactory factory;
-
- private File repositoryLocation;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
-
- factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-
- repositoryLocation = getTestFile( "src/test/repository" );
- }
-
- public void testDefaultExcludes()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
- assertNotNull( "Check artifacts not null", artifacts );
- boolean found = false;
- for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
- {
- String path = (String) i.next();
-
- found = path.indexOf( ".svn" ) >= 0;
- }
- assertTrue( "Check exclusion was found", found );
-
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact a = (Artifact) i.next();
- assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
- }
- }
-
- public void testStandardExcludes()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
- assertNotNull( "Check artifacts not null", artifacts );
- boolean found = false;
- for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
- {
- String path = (String) i.next();
-
- found = path.equals( "KEYS" );
- }
- assertTrue( "Check exclusion was found", found );
-
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact a = (Artifact) i.next();
- assertFalse( "Check not KEYS", a.getFile().getName().equals( "KEYS" ) );
- }
- }
-
- public void testBlacklistedExclude()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, "javax/**", false );
- assertNotNull( "Check artifacts not null", artifacts );
- boolean found = false;
- for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
- {
- String path = (String) i.next();
-
- found = path.replace( '\\', '/' ).equals( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
- }
- assertTrue( "Check exclusion was found", found );
-
- assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
- }
-
- public void testKickoutWithShortPath()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
- assertNotNull( "Check artifacts not null", artifacts );
- boolean found = false;
- for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
- {
- String path = (String) i.next();
-
- found = path.replace( '\\', '/' ).equals( "invalid/invalid-1.0.jar" );
- }
- assertTrue( "Check kickout was found", found );
-
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact a = (Artifact) i.next();
- assertFalse( "Check not invalid-1.0.jar", a.getFile().getName().equals( "invalid-1.0.jar" ) );
- }
- }
-
- public void testKickoutWithWrongArtifactId()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
- assertNotNull( "Check artifacts not null", artifacts );
- boolean found = false;
- for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
- {
- String path = (String) i.next();
-
- found = path.replace( '\\', '/' ).equals(
- "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
- }
- assertTrue( "Check kickout was found", found );
-
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
- {
- Artifact a = (Artifact) i.next();
- assertFalse( "Check not wrong jar",
- a.getFile().getName().equals( "wrong-artifactId-1.0-20050611.112233-1.jar" ) );
- }
- }
-
- public void testSnapshotInclusion()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
- assertNotNull( "Check artifacts not null", artifacts );
-
- assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
- assertTrue( "Check snapshot included",
- artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
- }
-
- public void testSnapshotExclusion()
- {
- List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
- assertNotNull( "Check artifacts not null", artifacts );
-
- assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
- assertFalse( "Check snapshot included",
- artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
- }
-
- private Artifact createArtifact( String groupId, String artifactId, String version )
- {
- return factory.createArtifact( groupId, artifactId, version, null, "jar" );
- }
-
- }
|