]> source.dussan.org Git - archiva.git/commitdiff
[MRM-166] add filtering and problem identification
authorBrett Porter <brett@apache.org>
Mon, 11 Sep 2006 02:13:21 +0000 (02:13 +0000)
committerBrett Porter <brett@apache.org>
Mon, 11 Sep 2006 02:13:21 +0000 (02:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@442072 13f79535-47bb-0310-9956-ffa450edef68

18 files changed:
archiva-converter/src/main/java/org/apache/maven/archiva/converter/DefaultRepositoryConverter.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportGroup.java
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/main/java/org/apache/maven/archiva/reporting/OldArtifactReportGroup.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportGroup.java
archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java
archiva-reports-standard/src/main/mdo/reporting.mdo
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java [deleted file]
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DefaultArtifactReporterTest.java
archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java
archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp

index 74e9bac4ee632b5edaaa7b88edd1e21142c652bb..d45a26a16368e0e6b76d65174e197059e770b7be 100644 (file)
@@ -295,14 +295,14 @@ public class DefaultRepositoryConverter
 
         if ( !metadata.getGroupId().equals( artifact.getGroupId() ) )
         {
-            reporter.addFailure( artifact, getI18NString( groupIdKey ) );
+            addFailure( reporter, artifact, groupIdKey );
             result = false;
         }
         if ( !repositoryMetadata.storedInGroupDirectory() )
         {
             if ( !metadata.getArtifactId().equals( artifact.getArtifactId() ) )
             {
-                reporter.addFailure( artifact, getI18NString( artifactIdKey ) );
+                addFailure( reporter, artifact, artifactIdKey );
                 result = false;
             }
             if ( !repositoryMetadata.storedInArtifactVersionDirectory() )
@@ -325,7 +325,7 @@ public class DefaultRepositoryConverter
 
                 if ( !foundVersion )
                 {
-                    reporter.addFailure( artifact, getI18NString( versionsKey ) );
+                    addFailure( reporter, artifact, versionsKey );
                     result = false;
                 }
             }
@@ -334,7 +334,7 @@ public class DefaultRepositoryConverter
                 // snapshot metadata
                 if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) )
                 {
-                    reporter.addFailure( artifact, getI18NString( versionKey ) );
+                    addFailure( reporter, artifact, versionKey );
                     result = false;
                 }
 
@@ -357,7 +357,7 @@ public class DefaultRepositoryConverter
 
                         if ( !correct )
                         {
-                            reporter.addFailure( artifact, getI18NString( snapshotKey ) );
+                            addFailure( reporter, artifact, snapshotKey );
                             result = false;
                         }
                     }
@@ -367,6 +367,24 @@ public class DefaultRepositoryConverter
         return result;
     }
 
+    private void addFailure( ReportingDatabase reporter, Artifact artifact, String key )
+    {
+        addFailureWithReason( reporter, artifact, getI18NString( key ) );
+
+    }
+
+    private static void addWarning( ReportingDatabase reporter, Artifact artifact, String message )
+    {
+        // TODO: should we be able to identify/fix these?
+        reporter.addWarning( artifact, null, null, message );
+    }
+
+    private static void addFailureWithReason( ReportingDatabase reporter, Artifact artifact, String reason )
+    {
+        // TODO: should we be able to identify/fix these?
+        reporter.addFailure( artifact, null, null, reason );
+    }
+
     private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, ReportingDatabase reporter,
                              FileTransaction transaction )
         throws RepositoryConversionException
@@ -452,12 +470,13 @@ public class DefaultRepositoryConverter
                     for ( Iterator i = warnings.iterator(); i.hasNext(); )
                     {
                         String message = (String) i.next();
-                        reporter.addWarning( artifact, message );
+                        addWarning( reporter, artifact, message );
                     }
                 }
                 catch ( XmlPullParserException e )
                 {
-                    reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
+                    addFailureWithReason( reporter, artifact,
+                                          getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
                     result = false;
                 }
                 catch ( IOException e )
@@ -466,7 +485,8 @@ public class DefaultRepositoryConverter
                 }
                 catch ( PomTranslationException e )
                 {
-                    reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
+                    addFailureWithReason( reporter, artifact,
+                                          getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
                     result = false;
                 }
                 finally
@@ -477,7 +497,7 @@ public class DefaultRepositoryConverter
         }
         else
         {
-            reporter.addWarning( artifact, getI18NString( "warning.missing.pom" ) );
+            addWarning( reporter, artifact, getI18NString( "warning.missing.pom" ) );
         }
         return result;
     }
@@ -598,7 +618,7 @@ public class DefaultRepositoryConverter
             }
             catch ( DigesterException e )
             {
-                reporter.addFailure( artifact, getI18NString( key ) );
+                addFailure( reporter, artifact, key );
                 result = false;
             }
         }
@@ -622,7 +642,7 @@ public class DefaultRepositoryConverter
                 matching = FileUtils.contentEquals( sourceFile, targetFile );
                 if ( !matching )
                 {
-                    reporter.addFailure( artifact, getI18NString( "failure.target.already.exists" ) );
+                    addFailure( reporter, artifact, "failure.target.already.exists" );
                     result = false;
                 }
             }
index 907bed9b0bfc50362a38d8ed3d6701c00e643707..d493158b8cafc953e51d1db9844759d00cd2f753 100644 (file)
@@ -57,6 +57,8 @@ public class BadMetadataReportProcessor
      */
     private RepositoryQueryLayerFactory repositoryQueryLayerFactory;
 
