Browse Source

more legacy discoverer tests

PR: MRM-9

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@349647 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-0.9-alpha-1
Brett Porter 18 years ago
parent
commit
fcd8104a67

+ 1
- 0
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java View File

* Add a path to the list of files that were kicked out due to being invalid. * Add a path to the list of files that were kicked out due to being invalid.
* *
* @param path the path to add * @param path the path to add
* @todo add a reason
*/ */
protected void addKickedOutPath( String path ) protected void addKickedOutPath( String path )
{ {

+ 11
- 6
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java View File

return null; return null;
} }


//discard the actual artifact filename.
pathParts.remove( 0 );
// the actual artifact filename.
String filename = (String) pathParts.remove( 0 );


// the next one is the version. // the next one is the version.
String version = (String) pathParts.get( 0 );
pathParts.remove( 0 );
String version = (String) pathParts.remove( 0 );


// the next one is the artifactId. // the next one is the artifactId.
String artifactId = (String) pathParts.get( 0 );
pathParts.remove( 0 );
String artifactId = (String) pathParts.remove( 0 );


// the remaining are the groupId. // the remaining are the groupId.
Collections.reverse( pathParts ); Collections.reverse( pathParts );
String groupId = StringUtils.join( pathParts.iterator(), "." ); String groupId = StringUtils.join( pathParts.iterator(), "." );


if ( !filename.startsWith( artifactId + "-" ) )
{
addKickedOutPath( path );

return null;
}

result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );


result.setFile( new File( path ) ); result.setFile( new File( path ) );

+ 4
- 1
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java View File

} }
} }


result.setFile( new File( path ) );
if ( result != null )
{
result.setFile( new File( path ) );
}


return result; return result;
} }

+ 24
- 1
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java View File

* *
* @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$ * @version $Id$
* @todo other tests for kickouts to do here, along the lines of wrong artifactId, parse classifiers, locate poms
*/ */
public class DefaultArtifactDiscovererTest public class DefaultArtifactDiscovererTest
extends PlexusTestCase extends PlexusTestCase


found = path.replace( '\\', '/' ).equals( "invalid/invalid-1.0.jar" ); found = path.replace( '\\', '/' ).equals( "invalid/invalid-1.0.jar" );
} }
assertTrue( "Check exclusion was found", found );
assertTrue( "Check kickout was found", found );


for ( Iterator i = artifacts.iterator(); i.hasNext(); ) for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{ {
} }
} }


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() public void testSnapshotInclusion()
{ {
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );

+ 22
- 4
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java View File

assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
} }


/*
public void testKickoutWithShortPath() public void testKickoutWithShortPath()
{ {
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false ); List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
} }
} }


public void testKickoutWithLongPath()
{
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/jars/1.0/invalid-1.0.jar" );
}
assertTrue( "Check exclusion 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 testSnapshotInclusion() public void testSnapshotInclusion()
{ {
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );


assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
assertTrue( "Check snapshot included", assertTrue( "Check snapshot included",
artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
} }


public void testSnapshotExclusion() public void testSnapshotExclusion()


assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) ); assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
assertFalse( "Check snapshot included", assertFalse( "Check snapshot included",
artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
} }
*/


private Artifact createArtifact( String groupId, String artifactId, String version ) private Artifact createArtifact( String groupId, String artifactId, String version )
{ {

maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/maven-test-1.0-20050611.112233-1.jar → maven-repository-discovery/src/test/legacy-repository/invalid/invalid-1.0.jar View File


+ 0
- 0
maven-repository-discovery/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar View File


+ 0
- 0
maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar View File


+ 0
- 0
maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar View File


+ 0
- 0
maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar View File


Loading…
Cancel
Save