[MRM-166] add filtering and problem identification

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@442072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-09-11 02:13:21 +00:00
parent 40b955d387
commit 0f5630ecf1
18 changed files with 448 additions and 274 deletions

View File

@ -295,14 +295,14 @@ public class DefaultRepositoryConverter
if ( !metadata.getGroupId().equals( artifact.getGroupId() ) )
{
reporter.addFailure( artifact, getI18NString( groupIdKey ) );
addFailure( reporter, artifact, groupIdKey );
result = false;
}
if ( !repositoryMetadata.storedInGroupDirectory() )
{
if ( !metadata.getArtifactId().equals( artifact.getArtifactId() ) )
{
reporter.addFailure( artifact, getI18NString( artifactIdKey ) );
addFailure( reporter, artifact, artifactIdKey );
result = false;
}
if ( !repositoryMetadata.storedInArtifactVersionDirectory() )
@ -325,7 +325,7 @@ public class DefaultRepositoryConverter
if ( !foundVersion )
{
reporter.addFailure( artifact, getI18NString( versionsKey ) );
addFailure( reporter, artifact, versionsKey );
result = false;
}
}
@ -334,7 +334,7 @@ public class DefaultRepositoryConverter
// snapshot metadata
if ( !artifact.getBaseVersion().equals( metadata.getVersion() ) )
{
reporter.addFailure( artifact, getI18NString( versionKey ) );
addFailure( reporter, artifact, versionKey );
result = false;
}
@ -357,7 +357,7 @@ public class DefaultRepositoryConverter
if ( !correct )
{
reporter.addFailure( artifact, getI18NString( snapshotKey ) );
addFailure( reporter, artifact, snapshotKey );
result = false;
}
}
@ -367,6 +367,24 @@ public class DefaultRepositoryConverter
return result;
}
private void addFailure( ReportingDatabase reporter, Artifact artifact, String key )
{
addFailureWithReason( reporter, artifact, getI18NString( key ) );
}
private static void addWarning( ReportingDatabase reporter, Artifact artifact, String message )
{
// TODO: should we be able to identify/fix these?
reporter.addWarning( artifact, null, null, message );
}
private static void addFailureWithReason( ReportingDatabase reporter, Artifact artifact, String reason )
{
// TODO: should we be able to identify/fix these?
reporter.addFailure( artifact, null, null, reason );
}
private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, ReportingDatabase reporter,
FileTransaction transaction )
throws RepositoryConversionException
@ -452,12 +470,13 @@ public class DefaultRepositoryConverter
for ( Iterator i = warnings.iterator(); i.hasNext(); )
{
String message = (String) i.next();
reporter.addWarning( artifact, message );
addWarning( reporter, artifact, message );
}
}
catch ( XmlPullParserException e )
{
reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
addFailureWithReason( reporter, artifact,
getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
result = false;
}
catch ( IOException e )
@ -466,7 +485,8 @@ public class DefaultRepositoryConverter
}
catch ( PomTranslationException e )
{
reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
addFailureWithReason( reporter, artifact,
getI18NString( "failure.invalid.source.pom", e.getMessage() ) );
result = false;
}
finally
@ -477,7 +497,7 @@ public class DefaultRepositoryConverter
}
else
{
reporter.addWarning( artifact, getI18NString( "warning.missing.pom" ) );
addWarning( reporter, artifact, getI18NString( "warning.missing.pom" ) );
}
return result;
}
@ -598,7 +618,7 @@ public class DefaultRepositoryConverter
}
catch ( DigesterException e )
{
reporter.addFailure( artifact, getI18NString( key ) );
addFailure( reporter, artifact, key );
result = false;
}
}
@ -622,7 +642,7 @@ public class DefaultRepositoryConverter
matching = FileUtils.contentEquals( sourceFile, targetFile );
if ( !matching )
{
reporter.addFailure( artifact, getI18NString( "failure.target.already.exists" ) );
addFailure( reporter, artifact, "failure.target.already.exists" );
result = false;
}
}

View File