+    private static final String ROLE_HINT = "bad-metadata";
+
     /**
      * Process the metadata encountered in the repository and report all errors found, if any.
      *
@@ -75,7 +77,7 @@ public class BadMetadataReportProcessor
             }
             catch ( IOException e )
             {
-                reporter.addWarning( metadata, "Error getting plugin artifact directories versions: " + e );
+                addWarning( reporter, metadata, null, "Error getting plugin artifact directories versions: " + e );
             }
         }
         else
@@ -92,7 +94,8 @@ public class BadMetadataReportProcessor
             }
             if ( !found )
             {
-                reporter.addFailure( metadata, "Missing lastUpdated element inside the metadata." );
+                addFailure( reporter, metadata, "missing-last-updated",
+                            "Missing lastUpdated element inside the metadata." );
             }
 
             if ( metadata.storedInArtifactVersionDirectory() )
@@ -109,12 +112,20 @@ public class BadMetadataReportProcessor
                 }
                 catch ( IOException e )
                 {
-                    reporter.addWarning( metadata, "Error getting plugin artifact directories versions: " + e );
+                    String reason = "Error getting plugin artifact directories versions: " + e;
+                    addWarning( reporter, metadata, null, reason );
                 }
             }
         }
     }
 
+    private static void addWarning( ReportingDatabase reporter, RepositoryMetadata metadata, String problem,
+                                    String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addWarning( metadata, ROLE_HINT, problem, reason );
+    }
+
     /**
      * Method for processing a GroupRepositoryMetadata
      *
@@ -138,20 +149,22 @@ public class BadMetadataReportProcessor
             String artifactId = plugin.getArtifactId();
             if ( artifactId == null || artifactId.length() == 0 )
             {
-                reporter.addFailure( metadata,
-                                     "Missing or empty artifactId in group metadata for plugin " + plugin.getPrefix() );
+                addFailure( reporter, metadata, "missing-artifact-id:" + plugin.getPrefix(),
+                            "Missing or empty artifactId in group metadata for plugin " + plugin.getPrefix() );
             }
 
             String prefix = plugin.getPrefix();
             if ( prefix == null || prefix.length() == 0 )
             {
-                reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId + "." );
+                addFailure( reporter, metadata, "missing-plugin-prefix:" + artifactId,
+                            "Missing or empty plugin prefix for artifactId " + artifactId + "." );
             }
             else
             {
                 if ( prefixes.containsKey( prefix ) )
                 {
-                    reporter.addFailure( metadata, "Duplicate plugin prefix found: " + prefix + "." );
+                    addFailure( reporter, metadata, "duplicate-plugin-prefix:" + prefix,
+                                "Duplicate plugin prefix found: " + prefix + "." );
                 }
                 else
                 {
@@ -164,7 +177,8 @@ public class BadMetadataReportProcessor
                 File pluginDir = new File( metadataDir, artifactId );
                 if ( !pluginDirs.contains( pluginDir ) )
                 {
-                    reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" );
+                    addFailure( reporter, metadata, "missing-plugin-from-repository:" + artifactId,
+                                "Metadata plugin " + artifactId + " not found in the repository" );
                 }
                 else
                 {
@@ -178,8 +192,8 @@ public class BadMetadataReportProcessor
             for ( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); )
             {
                 File plugin = (File) plugins.next();
-                reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " +
-                    "missing in the metadata." );
+                addFailure( reporter, metadata, "missing-plugin-from-metadata:" + plugin.getName(), "Plugin " +
+                    plugin.getName() + " is present in the repository but " + "missing in the metadata." );
             }
         }
     }
@@ -210,7 +224,8 @@ public class BadMetadataReportProcessor
 
             if ( !repositoryQueryLayer.containsArtifact( artifact ) )
             {
-                reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
+                addFailure( reporter, metadata, "missing-snapshot-artifact-from-repository:" + version,
+                            "Snapshot artifact " + version + " does not exist." );
             }
         }
     }
@@ -240,8 +255,8 @@ public class BadMetadataReportProcessor
 
                 if ( !repositoryQueryLayer.containsArtifact( artifact ) )
                 {
-                    reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " +
-                        "missing in the repository." );
+                    addFailure( reporter, metadata, "missing-artifact-from-repository:" + version, "Artifact version " +
+                        version + " is present in metadata but " + "missing in the repository." );
                 }
             }
         }
@@ -254,6 +269,7 @@ public class BadMetadataReportProcessor
      * @param metadata   the metadata to be processed.
      * @param repository the repository where the metadata was encountered
      * @param reporter   the ReportingDatabase to receive processing results
+     * @throws java.io.IOException if there is a problem reading from the file system
      */
     private void checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository,
                                           ReportingDatabase reporter )
@@ -275,14 +291,14 @@ public class BadMetadataReportProcessor
                 String version = path.getParentFile().getName();
                 if ( !metadataVersions.contains( version ) )
                 {
-                    reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " +
-                        "missing in the metadata." );
+                    addFailure( reporter, metadata, "missing-artifact-from-metadata:" + version, "Artifact version " +
+                        version + " found in the repository but " + "missing in the metadata." );
                 }
             }
         }
         else
         {
-            reporter.addFailure( metadata, "Metadata's directory did not exist: " + versionsDir );
+            addFailure( reporter, metadata, null, "Metadata's directory did not exist: " + versionsDir );
         }
     }
 
@@ -318,4 +334,11 @@ public class BadMetadataReportProcessor
 
         return artifactIdFiles;
     }
+
+    private static void addFailure( ReportingDatabase reporter, RepositoryMetadata metadata, String problem,
+                                    String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( metadata, ROLE_HINT, problem, reason );
+    }
 }
index c425cd96531e733d7dc78791c799e840d548b56e..776336d3fe133df894689c615024e63dd561f33f 100644 (file)
@@ -45,6 +45,8 @@ public class ChecksumArtifactReportProcessor
      */
     private Digester md5Digester;
 
+    private static final String ROLE_HINT = "checksum";
+
     public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
     {
         ArtifactRepository repository = artifact.getRepository();
@@ -77,16 +79,23 @@ public class ChecksumArtifactReportProcessor
             }
             catch ( DigesterException e )
             {
-                reporter.addFailure( artifact, e.getMessage() );
+                addFailure( reporter, artifact, "checksum-wrong", e.getMessage() );
             }
             catch ( IOException e )
             {
-                reporter.addFailure( artifact, "Read file error: " + e.getMessage() );
+                addFailure( reporter, artifact, "checksum-io-exception", "Read file error: " + e.getMessage() );
             }
         }
         else
         {
-            reporter.addFailure( artifact, digester.getAlgorithm() + " checksum file does not exist." );
+            addFailure( reporter, artifact, "checksum-missing",
+                        digester.getAlgorithm() + " checksum file does not exist." );
         }
     }
