From: Brett Porter Date: Fri, 8 Sep 2006 17:32:50 +0000 (+0000) Subject: [MRM-77] fix for reports for distributions that are non-standard types X-Git-Tag: archiva-0.9-alpha-1~574 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=47e2bcd3684600c678b04c31c828d41d80352581;p=archiva.git [MRM-77] fix for reports for distributions that are non-standard types git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441583 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java index 12e2d365a..a0fbcaca1 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java @@ -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; diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java index e2dcff0e4..6d6d08d26 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java @@ -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; + } + } diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java index bab3a12cf..ee5aa4620 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java @@ -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 index 000000000..c2ea777c1 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 index 000000000..c2ea777c1 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