@ -57,6 +57,8 @@ public class BadMetadataReportProcessor
*/
private RepositoryQueryLayerFactory repositoryQueryLayerFactory;
private static final String ROLE_HINT = "bad-metadata";
/**
* Process the metadata encountered in the repository and report all errors found, if any.
*
@ -75,7 +77,7 @@ public class BadMetadataReportProcessor
}
catch ( IOException e )
{
reporter.addWarning( metadata, "Error getting plugin artifact directories versions: " + e );
addWarning( reporter, metadata, null, "Error getting plugin artifact directories versions: " + e );
}
}
else
@ -92,7 +94,8 @@ public class BadMetadataReportProcessor
}
if ( !found )
{
reporter.addFailure( metadata, "Missing lastUpdated element inside the metadata." );
addFailure( reporter, metadata, "missing-last-updated",
"Missing lastUpdated element inside the metadata." );
}
if ( metadata.storedInArtifactVersionDirectory() )
@ -109,12 +112,20 @@ public class BadMetadataReportProcessor
}
catch ( IOException e )
{
reporter.addWarning( metadata, "Error getting plugin artifact directories versions: " + e );
String reason = "Error getting plugin artifact directories versions: " + e;
addWarning( reporter, metadata, null, reason );
}
}
}
}
private static void addWarning( ReportingDatabase reporter, RepositoryMetadata metadata, String problem,
String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addWarning( metadata, ROLE_HINT, problem, reason );
}
/**
* Method for processing a GroupRepositoryMetadata
*
@ -138,20 +149,22 @@ public class BadMetadataReportProcessor
String artifactId = plugin.getArtifactId();
if ( artifactId == null || artifactId.length() == 0 )
{
reporter.addFailure( metadata,
"Missing or empty artifactId in group metadata for plugin " + plugin.getPrefix() );
addFailure( reporter, metadata, "missing-artifact-id:" + plugin.getPrefix(),
"Missing or empty artifactId in group metadata for plugin " + plugin.getPrefix() );
}
String prefix = plugin.getPrefix();
if ( prefix == null || prefix.length() == 0 )
{
reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId + "." );
addFailure( reporter, metadata, "missing-plugin-prefix:" + artifactId,
"Missing or empty plugin prefix for artifactId " + artifactId + "." );
}
else
{
if ( prefixes.containsKey( prefix ) )
{
reporter.addFailure( metadata, "Duplicate plugin prefix found: " + prefix + "." );
addFailure( reporter, metadata, "duplicate-plugin-prefix:" + prefix,
"Duplicate plugin prefix found: " + prefix + "." );
}
else
{
@ -164,7 +177,8 @@ public class BadMetadataReportProcessor
File pluginDir = new File( metadataDir, artifactId );
if ( !pluginDirs.contains( pluginDir ) )
{
reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" );
addFailure( reporter, metadata, "missing-plugin-from-repository:" + artifactId,
"Metadata plugin " + artifactId + " not found in the repository" );
}
else
{
@ -178,8 +192,8 @@ public class BadMetadataReportProcessor
for ( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); )
{
File plugin = (File) plugins.next();
reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " +
"missing in the metadata." );
addFailure( reporter, metadata, "missing-plugin-from-metadata:" + plugin.getName(), "Plugin " +
plugin.getName() + " is present in the repository but " + "missing in the metadata." );
}
}
}
@ -210,7 +224,8 @@ public class BadMetadataReportProcessor
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
addFailure( reporter, metadata, "missing-snapshot-artifact-from-repository:" + version,
"Snapshot artifact " + version + " does not exist." );
}
}
}
@ -240,8 +255,8 @@ public class BadMetadataReportProcessor
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " +
"missing in the repository." );
addFailure( reporter, metadata, "missing-artifact-from-repository:" + version, "Artifact version " +
version + " is present in metadata but " + "missing in the repository." );
}
}
}
@ -254,6 +269,7 @@ public class BadMetadataReportProcessor
* @param metadata the metadata to be processed.
* @param repository the repository where the metadata was encountered
* @param reporter the ReportingDatabase to receive processing results
* @throws java.io.IOException if there is a problem reading from the file system
*/
private void checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository,
ReportingDatabase reporter )
@ -275,14 +291,14 @@ public class BadMetadataReportProcessor
String version = path.getParentFile().getName();
if ( !metadataVersions.contains( version ) )
{
reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " +
"missing in the metadata." );
addFailure( reporter, metadata, "missing-artifact-from-metadata:" + version, "Artifact version " +
version + " found in the repository but " + "missing in the metadata." );
}
}
}
else
{
reporter.addFailure( metadata, "Metadata's directory did not exist: " + versionsDir );
addFailure( reporter, metadata, null, "Metadata's directory did not exist: " + versionsDir );
}
}
@ -318,4 +334,11 @@ public class BadMetadataReportProcessor
return artifactIdFiles;
}
private static void addFailure( ReportingDatabase reporter, RepositoryMetadata metadata, String problem,
String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( metadata, ROLE_HINT, problem, reason );
}
}

View File

@ -45,6 +45,8 @@ public class ChecksumArtifactReportProcessor
*/
private Digester md5Digester;
private static final String ROLE_HINT = "checksum";
public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
ArtifactRepository repository = artifact.getRepository();
@ -77,16 +79,23 @@ public class ChecksumArtifactReportProcessor
}
catch ( DigesterException e )
{
reporter.addFailure( artifact, e.getMessage() );
addFailure( reporter, artifact, "checksum-wrong", e.getMessage() );
}
catch ( IOException e )
{
reporter.addFailure( artifact, "Read file error: " + e.getMessage() );
addFailure( reporter, artifact, "checksum-io-exception", "Read file error: " + e.getMessage() );
}
}
else
{
reporter.addFailure( artifact, digester.getAlgorithm() + " checksum file does not exist." );
addFailure( reporter, artifact, "checksum-missing",
digester.getAlgorithm() + " checksum file does not exist." );
}
}
private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( artifact, ROLE_HINT, problem, reason );
}
}