+
+    private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( artifact, ROLE_HINT, problem, reason );
+    }
 }
index 0b41fedb396aa5781de17afd4ef2ce5ba51337c6..7a2e57b215671a1d43489ec7f744c833a49da548 100644 (file)
@@ -44,6 +44,8 @@ public class ChecksumMetadataReportProcessor
      */
     private Digester md5Digester;
 
+    private static final String ROLE_HINT = "checksum-metadata";
+
     /**
      * Validate the checksums of the metadata. Get the metadata file from the
      * repository then validate the checksum.
@@ -78,17 +80,25 @@ public class ChecksumMetadataReportProcessor
             }
             catch ( DigesterException e )
             {
-                reporter.addFailure( metadata, e.getMessage() );
+                addFailure( reporter, metadata, "checksum-wrong", e.getMessage() );
             }
             catch ( IOException e )
             {
-                reporter.addFailure( metadata, "Read file error: " + e.getMessage() );
+                addFailure( reporter, metadata, "checksum-io-exception", "Read file error: " + e.getMessage() );
             }
         }
         else
         {
-            reporter.addFailure( metadata, digester.getAlgorithm() + " checksum file does not exist." );
+            addFailure( reporter, metadata, "checksum-missing",
+                        digester.getAlgorithm() + " checksum file does not exist." );
         }
     }
 
+    private static void addFailure( ReportingDatabase reporter, RepositoryMetadata metadata, String problem,
+                                    String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( metadata, ROLE_HINT, problem, reason );
+    }
+
 }
index f4fae3b936df730572758a1080a30b0ee3278c50..21a12f02b83e64e9643b4ff98f22cce766fba10f 100644 (file)
@@ -118,7 +118,7 @@ public class DefaultReportExecutor
             }
             catch ( ProjectBuildingException e )
             {
-                reporter.addWarning( artifact, "Error reading project model: " + e );
+                reporter.addWarning( artifact, null, null, "Error reading project model: " + e );
             }
 
             reporter.removeArtifact( artifact );
index 6af0fe9142566dc28dec92296921524aed8eb69c..3f80c28092486436f56cb93310ba4ebc1563fa41 100644 (file)
@@ -16,10 +16,8 @@ package org.apache.maven.archiva.reporting;
  * limitations under the License.
  */
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
  * The default report set, for repository health.
@@ -32,18 +30,27 @@ public class DefaultReportGroup
 {
     /**
      * Role hints of the reports to include in this set.
-     *
-     * @todo re-enable duplicate, once a way to populate the index is determined!
      */
-    private static final Set reports = new LinkedHashSet( Arrays.asList( new String[]{"checksum", "dependency"
-/*, "duplicate"*/, "invalid-pom", "artifact-location", "bad-metadata", "checksum-metadata"} ) );
+    private static final Map reports = new LinkedHashMap();
+
+    static
+    {
+        reports.put( "checksum", "Checksum Problems" );
+        reports.put( "dependency", "Dependency Problems" );
+        // TODO re-enable duplicate, once a way to populate the index is determined!
+//        reports.put( "duplicate", "Duplicate Artifact Problems" );
+        reports.put( "invalid-pom", "POM Problems" );
+        reports.put( "bad-metadata", "Metadata Problems" );
+        reports.put( "checksum-metadata", "Metadata Checksum Problems" );
+        reports.put( "artifact-location", "Artifact Location Problems" );
+    }
 
     public boolean includeReport( String key )
     {
-        return reports.contains( key );
+        return reports.containsKey( key );
     }
 
-    public Collection getReportIds()
+    public Map getReports()
     {
         return reports;
     }
index f9960bfc2f05ff6d10e92717b021b4237326abe4..c62b2f16ffe7a35037b5a704f0e67e236e7ad522 100644 (file)
@@ -47,10 +47,16 @@ public class DependencyArtifactReportProcessor
 
     private static final String POM = "pom";
 
+    private static final String ROLE_HINT = "dependency";
+
     public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
     {
         RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
-        processArtifact( artifact, reporter, queryLayer );
+        if ( !queryLayer.containsArtifact( artifact ) )
+        {
+            // TODO: is this even possible?
+            addFailure( reporter, artifact, "missing-artifact", "Artifact does not exist in the repository" );
+        }
 
         if ( model != null && POM.equals( artifact.getType() ) )
         {
@@ -59,13 +65,10 @@ public class DependencyArtifactReportProcessor
         }
     }
 
-    private void processArtifact( Artifact artifact, ReportingDatabase reporter,
-                                  RepositoryQueryLayer repositoryQueryLayer )
+    private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
     {
-        if ( !repositoryQueryLayer.containsArtifact( artifact ) )
-        {
-            reporter.addFailure( artifact, "Artifact does not exist in the repository" );
-        }
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( artifact, ROLE_HINT, problem, reason );
     }
 
     private void processDependencies( List dependencies, ReportingDatabase reporter,
@@ -96,7 +99,8 @@ public class DependencyArtifactReportProcessor
                         String reason = MessageFormat.format(
                             "Artifact''s dependency {0} does not exist in the repository",
                             new String[]{getDependencyString( dependency )} );
-                        reporter.addFailure( sourceArtifact, reason );
+                        addFailure( reporter, sourceArtifact, "missing-dependency:" + getDependencyKey( dependency ),
+                                    reason );
                     }
                 }
                 catch ( InvalidVersionSpecificationException e )
@@ -104,12 +108,25 @@ public class DependencyArtifactReportProcessor
                     String reason = MessageFormat.format( "Artifact''s dependency {0} contains an invalid version {1}",
                                                           new String[]{getDependencyString( dependency ),
                                                               dependency.getVersion()} );
