From: Brett Porter Date: Sun, 10 Sep 2006 23:21:19 +0000 (+0000) Subject: [MRM-166] add multiple report groups X-Git-Tag: archiva-0.9-alpha-1~561 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b57273dff3f31895f05d8a669cc15a9db7a92f5b;p=archiva.git [MRM-166] add multiple report groups git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@442028 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java index b3add45a3..0f15f22fc 100644 --- a/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java +++ b/archiva-converter/src/test/java/org/apache/maven/archiva/converter/RepositoryConverterTest.java @@ -16,6 +16,7 @@ package org.apache.maven.archiva.converter; * limitations under the License. */ +import org.apache.maven.archiva.reporting.ReportGroup; import org.apache.maven.archiva.reporting.ReportingDatabase; import org.apache.maven.archiva.reporting.model.ArtifactResults; import org.apache.maven.archiva.reporting.model.Result; @@ -60,7 +61,7 @@ public class RepositoryConverterTest private ArtifactFactory artifactFactory; - private ReportingDatabase reporter; + private ReportingDatabase reportingDatabase; private static final int SLEEP_MILLIS = 100; @@ -93,7 +94,8 @@ public class RepositoryConverterTest i18n = (I18N) lookup( I18N.ROLE ); - reporter = new ReportingDatabase(); + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportingDatabase = new ReportingDatabase( reportGroup ); } private void copyDirectoryStructure( File sourceDirectory, File destinationDirectory ) @@ -162,7 +164,7 @@ public class RepositoryConverterTest File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); artifactFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); assertTrue( "Check artifact created", artifactFile.exists() ); @@ -204,7 +206,7 @@ public class RepositoryConverterTest targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); versionMetadataFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -245,7 +247,7 @@ public class RepositoryConverterTest targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); versionMetadataFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); //checkSuccess(); --> commented until MNG-2100 is fixed File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -280,9 +282,9 @@ public class RepositoryConverterTest targetRepository.pathOfRemoteRepositoryMetadata( versionMetadata ) ); versionMetadataFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); - assertEquals( "check no errors", 0, reporter.getNumFailures() ); - assertEquals( "check number of warnings", 2, reporter.getNumWarnings() ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); + assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() ); + assertEquals( "check number of warnings", 2, reportingDatabase.getNumWarnings() ); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); assertTrue( "Check artifact created", artifactFile.exists() ); @@ -314,7 +316,7 @@ public class RepositoryConverterTest targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); snapshotMetadataFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -357,7 +359,7 @@ public class RepositoryConverterTest targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); snapshotMetadataFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -417,7 +419,7 @@ public class RepositoryConverterTest targetRepository.pathOfRemoteRepositoryMetadata( snapshotMetadata ) ); snapshotMetadataFile.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -450,9 +452,9 @@ public class RepositoryConverterTest // test that a POM is not created when there was none at the source Artifact artifact = createArtifact( "test", "noPomArtifact", "1.0.0" ); - repositoryConverter.convert( artifact, targetRepository, reporter ); - assertEquals( "check no errors", 0, reporter.getNumFailures() ); - assertEquals( "check no warnings", 1, reporter.getNumWarnings() ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); + assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() ); + assertEquals( "check no warnings", 1, reportingDatabase.getNumWarnings() ); assertEquals( "check warning message", getI18nString( "warning.missing.pom" ), getWarning().getReason() ); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -476,7 +478,7 @@ public class RepositoryConverterTest File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); file.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); assertEquals( "check failure message", getI18nString( "failure.incorrect.md5" ), getFailure().getReason() ); @@ -497,7 +499,7 @@ public class RepositoryConverterTest File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); file.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); assertEquals( "check failure message", getI18nString( "failure.incorrect.sha1" ), getFailure().getReason() ); @@ -534,7 +536,7 @@ public class RepositoryConverterTest // Need to guarantee last modified is not equal Thread.sleep( SLEEP_MILLIS ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); compareFiles( sourceFile, targetFile ); @@ -570,7 +572,7 @@ public class RepositoryConverterTest // Need to guarantee last modified is not equal Thread.sleep( SLEEP_MILLIS ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ), getFailure().getReason() ); @@ -607,7 +609,7 @@ public class RepositoryConverterTest sourceFile.setLastModified( dateFormat.parse( "2006-01-01" ).getTime() ); sourcePomFile.setLastModified( dateFormat.parse( "2006-02-02" ).getTime() ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); compareFiles( sourceFile, targetFile ); @@ -637,7 +639,7 @@ public class RepositoryConverterTest File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); File targetPomFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( pomArtifact ) ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); assertTrue( "Check source file exists", sourceFile.exists() ); @@ -679,7 +681,7 @@ public class RepositoryConverterTest // Need to guarantee last modified is not equal Thread.sleep( SLEEP_MILLIS ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); assertEquals( "Check failure message", getI18nString( "failure.target.already.exists" ), getFailure().getReason() ); @@ -710,7 +712,7 @@ public class RepositoryConverterTest File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); String pattern = "^" + getI18nString( "failure.invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$"; assertTrue( "Check failure message", getFailure().getReason().matches( pattern ) ); @@ -729,9 +731,9 @@ public class RepositoryConverterTest artifacts.add( createArtifact( "test", "artifact-one", "1.0.0" ) ); artifacts.add( createArtifact( "test", "artifact-two", "1.0.0" ) ); artifacts.add( createArtifact( "test", "artifact-three", "1.0.0" ) ); - repositoryConverter.convert( artifacts, targetRepository, reporter ); - assertEquals( "check no errors", 0, reporter.getNumFailures() ); - assertEquals( "check no warnings", 0, reporter.getNumWarnings() ); + repositoryConverter.convert( artifacts, targetRepository, reportingDatabase ); + assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() ); + assertEquals( "check no warnings", 0, reportingDatabase.getNumWarnings() ); for ( Iterator i = artifacts.iterator(); i.hasNext(); ) { @@ -762,7 +764,7 @@ public class RepositoryConverterTest File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); file.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); assertEquals( "check failure message", getI18nString( "failure.incorrect.artifactMetadata.versions" ), getFailure().getReason() ); @@ -786,7 +788,7 @@ public class RepositoryConverterTest File file = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); file.delete(); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkFailure(); assertEquals( "check failure message", getI18nString( "failure.incorrect.snapshotMetadata.snapshot" ), getFailure().getReason() ); @@ -806,7 +808,7 @@ public class RepositoryConverterTest Artifact artifact = createArtifact( "test", "newversion-artifact", "1.0.1" ); - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); checkSuccess(); File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) ); @@ -844,7 +846,7 @@ public class RepositoryConverterTest try { - repositoryConverter.convert( artifact, targetRepository, reporter ); + repositoryConverter.convert( artifact, targetRepository, reportingDatabase ); fail( "Should have failed trying to convert within the same repository" ); } catch ( RepositoryConversionException e ) @@ -902,14 +904,14 @@ public class RepositoryConverterTest private void checkSuccess() { - assertEquals( "check no errors", 0, reporter.getNumFailures() ); - assertEquals( "check no warnings", 0, reporter.getNumWarnings() ); + assertEquals( "check no errors", 0, reportingDatabase.getNumFailures() ); + assertEquals( "check no warnings", 0, reportingDatabase.getNumWarnings() ); } private void checkFailure() { - assertEquals( "check num errors", 1, reporter.getNumFailures() ); - assertEquals( "check no warnings", 0, reporter.getNumWarnings() ); + assertEquals( "check num errors", 1, reportingDatabase.getNumFailures() ); + assertEquals( "check no warnings", 0, reportingDatabase.getNumWarnings() ); } private String getI18nString( String key ) @@ -919,13 +921,13 @@ public class RepositoryConverterTest private Result getFailure() { - ArtifactResults artifact = (ArtifactResults) reporter.getArtifactIterator().next(); + ArtifactResults artifact = (ArtifactResults) reportingDatabase.getArtifactIterator().next(); return (Result) artifact.getFailures().get( 0 ); } private Result getWarning() { - ArtifactResults artifact = (ArtifactResults) reporter.getArtifactIterator().next(); + ArtifactResults artifact = (ArtifactResults) reportingDatabase.getArtifactIterator().next(); return (Result) artifact.getWarnings().get( 0 ); } diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java b/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java index c37e6b608..eeb4b6895 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java @@ -6,6 +6,7 @@ import org.apache.maven.archiva.discoverer.ArtifactDiscoverer; import org.apache.maven.archiva.discoverer.DiscovererException; import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter; import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter; +import org.apache.maven.archiva.reporting.ReportGroup; import org.apache.maven.archiva.reporting.ReportingDatabase; import org.apache.maven.archiva.reporting.ReportingStore; import org.apache.maven.archiva.reporting.ReportingStoreException; @@ -55,6 +56,11 @@ public class DefaultRepositoryManager */ private ReportingStore reportingStore; + /** + * @plexus.requirement role-hint="health" + */ + private ReportGroup reportGroup; + public void convertLegacyRepository( File legacyRepositoryDirectory, File repositoryDirectory, boolean includeSnapshots ) throws RepositoryConversionException, DiscovererException @@ -85,7 +91,7 @@ public class DefaultRepositoryManager ReportingDatabase reporter; try { - reporter = reportingStore.getReportsFromStore( repository ); + reporter = reportingStore.getReportsFromStore( repository, reportGroup ); repositoryConverter.convert( legacyArtifacts, repository, reporter ); diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java index 454a4dabb..d563b7b28 100644 --- a/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java +++ b/archiva-core/src/main/java/org/apache/maven/archiva/scheduler/task/IndexerTask.java @@ -32,6 +32,7 @@ import org.apache.maven.archiva.indexer.RepositoryIndexException; import org.apache.maven.archiva.indexer.record.IndexRecordExistsArtifactFilter; import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory; import org.apache.maven.archiva.reporting.ReportExecutor; +import org.apache.maven.archiva.reporting.ReportGroup; import org.apache.maven.archiva.reporting.ReportingDatabase; import org.apache.maven.archiva.reporting.ReportingMetadataFilter; import org.apache.maven.archiva.reporting.ReportingStoreException; @@ -96,6 +97,11 @@ public class IndexerTask */ private ReportExecutor reportExecutor; + /** + * @plexus.requirement role-hint="health" + */ + private ReportGroup reportGroup; + private static final int ARTIFACT_BUFFER_SIZE = 1000; public void execute() @@ -154,7 +160,7 @@ public class IndexerTask boolean includeSnapshots = repositoryConfiguration.isIncludeSnapshots(); ArtifactRepository repository = repoFactory.createRepository( repositoryConfiguration ); - ReportingDatabase reporter = reportExecutor.getReportDatabase( repository ); + ReportingDatabase reporter = reportExecutor.getReportDatabase( repository, reportGroup ); // keep original value in case there is another process under way long origStartTime = reporter.getStartTime(); @@ -192,7 +198,7 @@ public class IndexerTask // run the reports. Done intermittently to avoid losing track of what is indexed since // that is what the filter is based on. - reportExecutor.runArtifactReports( currentArtifacts, repository ); + reportExecutor.runArtifactReports( reportGroup, currentArtifacts, repository ); index.indexArtifacts( currentArtifacts, recordFactory ); @@ -214,7 +220,7 @@ public class IndexerTask getLogger().info( "Discovered " + metadata.size() + " unprocessed metadata files" ); // run the reports - reportExecutor.runMetadataReports( metadata, repository ); + reportExecutor.runMetadataReports( reportGroup, metadata, repository ); } reporter.setStartTime( origStartTime ); diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/AbstractReportGroup.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/AbstractReportGroup.java new file mode 100644 index 000000000..d0bd7ce24 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/AbstractReportGroup.java @@ -0,0 +1,78 @@ +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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.model.Model; + +import java.util.Iterator; +import java.util.Map; + +/** + * Basic functionality for all report groups. + */ +public abstract class AbstractReportGroup + implements ReportGroup +{ + /** + * @plexus.requirement role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" + */ + private Map artifactReports; + + /** + * @plexus.requirement role="org.apache.maven.archiva.reporting.MetadataReportProcessor" + */ + private Map metadataReports; + + public void processArtifact( Artifact artifact, Model model, ReportingDatabase reportingDatabase ) + { + for ( Iterator i = artifactReports.entrySet().iterator(); i.hasNext(); ) + { + Map.Entry entry = (Map.Entry) i.next(); + + if ( includeReport( (String) entry.getKey() ) ) + { + ArtifactReportProcessor report = (ArtifactReportProcessor) entry.getValue(); + + report.processArtifact( artifact, model, reportingDatabase ); + } + } + } + + public void processMetadata( RepositoryMetadata repositoryMetadata, ArtifactRepository repository, + ReportingDatabase reportingDatabase ) + { + for ( Iterator i = metadataReports.entrySet().iterator(); i.hasNext(); ) + { + Map.Entry entry = (Map.Entry) i.next(); + + if ( includeReport( (String) entry.getKey() ) ) + { + MetadataReportProcessor report = (MetadataReportProcessor) entry.getValue(); + + report.processMetadata( repositoryMetadata, repository, reportingDatabase ); + } + } + } + + public String toString() + { + return getName(); + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java index 1d4e18c64..f4fae3b93 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportExecutor.java @@ -43,6 +43,7 @@ import java.util.Map; /** * Report executor implementation. * + * @todo should the report set be limitable by configuration? * @plexus.component */ public class DefaultReportExecutor @@ -64,17 +65,6 @@ public class DefaultReportExecutor */ private ArtifactFactory artifactFactory; - /** - * @todo replace with a ReportGroup that is identified as "health" and has requirements on the specific health reports - * @plexus.requirement role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" - */ - private List artifactReports; - - /** - * @plexus.requirement role="org.apache.maven.archiva.reporting.MetadataReportProcessor" - */ - private List metadataReports; - /** * @plexus.requirement role="org.apache.maven.archiva.discoverer.ArtifactDiscoverer" */ @@ -87,10 +77,10 @@ public class DefaultReportExecutor private static final int ARTIFACT_BUFFER_SIZE = 1000; - public void runMetadataReports( List metadata, ArtifactRepository repository ) + public void runMetadataReports( ReportGroup reportGroup, List metadata, ArtifactRepository repository ) throws ReportingStoreException { - ReportingDatabase reporter = getReportDatabase( repository ); + ReportingDatabase reporter = getReportDatabase( repository, reportGroup ); for ( Iterator i = metadata.iterator(); i.hasNext(); ) { @@ -100,28 +90,16 @@ public class DefaultReportExecutor new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repositoryMetadata ) ); reporter.cleanMetadata( repositoryMetadata, file.lastModified() ); - // TODO: should the report set be limitable by configuration? - runMetadataReports( repositoryMetadata, repository, reporter ); + reportGroup.processMetadata( repositoryMetadata, repository, reporter ); } reportingStore.storeReports( reporter, repository ); } - private void runMetadataReports( RepositoryMetadata repositoryMetadata, ArtifactRepository repository, - ReportingDatabase reporter ) - { - for ( Iterator i = metadataReports.iterator(); i.hasNext(); ) - { - MetadataReportProcessor report = (MetadataReportProcessor) i.next(); - - report.processMetadata( repositoryMetadata, repository, reporter ); - } - } - - public void runArtifactReports( List artifacts, ArtifactRepository repository ) + public void runArtifactReports( ReportGroup reportGroup, List artifacts, ArtifactRepository repository ) throws ReportingStoreException { - ReportingDatabase reporter = getReportDatabase( repository ); + ReportingDatabase reporter = getReportDatabase( repository, reportGroup ); for ( Iterator i = artifacts.iterator(); i.hasNext(); ) { @@ -145,24 +123,26 @@ public class DefaultReportExecutor reporter.removeArtifact( artifact ); - runArtifactReports( artifact, model, reporter ); + reportGroup.processArtifact( artifact, model, reporter ); } reportingStore.storeReports( reporter, repository ); } - public ReportingDatabase getReportDatabase( ArtifactRepository repository ) + public ReportingDatabase getReportDatabase( ArtifactRepository repository, ReportGroup reportGroup ) throws ReportingStoreException { - getLogger().debug( "Reading previous report database from repository " + repository.getId() ); - return reportingStore.getReportsFromStore( repository ); + getLogger().debug( + "Reading previous report database " + reportGroup.getName() + " from repository " + repository.getId() ); + return reportingStore.getReportsFromStore( repository, reportGroup ); } - public void runReports( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter ) + public void runReports( ReportGroup reportGroup, ArtifactRepository repository, List blacklistedPatterns, + ArtifactFilter filter ) throws DiscovererException, ReportingStoreException { // Flush (as in toilet, not store) the report database - ReportingDatabase database = getReportDatabase( repository ); + ReportingDatabase database = getReportDatabase( repository, reportGroup ); database.clear(); // Discovery process @@ -188,7 +168,7 @@ public class DefaultReportExecutor // TODO: proper queueing of this in case it was triggered externally (not harmful to do so at present, but not optimal) // run the reports. - runArtifactReports( currentArtifacts, repository ); + runArtifactReports( reportGroup, currentArtifacts, repository ); // MNG-142 - the project builder retains a lot of objects in its inflexible cache. This is a hack // around that. TODO: remove when it is configurable @@ -205,7 +185,7 @@ public class DefaultReportExecutor getLogger().info( "Discovered " + metadata.size() + " metadata files" ); // run the reports - runMetadataReports( metadata, repository ); + runMetadataReports( reportGroup, metadata, repository ); } } @@ -226,17 +206,6 @@ public class DefaultReportExecutor } } - private void runArtifactReports( Artifact artifact, Model model, ReportingDatabase reporter ) - { - // TODO: should the report set be limitable by configuration? - for ( Iterator i = artifactReports.iterator(); i.hasNext(); ) - { - ArtifactReportProcessor report = (ArtifactReportProcessor) i.next(); - - report.processArtifact( artifact, model, reporter ); - } - } - private void flushProjectBuilderCacheHack() { try diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportGroup.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportGroup.java new file mode 100644 index 000000000..6af0fe914 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportGroup.java @@ -0,0 +1,60 @@ +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 java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * The default report set, for repository health. + * + * @plexus.component role="org.apache.maven.archiva.reporting.ReportGroup" role-hint="health" + * @todo could these report groups be assembled dynamically by configuration rather than as explicit components? eg, reportGroup.addReport( ARP ), reportGroup.addReport( MRP ) + */ +public class DefaultReportGroup + extends AbstractReportGroup +{ + /** + * 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"} ) ); + + public boolean includeReport( String key ) + { + return reports.contains( key ); + } + + public Collection getReportIds() + { + return reports; + } + + public String getName() + { + return "Repository Health"; + } + + public String getFilename() + { + return "health-report.xml"; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java index 8a6f61371..768fd5e9f 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java @@ -16,6 +16,7 @@ package org.apache.maven.archiva.reporting; * limitations under the License. */ +import org.apache.maven.archiva.reporting.model.Reporting; import org.apache.maven.archiva.reporting.model.io.xpp3.ReportingXpp3Reader; import org.apache.maven.archiva.reporting.model.io.xpp3.ReportingXpp3Writer; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -47,18 +48,19 @@ public class DefaultReportingStore /** * The cached reports for given repositories. */ - private Map/**/ reports = new HashMap(); + private Map/**/ reports = new HashMap(); - public ReportingDatabase getReportsFromStore( ArtifactRepository repository ) + public ReportingDatabase getReportsFromStore( ArtifactRepository repository, ReportGroup reportGroup ) throws ReportingStoreException { - ReportingDatabase database = (ReportingDatabase) reports.get( repository ); + String key = getKey( repository, reportGroup ); + ReportingDatabase database = (ReportingDatabase) reports.get( key ); if ( database == null ) { ReportingXpp3Reader reader = new ReportingXpp3Reader(); - File file = getReportFilename( repository, "health" ); + File file = getReportFilename( repository, reportGroup ); FileReader fileReader = null; try @@ -67,7 +69,7 @@ public class DefaultReportingStore } catch ( FileNotFoundException e ) { - database = new ReportingDatabase( repository ); + database = new ReportingDatabase( reportGroup, repository ); } if ( database == null ) @@ -75,7 +77,8 @@ public class DefaultReportingStore getLogger().info( "Reading report database from " + file ); try { - database = new ReportingDatabase( reader.read( fileReader, false ), repository ); + Reporting reporting = reader.read( fileReader, false ); + database = new ReportingDatabase( reportGroup, reporting, repository ); } catch ( IOException e ) { @@ -91,15 +94,19 @@ public class DefaultReportingStore } } - reports.put( repository, database ); + reports.put( key, database ); } return database; } - private static File getReportFilename( ArtifactRepository repository, String s ) + private static String getKey( ArtifactRepository repository, ReportGroup reportGroup ) { - File file = new File( repository.getBasedir(), ".reports/" + s + ".xml" ); - return file; + return repository.getId() + "/" + reportGroup.getFilename(); + } + + private static File getReportFilename( ArtifactRepository repository, ReportGroup reportGroup ) + { + return new File( repository.getBasedir(), ".reports/" + reportGroup.getFilename() ); } public void storeReports( ReportingDatabase database, ArtifactRepository repository ) @@ -109,7 +116,7 @@ public class DefaultReportingStore ReportingXpp3Writer writer = new ReportingXpp3Writer(); - File file = getReportFilename( repository, "health" ); + File file = getReportFilename( repository, database.getReportGroup() ); getLogger().info( "Writing reports to " + file ); FileWriter fileWriter = null; try diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java index a5b116d62..680620799 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java @@ -61,59 +61,55 @@ public class DuplicateArtifactFileReportProcessor public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter ) { ArtifactRepository repository = artifact.getRepository(); - // TODO! always null currently, need to configure this properly - if ( indexDirectory != null ) + if ( artifact.getFile() != null ) { - if ( artifact.getFile() != null ) + RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) ); + + String checksum = null; + try + { + checksum = digester.calc( artifact.getFile() ); + } + catch ( DigesterException e ) { - RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) ); + reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e ); + } - String checksum = null; + if ( checksum != null ) + { try { - checksum = digester.calc( artifact.getFile() ); - } - catch ( DigesterException e ) - { - reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e ); - } + List results = index.search( new LuceneQuery( + new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) ); - if ( checksum != null ) - { - try + if ( !results.isEmpty() ) { - List results = index.search( new LuceneQuery( - new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) ); - - if ( !results.isEmpty() ) + for ( Iterator i = results.iterator(); i.hasNext(); ) { - for ( Iterator i = results.iterator(); i.hasNext(); ) - { - StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next(); + StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next(); - //make sure it is not the same artifact - if ( !result.getFilename().equals( repository.pathOf( artifact ) ) ) + //make sure it is not the same artifact + if ( !result.getFilename().equals( repository.pathOf( artifact ) ) ) + { + //report only duplicates from the same groupId + String groupId = artifact.getGroupId(); + if ( groupId.equals( result.getGroupId() ) ) { - //report only duplicates from the same groupId - String groupId = artifact.getGroupId(); - if ( groupId.equals( result.getGroupId() ) ) - { - reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() ); - } + 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" ); } } } diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportGroup.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportGroup.java new file mode 100644 index 000000000..73e6a77d2 --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/OldArtifactReportGroup.java @@ -0,0 +1,59 @@ +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 java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * The report set for finding old artifacts (both snapshot and release) + * + * @plexus.component role="org.apache.maven.archiva.reporting.ReportGroup" role-hint="old-artifact" + */ +public class OldArtifactReportGroup + extends AbstractReportGroup +{ + /** + * Role hints of the reports to include in this set. + * + * @todo implement these report processors! + */ + private static final Set reports = + new LinkedHashSet( Arrays.asList( new String[]{"old-artifact", "old-snapshot-artifact"} ) ); + + public boolean includeReport( String key ) + { + return reports.contains( key ); + } + + public Collection getReportIds() + { + return reports; + } + + public String getFilename() + { + return "old-artifacts-report.xml"; + } + + public String getName() + { + return "Old Artifacts"; + } +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java index 39aedd8d1..07da5bcb9 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportExecutor.java @@ -35,31 +35,34 @@ public interface ReportExecutor /** * Run reports on a set of metadata. * - * @param metadata the RepositoryMetadata objects to report on - * @param repository the repository that they come from + * @param reportGroup the report set to run + * @param metadata the RepositoryMetadata objects to report on + * @param repository the repository that they come from * @throws ReportingStoreException if there is a problem reading/writing the report database */ - public void runMetadataReports( List metadata, ArtifactRepository repository ) + public void runMetadataReports( ReportGroup reportGroup, List metadata, ArtifactRepository repository ) throws ReportingStoreException; /** * Run reports on a set of artifacts. * - * @param artifacts the Artifact objects to report on - * @param repository the repository that they come from + * @param reportGroup the report set to run + * @param artifacts the Artifact objects to report on + * @param repository the repository that they come from * @throws ReportingStoreException if there is a problem reading/writing the report database */ - public void runArtifactReports( List artifacts, ArtifactRepository repository ) + public void runArtifactReports( ReportGroup reportGroup, List artifacts, ArtifactRepository repository ) throws ReportingStoreException; /** * Get the report database in use for a given repository. * - * @param repository the repository + * @param repository the repository + * @param reportGroup the report set to run * @return the report database * @throws ReportingStoreException if there is a problem reading the report database */ - ReportingDatabase getReportDatabase( ArtifactRepository repository ) + ReportingDatabase getReportDatabase( ArtifactRepository repository, ReportGroup reportGroup ) throws ReportingStoreException; /** @@ -68,10 +71,12 @@ public interface ReportExecutor * @param repository the repository to run from * @param blacklistedPatterns the patterns to exclude during discovery * @param filter the filter to use during discovery to get a consistent list of artifacts + * @param reportGroup the report set to run * @throws ReportingStoreException if there is a problem reading/writing the report database * @throws org.apache.maven.archiva.discoverer.DiscovererException * if there is a problem finding the artifacts and metadata to report on */ - public void runReports( ArtifactRepository repository, List blacklistedPatterns, ArtifactFilter filter ) + public void runReports( ReportGroup reportGroup, ArtifactRepository repository, List blacklistedPatterns, + ArtifactFilter filter ) throws DiscovererException, ReportingStoreException; } diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportGroup.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportGroup.java new file mode 100644 index 000000000..e5708214d --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportGroup.java @@ -0,0 +1,84 @@ +package org.apache.maven.archiva.reporting; + +import org.apache.maven.artifact.Artifact; +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; + +/* + * 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. + */ + +/** + * A grouping or report processors for execution as a visible report from the web interface - eg, "health", + * "old artifacts", etc. + */ +public interface ReportGroup +{ + /** + * Plexus component role. + */ + String ROLE = ReportGroup.class.getName(); + + /** + * Run any artifact related reports in the report set. + * + * @param artifact the artifact to process + * @param model the POM associated with the artifact to process + * @param reportingDatabase the report database to store results in + */ + void processArtifact( Artifact artifact, Model model, ReportingDatabase reportingDatabase ); + + /** + * Run any metadata related reports in the report set. + * + * @param repositoryMetadata the metadata to process + * @param repository the repository the metadata is located in + * @param reportingDatabase the report database to store results in + */ + void processMetadata( RepositoryMetadata repositoryMetadata, ArtifactRepository repository, + ReportingDatabase reportingDatabase ); + + /** + * Whether a report with the given role hint is included in this report set. + * + * @param key the report role hint. + * @return whether the report is included + */ + boolean includeReport( String key ); + + /** + * Get a list of the report processors in this set. + * + * @return the report IDs + */ + Collection getReportIds(); + + /** + * Get the user-friendly name of this report. + * + * @return the report name + */ + String getName(); + + /** + * Get the filename of the reports within the repository's reports directory. + * + * @return the filename + */ + String getFilename(); +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java index f4ac83081..ca4a44c4b 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java @@ -50,23 +50,27 @@ public class ReportingDatabase private long startTime; - public ReportingDatabase() + private final ReportGroup reportGroup; + + public ReportingDatabase( ReportGroup reportGroup ) { - this( new Reporting(), null ); + this( reportGroup, new Reporting() ); } - public ReportingDatabase( Reporting reporting ) + public ReportingDatabase( ReportGroup reportGroup, Reporting reporting ) { - this( reporting, null ); + this( reportGroup, reporting, null ); } - public ReportingDatabase( ArtifactRepository repository ) + public ReportingDatabase( ReportGroup reportGroup, ArtifactRepository repository ) { - this( new Reporting(), repository ); + this( reportGroup, new Reporting(), repository ); } - public ReportingDatabase( Reporting reporting, ArtifactRepository repository ) + public ReportingDatabase( ReportGroup reportGroup, Reporting reporting, ArtifactRepository repository ) { + this.reportGroup = reportGroup; + this.reporting = reporting; this.repository = repository; @@ -338,4 +342,9 @@ public class ReportingDatabase } getReporting().setLastModified( endTime ); } + + public ReportGroup getReportGroup() + { + return reportGroup; + } } diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java index 00d9b7c14..8f52a5c86 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java @@ -34,11 +34,12 @@ public interface ReportingStore /** * Get the reports from the store. A cached version may be used. * - * @param repository the repository to load the reports for + * @param repository the repository to load the reports for + * @param reportGroup the report group to get the report for * @return the reporting database * @throws ReportingStoreException if there was a problem reading the store */ - ReportingDatabase getReportsFromStore( ArtifactRepository repository ) + ReportingDatabase getReportsFromStore( ArtifactRepository repository, ReportGroup reportGroup ) throws ReportingStoreException; /** 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 index f8ea2d3ce..6e8c89613 100644 --- 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 @@ -30,7 +30,7 @@ import java.util.Iterator; public class ArtifactReporterTest extends AbstractRepositoryReportsTestCase { - private ReportingDatabase reporter; + private ReportingDatabase reportingDatabase; private Artifact artifact; @@ -38,19 +38,21 @@ public class ArtifactReporterTest throws Exception { super.setUp(); - reporter = new ReportingDatabase(); 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() { - reporter.addFailure( artifact, "failed once" ); + reportingDatabase.addFailure( artifact, "failed once" ); - Iterator artifactIterator = reporter.getArtifactIterator(); + Iterator artifactIterator = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) artifactIterator.next(); assertFalse( artifactIterator.hasNext() ); @@ -60,17 +62,17 @@ public class ArtifactReporterTest i.next(); } assertEquals( 1, count ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } public void testArtifactReporterMultipleFailure() { - reporter.addFailure( artifact, "failed once" ); - reporter.addFailure( artifact, "failed twice" ); - reporter.addFailure( artifact, "failed thrice" ); + reportingDatabase.addFailure( artifact, "failed once" ); + reportingDatabase.addFailure( artifact, "failed twice" ); + reportingDatabase.addFailure( artifact, "failed thrice" ); - Iterator artifactIterator = reporter.getArtifactIterator(); + Iterator artifactIterator = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) artifactIterator.next(); assertFalse( artifactIterator.hasNext() ); @@ -80,16 +82,16 @@ public class ArtifactReporterTest i.next(); } assertEquals( 3, count ); - assertEquals( 3, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + assertEquals( 3, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } public void testFailureMessages() { - reporter.addFailure( artifact, "failed once" ); - reporter.addFailure( artifact, "failed twice" ); - reporter.addFailure( artifact, "failed thrice" ); - Iterator artifactIterator = reporter.getArtifactIterator(); + 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(); @@ -100,8 +102,8 @@ public class ArtifactReporterTest public void testArtifactReporterSingleWarning() { - reporter.addWarning( artifact, "you've been warned" ); - Iterator artifactIterator = reporter.getArtifactIterator(); + reportingDatabase.addWarning( artifact, "you've been warned" ); + Iterator artifactIterator = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) artifactIterator.next(); assertFalse( artifactIterator.hasNext() ); @@ -111,17 +113,17 @@ public class ArtifactReporterTest i.next(); } assertEquals( 1, count ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 1, reporter.getNumWarnings() ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 1, reportingDatabase.getNumWarnings() ); } public void testArtifactReporterMultipleWarning() { - reporter.addWarning( artifact, "i'm warning you" ); - reporter.addWarning( artifact, "you have to stop now" ); - reporter.addWarning( artifact, "all right... that does it!" ); + 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 = reporter.getArtifactIterator(); + Iterator artifactIterator = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) artifactIterator.next(); assertFalse( artifactIterator.hasNext() ); @@ -131,17 +133,17 @@ public class ArtifactReporterTest i.next(); } assertEquals( 3, count ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 3, reporter.getNumWarnings() ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 3, reportingDatabase.getNumWarnings() ); } public void testWarningMessages() { - reporter.addWarning( artifact, "i'm warning you" ); - reporter.addWarning( artifact, "you have to stop now" ); - reporter.addWarning( artifact, "all right... that does it!" ); + 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 = reporter.getArtifactIterator(); + Iterator artifactIterator = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) artifactIterator.next(); assertFalse( artifactIterator.hasNext() ); Iterator warning = results.getWarnings().iterator(); diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java index 67e36fd7b..6c23232e0 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java @@ -37,7 +37,7 @@ public class BadMetadataReportProcessorTest private MetadataReportProcessor badMetadataReportProcessor; - private ReportingDatabase reporter = new ReportingDatabase(); + private ReportingDatabase reportingDatabase; protected void setUp() throws Exception @@ -47,6 +47,9 @@ public class BadMetadataReportProcessorTest artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE ); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportingDatabase = new ReportingDatabase( reportGroup ); } public void testMetadataMissingLastUpdated() @@ -59,9 +62,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -78,9 +81,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, null ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -106,9 +109,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -130,9 +133,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertFalse( "check there are no failures", failures.hasNext() ); } @@ -146,9 +149,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -174,9 +177,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -201,9 +204,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -229,9 +232,9 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertFalse( "check there are no failures", failures.hasNext() ); } @@ -242,9 +245,9 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -261,9 +264,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -284,9 +287,9 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -309,9 +312,9 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "" ) ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -333,9 +336,9 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default" ) ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -357,9 +360,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertFalse( "check there are no failures", failures.hasNext() ); } @@ -374,9 +377,9 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); - badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); + badMetadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java index e92cf8ad0..03eb1387b 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java @@ -37,7 +37,7 @@ public class ChecksumArtifactReporterTest { private ArtifactReportProcessor artifactReportProcessor; - private ReportingDatabase reporter = new ReportingDatabase(); + private ReportingDatabase reportingDatabase; private MetadataReportProcessor metadataReportProcessor; @@ -47,6 +47,9 @@ public class ChecksumArtifactReporterTest super.setUp(); artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" ); metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" ); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportingDatabase = new ReportingDatabase( reportGroup ); } /** @@ -60,9 +63,9 @@ public class ChecksumArtifactReporterTest Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + artifactReportProcessor.processArtifact( artifact, null, reportingDatabase ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } /** @@ -74,14 +77,14 @@ public class ChecksumArtifactReporterTest String s1 = "1.0"; Artifact artifact = createArtifact( "checksumTest", s, s1 ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + artifactReportProcessor.processArtifact( artifact, null, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } /** * Test the valid checksum of a metadata file. - * The reporter should report 2 success validation. + * The reportingDatabase should report 2 success validation. */ public void testChecksumMetadataReporterSuccess() throws DigesterException, IOException @@ -93,29 +96,29 @@ public class ChecksumArtifactReporterTest //Version level metadata RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); + metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); //Artifact level metadata metadata = new ArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); + metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); //Group level metadata metadata = new GroupRepositoryMetadata( "checksumTest" ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); + metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); } /** * Test the corrupted checksum of a metadata file. - * The reporter must report 2 failures. + * The reportingDatabase must report 2 failures. */ public void testChecksumMetadataReporterFailure() { Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" ); RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); + metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -134,13 +137,13 @@ public class ChecksumArtifactReporterTest Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 1, reporter.getNumFailures() ); + artifactReportProcessor.processArtifact( artifact, null, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - metadataReportProcessor.processMetadata( metadata, repository, reporter ); + metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DefaultArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DefaultArtifactReporterTest.java index 39cc0c0d9..37494f6aa 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DefaultArtifactReporterTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DefaultArtifactReporterTest.java @@ -32,25 +32,25 @@ import java.util.Iterator; public class DefaultArtifactReporterTest extends AbstractRepositoryReportsTestCase { - private ReportingDatabase reporter; + private ReportingDatabase reportingDatabase; private RepositoryMetadata metadata; public void testEmptyArtifactReporter() { - assertEquals( "No failures", 0, reporter.getNumFailures() ); - assertEquals( "No warnings", 0, reporter.getNumWarnings() ); - assertFalse( "No artifact failures", reporter.getArtifactIterator().hasNext() ); - assertFalse( "No metadata failures", reporter.getMetadataIterator().hasNext() ); + assertEquals( "No failures", 0, reportingDatabase.getNumFailures() ); + assertEquals( "No warnings", 0, reportingDatabase.getNumWarnings() ); + assertFalse( "No artifact failures", reportingDatabase.getArtifactIterator().hasNext() ); + assertFalse( "No metadata failures", reportingDatabase.getMetadataIterator().hasNext() ); } public void testMetadataSingleFailure() { - reporter.addFailure( metadata, "Single Failure Reason" ); - assertEquals( "failures count", 1, reporter.getNumFailures() ); - assertEquals( "warnings count", 0, reporter.getNumWarnings() ); + reportingDatabase.addFailure( metadata, "Single Failure Reason" ); + assertEquals( "failures count", 1, reportingDatabase.getNumFailures() ); + assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -70,12 +70,12 @@ public class DefaultArtifactReporterTest public void testMetadataMultipleFailures() { - reporter.addFailure( metadata, "First Failure Reason" ); - reporter.addFailure( metadata, "Second Failure Reason" ); - assertEquals( "failures count", 2, reporter.getNumFailures() ); - assertEquals( "warnings count", 0, reporter.getNumWarnings() ); + reportingDatabase.addFailure( metadata, "First Failure Reason" ); + reportingDatabase.addFailure( metadata, "Second Failure Reason" ); + assertEquals( "failures count", 2, reportingDatabase.getNumFailures() ); + assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getMetadataIterator(); + Iterator failures = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", failures.hasNext() ); MetadataResults results = (MetadataResults) failures.next(); failures = results.getFailures().iterator(); @@ -91,11 +91,11 @@ public class DefaultArtifactReporterTest public void testMetadataSingleWarning() { - reporter.addWarning( metadata, "Single Warning Message" ); - assertEquals( "warnings count", 0, reporter.getNumFailures() ); - assertEquals( "warnings count", 1, reporter.getNumWarnings() ); + reportingDatabase.addWarning( metadata, "Single Warning Message" ); + assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() ); + assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() ); - Iterator warnings = reporter.getMetadataIterator(); + Iterator warnings = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", warnings.hasNext() ); MetadataResults results = (MetadataResults) warnings.next(); warnings = results.getWarnings().iterator(); @@ -108,12 +108,12 @@ public class DefaultArtifactReporterTest public void testMetadataMultipleWarnings() { - reporter.addWarning( metadata, "First Warning" ); - reporter.addWarning( metadata, "Second Warning" ); - assertEquals( "warnings count", 0, reporter.getNumFailures() ); - assertEquals( "warnings count", 2, reporter.getNumWarnings() ); + reportingDatabase.addWarning( metadata, "First Warning" ); + reportingDatabase.addWarning( metadata, "Second Warning" ); + assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() ); + assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() ); - Iterator warnings = reporter.getMetadataIterator(); + Iterator warnings = reportingDatabase.getMetadataIterator(); assertTrue( "check there is a failure", warnings.hasNext() ); MetadataResults results = (MetadataResults) warnings.next(); warnings = results.getWarnings().iterator(); @@ -132,7 +132,6 @@ public class DefaultArtifactReporterTest { super.setUp(); - reporter = new ReportingDatabase(); ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); @@ -141,5 +140,8 @@ public class DefaultArtifactReporterTest versioning.addVersion( "1.0-alpha-2" ); metadata = new ArtifactRepositoryMetadata( artifact, versioning ); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportingDatabase = new ReportingDatabase( reportGroup ); } } diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java index 3894e614f..1f94e276d 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java @@ -37,7 +37,7 @@ public class DependencyArtifactReportProcessorTest private static final String VALID_VERSION = "1.0-alpha-1"; - private ReportingDatabase reporter; + private ReportingDatabase reportingDatabase; private Model model; @@ -51,19 +51,21 @@ public class DependencyArtifactReportProcessorTest throws Exception { super.setUp(); - reporter = new ReportingDatabase(); model = new Model(); processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "dependency" ); artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportingDatabase = new ReportingDatabase( reportGroup ); } public void testArtifactFoundButNoDirectDependencies() { Artifact artifact = createValidArtifact(); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } private Artifact createValidArtifact() @@ -78,10 +80,10 @@ public class DependencyArtifactReportProcessorTest { Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID ); artifact.setRepository( repository ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); @@ -96,9 +98,9 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createValidDependency(); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } private Dependency createValidDependency() @@ -113,9 +115,9 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createValidDependency(); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } public void testValidArtifactWithValidMultipleDependencies() @@ -128,9 +130,9 @@ public class DependencyArtifactReportProcessorTest model.addDependency( dependency ); Artifact artifact = createValidArtifact(); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } public void testValidArtifactWithAnInvalidDependency() @@ -143,11 +145,11 @@ public class DependencyArtifactReportProcessorTest model.addDependency( createDependency( INVALID, INVALID, INVALID ) ); Artifact artifact = createValidArtifact(); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); @@ -163,11 +165,11 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION ); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); @@ -191,11 +193,11 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION ); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); @@ -210,11 +212,11 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID ); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); @@ -229,11 +231,11 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" ); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); @@ -248,9 +250,9 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[1.0,)" ); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 0, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); } public void testValidArtifactWithMissingDependencyVersion() @@ -260,11 +262,11 @@ public class DependencyArtifactReportProcessorTest Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, null ); model.addDependency( dependency ); - processor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + processor.processArtifact( artifact, model, reportingDatabase ); + assertEquals( 1, reportingDatabase.getNumFailures() ); + assertEquals( 0, reportingDatabase.getNumWarnings() ); - Iterator failures = reporter.getArtifactIterator(); + Iterator failures = reportingDatabase.getArtifactIterator(); ArtifactResults results = (ArtifactResults) failures.next(); assertFalse( failures.hasNext() ); failures = results.getFailures().iterator(); diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.java index 902e32326..69f155717 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.java @@ -43,7 +43,7 @@ public class DuplicateArtifactFileReportProcessorTest File indexDirectory; - private ReportingDatabase reportDatabase = new ReportingDatabase(); + private ReportingDatabase reportDatabase; protected void setUp() throws Exception @@ -68,6 +68,9 @@ public class DuplicateArtifactFileReportProcessorTest index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact ) ) ); processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" ); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportDatabase = new ReportingDatabase( reportGroup ); } public void testNullArtifactFile() diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessorTest.java index f9364ea47..c71a06f9e 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessorTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessorTest.java @@ -26,13 +26,16 @@ public class InvalidPomArtifactReportProcessorTest { private ArtifactReportProcessor artifactReportProcessor; - private ReportingDatabase reporter = new ReportingDatabase(); + private ReportingDatabase reportDatabase; public void setUp() throws Exception { super.setUp(); artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "invalid-pom" ); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportDatabase = new ReportingDatabase( reportGroup ); } /** @@ -42,8 +45,8 @@ public class InvalidPomArtifactReportProcessorTest { Artifact artifact = createArtifact( "org.apache.maven", "artifactId", "1.0-alpha-3", "pom" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 1, reporter.getNumFailures() ); + artifactReportProcessor.processArtifact( artifact, null, reportDatabase ); + assertEquals( 1, reportDatabase.getNumFailures() ); } @@ -54,9 +57,9 @@ public class InvalidPomArtifactReportProcessorTest { Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + artifactReportProcessor.processArtifact( artifact, null, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } @@ -67,8 +70,8 @@ public class InvalidPomArtifactReportProcessorTest { Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "jar" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + artifactReportProcessor.processArtifact( artifact, null, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } } diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java index ee5aa4620..9a332bdca 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java @@ -34,16 +34,16 @@ public class LocationArtifactReportProcessorTest { private ArtifactReportProcessor artifactReportProcessor; - private ReportingDatabase reporter = new ReportingDatabase(); - - private MavenXpp3Reader pomReader; + private ReportingDatabase reportDatabase; public void setUp() throws Exception { super.setUp(); artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" ); - pomReader = new MavenXpp3Reader(); + + ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" ); + reportDatabase = new ReportingDatabase( reportGroup ); } /** @@ -55,9 +55,9 @@ public class LocationArtifactReportProcessorTest { Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); + artifactReportProcessor.processArtifact( artifact, null, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } /** @@ -71,9 +71,9 @@ public class LocationArtifactReportProcessorTest 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() ); + artifactReportProcessor.processArtifact( artifact, model, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } /** @@ -86,9 +86,9 @@ public class LocationArtifactReportProcessorTest 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() ); + artifactReportProcessor.processArtifact( pomArtifact, model, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } /** @@ -102,9 +102,9 @@ public class LocationArtifactReportProcessorTest 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() ); + artifactReportProcessor.processArtifact( artifact, model, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } /** @@ -119,9 +119,9 @@ public class LocationArtifactReportProcessorTest 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() ); + artifactReportProcessor.processArtifact( artifact, model, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } /** @@ -136,9 +136,9 @@ public class LocationArtifactReportProcessorTest 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() ); + artifactReportProcessor.processArtifact( artifact, model, reportDatabase ); + assertEquals( 0, reportDatabase.getNumFailures() ); + assertEquals( 0, reportDatabase.getNumWarnings() ); } /** @@ -154,7 +154,7 @@ public class LocationArtifactReportProcessorTest try { Model model = readPom( repository.pathOf( pomArtifact ) ); - artifactReportProcessor.processArtifact( artifact, model, reporter ); + artifactReportProcessor.processArtifact( artifact, model, reportDatabase ); fail( "Should not have passed the artifact" ); } catch ( IllegalStateException e ) @@ -174,15 +174,15 @@ public class LocationArtifactReportProcessorTest Artifact pomArtifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0", "pom" ); Model model = readPom( repository.pathOf( pomArtifact ) ); - artifactReportProcessor.processArtifact( artifact, model, reporter ); - assertEquals( 1, reporter.getNumFailures() ); + artifactReportProcessor.processArtifact( artifact, model, reportDatabase ); + assertEquals( 1, reportDatabase.getNumFailures() ); } private Model readPom( String path ) throws IOException, XmlPullParserException { Reader reader = new FileReader( new File( repository.getBasedir(), path ) ); - Model model = pomReader.read( reader ); + Model model = new MavenXpp3Reader().read( reader ); // hokey inheritence to avoid some errors right now if ( model.getGroupId() == null ) { @@ -204,8 +204,8 @@ public class LocationArtifactReportProcessorTest { Artifact artifact = createArtifact( "org.apache.maven", "maven-monitor", "2.1" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 1, reporter.getNumFailures() ); + artifactReportProcessor.processArtifact( artifact, null, reportDatabase ); + assertEquals( 1, reportDatabase.getNumFailures() ); } /** @@ -217,8 +217,8 @@ public class LocationArtifactReportProcessorTest { Artifact artifact = createArtifact( "org.apache.maven", "maven-project", "2.1" ); - artifactReportProcessor.processArtifact( artifact, null, reporter ); - assertEquals( 1, reporter.getNumFailures() ); + artifactReportProcessor.processArtifact( artifact, null, reportDatabase ); + assertEquals( 1, reportDatabase.getNumFailures() ); } } diff --git a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java index 73fb380c6..0942a328b 100644 --- a/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java +++ b/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ReportsAction.java @@ -25,6 +25,7 @@ import org.apache.maven.archiva.configuration.RepositoryConfiguration; import org.apache.maven.archiva.discoverer.filter.AcceptAllArtifactFilter; import org.apache.maven.archiva.discoverer.filter.SnapshotArtifactFilter; import org.apache.maven.archiva.reporting.ReportExecutor; +import org.apache.maven.archiva.reporting.ReportGroup; import org.apache.maven.archiva.reporting.ReportingDatabase; import org.apache.maven.archiva.reporting.ReportingStore; import org.apache.maven.archiva.reporting.ReportingStoreException; @@ -34,6 +35,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map; /** * Repository reporting. @@ -70,15 +72,26 @@ public class ReportsAction private Configuration configuration; + /** + * @plexus.requirement role="org.apache.maven.archiva.reporting.ReportGroup" + */ + private Map reports; + + private String reportGroup = DEFAULT_REPORT_GROUP; + + private static final String DEFAULT_REPORT_GROUP = "health"; + public String execute() throws Exception { + ReportGroup reportGroup = (ReportGroup) reports.get( this.reportGroup ); + databases = new ArrayList(); if ( repositoryId != null && !repositoryId.equals( "-" ) ) { RepositoryConfiguration repositoryConfiguration = configuration.getRepositoryById( repositoryId ); - getReport( repositoryConfiguration ); + getReport( repositoryConfiguration, reportGroup ); } else { @@ -86,18 +99,18 @@ public class ReportsAction { RepositoryConfiguration repositoryConfiguration = (RepositoryConfiguration) i.next(); - getReport( repositoryConfiguration ); + getReport( repositoryConfiguration, reportGroup ); } } return SUCCESS; } - private void getReport( RepositoryConfiguration repositoryConfiguration ) + private void getReport( RepositoryConfiguration repositoryConfiguration, ReportGroup reportGroup ) throws ReportingStoreException { ArtifactRepository repository = factory.createRepository( repositoryConfiguration ); - ReportingDatabase database = reportingStore.getReportsFromStore( repository ); + ReportingDatabase database = reportingStore.getReportsFromStore( repository, reportGroup ); databases.add( database ); } @@ -105,12 +118,12 @@ public class ReportsAction public String runReport() throws Exception { - // TODO: this should be one that runs in the background - see the showcase + ReportGroup reportGroup = (ReportGroup) reports.get( this.reportGroup ); RepositoryConfiguration repositoryConfiguration = configuration.getRepositoryById( repositoryId ); ArtifactRepository repository = factory.createRepository( repositoryConfiguration ); - ReportingDatabase database = executor.getReportDatabase( repository ); + ReportingDatabase database = executor.getReportDatabase( repository, reportGroup ); if ( database.isInProgress() ) { return SUCCESS; @@ -140,7 +153,7 @@ public class ReportsAction try { - executor.runReports( repository, blacklistedPatterns, filter ); + executor.runReports( reportGroup, repository, blacklistedPatterns, filter ); } finally { @@ -150,6 +163,16 @@ public class ReportsAction return SUCCESS; } + public void setReportGroup( String reportGroup ) + { + this.reportGroup = reportGroup; + } + + public String getReportGroup() + { + return reportGroup; + } + public String getRepositoryId() { return repositoryId; @@ -175,4 +198,9 @@ public class ReportsAction { return configuration; } + + public Map getReports() + { + return reports; + } } diff --git a/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp b/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp index 563558d41..ad043764d 100644 --- a/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp +++ b/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/reports.jsp @@ -21,8 +21,9 @@ - <%-- TODO! change the name --%> - Report: Repository Health + + + Report: ${reports[reportGroup].name} @@ -32,8 +33,9 @@
-<%-- TODO!: select report, filter --%> +<%-- TODO!: select filter --%> +