View File

@ -44,6 +44,8 @@ public class ChecksumMetadataReportProcessor
*/
private Digester md5Digester;
private static final String ROLE_HINT = "checksum-metadata";
/**
* Validate the checksums of the metadata. Get the metadata file from the
* repository then validate the checksum.
@ -78,17 +80,25 @@ public class ChecksumMetadataReportProcessor
}
catch ( DigesterException e )
{
reporter.addFailure( metadata, e.getMessage() );
addFailure( reporter, metadata, "checksum-wrong", e.getMessage() );
}
catch ( IOException e )
{
reporter.addFailure( metadata, "Read file error: " + e.getMessage() );
addFailure( reporter, metadata, "checksum-io-exception", "Read file error: " + e.getMessage() );
}
}
else
{
reporter.addFailure( metadata, digester.getAlgorithm() + " checksum file does not exist." );
addFailure( reporter, metadata, "checksum-missing",
digester.getAlgorithm() + " checksum file does not exist." );
}
}
private static void addFailure( ReportingDatabase reporter, RepositoryMetadata metadata, String problem,
String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( metadata, ROLE_HINT, problem, reason );
}
}

View File

@ -118,7 +118,7 @@ public class DefaultReportExecutor
}
catch ( ProjectBuildingException e )
{
reporter.addWarning( artifact, "Error reading project model: " + e );
reporter.addWarning( artifact, null, null, "Error reading project model: " + e );
}
reporter.removeArtifact( artifact );

View File

@ -16,10 +16,8 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* The default report set, for repository health.
@ -32,18 +30,27 @@ public class DefaultReportGroup
{
/**
* Role hints of the reports to include in this set.
*
* @todo re-enable duplicate, once a way to populate the index is determined!
*/
private static final Set reports = new LinkedHashSet( Arrays.asList( new String[]{"checksum", "dependency"
/*, "duplicate"*/, "invalid-pom", "artifact-location", "bad-metadata", "checksum-metadata"} ) );
private static final Map reports = new LinkedHashMap();
static
{
reports.put( "checksum", "Checksum Problems" );
reports.put( "dependency", "Dependency Problems" );
// TODO re-enable duplicate, once a way to populate the index is determined!
// reports.put( "duplicate", "Duplicate Artifact Problems" );
reports.put( "invalid-pom", "POM Problems" );
reports.put( "bad-metadata", "Metadata Problems" );
reports.put( "checksum-metadata", "Metadata Checksum Problems" );
reports.put( "artifact-location", "Artifact Location Problems" );
}
public boolean includeReport( String key )
{
return reports.contains( key );
return reports.containsKey( key );
}
public Collection getReportIds()
public Map getReports()
{
return reports;
}

View File

@ -47,10 +47,16 @@ public class DependencyArtifactReportProcessor
private static final String POM = "pom";
private static final String ROLE_HINT = "dependency";
public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
processArtifact( artifact, reporter, queryLayer );
if ( !queryLayer.containsArtifact( artifact ) )
{
// TODO: is this even possible?
addFailure( reporter, artifact, "missing-artifact", "Artifact does not exist in the repository" );
}
if ( model != null && POM.equals( artifact.getType() ) )
{
@ -59,13 +65,10 @@ public class DependencyArtifactReportProcessor
}
}
private void processArtifact( Artifact artifact, ReportingDatabase reporter,
RepositoryQueryLayer repositoryQueryLayer )
private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
{
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addFailure( artifact, "Artifact does not exist in the repository" );
}
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( artifact, ROLE_HINT, problem, reason );
}
private void processDependencies( List dependencies, ReportingDatabase reporter,
@ -96,7 +99,8 @@ public class DependencyArtifactReportProcessor
String reason = MessageFormat.format(
"Artifact''s dependency {0} does not exist in the repository",
new String[]{getDependencyString( dependency )} );
reporter.addFailure( sourceArtifact, reason );
addFailure( reporter, sourceArtifact, "missing-dependency:" + getDependencyKey( dependency ),
reason );
}
}
catch ( InvalidVersionSpecificationException e )
@ -104,12 +108,25 @@ public class DependencyArtifactReportProcessor
String reason = MessageFormat.format( "Artifact''s dependency {0} contains an invalid version {1}",
new String[]{getDependencyString( dependency ),
dependency.getVersion()} );
reporter.addFailure( sourceArtifact, reason );
addFailure( reporter, sourceArtifact, "bad-version:" + getDependencyKey( dependency ), reason );
}
}
}
}
private String getDependencyKey( Dependency dependency )
{
String str = dependency.getGroupId();
str += ":" + dependency.getArtifactId();
str += ":" + dependency.getVersion();
str += ":" + dependency.getType();
if ( dependency.getClassifier() != null )
{
str += ":" + dependency.getClassifier();
}
return str;
}
static String getDependencyString( Dependency dependency )
{
String str = "(group=" + dependency.getGroupId();

View File

@ -58,6 +58,8 @@ public class DuplicateArtifactFileReportProcessor
*/
private String indexDirectory;
private static final String ROLE_HINT = "duplicate";
public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
ArtifactRepository repository = artifact.getRepository();
@ -72,7 +74,8 @@ public class DuplicateArtifactFileReportProcessor
}
catch ( DigesterException e )
{
reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
addWarning( reporter, artifact, null,
"Unable to generate checksum for " + artifact.getFile() + ": " + e );
}
if ( checksum != null )
@ -95,7 +98,8 @@ public class DuplicateArtifactFileReportProcessor
String groupId = artifact.getGroupId();
if ( groupId.equals( result.getGroupId() ) )
{
reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
addFailures( reporter, artifact, "duplicate",
"Found duplicate for " + artifact.getId() );
}
}
}
@ -103,13 +107,25 @@ public class DuplicateArtifactFileReportProcessor
}
catch ( RepositoryIndexSearchException e )
{
reporter.addWarning( artifact, "Failed to search in index" + e );
addWarning( reporter, artifact, null, "Failed to search in index" + e );
}
}
}
else
{
reporter.addWarning( artifact, "Artifact file is null" );
addWarning( reporter, artifact, null, "Artifact file is null" );
}
}
private static void addFailures( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( artifact, ROLE_HINT, problem, reason );
}
private static void addWarning( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addWarning( artifact, ROLE_HINT, problem, reason );
}
}

