From: Carlos Sanchez Gonzalez Date: Fri, 22 Dec 2006 15:56:26 +0000 (+0000) Subject: [MRM-262] Reporting adds duplicated entries on each run X-Git-Tag: archiva-0.9-alpha-1~204 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fa19720b7ff03fee228178a87ba3c7c48b3636ed;p=archiva.git [MRM-262] Reporting adds duplicated entries on each run git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@489678 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/database/ReportingDatabase.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/database/ReportingDatabase.java index b00982570..c477cf03a 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/database/ReportingDatabase.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/database/ReportingDatabase.java @@ -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 ); diff --git a/archiva-reports-standard/src/main/mdo/reporting.mdo b/archiva-reports-standard/src/main/mdo/reporting.mdo index 427fc95bf..1f7326c6f 100644 --- a/archiva-reports-standard/src/main/mdo/reporting.mdo +++ b/archiva-reports-standard/src/main/mdo/reporting.mdo @@ -238,6 +238,41 @@ + + + + 1.0.0 + + + + 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 index 000000000..90278fdf2 --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/database/ReportingDatabaseTest.java @@ -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 Carlos Sanchez + * @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() ); + } +}