]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1246] - MetadataUpdaterConsumer didn't run during a repository scan after deleti...
authorJevica Arianne B. Zurbano <jzurbano@apache.org>
Mon, 12 Oct 2009 04:29:06 +0000 (04:29 +0000)
committerJevica Arianne B. Zurbano <jzurbano@apache.org>
Mon, 12 Oct 2009 04:29:06 +0000 (04:29 +0000)
- 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

archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerTest.java
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
archiva-modules/archiva-base/archiva-repository-layer/src/test/repositories/metadata-repository/org/apache/archiva/metadata/tests/missing_artifact/maven-metadata.xml [new file with mode: 0644]

index e11dc6f772aeb267955b8531ff55fcc4716f22ea..adf75796db929643f1152c595fe9c400c4475e43 100644 (file)
@@ -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;   
+                        }
                     }
                 }
             }
index 468a6b3e157b850c685f9cedb8c60771202b9679..fec4d0150dc5cca4402dc5b3d49b3358b86f0980 100644 (file)
@@ -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( "<metadata>\n" );
+        buf.append( "  <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
+        buf.append( "  <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
+        
+        if ( expectedVersions != null )
+        {
+            buf.append( "  <versioning>\n" );
+            if ( latestVersion != null )
+            {
+                buf.append( "    <latest>" ).append( latestVersion ).append( "</latest>\n" );
+            }
+            if ( releaseVersion != null )
+            {
+                buf.append( "    <release>" ).append( releaseVersion ).append( "</release>\n" );
+            }
+
+            buf.append( "    <versions>\n" );
+            for ( int i = 0; i < expectedVersions.length; i++ )
+            {
+                buf.append( "      <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
+            }
+            buf.append( "    </versions>\n" );
+            buf.append( "  </versioning>\n" );
+        }
+        buf.append( "</metadata>" );
+
+        assertMetadata( buf.toString(), testRepo, reference );
+    }
+
     private void assertUpdatedReleaseVersionMetadata( String artifactId, String version )
         throws Exception
     {
index 22cd183b0731cace52485da047789ff85599f521..f7451460ca52d6cc550208dcfe47418c5e564b10 100644 (file)
@@ -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 (file)
index 0000000..e8840e7
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<metadata>
+  <groupId>org.apache.archiva.metadata.tests</groupId>
+  <artifactId>missing_artifact</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <versioning>
+    <snapshot>
+      <buildNumber>1</buildNumber>
+      <timestamp>20091007.132409</timestamp>
+    </snapshot>
+  </versioning>
+</metadata>
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 (file)
index 0000000..e69de29
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 (file)
index 0000000..d2c43ab
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.archiva.metadata.tests</groupId>
+  <artifactId>missing_artifact</artifactId>
+  <version>1.0-SNAPSHOT</version>
+</project>
\ 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 (file)
index 0000000..1487bb2
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?><metadata>
+  <groupId>org.apache.archiva.metadata.tests</groupId>
+  <artifactId>missing_artifact</artifactId>
+  <version>1.2-SNAPSHOT</version>
+  <versioning>
+    <snapshot>
+      <timestamp>20091011.133751</timestamp>
+      <buildNumber>1</buildNumber>
+    </snapshot>
+  </versioning>
+</metadata>
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 (file)
index 0000000..e69de29
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 (file)
index 0000000..f68e523
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.archiva.metadata.tests</groupId>
+  <artifactId>missing_artifact</artifactId>
+  <version>1.2-SNAPSHOT</version>
+</project>
\ 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 (file)
index 0000000..3867fb5
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?><metadata>
+  <groupId>org.apache.archiva.metadata.tests</groupId>
+  <artifactId>missing_artifact</artifactId>
+  <versioning>
+    <latest>1.2-SNAPSHOT</latest>
+    <versions>
+      <version>1.0-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
+      <version>1.2-SNAPSHOT</version>
+    </versions>
+  </versioning>
+</metadata>