From 071eb2dced2ca0a98bc43ddefdd2cf36dbd3d320 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 27 Jul 2006 04:58:38 +0000 Subject: [PATCH] [MRM-127] add a blackout on discovery to ensure indexer will work correctly in all sensible cases git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425963 13f79535-47bb-0310-9956-ffa450edef68 --- .../discovery/AbstractDiscoverer.java | 13 +++++- .../AbstractArtifactDiscovererTest.java | 45 ++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) 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 {