]> source.dussan.org Git - archiva.git/commitdiff
[MRM-127] add a blackout on discovery to ensure indexer will work correctly in all...
authorBrett Porter <brett@apache.org>
Thu, 27 Jul 2006 04:58:38 +0000 (04:58 +0000)
committerBrett Porter <brett@apache.org>
Thu, 27 Jul 2006 04:58:38 +0000 (04:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@425963 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/AbstractArtifactDiscovererTest.java

index 88a85229f05c8f0a70079b3a3080a7ab437b1ad3..b9c721c01ad8f6d0f1339c16f5f791be2c81fbf8 100644 (file)
@@ -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 );
+                }
             }
         }
 
index 9a3f018508f8afd57f4d6c1ab5761c6f91cc3597..c016fe0bc0ebf72004e3bb8a7cfb9ed5e8e28336 100644 (file)
@@ -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
     {