]> source.dussan.org Git - archiva.git/commitdiff
[MRM-262] Reporting adds duplicated entries on each run
authorCarlos Sanchez Gonzalez <carlos@apache.org>
Fri, 22 Dec 2006 15:56:26 +0000 (15:56 +0000)
committerCarlos Sanchez Gonzalez <carlos@apache.org>
Fri, 22 Dec 2006 15:56:26 +0000 (15:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@489678 13f79535-47bb-0310-9956-ffa450edef68

archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/database/ReportingDatabase.java
archiva-reports-standard/src/main/mdo/reporting.mdo
archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/database/ReportingDatabaseTest.java [new file with mode: 0644]

index b009825707ae9a7408f8e324cfde095fb9c54f7b..c477cf03aac69a2a38abedc56ea5b2ea0edb7c3e 100644 (file)
@@ -92,8 +92,12 @@ public class ReportingDatabase
     public void addFailure( Artifact artifact, String processor, String problem, String reason )
     {
         ArtifactResults results = getArtifactResults( artifact );
-        results.addFailure( createResult( processor, problem, reason ) );
-        numFailures++;
+        Result result = createResult( processor, problem, reason );
+        if ( !results.getFailures().contains( result ) )
+        {
+            results.addFailure( result );
+            numFailures++;
+        }
         updateTimings();
 
         if ( filteredDatabases.containsKey( problem ) )
@@ -107,8 +111,12 @@ public class ReportingDatabase
     public void addNotice( Artifact artifact, String processor, String problem, String reason )
     {
         ArtifactResults results = getArtifactResults( artifact );
-        results.addNotice( createResult( processor, problem, reason ) );
-        numNotices++;
+        Result result = createResult( processor, problem, reason );
+        if ( !results.getNotices().contains( result ) )
+        {
+            results.addNotice( result );
+            numNotices++;
+        }
         updateTimings();
 
         if ( filteredDatabases.containsKey( problem ) )
@@ -122,8 +130,12 @@ public class ReportingDatabase
     public void addWarning( Artifact artifact, String processor, String problem, String reason )
     {
         ArtifactResults results = getArtifactResults( artifact );
-        results.addWarning( createResult( processor, problem, reason ) );
-        numWarnings++;
+        Result result = createResult( processor, problem, reason );
+        if ( !results.getWarnings().contains( result ) )
+        {
+            results.addWarning( result );
+            numWarnings++;
+        }
         updateTimings();
 
         if ( filteredDatabases.containsKey( problem ) )
@@ -134,7 +146,7 @@ public class ReportingDatabase
         }
     }
 
-    private ArtifactResults getArtifactResults( Artifact artifact )
+    ArtifactResults getArtifactResults( Artifact artifact )
     {
         return getArtifactResults( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
                                    artifact.getType(), artifact.getClassifier() );
@@ -203,8 +215,12 @@ public class ReportingDatabase
         {
             metadataWithProblems.add( results );
         }
-        results.addFailure( createResult( processor, problem, reason ) );
-        numFailures++;
+        Result result = createResult( processor, problem, reason );
+        if ( !results.getFailures().contains( result ) )
+        {
+            results.addFailure( result );
+            numFailures++;
+        }
         updateTimings();
 
         if ( filteredDatabases.containsKey( problem ) )
@@ -222,8 +238,12 @@ public class ReportingDatabase
         {
             metadataWithProblems.add( results );
         }
-        results.addWarning( createResult( processor, problem, reason ) );
-        numWarnings++;
+        Result result = createResult( processor, problem, reason );
+        if ( !results.getWarnings().contains( result ) )
+        {
+            results.addWarning( result );
+            numWarnings++;
+        }
         updateTimings();
 
         if ( filteredDatabases.containsKey( problem ) )
@@ -241,8 +261,12 @@ public class ReportingDatabase
         {
             metadataWithProblems.add( results );
         }
-        results.addNotice( createResult( processor, problem, reason ) );
-        numNotices++;
+        Result result = createResult( processor, problem, reason );
+        if ( !results.getNotices().contains( result ) )
+        {
+            results.addNotice( result );
+            numNotices++;
+        }
         updateTimings();
 
         if ( filteredDatabases.containsKey( problem ) )
@@ -346,7 +370,7 @@ public class ReportingDatabase
         metadataWithProblems.remove( results );
     }
 
-    private MetadataResults getMetadataResults( RepositoryMetadata metadata, long lastModified )
+    MetadataResults getMetadataResults( RepositoryMetadata metadata, long lastModified )
     {
         return getMetadataResults( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion(),
                                    lastModified );
index 427fc95bf643579d2d9920b47ecd87d8e051cde2..1f7326c6fff207fb6f7648e5a108212e1cfaa355 100644 (file)
           </description>
         </field>
       </fields>
+
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0</version>
+          <code><![CDATA[
+            public boolean equals( Object obj )
+            {
+                if ( obj instanceof Result )
+                {
+                    if ( this == obj )
+                    {
+                        return true;
+                    }
+                    Result rhs = (Result) obj;
+                    return new org.apache.commons.lang.builder.EqualsBuilder()
+                        .append( problem, rhs.problem )
+                        .append( processor, rhs.processor )
+                        .append( reason, rhs.reason )
+                        .isEquals();
+                }
+                return false;
+            }
+
+            public int hashCode()
+            {
+                return new org.apache.commons.lang.builder.HashCodeBuilder( 19, 43 )
+                    .append( getReason() )
+                    .append( getProcessor() )
+                    .append( getProblem() )
+                    .toHashCode();
+            }
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
+
     </class>
   </classes>
 </model>
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/database/ReportingDatabaseTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/database/ReportingDatabaseTest.java
new file mode 100644 (file)
index 0000000..90278fd
--- /dev/null
@@ -0,0 +1,146 @@
+package org.apache.maven.archiva.reporting.database;
+
+/*
+ * Copyright 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 junit.framework.TestCase;
+
+import org.apache.maven.archiva.reporting.model.ArtifactResults;
+import org.apache.maven.archiva.reporting.model.MetadataResults;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+/**
+ * Test for {@link ReportingDatabase}.
+ * 
+ * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
+ * @version $Id$
+ */
+public class ReportingDatabaseTest
+    extends TestCase
+{
+    private Artifact artifact;
+    private String processor, problem, reason;
+    private ReportingDatabase reportingDatabase;
+    private RepositoryMetadata metadata;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        artifact = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1.0" ), "scope", "type",
+                                        "classifier", null );
+        processor = "processor";
+        problem = "problem";
+        reason = "reason";
+        reportingDatabase = new ReportingDatabase( null );
+
+        metadata = new ArtifactRepositoryMetadata( artifact );
+    }
+
+    public void testAddNoticeArtifactStringStringString()
+    {
+        reportingDatabase.addNotice( artifact, processor, problem, reason );
+        ArtifactResults artifactResults = reportingDatabase.getArtifactResults( artifact );
+
+        assertEquals( 1, reportingDatabase.getNumNotices() );
+        assertEquals( 1, artifactResults.getNotices().size() );
+
+        reportingDatabase.addNotice( artifact, processor, problem, reason );
+        artifactResults = reportingDatabase.getArtifactResults( artifact );
+
+        assertEquals( 1, reportingDatabase.getNumNotices() );
+        assertEquals( 1, artifactResults.getNotices().size() );
+    }
+
+    public void testAddWarningArtifactStringStringString()
+    {
+        reportingDatabase.addWarning( artifact, processor, problem, reason );
+        ArtifactResults artifactResults = reportingDatabase.getArtifactResults( artifact );
+
+        assertEquals( 1, reportingDatabase.getNumWarnings() );
+        assertEquals( 1, artifactResults.getWarnings().size() );
+
+        reportingDatabase.addWarning( artifact, processor, problem, reason );
+        artifactResults = reportingDatabase.getArtifactResults( artifact );
+
+        assertEquals( 1, reportingDatabase.getNumWarnings() );
+        assertEquals( 1, artifactResults.getWarnings().size() );
+    }
+
+    public void testAddFailureArtifactStringStringString()
+    {
+        reportingDatabase.addFailure( artifact, processor, problem, reason );
+        ArtifactResults artifactResults = reportingDatabase.getArtifactResults( artifact );
+
+        assertEquals( 1, reportingDatabase.getNumFailures() );
+        assertEquals( 1, artifactResults.getFailures().size() );
+
+        reportingDatabase.addFailure( artifact, processor, problem, reason );
+        artifactResults = reportingDatabase.getArtifactResults( artifact );
+
+        assertEquals( 1, reportingDatabase.getNumFailures() );
+        assertEquals( 1, artifactResults.getFailures().size() );
+    }
+
+    public void testAddNoticeRepositoryMetadataStringStringString()
+    {
+        reportingDatabase.addNotice( metadata, processor, problem, reason );
+        MetadataResults metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
+
+        assertEquals( 1, reportingDatabase.getNumNotices() );
+        assertEquals( 1, metadataResults.getNotices().size() );
+
+        reportingDatabase.addNotice( metadata, processor, problem, reason );
+        metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
+
+        assertEquals( 1, reportingDatabase.getNumNotices() );
+        assertEquals( 1, metadataResults.getNotices().size() );
+    }
+
+    public void testAddWarningRepositoryMetadataStringStringString()
+    {
+        reportingDatabase.addWarning( metadata, processor, problem, reason );
+        MetadataResults metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
+
+        assertEquals( 1, reportingDatabase.getNumWarnings() );
+        assertEquals( 1, metadataResults.getWarnings().size() );
+
+        reportingDatabase.addWarning( metadata, processor, problem, reason );
+        metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
+
+        assertEquals( 1, reportingDatabase.getNumWarnings() );
+        assertEquals( 1, metadataResults.getWarnings().size() );
+    }
+
+    public void testAddFailureRepositoryMetadataStringStringString()
+    {
+        reportingDatabase.addFailure( metadata, processor, problem, reason );
+        MetadataResults metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
+
+        assertEquals( 1, reportingDatabase.getNumFailures() );
+        assertEquals( 1, metadataResults.getFailures().size() );
+
+        reportingDatabase.addFailure( metadata, processor, problem, reason );
+        metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
+
+        assertEquals( 1, reportingDatabase.getNumFailures() );
+        assertEquals( 1, metadataResults.getFailures().size() );
+    }
+}