View File

@ -24,7 +24,6 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
@ -38,6 +37,8 @@ import java.io.Reader;
public class InvalidPomArtifactReportProcessor
implements ArtifactReportProcessor
{
private static final String ROLE_HINT = "invalid-pom";
/**
* @param artifact The pom xml file to be validated, passed as an artifact object.
* @param reporter The artifact reporter object.
@ -59,7 +60,7 @@ public class InvalidPomArtifactReportProcessor
if ( !f.exists() )
{
reporter.addFailure( artifact, "Artifact not found." );
addFailure( reporter, artifact, "pom-missing", "POM not found." );
}
else
{
@ -74,16 +75,13 @@ public class InvalidPomArtifactReportProcessor
}
catch ( XmlPullParserException e )
{
reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " +
e.getMessage() );
}
catch ( FileNotFoundException e )
{
reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
addFailure( reporter, artifact, "pom-parse-exception",
"The pom xml file is not well-formed. Error while parsing: " + e.getMessage() );
}
catch ( IOException e )
{
reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
addFailure( reporter, artifact, "pom-io-exception",
"Error while reading the pom xml file: " + e.getMessage() );
}
finally
{
@ -92,4 +90,10 @@ public class InvalidPomArtifactReportProcessor
}
}
}
private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( artifact, ROLE_HINT, problem, reason );
}
}

View File

@ -63,6 +63,8 @@ public class LocationArtifactReportProcessor
private static final String POM = "pom";
private static final String ROLE_HINT = "artifact-location";
/**
* Check whether the artifact is in its proper location. The location of the artifact
* is validated first against the groupId, artifactId and versionId in the specified model
@ -104,9 +106,9 @@ public class LocationArtifactReportProcessor
String modelPath = repository.pathOf( modelArtifact );
if ( !modelPath.equals( artifactPath ) )
{
reporter.addFailure( artifact,
"The artifact is out of place. It does not match the specified location in the repository pom: " +
modelPath );
addFailure( reporter, artifact, "repository-pom-location",
"The artifact is out of place. It does not match the specified location in the repository pom: " +
modelPath );
}
}
}
@ -130,8 +132,8 @@ public class LocationArtifactReportProcessor
extractedModel.getPackaging() );
if ( !repository.pathOf( extractedArtifact ).equals( artifactPath ) )
{
reporter.addFailure( artifact,
"The artifact is out of place. It does not match the specified location in the packaged pom." );
addFailure( reporter, artifact, "packaged-pom-location",
"The artifact is out of place. It does not match the specified location in the packaged pom." );
}
}
}
@ -142,6 +144,12 @@ public class LocationArtifactReportProcessor
}
}
private static void addFailure( ReportingDatabase reporter, Artifact artifact, String problem, String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addFailure( artifact, ROLE_HINT, problem, reason );
}
private static void adjustDistributionArtifactHandler( Artifact artifact )
{
// need to tweak these as they aren't currently in the known type converters. TODO - add them in Maven
@ -185,11 +193,11 @@ public class LocationArtifactReportProcessor
}
catch ( IOException e )
{
reporter.addWarning( artifact, "Unable to read artifact to extract model: " + e );
addWarning( reporter, artifact, "Unable to read artifact to extract model: " + e );
}
catch ( XmlPullParserException e )
{
reporter.addWarning( artifact, "Unable to parse extracted model: " + e );
addWarning( reporter, artifact, "Unable to parse extracted model: " + e );
}
finally
{
@ -209,6 +217,12 @@ public class LocationArtifactReportProcessor
return model;
}
private static void addWarning( ReportingDatabase reporter, Artifact artifact, String reason )
{
// TODO: reason could be an i18n key derived from the processor and the problem ID and the
reporter.addWarning( artifact, ROLE_HINT, null, reason );
}
private Model readModel( InputStream entryStream )
throws IOException, XmlPullParserException
{

View File

@ -16,10 +16,8 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* The report set for finding old artifacts (both snapshot and release)
@ -34,15 +32,20 @@ public class OldArtifactReportGroup
*
* @todo implement these report processors!
*/
private static final Set reports =
new LinkedHashSet( Arrays.asList( new String[]{"old-artifact", "old-snapshot-artifact"} ) );
private static final Map reports = new LinkedHashMap();
static
{
reports.put( "old-artifact", "Old Artifacts" );
reports.put( "old-snapshot-artifact", "Old Snapshot Artifacts" );
}
public boolean includeReport( String key )
{
return reports.contains( key );
return reports.containsKey( key );
}
public Collection getReportIds()
public Map getReports()
{
return reports;
}

View File

@ -5,7 +5,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.model.Model;
import java.util.Collection;
import java.util.Map;
/*
* Copyright 2005-2006 The Apache Software Foundation.
@ -62,11 +62,12 @@ public interface ReportGroup
boolean includeReport( String key );
/**
* Get a list of the report processors in this set.
* Get the report processors in this set. The map is keyed by the report's role hint, and the value is it's
* display name.
*
* @return the report IDs
* @return the reports
*/
Collection getReportIds();
Map getReports();
/**
* Get the user-friendly name of this report.

View File

@ -56,6 +56,8 @@ public class ReportingDatabase
private Set metadataWithProblems;
private Map filteredDatabases = new HashMap();
public ReportingDatabase( ReportGroup reportGroup )
{
this( reportGroup, new Reporting() );
@ -84,37 +86,57 @@ public class ReportingDatabase
initMetadataMap();
}
public void addFailure( Artifact artifact, String reason )
public void addFailure( Artifact artifact, String processor, String problem, String reason )
{
ArtifactResults results = getArtifactResults( artifact );
results.addFailure( createResults( reason ) );
results.addFailure( createResult( processor, problem, reason ) );
numFailures++;
updateTimings();
if ( filteredDatabases.containsKey( problem ) )
{
ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
reportingDatabase.addFailure( artifact, processor, problem, reason );
}
}
public void addWarning( Artifact artifact, String reason )
public void addWarning( Artifact artifact, String processor, String problem, String reason )
{
ArtifactResults results = getArtifactResults( artifact );
results.addWarning( createResults( reason ) );
results.addWarning( createResult( processor, problem, reason ) );
numWarnings++;
updateTimings();
if ( filteredDatabases.containsKey( problem ) )
{
ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
reportingDatabase.addWarning( artifact, processor, problem, reason );
}
}
private ArtifactResults getArtifactResults( Artifact artifact )
{
return getArtifactResults( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
artifact.getType(), artifact.getClassifier() );
}
private ArtifactResults getArtifactResults( String groupId, String artifactId, String version, String type,
String classifier )
{
Map artifactMap = this.artifactMap;
String key = getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
artifact.getType(), artifact.getClassifier() );
String key = getArtifactKey( groupId, artifactId, version, type, classifier );
ArtifactResults results = (ArtifactResults) artifactMap.get( key );
if ( results == null )
{
results = new ArtifactResults();
results.setArtifactId( artifact.getArtifactId() );
results.setClassifier( artifact.getClassifier() );
results.setGroupId( artifact.getGroupId() );
results.setType( artifact.getType() );
results.setVersion( artifact.getVersion() );
results.setArtifactId( artifactId );
results.setClassifier( classifier );
results.setGroupId( groupId );
results.setType( type );
results.setVersion( version );
artifactMap.put( key, results );
reporting.getArtifacts().add( results );
@ -146,35 +168,51 @@ public class ReportingDatabase
return groupId + ":" + artifactId + ":" + version + ":" + type + ":" + classifier;
}
private static Result createResults( String reason )
private static Result createResult( String processor, String problem, String reason )
{
Result result = new Result();
result.setProcessor( processor );
result.setProblem( problem );
result.setReason( reason );
return result;
}
public void addFailure( RepositoryMetadata metadata, String reason )
public void addFailure( RepositoryMetadata metadata, String processor, String problem, String reason )
{
MetadataResults results = getMetadataResults( metadata, System.currentTimeMillis() );
if ( !metadataWithProblems.contains( results ) )
{
metadataWithProblems.add( results );
}
results.addFailure( createResults( reason ) );
results.addFailure( createResult( processor, problem, reason ) );
numFailures++;
updateTimings();
if ( filteredDatabases.containsKey( problem ) )
{
ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
reportingDatabase.addFailure( metadata, processor, problem, reason );
}
}
public void addWarning( RepositoryMetadata metadata, String reason )
public void addWarning( RepositoryMetadata metadata, String processor, String problem, String reason )
{
MetadataResults results = getMetadataResults( metadata, System.currentTimeMillis() );
if ( !metadataWithProblems.contains( results ) )
{
metadataWithProblems.add( results );
}
results.addWarning( createResults( reason ) );
results.addWarning( createResult( processor, problem, reason ) );
numWarnings++;
updateTimings();
if ( filteredDatabases.containsKey( problem ) )
{
ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( problem );
reportingDatabase.addWarning( metadata, processor, problem, reason );
}
}
public Set getMetadataWithProblems()
@ -239,7 +277,7 @@ public class ReportingDatabase
public boolean isMetadataUpToDate( RepositoryMetadata metadata, long timestamp )
{
String key = getMetadataKey( metadata );
String key = getMetadataKey( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
Map map = metadataMap;
MetadataResults results = (MetadataResults) map.get( key );
return results != null && results.getLastModified() >= timestamp;
@ -268,15 +306,22 @@ public class ReportingDatabase
private MetadataResults getMetadataResults( RepositoryMetadata metadata, long lastModified )
{
String key = getMetadataKey( metadata );
return getMetadataResults( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion(),
lastModified );
}
private MetadataResults getMetadataResults( String groupId, String artifactId, String baseVersion,
long lastModified )
{
String key = getMetadataKey( groupId, artifactId, baseVersion );
Map metadataMap = this.metadataMap;
MetadataResults results = (MetadataResults) metadataMap.get( key );
if ( results == null )
{
results = new MetadataResults();
results.setArtifactId( metadata.getArtifactId() );
results.setGroupId( metadata.getGroupId() );
results.setVersion( metadata.getBaseVersion() );
results.setArtifactId( artifactId );
results.setGroupId( groupId );
results.setVersion( baseVersion );
results.setLastModified( lastModified );
metadataMap.put( key, results );
@ -285,11 +330,6 @@ public class ReportingDatabase
return results;
}
private static String getMetadataKey( RepositoryMetadata metadata )
{
return getMetadataKey( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
}
public void removeArtifact( Artifact artifact )
{
Map map = artifactMap;
@ -343,6 +383,7 @@ public class ReportingDatabase
artifactMap.clear();
metadataMap.clear();
metadataWithProblems.clear();
filteredDatabases.clear();
reporting.getArtifacts().clear();
reporting.getMetadata().clear();
@ -375,4 +416,113 @@ public class ReportingDatabase
{
return reportGroup;
}
public ReportingDatabase getFilteredDatabase( String filter )
{
ReportingDatabase reportingDatabase = (ReportingDatabase) filteredDatabases.get( filter );
if ( reportingDatabase == null )
{
reportingDatabase = new ReportingDatabase( reportGroup, repository );
Reporting reporting = reportingDatabase.getReporting();
reporting.setExecutionTime( this.reporting.getExecutionTime() );
reporting.setLastModified( this.reporting.getLastModified() );
for ( Iterator i = this.reporting.getArtifacts().iterator(); i.hasNext(); )
{
ArtifactResults results = (ArtifactResults) i.next();
ArtifactResults targetResults = null;
for ( Iterator j = results.getFailures().iterator(); j.hasNext(); )
{
Result result = (Result) j.next();
if ( filter.equals( result.getProcessor() ) )
{
if ( targetResults == null )
{
// lazily create so it is not added unless it has to be
targetResults = createArtifactResults( reportingDatabase, results );
}
targetResults.addFailure( result );
reportingDatabase.numFailures++;
}
}
for ( Iterator j = results.getWarnings().iterator(); j.hasNext(); )
{
Result result = (Result) j.next();
if ( filter.equals( result.getProcessor() ) )
{
if ( targetResults == null )
{
// lazily create so it is not added unless it has to be
targetResults = createArtifactResults( reportingDatabase, results );
}
targetResults.addWarning( result );
reportingDatabase.numWarnings++;
}
}
}
for ( Iterator i = this.reporting.getMetadata().iterator(); i.hasNext(); )
{
MetadataResults results = (MetadataResults) i.next();
MetadataResults targetResults = null;
for ( Iterator j = results.getFailures().iterator(); j.hasNext(); )
{
Result result = (Result) j.next();
if ( filter.equals( result.getProcessor() ) )
{
if ( targetResults == null )
{
// lazily create so it is not added unless it has to be
targetResults = createMetadataResults( reportingDatabase, results );
}
targetResults.addFailure( result );
reportingDatabase.numFailures++;
}
}
for ( Iterator j = results.getWarnings().iterator(); j.hasNext(); )
{
Result result = (Result) j.next();
if ( filter.equals( result.getProcessor() ) )
{
if ( targetResults == null )
{
// lazily create so it is not added unless it has to be
targetResults = createMetadataResults( reportingDatabase, results );
}
targetResults.addWarning( result );
reportingDatabase.numWarnings++;
}
}
}
filteredDatabases.put( filter, reportingDatabase );
}
return reportingDatabase;
}
private static MetadataResults createMetadataResults( ReportingDatabase reportingDatabase, MetadataResults results )
{
MetadataResults targetResults = reportingDatabase.getMetadataResults( results.getGroupId(),
results.getArtifactId(),
results.getVersion(),
results.getLastModified() );
reportingDatabase.metadataWithProblems.add( targetResults );
return targetResults;
}
private static ArtifactResults createArtifactResults( ReportingDatabase reportingDatabase, ArtifactResults results )
{
return reportingDatabase.getArtifactResults( results.getGroupId(), results.getArtifactId(),
results.getVersion(), results.getType(), results.getClassifier() );
}
}

View File

@ -200,6 +200,26 @@
<description>
The reason given for the result.
</description>
<required>true</required>
</field>
<field xml.attribute="true">
<name>processor</name>
<version>1.0.0</version>
<type>String</type>
<description>
The processor identifier for the report that triggered the problem. This matches the role-hint of a report
processor.
</description>
<required>true</required>
</field>
<field xml.attribute="true">
<name>problem</name>
<version>1.0.0</version>
<type>String</type>
<description>
The problem identifier for the problem that occurred. This is so that the processor can identify how to
fix the problem. It may be null if it cannot be fixed automatically.
</description>
</field>
</fields>
</class>

View File

@ -1,154 +0,0 @@
package org.apache.maven.archiva.reporting;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.archiva.reporting.model.ArtifactResults;
import org.apache.maven.archiva.reporting.model.Result;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.metadata.Versioning;
import java.util.Iterator;
/**
*
*/
public class ArtifactReporterTest
extends AbstractRepositoryReportsTestCase
{
private ReportingDatabase reportingDatabase;
private Artifact artifact;
protected void setUp()
throws Exception
{
super.setUp();
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
Versioning versioning = new Versioning();
versioning.addVersion( "1.0-alpha-1" );
versioning.setLastUpdated( "20050611.202020" );
ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
reportingDatabase = new ReportingDatabase( reportGroup );
}
public void testArtifactReporterSingleFailure()
{
reportingDatabase.addFailure( artifact, "failed once" );
Iterator artifactIterator = reportingDatabase.getArtifactIterator();
ArtifactResults results = (ArtifactResults) artifactIterator.next();
assertFalse( artifactIterator.hasNext() );
int count = 0;
for ( Iterator i = results.getFailures().iterator(); i.hasNext(); count++ )
{
i.next();
}
assertEquals( 1, count );
assertEquals( 1, reportingDatabase.getNumFailures() );
assertEquals( 0, reportingDatabase.getNumWarnings() );
}
public void testArtifactReporterMultipleFailure()
{
reportingDatabase.addFailure( artifact, "failed once" );
reportingDatabase.addFailure( artifact, "failed twice" );
reportingDatabase.addFailure( artifact, "failed thrice" );
Iterator artifactIterator = reportingDatabase.getArtifactIterator();
ArtifactResults results = (ArtifactResults) artifactIterator.next();
assertFalse( artifactIterator.hasNext() );
int count = 0;
for ( Iterator i = results.getFailures().iterator(); i.hasNext(); count++ )
{
i.next();
}
assertEquals( 3, count );
assertEquals( 3, reportingDatabase.getNumFailures() );
assertEquals( 0, reportingDatabase.getNumWarnings() );
}
public void testFailureMessages()
{
reportingDatabase.addFailure( artifact, "failed once" );
reportingDatabase.addFailure( artifact, "failed twice" );
reportingDatabase.addFailure( artifact, "failed thrice" );
Iterator artifactIterator = reportingDatabase.getArtifactIterator();
ArtifactResults results = (ArtifactResults) artifactIterator.next();
assertFalse( artifactIterator.hasNext() );
Iterator failure = results.getFailures().iterator();
assertEquals( "failed once", ( (Result) failure.next() ).getReason() );
assertEquals( "failed twice", ( (Result) failure.next() ).getReason() );
assertEquals( "failed thrice", ( (Result) failure.next() ).getReason() );
}
public void testArtifactReporterSingleWarning()
{
reportingDatabase.addWarning( artifact, "you've been warned" );
Iterator artifactIterator = reportingDatabase.getArtifactIterator();
ArtifactResults results = (ArtifactResults) artifactIterator.next();
assertFalse( artifactIterator.hasNext() );
int count = 0;
for ( Iterator i = results.getWarnings().iterator(); i.hasNext(); count++ )
{
i.next();
}
assertEquals( 1, count );
assertEquals( 0, reportingDatabase.getNumFailures() );
assertEquals( 1, reportingDatabase.getNumWarnings() );
}
public void testArtifactReporterMultipleWarning()
{
reportingDatabase.addWarning( artifact, "i'm warning you" );
reportingDatabase.addWarning( artifact, "you have to stop now" );
reportingDatabase.addWarning( artifact, "all right... that does it!" );
Iterator artifactIterator = reportingDatabase.getArtifactIterator();
ArtifactResults results = (ArtifactResults) artifactIterator.next();
assertFalse( artifactIterator.hasNext() );
int count = 0;
for ( Iterator i = results.getWarnings().iterator(); i.hasNext(); count++ )
{
i.next();
}
assertEquals( 3, count );
assertEquals( 0, reportingDatabase.getNumFailures() );
assertEquals( 3, reportingDatabase.getNumWarnings() );
}
public void testWarningMessages()
{
reportingDatabase.addWarning( artifact, "i'm warning you" );
reportingDatabase.addWarning( artifact, "you have to stop now" );
reportingDatabase.addWarning( artifact, "all right... that does it!" );
Iterator artifactIterator = reportingDatabase.getArtifactIterator();
ArtifactResults results = (ArtifactResults) artifactIterator.next();
assertFalse( artifactIterator.hasNext() );
Iterator warning = results.getWarnings().iterator();
assertEquals( "i'm warning you", ( (Result) warning.next() ).getReason() );
assertEquals( "you have to stop now", ( (Result) warning.next() ).getReason() );
assertEquals( "all right... that does it!", ( (Result) warning.next() ).getReason() );
}
}

View File

@ -36,6 +36,10 @@ public class DefaultArtifactReporterTest
private RepositoryMetadata metadata;
private static final String PROCESSOR = "processor";
private static final String PROBLEM = "problem";
public void testEmptyArtifactReporter()
{
assertEquals( "No failures", 0, reportingDatabase.getNumFailures() );
@ -46,7 +50,7 @@ public class DefaultArtifactReporterTest
public void testMetadataSingleFailure()
{
reportingDatabase.addFailure( metadata, "Single Failure Reason" );
reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Single Failure Reason" );
assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
@ -58,6 +62,8 @@ public class DefaultArtifactReporterTest
Result result = (Result) failures.next();
assertMetadata( results );
assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
assertFalse( "no more failures", failures.hasNext() );
}
@ -70,8 +76,8 @@ public class DefaultArtifactReporterTest
public void testMetadataMultipleFailures()
{
reportingDatabase.addFailure( metadata, "First Failure Reason" );
reportingDatabase.addFailure( metadata, "Second Failure Reason" );
reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "First Failure Reason" );
reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Second Failure Reason" );
assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
@ -83,15 +89,19 @@ public class DefaultArtifactReporterTest
Result result = (Result) failures.next();
assertMetadata( results );
assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
assertTrue( "must have 2nd failure", failures.hasNext() );
result = (Result) failures.next();
assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
assertFalse( "no more failures", failures.hasNext() );
}
public void testMetadataSingleWarning()
{
reportingDatabase.addWarning( metadata, "Single Warning Message" );
reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Single Warning Message" );
assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
@ -103,13 +113,15 @@ public class DefaultArtifactReporterTest
Result result = (Result) warnings.next();
assertMetadata( results );
assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
assertFalse( "no more warnings", warnings.hasNext() );
}
public void testMetadataMultipleWarnings()
{
reportingDatabase.addWarning( metadata, "First Warning" );
reportingDatabase.addWarning( metadata, "Second Warning" );
reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "First Warning" );
reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Second Warning" );
assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
@ -121,9 +133,13 @@ public class DefaultArtifactReporterTest
Result result = (Result) warnings.next();
assertMetadata( results );
assertEquals( "check failure reason", "First Warning", result.getReason() );
assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
assertTrue( "must have 2nd warning", warnings.hasNext() );
result = (Result) warnings.next();
assertEquals( "check failure reason", "Second Warning", result.getReason() );
assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
assertFalse( "no more warnings", warnings.hasNext() );
}

