]> source.dussan.org Git - archiva.git/commitdiff
[MRM-161] clean up report results
authorBrett Porter <brett@apache.org>
Fri, 8 Sep 2006 05:58:25 +0000 (05:58 +0000)
committerBrett Porter <brett@apache.org>
Fri, 8 Sep 2006 05:58:25 +0000 (05:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441391 13f79535-47bb-0310-9956-ffa450edef68

archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessorTest.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-sources.jar [new file with mode: 0644]

index 851bbd9021ceb8a25c3e23fc40cfaefdd814e6d7..ba8e1e8f09ef52658e9ec6f07174c65388e2caad 100644 (file)
@@ -45,12 +45,14 @@ public class DependencyArtifactReportProcessor
      */
     private RepositoryQueryLayerFactory layerFactory;
 
+    private static final String POM = "pom";
+
     public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
     {
         RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
         processArtifact( artifact, reporter, queryLayer );
 
-        if ( model != null )
+        if ( model != null && POM.equals( artifact.getType() ) )
         {
             List dependencies = model.getDependencies();
             processDependencies( dependencies, reporter, queryLayer, artifact );
index 3445860902977206e8ed1bdd325a4c937191ed52..a5b116d626f6a7f06320180eb9ba659e44165e4c 100644 (file)
@@ -62,55 +62,58 @@ public class DuplicateArtifactFileReportProcessor
     {
         ArtifactRepository repository = artifact.getRepository();
         // TODO! always null currently, need to configure this properly
-        if ( artifact.getFile() != null && indexDirectory != null )
+        if ( indexDirectory != null )
         {
-            RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) );
-
-            String checksum = null;
-            try
-            {
-                checksum = digester.calc( artifact.getFile() );
-            }
-            catch ( DigesterException e )
+            if ( artifact.getFile() != null )
             {
-                reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
-            }
+                RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) );
 
-            if ( checksum != null )
-            {
+                String checksum = null;
                 try
                 {
-                    List results = index.search( new LuceneQuery(
-                        new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
+                    checksum = digester.calc( artifact.getFile() );
+                }
+                catch ( DigesterException e )
+                {
+                    reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
+                }
 
-                    if ( !results.isEmpty() )
+                if ( checksum != null )
+                {
+                    try
                     {
-                        for ( Iterator i = results.iterator(); i.hasNext(); )
-                        {
-                            StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+                        List results = index.search( new LuceneQuery(
+                            new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
 
-                            //make sure it is not the same artifact
-                            if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
+                        if ( !results.isEmpty() )
+                        {
+                            for ( Iterator i = results.iterator(); i.hasNext(); )
                             {
-                                //report only duplicates from the same groupId
-                                String groupId = artifact.getGroupId();
-                                if ( groupId.equals( result.getGroupId() ) )
+                                StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+
+                                //make sure it is not the same artifact
+                                if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
                                 {
-                                    reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+                                    //report only duplicates from the same groupId
+                                    String groupId = artifact.getGroupId();
+                                    if ( groupId.equals( result.getGroupId() ) )
+                                    {
+                                        reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+                                    }
                                 }
                             }
                         }
                     }
-                }
-                catch ( RepositoryIndexSearchException e )
-                {
-                    reporter.addWarning( artifact, "Failed to search in index" + e );
+                    catch ( RepositoryIndexSearchException e )
+                    {
+                        reporter.addWarning( artifact, "Failed to search in index" + e );
+                    }
                 }
             }
-        }
-        else
-        {
-            reporter.addWarning( artifact, "Artifact file is null" );
+            else
+            {
+                reporter.addWarning( artifact, "Artifact file is null" );
+            }
         }
     }
 }
index 716b182f4384a941b60f007eadb9e68edb0378cb..bad32f70286fdb4cf04fab23d5bf1c6d9bea565f 100644 (file)
@@ -32,6 +32,7 @@ import java.io.Reader;
 /**
  * This class validates well-formedness of pom xml file.
  *
+ * @todo nice to have this a specific, tested report - however it is likely to double up with project building exceptions from IndexerTask. Resolve [!]
  * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="invalid-pom"
  */
 public class InvalidPomArtifactReportProcessor
@@ -90,9 +91,5 @@ public class InvalidPomArtifactReportProcessor
                 }
             }
         }
-        else
-        {
-            reporter.addWarning( artifact, "The artifact is not a pom xml file." );
-        }
     }
 }