-                    reporter.addFailure( sourceArtifact, reason );
+                    addFailure( reporter, sourceArtifact, "bad-version:" + getDependencyKey( dependency ), reason );
                 }
             }
         }
     }
 
+    private String getDependencyKey( Dependency dependency )
+    {
+        String str = dependency.getGroupId();
+        str += ":" + dependency.getArtifactId();
+        str += ":" + dependency.getVersion();
+        str += ":" + dependency.getType();
+        if ( dependency.getClassifier() != null )
+        {
+            str += ":" + dependency.getClassifier();
+        }
+        return str;
+    }
+
     static String getDependencyString( Dependency dependency )
     {
         String str = "(group=" + dependency.getGroupId();
index 68062079933faeffea6acfa316426cf06519081c..5364851c172e2857a389ca11deeff59395e4a39a 100644 (file)
@@ -58,6 +58,8 @@ public class DuplicateArtifactFileReportProcessor
      */
     private String indexDirectory;
 
+    private static final String ROLE_HINT = "duplicate";
+
     public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
     {
         ArtifactRepository repository = artifact.getRepository();
@@ -72,7 +74,8 @@ public class DuplicateArtifactFileReportProcessor
             }
             catch ( DigesterException e )
             {
-                reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
+                addWarning( reporter, artifact, null,
+                            "Unable to generate checksum for " + artifact.getFile() + ": " + e );
             }
 
             if ( checksum != null )
@@ -95,7 +98,8 @@ public class DuplicateArtifactFileReportProcessor
                                 String groupId = artifact.getGroupId();
                                 if ( groupId.equals( result.getGroupId() ) )
                                 {
-                                    reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+                                    addFailures( reporter, artifact, "duplicate",
+                                                 "Found duplicate for " + artifact.getId() );
                                 }
                             }
                         }
@@ -103,13 +107,25 @@ public class DuplicateArtifactFileReportProcessor
                 }
                 catch ( RepositoryIndexSearchException e )
                 {
-                    reporter.addWarning( artifact, "Failed to search in index" + e );
+                    addWarning( reporter, artifact, null, "Failed to search in index" + e );
                 }
             }
         }
         else
         {
-            reporter.addWarning( artifact, "Artifact file is null" );
+            addWarning( reporter, artifact, null, "Artifact file is null" );
         }
     }
+
+    private static void addFailures( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( artifact, ROLE_HINT, problem, reason );
+    }
+
+    private static void addWarning( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addWarning( artifact, ROLE_HINT, problem, reason );
+    }
 }
