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 93cee98c7..ee5c9bd81 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 @@ -107,8 +107,16 @@ public class DefaultArtifactDiscoverer 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 ) ); + result = artifactFactory.createArtifact( groupId, artifactId, + remainingFilename.substring( 0, remainingFilename.length() - 4 ), + Artifact.SCOPE_RUNTIME, "jar" ); + // poor encapsulation requires we do this to populate base version + if ( !result.isSnapshot() ) + { + addKickedOutPath( path ); + + return null; + } if ( !result.getBaseVersion().equals( version ) ) { addKickedOutPath( 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 5d163414d..a3780557a 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 @@ -170,6 +170,26 @@ public class DefaultArtifactDiscovererTest } } + public void testKickoutWithWrongSnapshotVersion() + { + 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-SNAPSHOT/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 testSnapshotInclusion() { List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); diff --git a/maven-repository-discovery/src/test/repository/invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar b/maven-repository-discovery/src/test/repository/invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar new file mode 100644 index 000000000..e69de29bb