diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java index 88a85229f..b9c721c01 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java @@ -61,6 +61,11 @@ public abstract class AbstractDiscoverer private List excludedPaths = new ArrayList(); + /** + * @plexus.configuration default-value="60000" + */ + private int blackoutPeriod; + protected static final String DATE_FMT = "yyyyMMddHHmmss"; /** @@ -122,9 +127,13 @@ public abstract class AbstractDiscoverer { String path = files.next().toString(); - if ( comparisonTimestamp == 0 || new File( repositoryBase, path ).lastModified() > comparisonTimestamp ) + long modTime = new File( repositoryBase, path ).lastModified(); + if ( modTime < System.currentTimeMillis() - blackoutPeriod ) { - includedPaths.add( path ); + if ( modTime > comparisonTimestamp ) + { + includedPaths.add( path ); + } } } diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java index 9a3f01850..c016fe0bc 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java @@ -79,7 +79,10 @@ public abstract class AbstractArtifactDiscovererTest protected Artifact createArtifact( String groupId, String artifactId, String version ) { - return factory.createArtifact( groupId, artifactId, version, null, "jar" ); + Artifact artifact = factory.createArtifact( groupId, artifactId, version, null, "jar" ); + artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); + artifact.setRepository( repository ); + return artifact; } protected Artifact createArtifact( String groupId, String artifactId, String version, String type ) @@ -146,6 +149,46 @@ public abstract class AbstractArtifactDiscovererTest artifacts.contains( createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ) ) ); } + public void testUpdatedInRepositoryBlackout() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.resetLastCheckedTime( repository, "update" ); + + Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ); + artifact.getFile().setLastModified( System.currentTimeMillis() ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", artifacts.contains( artifact ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", artifacts.contains( artifact ) ); + } + + public void testUpdatedInRepositoryNotBlackout() + throws ComponentLookupException, DiscovererException, IOException + { + discoverer.resetLastCheckedTime( repository, "update" ); + + Artifact artifact = createArtifact( "org.apache.maven.update", "test-not-updated", "1.0" ); + artifact.getFile().setLastModified( System.currentTimeMillis() - 61000 ); + + List artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check included", artifacts.contains( artifact ) ); + + // try again with the updated timestamp + artifacts = discoverer.discoverArtifacts( repository, "update", null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertFalse( "Check not included", artifacts.contains( artifact ) ); + } + public void testNotUpdatedInRepositoryForcedDiscoveryMetadataAlreadyExists() throws ComponentLookupException, DiscovererException, IOException {