index bad32f70286fdb4cf04fab23d5bf1c6d9bea565f..3ed9246616789dde277d3a1c7304c82b9fa42836 100644 (file)
@@ -24,7 +24,6 @@ import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.Reader;
@@ -38,6 +37,8 @@ import java.io.Reader;
 public class InvalidPomArtifactReportProcessor
     implements ArtifactReportProcessor
 {
+    private static final String ROLE_HINT = "invalid-pom";
+
     /**
      * @param artifact The pom xml file to be validated, passed as an artifact object.
      * @param reporter The artifact reporter object.
@@ -59,7 +60,7 @@ public class InvalidPomArtifactReportProcessor
 
             if ( !f.exists() )
             {
-                reporter.addFailure( artifact, "Artifact not found." );
+                addFailure( reporter, artifact, "pom-missing", "POM not found." );
             }
             else
             {
@@ -74,16 +75,13 @@ public class InvalidPomArtifactReportProcessor
                 }
                 catch ( XmlPullParserException e )
                 {
-                    reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " +
-                        e.getMessage() );
-                }
-                catch ( FileNotFoundException e )
-                {
-                    reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
+                    addFailure( reporter, artifact, "pom-parse-exception",
+                                "The pom xml file is not well-formed. Error while parsing: " + e.getMessage() );
                 }
                 catch ( IOException e )
                 {
-                    reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
+                    addFailure( reporter, artifact, "pom-io-exception",
+                                "Error while reading the pom xml file: " + e.getMessage() );
                 }
                 finally
                 {
@@ -92,4 +90,10 @@ public class InvalidPomArtifactReportProcessor
             }
         }
     }
+
+    private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( artifact, ROLE_HINT, problem, reason );
+    }
 }
index a0fbcaca1e49f9586324dffdac5a940e8c7a2787..be5f9fc5f1b17a9b8bd6a208773d28f0ef66f858 100644 (file)
@@ -63,6 +63,8 @@ public class LocationArtifactReportProcessor
 
     private static final String POM = "pom";
 
+    private static final String ROLE_HINT = "artifact-location";
+
     /**
      * 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
@@ -104,9 +106,9 @@ public class LocationArtifactReportProcessor
                 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 );
+                    addFailure( reporter, artifact, "repository-pom-location",
+                                "The artifact is out of place. It does not match the specified location in the repository pom: " +
+                                    modelPath );
                 }
             }
         }
@@ -130,8 +132,8 @@ public class LocationArtifactReportProcessor
                                                                                       extractedModel.getPackaging() );
                     if ( !repository.pathOf( extractedArtifact ).equals( artifactPath ) )
                     {
-                        reporter.addFailure( artifact,
-                                             "The artifact is out of place. It does not match the specified location in the packaged pom." );
+                        addFailure( reporter, artifact, "packaged-pom-location",
+                                    "The artifact is out of place. It does not match the specified location in the packaged pom." );
                     }
                 }
             }
@@ -142,6 +144,12 @@ public class LocationArtifactReportProcessor
         }
     }
 
+    private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addFailure( artifact, ROLE_HINT, problem, reason );
+    }
+
     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
@@ -185,11 +193,11 @@ public class LocationArtifactReportProcessor
         }
         catch ( IOException e )
         {
-            reporter.addWarning( artifact, "Unable to read artifact to extract model: " + e );
+            addWarning( reporter, artifact, "Unable to read artifact to extract model: " + e );
         }
         catch ( XmlPullParserException e )
         {
-            reporter.addWarning( artifact, "Unable to parse extracted model: " + e );
+            addWarning( reporter, artifact, "Unable to parse extracted model: " + e );
         }
         finally
         {
@@ -209,6 +217,12 @@ public class LocationArtifactReportProcessor
         return model;
     }
 
+    private static void addWarning( ReportingDatabase reporter, Artifact artifact, String reason )
+    {
+        // TODO: reason could be an i18n key derived from the processor and the problem ID and the
+        reporter.addWarning( artifact, ROLE_HINT, null, reason );
+    }
+
     private Model readModel( InputStream entryStream )
         throws IOException, XmlPullParserException
     {
index 73e6a77d26d17f195259ff47d462b6e5dc7d5923..d41dc962b76b3fe4043b0f1ce915040126def542 100644 (file)
@@ -16,10 +16,8 @@ package org.apache.maven.archiva.reporting;
  * limitations under the License.
  */
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
  * The report set for finding old artifacts (both snapshot and release)
@@ -34,15 +32,20 @@ public class OldArtifactReportGroup
      *
      * @todo implement these report processors!
      */
-    private static final Set reports =
-        new LinkedHashSet( Arrays.asList( new String[]{"old-artifact", "old-snapshot-artifact"} ) );
+    private static final Map reports = new LinkedHashMap();
+
+    static
+    {
+        reports.put( "old-artifact", "Old Artifacts" );
+        reports.put( "old-snapshot-artifact", "Old Snapshot Artifacts" );
+    }
 
     public boolean includeReport( String key )
     {
-        return reports.contains( key );
+        return reports.containsKey( key );
     }
 
-    public Collection getReportIds()
+    public Map getReports()
     {
         return reports;
     }
index e5708214d25770699e6d91555157f3404c947ddf..eec3b01f9670caeba3b6e94a85f850dfdc9ef4f7 100644 (file)
@@ -5,7 +5,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.model.Model;
 
-import java.util.Collection;
+import java.util.Map;
 
 /*
  * Copyright 2005-2006 The Apache Software Foundation.
@@ -62,11 +62,12 @@ public interface ReportGroup
     boolean includeReport( String key );
 
     /**
-     * Get a list of the report processors in this set.
+     * Get the report processors in this set. The map is keyed by the report's role hint, and the value is it's
+     * display name.
      *
-     * @return the report IDs
+     * @return the reports
      */
-    Collection getReportIds();
+    Map getReports();
 
     /**
      * Get the user-friendly name of this report.
index a2f9bf74b74be78ae0680ceecb9d89d0f278b31d..e81d47faa10f2b53912fa915a1e29be8eb9487db 100644 (file)
@@ -56,6 +56,8 @@ public class ReportingDatabase
 
     private Set metadataWithProblems;
 
+    private Map filteredDatabases = new HashMap();
+
     public ReportingDatabase( ReportGroup reportGroup )
     {
         this( reportGroup, new Reporting() );
@@ -84,37 +86,57 @@ public class ReportingDatabase
         initMetadataMap();
     }
 
-    public void addFailure( Artifact artifact, String reason )
+    public void addFailure( Artifact artifact, String processor, String problem, String reason )
     {
         ArtifactResults results = getArtifactResults( artifact );
-        results.addFailure( createResults( reason ) );
+        results.addFailure( createResult( processor, problem, reason ) );
         numFailures++;
         updateTimings();
+
+        if ( filteredDatabases.containsKey( problem ) )
+        {
+            ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
+
+            reportingDatabase.addFailure( artifact, processor, problem, reason );
+        }
     }
 
-    public void addWarning( Artifact artifact, String reason )
+    public void addWarning( Artifact artifact, String processor, String problem, String reason )
     {
         ArtifactResults results = getArtifactResults( artifact );
-        results.addWarning( createResults( reason ) );
+        results.addWarning( createResult( processor, problem, reason ) );
         numWarnings++;
         updateTimings();
+
+        if ( filteredDatabases.containsKey( problem ) )
+        {
+            ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
+
+            reportingDatabase.addWarning( artifact, processor, problem, reason );
+        }
     }
 
     private ArtifactResults getArtifactResults( Artifact artifact )
+    {
+        return getArtifactResults( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
+                                   artifact.getType(), artifact.getClassifier() );
+    }
+
+    private ArtifactResults getArtifactResults( String groupId, String artifactId, String version, String type,
+                                                String classifier )
     {
         Map artifactMap = this.artifactMap;
 
-        String key = getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
-                                     artifact.getType(), artifact.getClassifier() );
+        String key = getArtifactKey( groupId, artifactId, version, type, classifier );
         ArtifactResults results = (ArtifactResults) artifactMap.get( key );
         if ( results == null )
         {
             results = new ArtifactResults();
-            results.setArtifactId( artifact.getArtifactId() );
-            results.setClassifier( artifact.getClassifier() );
-            results.setGroupId( artifact.getGroupId() );
-            results.setType( artifact.getType() );
-            results.setVersion( artifact.getVersion() );
+            results.setArtifactId( artifactId );
+            results.setClassifier( classifier );
+            results.setGroupId( groupId );
+            results.setType( type );
+            results.setVersion( version );
 
             artifactMap.put( key, results );
             reporting.getArtifacts().add( results );
@@ -146,35 +168,51 @@ public class ReportingDatabase
         return groupId + ":" + artifactId + ":" + version + ":" + type + ":" + classifier;
     }
 
-    private static Result createResults( String reason )
+    private static Result createResult( String processor, String problem, String reason )
     {
         Result result = new Result();
+        result.setProcessor( processor );
+        result.setProblem( problem );
         result.setReason( reason );
         return result;
     }
 
-    public void addFailure( RepositoryMetadata metadata, String reason )
+    public void addFailure( RepositoryMetadata metadata, String processor, String problem, String reason )
     {
         MetadataResults results = getMetadataResults( metadata, System.currentTimeMillis() );
         if ( !metadataWithProblems.contains( results ) )
         {
             metadataWithProblems.add( results );
         }
-        results.addFailure( createResults( reason ) );
+        results.addFailure( createResult( processor, problem, reason ) );
         numFailures++;
         updateTimings();
+
+        if ( filteredDatabases.containsKey( problem ) )
+        {
+            ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
+
+            reportingDatabase.addFailure( metadata, processor, problem, reason );
+        }
     }
 
-    public void addWarning( RepositoryMetadata metadata, String reason )
+    public void addWarning( RepositoryMetadata metadata, String processor, String problem, String reason )
     {
         MetadataResults results = getMetadataResults( metadata, System.currentTimeMillis() );
         if ( !metadataWithProblems.contains( results ) )
         {
             metadataWithProblems.add( results );
         }
-        results.addWarning( createResults( reason ) );
+        results.addWarning( createResult( processor, problem, reason ) );
         numWarnings++;
         updateTimings();
+
+        if ( filteredDatabases.containsKey( problem ) )
+        {
+            ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
+
+            reportingDatabase.addWarning( metadata, processor, problem, reason );
+        }
     }
 
     public Set getMetadataWithProblems()
@@ -239,7 +277,7 @@ public class ReportingDatabase
 
     public boolean isMetadataUpToDate( RepositoryMetadata metadata, long timestamp )
     {
-        String key = getMetadataKey( metadata );
+        String key = getMetadataKey( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
         Map map = metadataMap;
         MetadataResults results = (MetadataResults) map.get( key );
         return results != null && results.getLastModified() >= timestamp;
@@ -268,15 +306,22 @@ public class ReportingDatabase
 
     private MetadataResults getMetadataResults( RepositoryMetadata metadata, long lastModified )
     {
-        String key = getMetadataKey( metadata );
+        return getMetadataResults( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion(),
+                                   lastModified );
+    }
+
+    private MetadataResults getMetadataResults( String groupId, String artifactId, String baseVersion,
+                                                long lastModified )
+    {
+        String key = getMetadataKey( groupId, artifactId, baseVersion );
         Map metadataMap = this.metadataMap;
         MetadataResults results = (MetadataResults) metadataMap.get( key );
         if ( results == null )
         {
             results = new MetadataResults();
-            results.setArtifactId( metadata.getArtifactId() );
-            results.setGroupId( metadata.getGroupId() );
-            results.setVersion( metadata.getBaseVersion() );
+            results.setArtifactId( artifactId );
+            results.setGroupId( groupId );
+            results.setVersion( baseVersion );
             results.setLastModified( lastModified );
 
             metadataMap.put( key, results );
@@ -285,11 +330,6 @@ public class ReportingDatabase
         return results;
     }
 
-    private static String getMetadataKey( RepositoryMetadata metadata )
-    {
-        return getMetadataKey( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
-    }
-
     public void removeArtifact( Artifact artifact )
     {
         Map map = artifactMap;
@@ -343,6 +383,7 @@ public class ReportingDatabase
         artifactMap.clear();
         metadataMap.clear();
         metadataWithProblems.clear();
+        filteredDatabases.clear();
 
         reporting.getArtifacts().clear();
         reporting.getMetadata().clear();
@@ -375,4 +416,113 @@ public class ReportingDatabase
     {
         return reportGroup;
     }
+
+    public ReportingDatabase getFilteredDatabase( String filter )
+    {
+        ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( filter );
+
+        if ( reportingDatabase == null )
+        {
+            reportingDatabase = new ReportingDatabase( reportGroup, repository );
+
+            Reporting reporting = reportingDatabase.getReporting();
+            reporting.setExecutionTime( this.reporting.getExecutionTime() );
+            reporting.setLastModified( this.reporting.getLastModified() );
+
+            for ( Iterator i = this.reporting.getArtifacts().iterator(); i.hasNext(); )
+            {
+                ArtifactResults results = (ArtifactResults) i.next();
+                ArtifactResults targetResults = null;
+                for ( Iterator j = results.getFailures().iterator(); j.hasNext(); )
+                {
+                    Result result = (Result) j.next();
+
+                    if ( filter.equals( result.getProcessor() ) )
+                    {
+                        if ( targetResults == null )
+                        {
+                            // lazily create so it is not added unless it has to be
+                            targetResults = createArtifactResults( reportingDatabase, results );
+                        }
+
+                        targetResults.addFailure( result );
+                        reportingDatabase.numFailures++;
+                    }
+                }
+                for ( Iterator j = results.getWarnings().iterator(); j.hasNext(); )
+                {
+                    Result result = (Result) j.next();
+
+                    if ( filter.equals( result.getProcessor() ) )
+                    {
+                        if ( targetResults == null )
+                        {
+                            // lazily create so it is not added unless it has to be
+                            targetResults = createArtifactResults( reportingDatabase, results );
+                        }
+
+                        targetResults.addWarning( result );
+                        reportingDatabase.numWarnings++;
+                    }
+                }
+            }
+            for ( Iterator i = this.reporting.getMetadata().iterator(); i.hasNext(); )
+            {
+                MetadataResults results = (MetadataResults) i.next();
+                MetadataResults targetResults = null;
+                for ( Iterator j = results.getFailures().iterator(); j.hasNext(); )
+                {
+                    Result result = (Result) j.next();
+
+                    if ( filter.equals( result.getProcessor() ) )
+                    {
+                        if ( targetResults == null )
+                        {
+                            // lazily create so it is not added unless it has to be
+                            targetResults = createMetadataResults( reportingDatabase, results );
+                        }
+
+                        targetResults.addFailure( result );
+                        reportingDatabase.numFailures++;
+                    }
+                }
+                for ( Iterator j = results.getWarnings().iterator(); j.hasNext(); )
+                {
+                    Result result = (Result) j.next();
+
+                    if ( filter.equals( result.getProcessor() ) )
+                    {
+                        if ( targetResults == null )
+                        {
+                            // lazily create so it is not added unless it has to be
+                            targetResults = createMetadataResults( reportingDatabase, results );
+                        }
+
+                        targetResults.addWarning( result );
+                        reportingDatabase.numWarnings++;
+                    }
+                }
+            }
+
+            filteredDatabases.put( filter, reportingDatabase );
+        }
+
+        return reportingDatabase;
+    }
+
+    private static MetadataResults createMetadataResults( ReportingDatabase reportingDatabase, MetadataResults results )
+    {
+        MetadataResults targetResults = reportingDatabase.getMetadataResults( results.getGroupId(),
+                                                                              results.getArtifactId(),
+                                                                              results.getVersion(),
+                                                                              results.getLastModified() );
+        reportingDatabase.metadataWithProblems.add( targetResults );
+        return targetResults;
+    }
+
+    private static ArtifactResults createArtifactResults( ReportingDatabase reportingDatabase, ArtifactResults results )
+    {
+        return reportingDatabase.getArtifactResults( results.getGroupId(), results.getArtifactId(),
+                                                     results.getVersion(), results.getType(), results.getClassifier() );
+    }
 }
index 575f1329d94a6c839cd19bf6090ec90516cca86f..74a75f4da1fc9e07da073ecc80d4d21974d327d4 100644 (file)
           <description>
             The reason given for the result.
           </description>
+          <required>true</required>
+        </field>
+        <field xml.attribute="true">
+          <name>processor</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <description>
+            The processor identifier for the report that triggered the problem. This matches the role-hint of a report
+            processor.
+          </description>
+          <required>true</required>
+        </field>
+        <field xml.attribute="true">
+          <name>problem</name>
+          <version>1.0.0</version>
+          <type>String</type>
+          <description>
+            The problem identifier for the problem that occurred. This is so that the processor can identify how to
+            fix the problem. It may be null if it cannot be fixed automatically.
+          </description>
         </field>
       </fields>
     </class>
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java
deleted file mode 100644 (file)
index 6e8c896..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.archiva.reporting.model.ArtifactResults;
-import org.apache.maven.archiva.reporting.model.Result;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.metadata.Versioning;
-
-import java.util.Iterator;
-
-/**
- *
- */
-public class ArtifactReporterTest
-    extends AbstractRepositoryReportsTestCase
-{
-    private ReportingDatabase reportingDatabase;
-
-    private Artifact artifact;
-
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
-        artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
-        Versioning versioning = new Versioning();
-        versioning.addVersion( "1.0-alpha-1" );
-        versioning.setLastUpdated( "20050611.202020" );
-
-        ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
-        reportingDatabase = new ReportingDatabase( reportGroup );
-    }
-
-    public void testArtifactReporterSingleFailure()
-    {
-        reportingDatabase.addFailure( artifact, "failed once" );
-
-        Iterator artifactIterator = reportingDatabase.getArtifactIterator();
-        ArtifactResults results = (ArtifactResults) artifactIterator.next();
-        assertFalse( artifactIterator.hasNext() );
-
-        int count = 0;
-        for ( Iterator i = results.getFailures().iterator(); i.hasNext(); count++ )
-        {
-            i.next();
-        }
-        assertEquals( 1, count );
-        assertEquals( 1, reportingDatabase.getNumFailures() );
-        assertEquals( 0, reportingDatabase.getNumWarnings() );
-    }
-
-    public void testArtifactReporterMultipleFailure()
-    {
-        reportingDatabase.addFailure( artifact, "failed once" );
-        reportingDatabase.addFailure( artifact, "failed twice" );
-        reportingDatabase.addFailure( artifact, "failed thrice" );
-
-        Iterator artifactIterator = reportingDatabase.getArtifactIterator();
-        ArtifactResults results = (ArtifactResults) artifactIterator.next();
-        assertFalse( artifactIterator.hasNext() );
-
-        int count = 0;
-        for ( Iterator i = results.getFailures().iterator(); i.hasNext(); count++ )
-        {
-            i.next();
-        }
-        assertEquals( 3, count );
-        assertEquals( 3, reportingDatabase.getNumFailures() );
-        assertEquals( 0, reportingDatabase.getNumWarnings() );
-    }
-
-    public void testFailureMessages()
-    {
-        reportingDatabase.addFailure( artifact, "failed once" );
-        reportingDatabase.addFailure( artifact, "failed twice" );
-        reportingDatabase.addFailure( artifact, "failed thrice" );
-        Iterator artifactIterator = reportingDatabase.getArtifactIterator();
-        ArtifactResults results = (ArtifactResults) artifactIterator.next();
-        assertFalse( artifactIterator.hasNext() );
-        Iterator failure = results.getFailures().iterator();
-        assertEquals( "failed once", ( (Result) failure.next() ).getReason() );
-        assertEquals( "failed twice", ( (Result) failure.next() ).getReason() );
-        assertEquals( "failed thrice", ( (Result) failure.next() ).getReason() );
-    }
-
-    public void testArtifactReporterSingleWarning()
-    {
-        reportingDatabase.addWarning( artifact, "you've been warned" );
-        Iterator artifactIterator = reportingDatabase.getArtifactIterator();
-        ArtifactResults results = (ArtifactResults) artifactIterator.next();
-        assertFalse( artifactIterator.hasNext() );
-
-        int count = 0;
-        for ( Iterator i = results.getWarnings().iterator(); i.hasNext(); count++ )
-        {
-            i.next();
-        }
-        assertEquals( 1, count );
-        assertEquals( 0, reportingDatabase.getNumFailures() );
-        assertEquals( 1, reportingDatabase.getNumWarnings() );
-    }
-
-    public void testArtifactReporterMultipleWarning()
-    {
-        reportingDatabase.addWarning( artifact, "i'm warning you" );
-        reportingDatabase.addWarning( artifact, "you have to stop now" );
-        reportingDatabase.addWarning( artifact, "all right... that does it!" );
-
-        Iterator artifactIterator = reportingDatabase.getArtifactIterator();
-        ArtifactResults results = (ArtifactResults) artifactIterator.next();
-        assertFalse( artifactIterator.hasNext() );
-
-        int count = 0;
-        for ( Iterator i = results.getWarnings().iterator(); i.hasNext(); count++ )
-        {
-            i.next();
-        }
-        assertEquals( 3, count );
-        assertEquals( 0, reportingDatabase.getNumFailures() );
-        assertEquals( 3, reportingDatabase.getNumWarnings() );
-    }
-
-    public void testWarningMessages()
-    {
-        reportingDatabase.addWarning( artifact, "i'm warning you" );
-        reportingDatabase.addWarning( artifact, "you have to stop now" );
-        reportingDatabase.addWarning( artifact, "all right... that does it!" );
-
-        Iterator artifactIterator = reportingDatabase.getArtifactIterator();
-        ArtifactResults results = (ArtifactResults) artifactIterator.next();
-        assertFalse( artifactIterator.hasNext() );
-        Iterator warning = results.getWarnings().iterator();
-        assertEquals( "i'm warning you", ( (Result) warning.next() ).getReason() );
-        assertEquals( "you have to stop now", ( (Result) warning.next() ).getReason() );
-        assertEquals( "all right... that does it!", ( (Result) warning.next() ).getReason() );
-    }
-}
index 37494f6aa5ba0324f926f68f4d4a797db82026e2..94154945c4357c6e41ea7abd1189bd489ef6cec6 100644 (file)
@@ -36,6 +36,10 @@ public class DefaultArtifactReporterTest
 
     private RepositoryMetadata metadata;
 
