From: Jevica Arianne B. Zurbano Date: Mon, 12 Oct 2009 04:29:06 +0000 (+0000) Subject: [MRM-1246] - MetadataUpdaterConsumer didn't run during a repository scan after deleti... X-Git-Tag: archiva-1.3~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5a8a5a92f8491ae620278f36ca8d09800ef22e3f;p=archiva.git [MRM-1246] - MetadataUpdaterConsumer didn't run during a repository scan after deleting a version of an artifact. - added unit test for updating metadata - added unit test sample artifacts - applied the submitted patch Submitted by: Gwen Harold Autencio git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@824220 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java index e11dc6f77..adf75796d 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java @@ -19,14 +19,15 @@ package org.apache.maven.archiva.repository.scanner.functors; * under the License. */ +import java.io.File; +import java.util.List; + import org.apache.commons.collections.Predicate; import org.apache.commons.io.FilenameUtils; import org.apache.maven.archiva.common.utils.BaseFile; import org.apache.maven.archiva.consumers.RepositoryContentConsumer; import org.codehaus.plexus.util.SelectorUtils; -import java.util.List; - /** * ConsumerWantsFilePredicate * @@ -62,8 +63,19 @@ public class ConsumerWantsFilePredicate // Timestamp finished points to the last successful scan, not this current one. if ( basefile.lastModified() < changesSince ) { - // Skip file as no change has occured. - satisfies = false; + // MRM-1246 + // compares the lastModified of the version-level (basefile) and the project-level (parent) metadata + File parent = basefile.getParentFile().getParentFile(); + + if ( parent.lastModified() > basefile.lastModified() ) + { + satisfies = true; + } + else + { + // Skip file as no change has occurred. + satisfies = false; + } } } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java index 468a6b3e1..fec4d0150 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java @@ -130,6 +130,30 @@ public class MetadataToolsTest // } // } + public void testUpdateProjectNonExistingVersion() + throws Exception + { + ManagedRepositoryContent testRepo = createTestRepoContent(); + ProjectReference reference = new ProjectReference(); + reference.setGroupId( "org.apache.archiva.metadata.tests" ); + reference.setArtifactId( "missing_artifact" ); + + prepTestRepo( testRepo, reference ); + + // check metadata prior to update -- should contain the non-existing artifact version + assertProjectMetadata( testRepo, reference, "missing_artifact", new String[] { + "1.0-SNAPSHOT", + "1.1-SNAPSHOT", + "1.2-SNAPSHOT" }, "1.2-SNAPSHOT" , null ); + + tools.updateMetadata( testRepo, reference ); + + // metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT + assertProjectMetadata( testRepo, reference, "missing_artifact", new String[] { + "1.0-SNAPSHOT", + "1.2-SNAPSHOT" }, "1.2-SNAPSHOT" , null ); + } + public void testUpdateProjectMissingMultipleVersions() throws Exception { @@ -422,6 +446,40 @@ public class MetadataToolsTest assertMetadata( buf.toString(), testRepo, reference ); } + private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference, String artifactId, + String[] expectedVersions, String latestVersion, String releaseVersion ) + throws Exception + { + StringBuilder buf = new StringBuilder(); + buf.append( "\n" ); + buf.append( " " ).append( reference.getGroupId() ).append( "\n" ); + buf.append( " " ).append( reference.getArtifactId() ).append( "\n" ); + + if ( expectedVersions != null ) + { + buf.append( " \n" ); + if ( latestVersion != null ) + { + buf.append( " " ).append( latestVersion ).append( "\n" ); + } + if ( releaseVersion != null ) + { + buf.append( " " ).append( releaseVersion ).append( "\n" ); + } + + buf.append( " \n" ); + for ( int i = 0; i < expectedVersions.length; i++ ) + { + buf.append( " " ).append( expectedVersions[i] ).append( "\n" ); + } + buf.append( " \n" ); + buf.append( " \n" ); + } + buf.append( "" ); + + assertMetadata( buf.toString(), testRepo, reference ); + } + private void assertUpdatedReleaseVersionMetadata( String artifactId, String version ) throws Exception { diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerTest.java b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerTest.java index 22cd183b0..f7451460c 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerTest.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerTest.java @@ -140,7 +140,7 @@ public class RepositoryScannerTest assertNotNull( "Stats should not be null.", stats ); assertEquals( "Stats.totalFileCount", 4, stats.getTotalFileCount() ); assertEquals( "Stats.newFileCount", 3, stats.getNewFileCount() ); - assertEquals( "Processed Count", 2, consumer.getProcessCount() ); + assertEquals( "Processed Count", 3, consumer.getProcessCount() ); assertEquals( "Processed Count (of invalid items)", 1, badconsumer.getProcessCount() ); } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/maven-metadata.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..e8840e709 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,13 @@ + + + + org.apache.archiva.metadata.tests + missing_artifact + 1.0-SNAPSHOT + + + 1 + 20091007.132409 + + + diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/missing_artifact-1.0-20091007.132409-1.jar b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/missing_artifact-1.0-20091007.132409-1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/missing_artifact-1.0-20091007.132409-1.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/missing_artifact-1.0-20091007.132409-1.pom new file mode 100644 index 000000000..d2c43abe5 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.0-SNAPSHOT/missing_artifact-1.0-20091007.132409-1.pom @@ -0,0 +1,6 @@ + + 4.0.0 + org.apache.archiva.metadata.tests + missing_artifact + 1.0-SNAPSHOT + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/maven-metadata.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/maven-metadata.xml new file mode 100644 index 000000000..1487bb280 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/maven-metadata.xml @@ -0,0 +1,11 @@ + + org.apache.archiva.metadata.tests + missing_artifact + 1.2-SNAPSHOT + + + 20091011.133751 + 1 + + + diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/missing_artifact-1.2-20091011.133751-1.jar b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/missing_artifact-1.2-20091011.133751-1.jar new file mode 100644 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/missing_artifact-1.2-20091011.133751-1.pom b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/missing_artifact-1.2-20091011.133751-1.pom new file mode 100644 index 000000000..f68e5230b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/1.2-SNAPSHOT/missing_artifact-1.2-20091011.133751-1.pom @@ -0,0 +1,6 @@ + + 4.0.0 + org.apache.archiva.metadata.tests + missing_artifact + 1.2-SNAPSHOT + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/maven-metadata.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/maven-metadata.xml new file mode 100644 index 000000000..3867fb5bd --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/maven-metadata.xml @@ -0,0 +1,12 @@ + + org.apache.archiva.metadata.tests + missing_artifact + + 1.2-SNAPSHOT + + 1.0-SNAPSHOT + 1.1-SNAPSHOT + 1.2-SNAPSHOT + + +