]> source.dussan.org Git - archiva.git/commitdiff
[MRM-77] fix for reports for distributions that are non-standard types
authorBrett Porter <brett@apache.org>
Fri, 8 Sep 2006 17:32:50 +0000 (17:32 +0000)
committerBrett Porter <brett@apache.org>
Fri, 8 Sep 2006 17:32:50 +0000 (17:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441583 13f79535-47bb-0310-9956-ffa450edef68

archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java
archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.tar.gz [new file with mode: 0644]
archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.zip [new file with mode: 0644]

index 12e2d365a226602b1f148a70934dc7d94c587eeb..a0fbcaca1e49f9586324dffdac5a940e8c7a2787 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.maven.archiva.reporting;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -81,6 +82,8 @@ public class LocationArtifactReportProcessor
                 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
         }
 
+        adjustDistributionArtifactHandler( artifact );
+
         String artifactPath = repository.pathOf( artifact );
 
         if ( model != null )
@@ -97,6 +100,7 @@ public class LocationArtifactReportProcessor
                                                                                        artifact.getType(),
                                                                                        artifact.getClassifier() );
 
+                adjustDistributionArtifactHandler( modelArtifact );
                 String modelPath = repository.pathOf( modelArtifact );
                 if ( !modelPath.equals( artifactPath ) )
                 {
@@ -138,6 +142,19 @@ public class LocationArtifactReportProcessor
         }
     }
 
+    private static void adjustDistributionArtifactHandler( Artifact artifact )
+    {
+        // need to tweak these as they aren't currently in the known type converters. TODO - add them in Maven
+        if ( "distribution-zip".equals( artifact.getType() ) )
+        {
+            artifact.setArtifactHandler( new DefaultArtifactHandler( "zip" ) );
+        }
+        else if ( "distribution-tgz".equals( artifact.getType() ) )
+        {
+            artifact.setArtifactHandler( new DefaultArtifactHandler( "tar.gz" ) );
+        }
+    }
+
     private Model readArtifactModel( File file, Artifact artifact, ReportingDatabase reporter )
     {
         Model model = null;
index e2dcff0e442d40906ceafc3860cffd139f22f4ad..6d6d08d26994e729720b853d990d43bf8bcd1a81 100644 (file)
@@ -64,4 +64,13 @@ public abstract class AbstractRepositoryReportsTestCase
         return artifact;
     }
 
+    protected Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type,
+                                                     String classifier )
+    {
+        Artifact artifact =
+            artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
+        artifact.setRepository( repository );
+        return artifact;
+    }
+
 }
index bab3a12cf5d945f5f9312bd1de43dda6364bef29..ee5aa46205c78410ff506544b0f3a463bd540984 100644 (file)
@@ -46,14 +46,6 @@ public class LocationArtifactReportProcessorTest
         pomReader = new MavenXpp3Reader();
     }
 
-    public void tearDown()
-        throws Exception
-    {
-        super.tearDown();
-        artifactReportProcessor = null;
-        pomReader = null;
-    }
-
     /**
      * Test the LocationArtifactReporter when the artifact's physical location matches the location specified
      * both in the file system pom and in the pom included in the package.
@@ -115,6 +107,40 @@ public class LocationArtifactReportProcessorTest
         assertEquals( 0, reporter.getNumWarnings() );
     }
 
+    /**
+     * Test the LocationArtifactReporter when the artifact is in the location specified in the
+     * file system pom, with a classifier.
+     */
+    public void testLocationArtifactReporterSuccessZip()
+        throws IOException, XmlPullParserException
+    {
+        Artifact artifact =
+            createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-zip", "src" );
+        Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
+
+        Model model = readPom( repository.pathOf( pomArtifact ) );
+        artifactReportProcessor.processArtifact( artifact, model, reporter );
+        assertEquals( 0, reporter.getNumFailures() );
+        assertEquals( 0, reporter.getNumWarnings() );
+    }
+
+    /**
+     * Test the LocationArtifactReporter when the artifact is in the location specified in the
+     * file system pom, with a classifier.
+     */
+    public void testLocationArtifactReporterSuccessTgz()
+        throws IOException, XmlPullParserException
+    {
+        Artifact artifact =
+            createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-tgz", "src" );
+        Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
+
+        Model model = readPom( repository.pathOf( pomArtifact ) );
+        artifactReportProcessor.processArtifact( artifact, model, reporter );
+        assertEquals( 0, reporter.getNumFailures() );
+        assertEquals( 0, reporter.getNumWarnings() );
+    }
+
     /**
      * Test the LocationArtifactReporter when the artifact is not in the location specified
      * in the file system pom.
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.tar.gz b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.tar.gz
new file mode 100644 (file)
index 0000000..c2ea777
Binary files /dev/null and b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.tar.gz differ
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.zip b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.zip
new file mode 100644 (file)
index 0000000..c2ea777
Binary files /dev/null and b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-src.zip differ