+    private static final String PROCESSOR = "processor";
+
+    private static final String PROBLEM = "problem";
+
     public void testEmptyArtifactReporter()
     {
         assertEquals( "No failures", 0, reportingDatabase.getNumFailures() );
@@ -46,7 +50,7 @@ public class DefaultArtifactReporterTest
 
     public void testMetadataSingleFailure()
     {
-        reportingDatabase.addFailure( metadata, "Single Failure Reason" );
+        reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Single Failure Reason" );
         assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
         assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
 
@@ -58,6 +62,8 @@ public class DefaultArtifactReporterTest
         Result result = (Result) failures.next();
         assertMetadata( results );
         assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
+        assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
+        assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
         assertFalse( "no more failures", failures.hasNext() );
     }
 
@@ -70,8 +76,8 @@ public class DefaultArtifactReporterTest
 
     public void testMetadataMultipleFailures()
     {
-        reportingDatabase.addFailure( metadata, "First Failure Reason" );
-        reportingDatabase.addFailure( metadata, "Second Failure Reason" );
+        reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "First Failure Reason" );
+        reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Second Failure Reason" );
         assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
         assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
 
@@ -83,15 +89,19 @@ public class DefaultArtifactReporterTest
         Result result = (Result) failures.next();
         assertMetadata( results );
         assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
+        assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
+        assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
         assertTrue( "must have 2nd failure", failures.hasNext() );
         result = (Result) failures.next();
         assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
+        assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
+        assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
         assertFalse( "no more failures", failures.hasNext() );
     }
 
     public void testMetadataSingleWarning()
     {
-        reportingDatabase.addWarning( metadata, "Single Warning Message" );
+        reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Single Warning Message" );
         assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
         assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
 
@@ -103,13 +113,15 @@ public class DefaultArtifactReporterTest
         Result result = (Result) warnings.next();
         assertMetadata( results );
         assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
+        assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
+        assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
         assertFalse( "no more warnings", warnings.hasNext() );
     }
 
     public void testMetadataMultipleWarnings()
     {
-        reportingDatabase.addWarning( metadata, "First Warning" );
-        reportingDatabase.addWarning( metadata, "Second Warning" );
+        reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "First Warning" );
+        reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Second Warning" );
         assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
         assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
 