View File

@ -76,6 +76,8 @@ public class ReportsAction
private static final String DEFAULT_REPORT_GROUP = "health";
private String filter;
public String execute()
throws Exception
{
@ -107,6 +109,11 @@ public class ReportsAction
ReportingDatabase database = executor.getReportDatabase( repository, reportGroup );
if ( filter != null && !filter.equals( "-" ) )
{
database = database.getFilteredDatabase( filter );
}
databases.add( database );
}
@ -205,4 +212,14 @@ public class ReportsAction
{
return reports;
}
public String getFilter()
{
return filter;
}
public void setFilter( String filter )
{
this.filter = filter;
}
}

View File

@ -33,11 +33,12 @@
<div id="contentArea">
<%-- TODO!: select filter --%>
<ww:form action="reports" namespace="/admin">
<ww:select list="reports" label="Report" name="reportGroup"/>
<ww:select list="reports" label="Report" name="reportGroup" onchange="document.reports.submit();"/>
<ww:select list="configuration.repositories" listKey="id" listValue="name" label="Repository" headerKey="-"
headerValue="(All repositories)" name="repositoryId"/>
headerValue="(All repositories)" name="repositoryId" onchange="document.reports.submit();"/>
<ww:select list="reports[reportGroup].reports" label="Filter" headerKey="-" headerValue="(All Problems)"
name="filter" onchange="document.reports.submit();"/>
<ww:submit value="Get Report"/>
</ww:form>