diff --git a/maven-repository-discovery/pom.xml b/maven-repository-discovery/pom.xml index 48b1abb4f..651c4f4e2 100755 --- a/maven-repository-discovery/pom.xml +++ b/maven-repository-discovery/pom.xml @@ -22,18 +22,4 @@ maven-artifact - - - - - org.apache.maven.plugins - maven-clover-plugin - - threaded - 100 - - - - - diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java index 24ee9ce01..93cee98c7 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java @@ -94,14 +94,34 @@ public class DefaultArtifactDiscoverer Collections.reverse( pathParts ); String groupId = StringUtils.join( pathParts.iterator(), "." ); - if ( !filename.startsWith( artifactId + "-" ) ) + result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); + + String remainingFilename = filename; + if ( !remainingFilename.startsWith( artifactId + "-" ) ) { addKickedOutPath( path ); return null; } - result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); + remainingFilename = remainingFilename.substring( artifactId.length() + 1 ); + if ( result.isSnapshot() ) + { + result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); + result.setResolvedVersion( remainingFilename.substring( 0, remainingFilename.length() - 4 ) ); + if ( !result.getBaseVersion().equals( version ) ) + { + addKickedOutPath( path ); + + return null; + } + } + else if ( !remainingFilename.startsWith( version ) ) + { + addKickedOutPath( path ); + + return null; + } result.setFile( new File( path ) ); diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java index 1ea6c2a09..5d163414d 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java @@ -150,6 +150,26 @@ public class DefaultArtifactDiscovererTest } } + public void testKickoutWithWrongVersion() + { + 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/invalid-2.0.jar" ); + } + assertTrue( "Check kickout was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not 'invalid-2.0.jar'", a.getFile().getName().equals( "invalid-2.0.jar" ) ); + } + } + public void testSnapshotInclusion() { List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); @@ -157,7 +177,7 @@ public class DefaultArtifactDiscovererTest 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" ) ) ); + artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-20050611.112233-1" ) ) ); } public void testSnapshotExclusion() diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1.0/invalid-2.0.jar b/maven-repository-discovery/src/test/repository/invalid/invalid/1.0/invalid-2.0.jar new file mode 100644 index 000000000..e69de29bb