@@ -121,9 +133,13 @@ public class DefaultArtifactReporterTest
         Result result = (Result) warnings.next();
         assertMetadata( results );
         assertEquals( "check failure reason", "First Warning", result.getReason() );
+        assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
+        assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
         assertTrue( "must have 2nd warning", warnings.hasNext() );
         result = (Result) warnings.next();
         assertEquals( "check failure reason", "Second Warning", result.getReason() );
+        assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
+        assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
         assertFalse( "no more warnings", warnings.hasNext() );
     }
 
index 86db54f3bec4c58514b235a58063d781f99abf2b..9b0bfdebc66f596de2fb365249c7bb6c5bce120f 100644 (file)
@@ -76,6 +76,8 @@ public class ReportsAction
 
     private static final String DEFAULT_REPORT_GROUP = "health";
 
+    private String filter;
+
     public String execute()
         throws Exception
     {
@@ -107,6 +109,11 @@ public class ReportsAction
 
         ReportingDatabase database = executor.getReportDatabase( repository, reportGroup );
 
+        if ( filter != null && !filter.equals( "-" ) )
+        {
+            database = database.getFilteredDatabase( filter );
+        }
+
         databases.add( database );
     }
 
@@ -205,4 +212,14 @@ public class ReportsAction
     {
         return reports;
     }
+
+    public String getFilter()
+    {
+        return filter;
+    }
+
+    public void setFilter( String filter )
+    {
+        this.filter = filter;
+    }
 }
index 4f91730a13d0fb7f199ee6a19cd903e321472ad7..713c47bd11b7ee050909597f1a17690a319aa98b 100644 (file)
 
 <div id="contentArea">
 
-<%-- TODO!: select filter --%>
 <ww:form action="reports" namespace="/admin">
-  <ww:select list="reports" label="Report" name="reportGroup"/>
+  <ww:select list="reports" label="Report" name="reportGroup" onchange="document.reports.submit();"/>
   <ww:select list="configuration.repositories" listKey="id" listValue="name" label="Repository" headerKey="-"
-             headerValue="(All repositories)" name="repositoryId"/>
+             headerValue="(All repositories)" name="repositoryId" onchange="document.reports.submit();"/>
+  <ww:select list="reports[reportGroup].reports" label="Filter" headerKey="-" headerValue="(All Problems)"
+             name="filter" onchange="document.reports.submit();"/>
   <ww:submit value="Get Report"/>
 </ww:form>