]> source.dussan.org Git - archiva.git/commitdiff
[MRM-77] hadle some edge cases in reports
authorBrett Porter <brett@apache.org>
Sat, 9 Sep 2006 07:05:03 +0000 (07:05 +0000)
committerBrett Porter <brett@apache.org>
Sat, 9 Sep 2006 07:05:03 +0000 (07:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441751 13f79535-47bb-0310-9956-ffa450edef68

archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java

index 354b67b76b010d4fac513e0f26d487aaa3872754..e1e7b8d91a5097bb03a0f37a19fcf17ac1f823c2 100644 (file)
@@ -197,17 +197,21 @@ public class BadMetadataReportProcessor
         RepositoryQueryLayer repositoryQueryLayer =
             repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
 
-        Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
+        Versioning versioning = metadata.getMetadata().getVersioning();
+        if ( versioning != null )
+        {
+            Snapshot snapshot = versioning.getSnapshot();
 
-        String version = StringUtils.replace( metadata.getBaseVersion(), Artifact.SNAPSHOT_VERSION,
-                                              snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
-        Artifact artifact =
-            artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
-        artifact.isSnapshot(); // trigger baseVersion correction
+            String version = StringUtils.replace( metadata.getBaseVersion(), Artifact.SNAPSHOT_VERSION,
+                                                  snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
+            Artifact artifact =
+                artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
+            artifact.isSnapshot(); // trigger baseVersion correction
 
-        if ( !repositoryQueryLayer.containsArtifact( artifact ) )
-        {
-            reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
+            if ( !repositoryQueryLayer.containsArtifact( artifact ) )
+            {
+                reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
+            }
         }
     }
 
index 0226b91314291d5c316a2c28a7b13abccb02c956..f9960bfc2f05ff6d10e92717b021b4237326abe4 100644 (file)
@@ -82,6 +82,15 @@ public class DependencyArtifactReportProcessor
                 {
                     Artifact artifact = createArtifact( dependency );
 
+                    // TODO: handle ranges properly. We should instead be mapping out all the artifacts in the
+                    // repository and mapping out the graph
+
+                    if ( artifact.getVersion() == null )
+                    {
+                        // it was a range, for now presume it exists
+                        continue;
+                    }
+
                     if ( !repositoryQueryLayer.containsArtifact( artifact ) )
                     {
                         String reason = MessageFormat.format(
@@ -118,8 +127,14 @@ public class DependencyArtifactReportProcessor
     private Artifact createArtifact( Dependency dependency )
         throws InvalidVersionSpecificationException
     {
-        return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
-                                                         VersionRange.createFromVersionSpec( dependency.getVersion() ),
+        VersionRange spec = VersionRange.createFromVersionSpec( dependency.getVersion() );
+
+        if ( spec == null )
+        {
+            throw new InvalidVersionSpecificationException( "Dependency version was null" );
+        }
+
+        return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), spec,
                                                          dependency.getType(), dependency.getClassifier(),
                                                          dependency.getScope() );
     }
index 4acec298294f21b755c20d4f0f4f92a69695ff09..67e36fd7b05bdf32cb99761e332a9070d8baa40c 100644 (file)
@@ -99,6 +99,26 @@ public class BadMetadataReportProcessorTest
         assertFalse( "check no more failures", failures.hasNext() );
     }
 
+    public void testSnapshotMetadataMissingVersioning()
+    {
+        Artifact artifact =
+            artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
+
+        RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+
+        badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+        Iterator failures = reporter.getMetadataIterator();
+        assertTrue( "check there is a failure", failures.hasNext() );
+        MetadataResults results = (MetadataResults) failures.next();
+        failures = results.getFailures().iterator();
+        assertTrue( "check there is a failure", failures.hasNext() );
+        assertMetadata( metadata, results );
+        Result result = (Result) failures.next();
+        assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() );
+        assertFalse( "check no more failures", failures.hasNext() );
+    }
+
     public void testMetadataValidVersions()
     {
         Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
index ae7edc2d182bc7972df77e1e62575d85bd68b797..3894e614ffbda1a518016b1f235501652f2a5294 100644 (file)
@@ -241,6 +241,37 @@ public class DependencyArtifactReportProcessorTest
         assertEquals( getDependencyVersionInvalidMessage( dependency, "[" ), result.getReason() );
     }
 
+    public void testValidArtifactWithInvalidDependencyVersionRange()
+    {
+        Artifact artifact = createValidArtifact();
+
+        Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[1.0,)" );
+        model.addDependency( dependency );
+
+        processor.processArtifact( artifact, model, reporter );
+        assertEquals( 0, reporter.getNumFailures() );
+        assertEquals( 0, reporter.getNumWarnings() );
+    }
+
+    public void testValidArtifactWithMissingDependencyVersion()
+    {
+        Artifact artifact = createValidArtifact();
+
+        Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, null );
+        model.addDependency( dependency );
+
+        processor.processArtifact( artifact, model, reporter );
+        assertEquals( 1, reporter.getNumFailures() );
+        assertEquals( 0, reporter.getNumWarnings() );
+
+        Iterator failures = reporter.getArtifactIterator();
+        ArtifactResults results = (ArtifactResults) failures.next();
+        assertFalse( failures.hasNext() );
+        failures = results.getFailures().iterator();
+        Result result = (Result) failures.next();
+        assertEquals( getDependencyVersionInvalidMessage( dependency, null ), result.getReason() );
+    }
+
     private String getDependencyVersionInvalidMessage( Dependency dependency, String version )
     {
         return "Artifact's dependency " + getDependencyString( dependency ) + " contains an invalid version " + version;