index a7121138e31b5d416c594bb0dc5adbdc6cbf3a56..12e2d365a226602b1f148a70934dc7d94c587eeb 100644 (file)
@@ -60,6 +60,8 @@ public class LocationArtifactReportProcessor
      */
     private MavenProjectBuilder projectBuilder;
 
+    private static final String POM = "pom";
+
     /**
      * Check whether the artifact is in its proper location. The location of the artifact
      * is validated first against the groupId, artifactId and versionId in the specified model
@@ -83,16 +85,25 @@ public class LocationArtifactReportProcessor
 
         if ( model != null )
         {
-            //check if the artifact is located in its proper location based on the info
-            //specified in the model object/pom
-            Artifact modelArtifact = artifactFactory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
-                                                                          model.getVersion(), model.getPackaging() );
-
-            String modelPath = repository.pathOf( modelArtifact );
-            if ( !modelPath.equals( artifactPath ) )
+            // only check if it is a standalone POM, or an artifact other than a POM
+            // ie, don't check the location of the POM for another artifact matches that of the artifact
+            if ( !POM.equals( artifact.getType() ) || POM.equals( model.getPackaging() ) )
             {
-                reporter.addFailure( artifact,
-                                     "The artifact is out of place. It does not match the specified location in the repository pom." );
+                //check if the artifact is located in its proper location based on the info
+                //specified in the model object/pom
+                Artifact modelArtifact = artifactFactory.createArtifactWithClassifier( model.getGroupId(),
+                                                                                       model.getArtifactId(),
+                                                                                       model.getVersion(),
+                                                                                       artifact.getType(),
+                                                                                       artifact.getClassifier() );
+
+                String modelPath = repository.pathOf( modelArtifact );
+                if ( !modelPath.equals( artifactPath ) )
+                {
+                    reporter.addFailure( artifact,
+                                         "The artifact is out of place. It does not match the specified location in the repository pom: " +
+                                             modelPath );
+                }
             }
         }
 
@@ -123,8 +134,7 @@ public class LocationArtifactReportProcessor
         }
         else
         {
-            reporter.addFailure( artifact,
-                                 "The artifact is out of place. It does not exist at the specified location in the repository pom." );
+            throw new IllegalStateException( "Couldn't find artifact " + file );
         }
     }
 
index 3351bc301ce3fb3560d4a3769be9206b5adb0e0f..f9364ea47a2e46ea8fa66b043f63510b29f32f9e 100644 (file)
@@ -69,6 +69,6 @@ public class InvalidPomArtifactReportProcessorTest
 
         artifactReportProcessor.processArtifact( artifact, null, reporter );
         assertEquals( 0, reporter.getNumFailures() );
-        assertEquals( 1, reporter.getNumWarnings() );
+        assertEquals( 0, reporter.getNumWarnings() );
     }
 }
index 4d901b11d1088edf384b995e2c8e0e5688405535..bab3a12cf5d945f5f9312bd1de43dda6364bef29 100644 (file)
@@ -76,8 +76,41 @@ public class LocationArtifactReportProcessorTest
         throws IOException, XmlPullParserException
     {
         Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
+        Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
 
-        artifactReportProcessor.processArtifact( artifact, null, reporter );
+        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, but the pom itself is passed in.
+     */
+    public void testLocationArtifactReporterSuccessPom()
+        throws IOException, XmlPullParserException
+    {
+        Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
+
+        Model model = readPom( repository.pathOf( pomArtifact ) );
+        artifactReportProcessor.processArtifact( pomArtifact, 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 testLocationArtifactReporterSuccessClassifier()
+        throws IOException, XmlPullParserException
+    {
+        Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "java-source" );
+        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() );
     }
@@ -90,9 +123,18 @@ public class LocationArtifactReportProcessorTest
         throws IOException, XmlPullParserException
     {
         Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
+        Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
 
-        artifactReportProcessor.processArtifact( artifact, null, reporter );
-        assertEquals( 1, reporter.getNumFailures() );
+        try
+        {
+            Model model = readPom( repository.pathOf( pomArtifact ) );
+            artifactReportProcessor.processArtifact( artifact, model, reporter );
+            fail( "Should not have passed the artifact" );
+        }
+        catch ( IllegalStateException e )
+        {
+            // correct!
+        }
     }
 
     /**
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-sources.jar b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1-sources.jar
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-sources.jar differ