aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-reports-standard
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-09-08 05:16:51 +0000
committerBrett Porter <brett@apache.org>2006-09-08 05:16:51 +0000
commit90f0dddc4363000f1b854f4fd8f9f3282433f21d (patch)
tree864a65b55815fb4b2aa9738d92fe4cafc8299195 /archiva-reports-standard
parent2ae0f74fec8ef399c913b584cbba87b7bf8df053 (diff)
downloadarchiva-90f0dddc4363000f1b854f4fd8f9f3282433f21d.tar.gz
archiva-90f0dddc4363000f1b854f4fd8f9f3282433f21d.zip
[MRM-161] introduce a model for storing reports in the repository, and wire them up on the back of the indexer.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441377 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-reports-standard')
-rwxr-xr-xarchiva-reports-standard/pom.xml34
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReportProcessor.java5
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java72
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactResult.java54
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java99
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java12
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java7
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java95
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java118
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java123
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java47
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessor.java62
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessor.java13
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java100
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/MetadataReportProcessor.java3
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java211
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java53
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStoreException.java (renamed from archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportProcessorException.java)14
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/RepositoryMetadataResult.java55
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/Result.java32
-rw-r--r--archiva-reports-standard/src/main/mdo/reporting.mdo190
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java19
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java123
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java108
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java73
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DefaultArtifactReporterTest.java145
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java117
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DuplicateArtifactFileReportProcessorTest.java37
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessorTest.java32
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessorTest.java85
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom6
31 files changed, 1114 insertions, 1030 deletions
diff --git a/archiva-reports-standard/pom.xml b/archiva-reports-standard/pom.xml
index 6a0bb7183..3ee54d169 100755
--- a/archiva-reports-standard/pom.xml
+++ b/archiva-reports-standard/pom.xml
@@ -66,4 +66,38 @@
<artifactId>archiva-indexer</artifactId>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <version>1.0-alpha-10</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>xpp3-writer</goal>
+ <goal>java</goal>
+ <goal>xpp3-reader</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <version>1.0.0</version>
+ <model>src/main/mdo/reporting.mdo</model>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <configuration>
+ <instrumentation>
+ <!-- exclude generated -->
+ <excludes>
+ <exclude>org/apache/maven/archiva/reporting/model/**</exclude>
+ </excludes>
+ </instrumentation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReportProcessor.java
index 0379626d1..8667821dc 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReportProcessor.java
@@ -17,7 +17,6 @@ package org.apache.maven.archiva.reporting;
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
/**
@@ -28,7 +27,5 @@ public interface ArtifactReportProcessor
{
String ROLE = ArtifactReportProcessor.class.getName();
- void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository )
- throws ReportProcessorException;
-
+ void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter );
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java
deleted file mode 100644
index 471e1b470..000000000
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java
+++ /dev/null
@@ -1,72 +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.artifact.Artifact;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-
-import java.util.Iterator;
-
-/**
- * This interface is used by the single artifact processor.
- * <p/>
- * The initial implementation of this will just need to be a mock implementation in src/test/java, used to track the
- * failures and successes for checking assertions. Later, implementations will be made to present reports on the
- * web interface, send them via mail, and so on.
- *
- * @todo i18n, including message formatting and parameterisation
- */
-public interface ArtifactReporter
-{
- String ROLE = ArtifactReporter.class.getName();
-
- String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository";
-
- String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository";
-
- String DEPENDENCY_INVALID_VERSION = "Artifact's dependency contains an invalid version";
-
- void addFailure( Artifact artifact, String reason );
-
- void addSuccess( Artifact artifact );
-
- void addWarning( Artifact artifact, String message );
-
- void addFailure( RepositoryMetadata metadata, String reason );
-
- void addSuccess( RepositoryMetadata metadata );
-
- void addWarning( RepositoryMetadata metadata, String message );
-
- Iterator getArtifactFailureIterator();
-
- Iterator getArtifactSuccessIterator();
-
- Iterator getArtifactWarningIterator();
-
- Iterator getRepositoryMetadataFailureIterator();
-
- Iterator getRepositoryMetadataSuccessIterator();
-
- Iterator getRepositoryMetadataWarningIterator();
-
- int getNumFailures();
-
- int getNumSuccesses();
-
- int getNumWarnings();
-}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactResult.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactResult.java
deleted file mode 100644
index d3685c29a..000000000
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactResult.java
+++ /dev/null
@@ -1,54 +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.artifact.Artifact;
-
-/**
- * A result of the report for a given artifact being processed.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @version $Id$
- */
-public class ArtifactResult
-{
- private final Artifact artifact;
-
- private final String reason;
-
- public ArtifactResult( Artifact artifact )
- {
- this.artifact = artifact;
- this.reason = null;
- }
-
- public ArtifactResult( Artifact artifact, String reason )
- {
- this.artifact = artifact;
- this.reason = reason;
- }
-
- public Artifact getArtifact()
- {
- return artifact;
- }
-
- public String getReason()
- {
- return reason;
- }
-}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
index 7eab35512..ae22e0a9e 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
@@ -61,23 +61,20 @@ public class BadMetadataReportProcessor
*
* @param metadata the metadata to be processed.
* @param repository the repository where the metadata was encountered
- * @param reporter the ArtifactReporter to receive processing results
- * @throws ReportProcessorException if an error was occurred while processing the metadata
+ * @param reporter the ReportingDatabase to receive processing results
*/
- public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
- throws ReportProcessorException
+ public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
{
- boolean hasFailures = false;
-
if ( metadata.storedInGroupDirectory() )
{
try
{
- hasFailures = checkPluginMetadata( metadata, repository, reporter );
+ checkPluginMetadata( metadata, repository, reporter );
}
catch ( IOException e )
{
- throw new ReportProcessorException( "Error getting plugin artifact directories versions", e );
+ reporter.addWarning( metadata, "Error getting plugin artifact directories versions: " + e );
}
}
else
@@ -86,38 +83,26 @@ public class BadMetadataReportProcessor
if ( lastUpdated == null || lastUpdated.length() == 0 )
{
reporter.addFailure( metadata, "Missing lastUpdated element inside the metadata." );
- hasFailures = true;
}
if ( metadata.storedInArtifactVersionDirectory() )
{
- hasFailures |= checkSnapshotMetadata( metadata, repository, reporter );
+ checkSnapshotMetadata( metadata, repository, reporter );
}
else
{
- if ( !checkMetadataVersions( metadata, repository, reporter ) )
- {
- hasFailures = true;
- }
+ checkMetadataVersions( metadata, repository, reporter );
try
{
- if ( checkRepositoryVersions( metadata, repository, reporter ) )
- {
- hasFailures = true;
- }
+ checkRepositoryVersions( metadata, repository, reporter );
}
catch ( IOException e )
{
- throw new ReportProcessorException( "Error getting versions", e );
+ reporter.addWarning( metadata, "Error getting plugin artifact directories versions: " + e );
}
}
}
-
- if ( !hasFailures )
- {
- reporter.addSuccess( metadata );
- }
}
/**
@@ -125,14 +110,12 @@ public class BadMetadataReportProcessor
*
* @param metadata the metadata to be processed.
* @param repository the repository where the metadata was encountered
- * @param reporter the ArtifactReporter to receive processing results
+ * @param reporter the ReportingDatabase to receive processing results
*/
- private boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
- ArtifactReporter reporter )
+ private void checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
throws IOException
{
- boolean hasFailures = false;
-
File metadataDir =
new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
List pluginDirs = getArtifactIdFiles( metadataDir );
@@ -145,22 +128,20 @@ public class BadMetadataReportProcessor
String artifactId = plugin.getArtifactId();
if ( artifactId == null || artifactId.length() == 0 )
{
- reporter.addFailure( metadata, "Missing or empty artifactId in group metadata." );
- hasFailures = true;
+ reporter.addFailure( metadata,
+ "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 + "." );
- hasFailures = true;
}
else
{
if ( prefixes.containsKey( prefix ) )
{
reporter.addFailure( metadata, "Duplicate plugin prefix found: " + prefix + "." );
- hasFailures = true;
}
else
{
@@ -174,7 +155,6 @@ public class BadMetadataReportProcessor
if ( !pluginDirs.contains( pluginDir ) )
{
reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" );
- hasFailures = true;
}
else
{
@@ -191,10 +171,7 @@ public class BadMetadataReportProcessor
reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " +
"missing in the metadata." );
}
- hasFailures = true;
}
-
- return hasFailures;
}
/**
@@ -202,16 +179,14 @@ public class BadMetadataReportProcessor
*
* @param metadata the metadata to be processed.
* @param repository the repository where the metadata was encountered
- * @param reporter the ArtifactReporter to receive processing results
+ * @param reporter the ReportingDatabase to receive processing results
*/
- private boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
- ArtifactReporter reporter )
+ private void checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
{
RepositoryQueryLayer repositoryQueryLayer =
repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
- boolean hasFailures = false;
-
Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
String version = StringUtils.replace( metadata.getBaseVersion(), Artifact.SNAPSHOT_VERSION,
@@ -223,10 +198,7 @@ public class BadMetadataReportProcessor
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
- hasFailures = true;
}
-
- return hasFailures;
}
/**
@@ -234,15 +206,14 @@ public class BadMetadataReportProcessor
*
* @param metadata the metadata to be processed.
* @param repository the repository where the metadata was encountered
- * @param reporter the ArtifactReporter to receive processing results
+ * @param reporter the ReportingDatabase to receive processing results
*/
- private boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository,
- ArtifactReporter reporter )
+ private void checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
{
RepositoryQueryLayer repositoryQueryLayer =
repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
- boolean hasFailures = false;
Versioning versioning = metadata.getMetadata().getVersioning();
for ( Iterator versions = versioning.getVersions().iterator(); versions.hasNext(); )
{
@@ -255,10 +226,8 @@ public class BadMetadataReportProcessor
{
reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " +
"missing in the repository." );
- hasFailures = true;
}
}
- return hasFailures;
}
/**
@@ -267,13 +236,12 @@ public class BadMetadataReportProcessor
*
* @param metadata the metadata to be processed.
* @param repository the repository where the metadata was encountered
- * @param reporter the ArtifactReporter to receive processing results
+ * @param reporter the ReportingDatabase to receive processing results
*/
- private boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository,
- ArtifactReporter reporter )
+ private void checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
throws IOException
{
- boolean hasFailures = false;
Versioning versioning = metadata.getMetadata().getVersioning();
File versionsDir =
new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
@@ -286,10 +254,8 @@ public class BadMetadataReportProcessor
{
reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " +
"missing in the metadata." );
- hasFailures = true;
}
}
- return hasFailures;
}
/**
@@ -304,17 +270,20 @@ public class BadMetadataReportProcessor
{
List artifactIdFiles = new ArrayList();
- List fileArray = new ArrayList( Arrays.asList( groupIdDir.listFiles() ) );
- for ( Iterator files = fileArray.iterator(); files.hasNext(); )
+ File[] files = groupIdDir.listFiles();
+ if ( files != null )
{
- File artifactDir = (File) files.next();
-
- if ( artifactDir.isDirectory() )
+ for ( Iterator i = Arrays.asList( files ).iterator(); i.hasNext(); )
{
- List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false );
- if ( versions.size() > 0 )
+ File artifactDir = (File) i.next();
+
+ if ( artifactDir.isDirectory() )
{
- artifactIdFiles.add( artifactDir );
+ List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false );
+ if ( versions.size() > 0 )
+ {
+ artifactIdFiles.add( artifactDir );
+ }
}
}
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java
index 896fd35bd..c425cd965 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java
@@ -45,9 +45,10 @@ public class ChecksumArtifactReportProcessor
*/
private Digester md5Digester;
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
+ public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
+ ArtifactRepository repository = artifact.getRepository();
+
if ( !"file".equals( repository.getProtocol() ) )
{
// We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
@@ -59,12 +60,13 @@ public class ChecksumArtifactReportProcessor
String path = repository.pathOf( artifact );
File file = new File( repository.getBasedir(), path );
- verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, artifact );
+ // TODO: make md5 configurable
+// verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, artifact );
verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, artifact );
}
private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester,
- ArtifactReporter reporter, Artifact artifact )
+ ReportingDatabase reporter, Artifact artifact )
{
File checksumFile = new File( repository.getBasedir(), path );
if ( checksumFile.exists() )
@@ -72,8 +74,6 @@ public class ChecksumArtifactReportProcessor
try
{
digester.verify( file, FileUtils.fileRead( checksumFile ) );
-
- reporter.addSuccess( artifact );
}
catch ( DigesterException e )
{
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java
index 18abad1ec..0b41fedb3 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java
@@ -48,7 +48,8 @@ public class ChecksumMetadataReportProcessor
* Validate the checksums of the metadata. Get the metadata file from the
* repository then validate the checksum.
*/
- public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
+ public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ReportingDatabase reporter )
{
if ( !"file".equals( repository.getProtocol() ) )
{
@@ -66,7 +67,7 @@ public class ChecksumMetadataReportProcessor
}
private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester,
- ArtifactReporter reporter, RepositoryMetadata metadata )
+ ReportingDatabase reporter, RepositoryMetadata metadata )
{
File checksumFile = new File( repository.getBasedir(), path );
if ( checksumFile.exists() )
@@ -74,8 +75,6 @@ public class ChecksumMetadataReportProcessor
try
{
digester.verify( file, FileUtils.fileRead( checksumFile ) );
-
- reporter.addSuccess( metadata );
}
catch ( DigesterException e )
{
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java
deleted file mode 100644
index ef926c725..000000000
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java
+++ /dev/null
@@ -1,95 +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.digest.Digester;
-import org.apache.maven.archiva.digest.DigesterException;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-import org.codehaus.plexus.util.FileUtils;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * This class reports invalid and mismatched checksums of artifacts and metadata files.
- * It validates MD5 and SHA-1 checksums.
- *
- * @plexus.component role="org.apache.maven.archiva.reporting.MetadataReportProcessor" role-hint="checksum-metadata"
- */
-public class ChecksumMetadataReporter
- implements MetadataReportProcessor
-{
- /**
- * @plexus.requirement role-hint="sha1"
- */
- private Digester sha1Digester;
-
- /**
- * @plexus.requirement role-hint="md5"
- */
- private Digester md5Digester;
-
- /**
- * Validate the checksums of the metadata. Get the metadata file from the
- * repository then validate the checksum.
- */
- public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
- {
- if ( !"file".equals( repository.getProtocol() ) )
- {
- // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
- throw new UnsupportedOperationException(
- "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
- }
-
- //check if checksum files exist
- String path = repository.pathOfRemoteRepositoryMetadata( metadata );
- File file = new File( repository.getBasedir(), path );
-
- verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, metadata );
- verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, metadata );
- }
-
- private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester,
- ArtifactReporter reporter, RepositoryMetadata metadata )
- {
- File checksumFile = new File( repository.getBasedir(), path );
- if ( checksumFile.exists() )
- {
- try
- {
- digester.verify( file, FileUtils.fileRead( checksumFile ) );
-
- reporter.addSuccess( metadata );
- }
- catch ( DigesterException e )
- {
- reporter.addFailure( metadata, e.getMessage() );
- }
- catch ( IOException e )
- {
- reporter.addFailure( metadata, "Read file error: " + e.getMessage() );
- }
- }
- else
- {
- reporter.addFailure( metadata, digester.getAlgorithm() + " checksum file does not exist." );
- }
- }
-
-}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java
deleted file mode 100644
index 7c10eb4e6..000000000
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java
+++ /dev/null
@@ -1,118 +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.artifact.Artifact;
-import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReporter"
- */
-public class DefaultArtifactReporter
- implements ArtifactReporter
-{
- private List artifactFailures = new ArrayList();
-
- private List artifactSuccesses = new ArrayList();
-
- private List artifactWarnings = new ArrayList();
-
- private List metadataFailures = new ArrayList();
-
- private List metadataSuccesses = new ArrayList();
-
- private List metadataWarnings = new ArrayList();
-
- public void addFailure( Artifact artifact, String reason )
- {
- artifactFailures.add( new ArtifactResult( artifact, reason ) );
- }
-
- public void addSuccess( Artifact artifact )
- {
- artifactSuccesses.add( new ArtifactResult( artifact ) );
- }
-
- public void addWarning( Artifact artifact, String message )
- {
- artifactWarnings.add( new ArtifactResult( artifact, message ) );
- }
-
- public void addFailure( RepositoryMetadata metadata, String reason )
- {
- metadataFailures.add( new RepositoryMetadataResult( metadata, reason ) );
- }
-
- public void addSuccess( RepositoryMetadata metadata )
- {
- metadataSuccesses.add( new RepositoryMetadataResult( metadata ) );
- }
-
- public void addWarning( RepositoryMetadata metadata, String message )
- {
- metadataWarnings.add( new RepositoryMetadataResult( metadata, message ) );
- }
-
- public Iterator getArtifactFailureIterator()
- {
- return artifactFailures.iterator();
- }
-
- public Iterator getArtifactSuccessIterator()
- {
- return artifactSuccesses.iterator();
- }
-
- public Iterator getArtifactWarningIterator()
- {
- return artifactWarnings.iterator();
- }
-
- public Iterator getRepositoryMetadataFailureIterator()
- {
- return metadataFailures.iterator();
- }
-
- public Iterator getRepositoryMetadataSuccessIterator()
- {
- return metadataSuccesses.iterator();
- }
-
- public Iterator getRepositoryMetadataWarningIterator()
- {
- return metadataWarnings.iterator();
- }
-
- public int getNumFailures()
- {
- return artifactFailures.size() + metadataFailures.size();
- }
-
- public int getNumSuccesses()
- {
- return artifactSuccesses.size() + metadataSuccesses.size();
- }
-
- public int getNumWarnings()
- {
- return artifactWarnings.size() + metadataWarnings.size();
- }
-}
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
new file mode 100644
index 000000000..d9495308f
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultReportingStore.java
@@ -0,0 +1,123 @@
+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.io.xpp3.ReportingXpp3Reader;
+import org.apache.maven.archiva.reporting.model.io.xpp3.ReportingXpp3Writer;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+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.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Load and store the reports. No synchronization is used, but it is unnecessary as the old object
+ * can continue to be used.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo would be great for plexus to do this for us - so the configuration would be a component itself rather than this store
+ * @todo support other implementations than XML file
+ * @plexus.component
+ */
+public class DefaultReportingStore
+ extends AbstractLogEnabled
+ implements ReportingStore
+{
+ /**
+ * The cached reports for given repositories.
+ */
+ private Map/*<ArtifactRepository,ReportingDatabase>*/ reports = new HashMap();
+
+ public ReportingDatabase getReportsFromStore( ArtifactRepository repository )
+ throws ReportingStoreException
+ {
+ ReportingDatabase database = (ReportingDatabase) reports.get( repository );
+
+ if ( database == null )
+ {
+ ReportingXpp3Reader reader = new ReportingXpp3Reader();
+
+ File file = new File( repository.getBasedir(), "report-database.xml" );
+
+ FileReader fileReader = null;
+ try
+ {
+ fileReader = new FileReader( file );
+ }
+ catch ( FileNotFoundException e )
+ {
+ database = new ReportingDatabase();
+ }
+
+ if ( database == null )
+ {
+ getLogger().info( "Reading report database from " + file );
+ try
+ {
+ database = new ReportingDatabase( reader.read( fileReader, false ) );
+ }
+ catch ( IOException e )
+ {
+ throw new ReportingStoreException( e.getMessage(), e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new ReportingStoreException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( fileReader );
+ }
+ }
+
+ reports.put( repository, database );
+ }
+ return database;
+ }
+
+ public void storeReports( ReportingDatabase database, ArtifactRepository repository )
+ throws ReportingStoreException
+ {
+ ReportingXpp3Writer writer = new ReportingXpp3Writer();
+
+ File file = new File( repository.getBasedir(), "report-database.xml" );
+ getLogger().info( "Writing reports to " + file );
+ FileWriter fileWriter = null;
+ try
+ {
+ file.getParentFile().mkdirs();
+
+ fileWriter = new FileWriter( file );
+ writer.write( fileWriter, database.getReporting() );
+ }
+ catch ( IOException e )
+ {
+ throw new ReportingStoreException( e.getMessage(), e );
+ }
+ finally
+ {
+ IOUtil.close( fileWriter );
+ }
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java
index ded3d586d..851bbd902 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java
@@ -20,12 +20,12 @@ import org.apache.maven.archiva.layer.RepositoryQueryLayer;
import org.apache.maven.archiva.layer.RepositoryQueryLayerFactory;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
+import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;
@@ -45,31 +45,29 @@ public class DependencyArtifactReportProcessor
*/
private RepositoryQueryLayerFactory layerFactory;
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
+ public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
- RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository );
+ RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( artifact.getRepository() );
processArtifact( artifact, reporter, queryLayer );
- List dependencies = model.getDependencies();
- processDependencies( dependencies, reporter, queryLayer );
+ if ( model != null )
+ {
+ List dependencies = model.getDependencies();
+ processDependencies( dependencies, reporter, queryLayer, artifact );
+ }
}
- private void processArtifact( Artifact artifact, ArtifactReporter reporter,
+ private void processArtifact( Artifact artifact, ReportingDatabase reporter,
RepositoryQueryLayer repositoryQueryLayer )
{
- if ( repositoryQueryLayer.containsArtifact( artifact ) )
- {
- reporter.addSuccess( artifact );
- }
- else
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
- reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
+ reporter.addFailure( artifact, "Artifact does not exist in the repository" );
}
}
- private void processDependencies( List dependencies, ArtifactReporter reporter,
- RepositoryQueryLayer repositoryQueryLayer )
+ private void processDependencies( List dependencies, ReportingDatabase reporter,
+ RepositoryQueryLayer repositoryQueryLayer, Artifact sourceArtifact )
{
if ( dependencies.size() > 0 )
{
@@ -78,23 +76,24 @@ public class DependencyArtifactReportProcessor
{
Dependency dependency = (Dependency) iterator.next();
- Artifact artifact = null;
try
{
- artifact = createArtifact( dependency );
+ Artifact artifact = createArtifact( dependency );
- if ( repositoryQueryLayer.containsArtifact( artifact ) )
- {
- reporter.addSuccess( artifact );
- }
- else
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
- reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
+ String reason = MessageFormat.format(
+ "Artifact''s dependency {0} does not exist in the repository",
+ new String[]{dependency.toString()} );
+ reporter.addFailure( sourceArtifact, reason );
}
}
catch ( InvalidVersionSpecificationException e )
{
- reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION );
+ String reason = MessageFormat.format( "Artifact''s dependency {0} contains an invalid version {1}",
+ new String[]{dependency.toString(),
+ dependency.getVersion()} );
+ reporter.addFailure( sourceArtifact, reason );
}
}
}
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 3cf8aba9a..344586090 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
@@ -58,62 +58,54 @@ public class DuplicateArtifactFileReportProcessor
*/
private String indexDirectory;
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
- throws ReportProcessorException
+ public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
- if ( artifact.getFile() != null )
+ ArtifactRepository repository = artifact.getRepository();
+ // TODO! always null currently, need to configure this properly
+ if ( artifact.getFile() != null && indexDirectory != null )
{
RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) );
- String checksum;
+ String checksum = null;
try
{
checksum = digester.calc( artifact.getFile() );
}
catch ( DigesterException e )
{
- throw new ReportProcessorException( "Failed to generate checksum", e );
+ reporter.addWarning( artifact, "Unable to generate checksum for " + artifact.getFile() + ": " + e );
}
- try
+ if ( checksum != null )
{
- List results = index.search( new LuceneQuery(
- new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
-
- if ( results.isEmpty() )
- {
- reporter.addSuccess( artifact );
- }
- else
+ try
{
- boolean hasDuplicates = false;
- for ( Iterator i = results.iterator(); i.hasNext(); )
- {
- StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+ List results = index.search( new LuceneQuery(
+ new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
- //make sure it is not the same artifact
- if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
+ if ( !results.isEmpty() )
+ {
+ for ( Iterator i = results.iterator(); i.hasNext(); )
{
- //report only duplicates from the same groupId
- String groupId = artifact.getGroupId();
- if ( groupId.equals( result.getGroupId() ) )
+ StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+
+ //make sure it is not the same artifact
+ if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
{
- hasDuplicates = true;
- reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+ //report only duplicates from the same groupId
+ String groupId = artifact.getGroupId();
+ if ( groupId.equals( result.getGroupId() ) )
+ {
+ reporter.addFailure( artifact, "Found duplicate for " + artifact.getId() );
+ }
}
}
}
-
- if ( !hasDuplicates )
- {
- reporter.addSuccess( artifact );
- }
}
- }
- catch ( RepositoryIndexSearchException e )
- {
- throw new ReportProcessorException( "Failed to search in index", e );
+ catch ( RepositoryIndexSearchException e )
+ {
+ reporter.addWarning( artifact, "Failed to search in index" + e );
+ }
}
}
else
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessor.java
index eeb5a6b4b..716b182f4 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/InvalidPomArtifactReportProcessor.java
@@ -38,14 +38,13 @@ public class InvalidPomArtifactReportProcessor
implements ArtifactReportProcessor
{
/**
- * @param model
- * @param artifact The pom xml file to be validated, passed as an artifact object.
- * @param reporter The artifact reporter object.
- * @param repository the repository where the artifact is located.
+ * @param artifact The pom xml file to be validated, passed as an artifact object.
+ * @param reporter The artifact reporter object.
*/
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
+ public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
+ ArtifactRepository repository = artifact.getRepository();
+
if ( !"file".equals( repository.getProtocol() ) )
{
// We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
@@ -71,7 +70,6 @@ public class InvalidPomArtifactReportProcessor
{
reader = new FileReader( f );
pomReader.read( reader );
- reporter.addSuccess( artifact );
}
catch ( XmlPullParserException e )
{
@@ -97,5 +95,4 @@ public class InvalidPomArtifactReportProcessor
reporter.addWarning( artifact, "The artifact is not a pom xml file." );
}
}
-
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java
index 311e6d218..a7121138e 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/LocationArtifactReportProcessor.java
@@ -21,6 +21,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -29,6 +30,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -47,6 +51,15 @@ public class LocationArtifactReportProcessor
*/
private ArtifactFactory artifactFactory;
+ // TODO: share with other code with the same
+ private static final Set JAR_FILE_TYPES =
+ new HashSet( Arrays.asList( new String[]{"jar", "war", "par", "ejb", "ear", "rar", "sar"} ) );
+
+ /**
+ * @plexus.requirement
+ */
+ private MavenProjectBuilder projectBuilder;
+
/**
* 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
@@ -54,16 +67,11 @@ public class LocationArtifactReportProcessor
* included in the package. If a model exists inside the package, then check if the artifact's
* location is valid based on the location specified in the pom. Check if the both the location
* specified in the file system pom and in the pom included in the package is the same.
- *
- * @param model Represents the pom in the file system.
- * @param artifact
- * @param reporter
- * @param repository
*/
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
- throws ReportProcessorException
+ public void processArtifact( Artifact artifact, Model model, ReportingDatabase reporter )
{
+ ArtifactRepository repository = artifact.getRepository();
+
if ( !"file".equals( repository.getProtocol() ) )
{
// We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
@@ -71,24 +79,33 @@ public class LocationArtifactReportProcessor
"Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
}
- //check if the artifact is located in its proper location based on the info
- //specified in the model object/pom
- Artifact modelArtifact = artifactFactory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
- model.getVersion(), model.getPackaging() );
-
- boolean failed = false;
- String modelPath = repository.pathOf( modelArtifact );
String artifactPath = repository.pathOf( artifact );
- if ( modelPath.equals( artifactPath ) )
+
+ if ( model != null )
{
- //get the location of the artifact itself
- File file = new File( repository.getBasedir(), artifactPath );
+ //check if the artifact is located in its proper location based on the info
+ //specified in the model object/pom
+ Artifact modelArtifact = artifactFactory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
+ model.getVersion(), model.getPackaging() );
+
+ 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." );
+ }
+ }
+
+ //get the location of the artifact itself
+ File file = new File( repository.getBasedir(), artifactPath );
- if ( file.exists() )
+ if ( file.exists() )
+ {
+ if ( JAR_FILE_TYPES.contains( artifact.getType() ) )
{
//unpack the artifact (using the groupId, artifactId & version specified in the artifact object itself
//check if the pom is included in the package
- Model extractedModel = readArtifactModel( file, artifact.getGroupId(), artifact.getArtifactId() );
+ Model extractedModel = readArtifactModel( file, artifact, reporter );
if ( extractedModel != null )
{
@@ -100,39 +117,18 @@ public class LocationArtifactReportProcessor
{
reporter.addFailure( artifact,
"The artifact is out of place. It does not match the specified location in the packaged pom." );
- failed = true;
}
}
}
- else
- {
- reporter.addFailure( artifact,
- "The artifact is out of place. It does not exist at the specified location in the repository pom." );
- failed = true;
- }
}
else
{
reporter.addFailure( artifact,
- "The artifact is out of place. It does not match the specified location in the repository pom." );
- failed = true;
- }
-
- if ( !failed )
- {
- reporter.addSuccess( artifact );
+ "The artifact is out of place. It does not exist at the specified location in the repository pom." );
}
}
- /**
- * Extract the contents of the artifact/jar file.
- *
- * @param file
- * @param groupId
- * @param artifactId
- */
- private Model readArtifactModel( File file, String groupId, String artifactId )
- throws ReportProcessorException
+ private Model readArtifactModel( File file, Artifact artifact, ReportingDatabase reporter )
{
Model model = null;
@@ -142,23 +138,31 @@ public class LocationArtifactReportProcessor
jar = new JarFile( file );
//Get the entry and its input stream.
- JarEntry entry = jar.getJarEntry( "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
+ JarEntry entry = jar.getJarEntry(
+ "META-INF/maven/" + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/pom.xml" );
// If the entry is not null, extract it.
if ( entry != null )
{
model = readModel( jar.getInputStream( entry ) );
+
+ if ( model.getGroupId() == null )
+ {
+ model.setGroupId( model.getParent().getGroupId() );
+ }
+ if ( model.getVersion() == null )
+ {
+ model.setVersion( model.getParent().getVersion() );
+ }
}
}
catch ( IOException e )
{
- // TODO: should just warn and continue!
- throw new ReportProcessorException( "Unable to read artifact to extract model", e );
+ reporter.addWarning( artifact, "Unable to read artifact to extract model: " + e );
}
catch ( XmlPullParserException e )
{
- // TODO: should just warn and continue!
- throw new ReportProcessorException( "Unable to read artifact to extract model", e );
+ reporter.addWarning( artifact, "Unable to parse extracted model: " + e );
}
finally
{
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/MetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/MetadataReportProcessor.java
index 712cb260e..d043a26ef 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/MetadataReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/MetadataReportProcessor.java
@@ -26,6 +26,5 @@ public interface MetadataReportProcessor
{
String ROLE = MetadataReportProcessor.class.getName();
- void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
- throws ReportProcessorException;
+ void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ReportingDatabase reporter );
}
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
new file mode 100644
index 000000000..0b17f1ab5
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingDatabase.java
@@ -0,0 +1,211 @@
+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.MetadataResults;
+import org.apache.maven.archiva.reporting.model.Reporting;
+import org.apache.maven.archiva.reporting.model.Result;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @todo i18n, including message formatting and parameterisation
+ */
+public class ReportingDatabase
+{
+ private final Reporting reporting;
+
+ private Map artifactMap;
+
+ private Map metadataMap;
+
+ private int totalFailures;
+
+ private int totalWarnings;
+
+ public ReportingDatabase()
+ {
+ reporting = new Reporting();
+ }
+
+ public ReportingDatabase( Reporting reporting )
+ {
+ this.reporting = reporting;
+ }
+
+ public void addFailure( Artifact artifact, String reason )
+ {
+ ArtifactResults results = getArtifactResults( artifact );
+ results.addFailure( createResults( reason ) );
+ totalFailures++;
+ }
+
+ public void addWarning( Artifact artifact, String reason )
+ {
+ ArtifactResults results = getArtifactResults( artifact );
+ results.addWarning( createResults( reason ) );
+ totalWarnings++;
+ }
+
+ private ArtifactResults getArtifactResults( Artifact artifact )
+ {
+ Map artifactMap = getArtifactMap();
+
+ String key = getArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
+ artifact.getType(), artifact.getClassifier() );
+ 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() );
+
+ artifactMap.put( key, results );
+ reporting.getArtifacts().add( results );
+ }
+
+ return results;
+ }
+
+ private Map getArtifactMap()
+ {
+ if ( artifactMap == null )
+ {
+ Map map = new HashMap();
+ for ( Iterator i = reporting.getArtifacts().iterator(); i.hasNext(); )
+ {
+ ArtifactResults result = (ArtifactResults) i.next();
+
+ String key = getArtifactKey( result.getGroupId(), result.getArtifactId(), result.getVersion(),
+ result.getType(), result.getClassifier() );
+ map.put( key, result );
+
+ totalFailures += result.getFailures().size();
+ totalWarnings += result.getWarnings().size();
+ }
+ artifactMap = map;
+ }
+ return artifactMap;
+ }
+
+ private static String getArtifactKey( String groupId, String artifactId, String version, String type,
+ String classifier )
+ {
+ return groupId + ":" + artifactId + ":" + version + ":" + type + ":" + classifier;
+ }
+
+ private static Result createResults( String reason )
+ {
+ Result result = new Result();
+ result.setReason( reason );
+ return result;
+ }
+
+ public void addFailure( RepositoryMetadata metadata, String reason )
+ {
+ MetadataResults results = getMetadataResults( metadata );
+ results.addFailure( createResults( reason ) );
+ totalFailures++;
+ }
+
+ public void addWarning( RepositoryMetadata metadata, String reason )
+ {
+ MetadataResults results = getMetadataResults( metadata );
+ results.addWarning( createResults( reason ) );
+ totalWarnings++;
+ }
+
+ private MetadataResults getMetadataResults( RepositoryMetadata metadata )
+ {
+ Map metadataMap = getMetadataMap();
+
+ String key = getMetadataKey( metadata.getGroupId(), metadata.getArtifactId(), metadata.getBaseVersion() );
+
+ MetadataResults results = (MetadataResults) metadataMap.get( key );
+ if ( results == null )
+ {
+ results = new MetadataResults();
+ results.setArtifactId( metadata.getArtifactId() );
+ results.setGroupId( metadata.getGroupId() );
+ results.setVersion( metadata.getBaseVersion() );
+
+ metadataMap.put( key, results );
+ reporting.getMetadata().add( results );
+ }
+
+ return results;
+ }
+
+ private Map getMetadataMap()
+ {
+ if ( metadataMap == null )
+ {
+ Map map = new HashMap();
+ for ( Iterator i = reporting.getMetadata().iterator(); i.hasNext(); )
+ {
+ MetadataResults result = (MetadataResults) i.next();
+
+ String key = getMetadataKey( result.getGroupId(), result.getArtifactId(), result.getVersion() );
+
+ map.put( key, result );
+
+ totalFailures += result.getFailures().size();
+ totalWarnings += result.getWarnings().size();
+ }
+ metadataMap = map;
+ }
+ return metadataMap;
+ }
+
+ private static String getMetadataKey( String groupId, String artifactId, String version )
+ {
+ return groupId + ":" + artifactId + ":" + version;
+ }
+
+ public int getNumFailures()
+ {
+ return totalFailures;
+ }
+
+ public int getNumWarnings()
+ {
+ return totalWarnings;
+ }
+
+ public Reporting getReporting()
+ {
+ return reporting;
+ }
+
+ public Iterator getArtifactIterator()
+ {
+ return reporting.getArtifacts().iterator();
+ }
+
+ public Iterator getMetadataIterator()
+ {
+ return reporting.getMetadata().iterator();
+ }
+}
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
new file mode 100644
index 000000000..2f9e71225
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStore.java
@@ -0,0 +1,53 @@
+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.repository.ArtifactRepository;
+
+/**
+ * A component for loading the reporting database into the model.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo this is something that could possibly be generalised into Modello.
+ */
+public interface ReportingStore
+{
+ /**
+ * The Plexus role for the component.
+ */
+ String ROLE = ReportingStore.class.getName();
+
+ /**
+ * Get the reports from the store. A cached version may be used.
+ *
+ * @param repository the repository to load the reports for
+ * @return the reporting database
+ * @throws ReportingStoreException if there was a problem reading the store
+ */
+ ReportingDatabase getReportsFromStore( ArtifactRepository repository )
+ throws ReportingStoreException;
+
+ /**
+ * Save the reporting to the store.
+ *
+ * @param database the reports to store
+ * @param repository the repositorry to store the reports in
+ * @throws ReportingStoreException if there was a problem writing the store
+ */
+ void storeReports( ReportingDatabase database, ArtifactRepository repository )
+ throws ReportingStoreException;
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportProcessorException.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStoreException.java
index 783f888c6..5e797e46b 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportProcessorException.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ReportingStoreException.java
@@ -17,16 +17,20 @@ package org.apache.maven.archiva.reporting;
*/
/**
- * Exception occurring during reporting.
+ * Exception occurring using the reporting store.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @version $Id$
*/
-public class ReportProcessorException
+public class ReportingStoreException
extends Exception
{
- public ReportProcessorException( String msg, Throwable cause )
+ public ReportingStoreException( String message )
{
- super( msg, cause );
+ super( message );
+ }
+
+ public ReportingStoreException( String message, Throwable e )
+ {
+ super( message, e );
}
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/RepositoryMetadataResult.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/RepositoryMetadataResult.java
deleted file mode 100644
index a3c13d844..000000000
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/RepositoryMetadataResult.java
+++ /dev/null
@@ -1,55 +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.artifact.repository.metadata.RepositoryMetadata;
-
-/**
- * A result of the report for a given artifact being processed.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @version $Id:RepositoryMetadataResult.java 437105 2006-08-26 17:22:22 +1000 (Sat, 26 Aug 2006) brett $
- */
-public class RepositoryMetadataResult
- implements Result
-{
- private final RepositoryMetadata metadata;
-
- private final String reason;
-
- public RepositoryMetadataResult( RepositoryMetadata metadata )
- {
- this.metadata = metadata;
- this.reason = null;
- }
-
- public RepositoryMetadataResult( RepositoryMetadata metadata, String reason )
- {
- this.metadata = metadata;
- this.reason = reason;
- }
-
- public RepositoryMetadata getMetadata()
- {
- return metadata;
- }
-
- public String getReason()
- {
- return reason;
- }
-}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/Result.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/Result.java
deleted file mode 100644
index 544113409..000000000
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/Result.java
+++ /dev/null
@@ -1,32 +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.
- */
-
-/**
- * A result record during the reporting.
- *
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- */
-public interface Result
-{
- /**
- * The reason given for the result.
- *
- * @return the message
- */
- String getReason();
-}
diff --git a/archiva-reports-standard/src/main/mdo/reporting.mdo b/archiva-reports-standard/src/main/mdo/reporting.mdo
new file mode 100644
index 000000000..84c8f4011
--- /dev/null
+++ b/archiva-reports-standard/src/main/mdo/reporting.mdo
@@ -0,0 +1,190 @@
+<!--
+ ~ 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.
+ -->
+
+<model>
+ <id>reporting</id>
+ <name>Reporting</name>
+ <description>
+ Storage database for reporting results in the repository.
+ </description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.maven.archiva.reporting.model</value>
+ </default>
+ </defaults>
+ <classes>
+ <class rootElement="true" xml.tagName="reporting">
+ <name>Reporting</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>artifacts</name>
+ <version>1.0.0</version>
+ <association>
+ <type>ArtifactResults</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>metadata</name>
+ <version>1.0.0</version>
+ <association>
+ <type>MetadataResults</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>ArtifactResults</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>failures</name>
+ <version>1.0.0</version>
+ <association>
+ <type>Result</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>warnings</name>
+ <version>1.0.0</version>
+ <association>
+ <type>Result</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field xml.attribute="true">
+ <name>groupId</name>
+ <identity>true</identity>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The group ID of the artifact in the result.
+ </description>
+ </field>
+ <field xml.attribute="true">
+ <name>artifactId</name>
+ <version>1.0.0</version>
+ <identity>true</identity>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The artifact ID of the artifact in the result.
+ </description>
+ </field>
+ <field xml.attribute="true">
+ <name>version</name>
+ <version>1.0.0</version>
+ <identity>true</identity>
+ <type>String</type>
+ <required>true</required>
+ <description>
+ The version of the artifact in the result.
+ </description>
+ </field>
+ <field xml.attribute="true">
+ <name>type</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <identity>true</identity>
+ <required>true</required>
+ <description>
+ The type of the artifact in the result.
+ </description>
+ </field>
+ <field xml.attribute="true">
+ <name>classifier</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <identity>true</identity>
+ <description>
+ The classifier of the artifact in the result.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>MetadataResults</name>
+ <version>1.0.0</version>
+ <fields>
+ <field>
+ <name>failures</name>
+ <version>1.0.0</version>
+ <association>
+ <type>Result</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field>
+ <name>warnings</name>
+ <version>1.0.0</version>
+ <association>
+ <type>Result</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ <field xml.attribute="true">
+ <name>groupId</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <required>true</required>
+ <identity>true</identity>
+ <description>
+ The group ID of the metadata in the result.
+ </description>
+ </field>
+ <field xml.attribute="true">
+ <name>artifactId</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <identity>true</identity>
+ <description>
+ The artifact ID of the metadata in the result.
+ </description>
+ </field>
+ <field xml.attribute="true">
+ <name>version</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <identity>true</identity>
+ <description>
+ The version of the metadata in the result.
+ </description>
+ </field>
+ </fields>
+ </class>
+ <class>
+ <name>Result</name>
+ <version>1.0.0</version>
+ <fields>
+ <field xml.attribute="true">
+ <name>reason</name>
+ <version>1.0.0</version>
+ <type>String</type>
+ <description>
+ The reason given for the result.
+ </description>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
+
+
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java
index 9c88157fd..e2dcff0e4 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryReportsTestCase.java
@@ -16,6 +16,8 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
@@ -24,7 +26,7 @@ import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
/**
- *
+ *
*/
public abstract class AbstractRepositoryReportsTestCase
extends PlexusTestCase
@@ -34,6 +36,8 @@ public abstract class AbstractRepositoryReportsTestCase
*/
protected ArtifactRepository repository;
+ private ArtifactFactory artifactFactory;
+
protected void setUp()
throws Exception
{
@@ -45,6 +49,19 @@ public abstract class AbstractRepositoryReportsTestCase
repository = factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout,
null, null );
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ }
+
+ protected Artifact createArtifact( String groupId, String artifactId, String version )
+ {
+ return createArtifact( groupId, artifactId, version, "jar" );
+ }
+
+ protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
+ {
+ Artifact artifact = artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
+ artifact.setRepository( repository );
+ return artifact;
}
}
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 71bcffca3..f8ea2d3ce 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
@@ -16,10 +16,11 @@ package org.apache.maven.archiva.reporting;
* 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 org.apache.maven.model.Model;
import java.util.Iterator;
@@ -29,66 +30,36 @@ import java.util.Iterator;
public class ArtifactReporterTest
extends AbstractRepositoryReportsTestCase
{
- private ArtifactReporter reporter;
+ private ReportingDatabase reporter;
private Artifact artifact;
- private Model model;
-
protected void setUp()
throws Exception
{
super.setUp();
- reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
+ 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" );
- model = new Model();
}
- public void testArtifactReporterSingleSuccess()
+ public void testArtifactReporterSingleFailure()
{
- reporter.addSuccess( artifact );
-
- assertEquals( 1, reporter.getNumSuccesses() );
+ reporter.addFailure( artifact, "failed once" );
- Iterator success = reporter.getArtifactSuccessIterator();
- assertTrue( success.hasNext() );
- Artifact result = ( (ArtifactResult) success.next() ).getArtifact();
- assertEquals( "groupId", result.getGroupId() );
- assertEquals( "artifactId", result.getArtifactId() );
- assertEquals( "1.0-alpha-1", result.getVersion() );
- assertFalse( success.hasNext() );
- }
+ Iterator artifactIterator = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) artifactIterator.next();
+ assertFalse( artifactIterator.hasNext() );
- public void testArtifactReporterMultipleSuccess()
- {
- reporter.addSuccess( artifact );
- reporter.addSuccess( artifact );
- reporter.addSuccess( artifact );
- Iterator success = reporter.getArtifactSuccessIterator();
- assertTrue( success.hasNext() );
- int i;
- for ( i = 0; success.hasNext(); i++ )
+ int count = 0;
+ for ( Iterator i = results.getFailures().iterator(); i.hasNext(); count++ )
{
- success.next();
+ i.next();
}
- assertEquals( 3, i );
- assertEquals( 3, reporter.getNumSuccesses() );
- assertEquals( 0, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
- }
-
- public void testArtifactReporterSingleFailure()
- {
- reporter.addFailure( artifact, "failed once" );
- Iterator failure = reporter.getArtifactFailureIterator();
- assertTrue( failure.hasNext() );
- failure.next();
- assertFalse( failure.hasNext() );
- assertEquals( 0, reporter.getNumSuccesses() );
+ assertEquals( 1, count );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
@@ -98,15 +69,17 @@ public class ArtifactReporterTest
reporter.addFailure( artifact, "failed once" );
reporter.addFailure( artifact, "failed twice" );
reporter.addFailure( artifact, "failed thrice" );
- Iterator failure = reporter.getArtifactFailureIterator();
- assertTrue( failure.hasNext() );
- int i;
- for ( i = 0; failure.hasNext(); i++ )
+
+ Iterator artifactIterator = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) artifactIterator.next();
+ assertFalse( artifactIterator.hasNext() );
+
+ int count = 0;
+ for ( Iterator i = results.getFailures().iterator(); i.hasNext(); count++ )
{
- failure.next();
+ i.next();
}
- assertEquals( 3, i );
- assertEquals( 0, reporter.getNumSuccesses() );
+ assertEquals( 3, count );
assertEquals( 3, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
@@ -116,20 +89,28 @@ public class ArtifactReporterTest
reporter.addFailure( artifact, "failed once" );
reporter.addFailure( artifact, "failed twice" );
reporter.addFailure( artifact, "failed thrice" );
- Iterator failure = reporter.getArtifactFailureIterator();
- assertEquals( "failed once", ( (ArtifactResult) failure.next() ).getReason() );
- assertEquals( "failed twice", ( (ArtifactResult) failure.next() ).getReason() );
- assertEquals( "failed thrice", ( (ArtifactResult) failure.next() ).getReason() );
+ Iterator artifactIterator = reporter.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()
{
reporter.addWarning( artifact, "you've been warned" );
- Iterator warning = reporter.getArtifactWarningIterator();
- assertTrue( warning.hasNext() );
- warning.next();
- assertFalse( warning.hasNext() );
- assertEquals( 0, reporter.getNumSuccesses() );
+ Iterator artifactIterator = reporter.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, reporter.getNumFailures() );
assertEquals( 1, reporter.getNumWarnings() );
}
@@ -140,15 +121,16 @@ public class ArtifactReporterTest
reporter.addWarning( artifact, "you have to stop now" );
reporter.addWarning( artifact, "all right... that does it!" );
- Iterator warning = reporter.getArtifactWarningIterator();
- assertTrue( warning.hasNext() );
- int i;
- for ( i = 0; warning.hasNext(); i++ )
+ Iterator artifactIterator = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) artifactIterator.next();
+ assertFalse( artifactIterator.hasNext() );
+
+ int count = 0;
+ for ( Iterator i = results.getWarnings().iterator(); i.hasNext(); count++ )
{
- warning.next();
+ i.next();
}
- assertEquals( 3, i );
- assertEquals( 0, reporter.getNumSuccesses() );
+ assertEquals( 3, count );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 3, reporter.getNumWarnings() );
}
@@ -159,9 +141,12 @@ public class ArtifactReporterTest
reporter.addWarning( artifact, "you have to stop now" );
reporter.addWarning( artifact, "all right... that does it!" );
- Iterator warning = reporter.getArtifactWarningIterator();
- assertEquals( "i'm warning you", ( (ArtifactResult) warning.next() ).getReason() );
- assertEquals( "you have to stop now", ( (ArtifactResult) warning.next() ).getReason() );
- assertEquals( "all right... that does it!", ( (ArtifactResult) warning.next() ).getReason() );
+ Iterator artifactIterator = reporter.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() );
}
}
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 79636c6f1..49ebe469a 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
@@ -16,6 +16,8 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
+import org.apache.maven.archiva.reporting.model.MetadataResults;
+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.ArtifactRepositoryMetadata;
@@ -35,7 +37,7 @@ public class BadMetadataReportProcessorTest
private MetadataReportProcessor badMetadataReportProcessor;
- private ArtifactReporter reporter = new DefaultArtifactReporter();
+ private ReportingDatabase reporter = new ReportingDatabase();
protected void setUp()
throws Exception
@@ -48,7 +50,6 @@ public class BadMetadataReportProcessorTest
}
public void testMetadataMissingLastUpdated()
- throws ReportProcessorException
{
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
@@ -60,16 +61,18 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
assertTrue( "check there is a failure", failures.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
- assertEquals( "check metadata", metadata, result.getMetadata() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ Result result = (Result) failures.next();
+ assertMetadata( metadata, results );
assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() );
assertFalse( "check no more failures", failures.hasNext() );
}
public void testMetadataValidVersions()
- throws ReportProcessorException
{
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
@@ -82,12 +85,11 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
assertFalse( "check there are no failures", failures.hasNext() );
}
public void testMetadataMissingADirectory()
- throws ReportProcessorException
{
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
@@ -99,10 +101,13 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
- assertEquals( "check metadata", metadata, result.getMetadata() );
+ Result result = (Result) failures.next();
+ assertMetadata( metadata, results );
// TODO: should be more robust
assertEquals( "check reason",
"Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.",
@@ -111,7 +116,6 @@ public class BadMetadataReportProcessorTest
}
public void testMetadataInvalidArtifactVersion()
- throws ReportProcessorException
{
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
@@ -125,10 +129,13 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
- assertEquals( "check metadata", metadata, result.getMetadata() );
+ Result result = (Result) failures.next();
+ assertMetadata( metadata, results );
// TODO: should be more robust
assertEquals( "check reason",
"Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.",
@@ -137,7 +144,6 @@ public class BadMetadataReportProcessorTest
}
public void testMoreThanOneMetadataVersionErrors()
- throws ReportProcessorException
{
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
@@ -150,16 +156,19 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
assertTrue( "check there is a failure", failures.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
- assertEquals( "check metadata", metadata, result.getMetadata() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ Result result = (Result) failures.next();
+ assertMetadata( metadata, results );
// TODO: should be more robust
assertEquals( "check reason",
"Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.",
result.getReason() );
assertTrue( "check there is a 2nd failure", failures.hasNext() );
- result = (RepositoryMetadataResult) failures.next();
+ result = (Result) failures.next();
// TODO: should be more robust
assertEquals( "check reason",
"Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.",
@@ -168,7 +177,6 @@ public class BadMetadataReportProcessorTest
}
public void testValidPluginMetadata()
- throws ReportProcessorException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
@@ -176,12 +184,11 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
assertFalse( "check there are no failures", failures.hasNext() );
}
public void testMissingMetadataPlugin()
- throws ReportProcessorException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
@@ -190,7 +197,10 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
Result result = (Result) failures.next();
// TODO: should be more robust
@@ -200,14 +210,16 @@ public class BadMetadataReportProcessorTest
}
public void testIncompletePluginMetadata()
- throws ReportProcessorException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
Result result = (Result) failures.next();
// TODO: should be more robust
@@ -218,7 +230,6 @@ public class BadMetadataReportProcessorTest
}
public void testInvalidPluginArtifactId()
- throws ReportProcessorException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
@@ -228,20 +239,24 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
Result result = (Result) failures.next();
// TODO: should be more robust
- assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() );
+ assertEquals( "check reason", "Missing or empty artifactId in group metadata for plugin default3",
+ result.getReason() );
assertTrue( "check there is a 2nd failure", failures.hasNext() );
result = (Result) failures.next();
// TODO: should be more robust
- assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() );
+ assertEquals( "check reason", "Missing or empty artifactId in group metadata for plugin default4",
+ result.getReason() );
assertFalse( "check no more failures", failures.hasNext() );
}
public void testInvalidPluginPrefix()
- throws ReportProcessorException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) );
@@ -249,7 +264,10 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
Result result = (Result) failures.next();
// TODO: should be more robust
@@ -263,7 +281,6 @@ public class BadMetadataReportProcessorTest
}
public void testDuplicatePluginPrefixes()
- throws ReportProcessorException
{
RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
@@ -271,7 +288,10 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
assertTrue( "check there is a failure", failures.hasNext() );
Result result = (Result) failures.next();
// TODO: should be more robust
@@ -280,7 +300,6 @@ public class BadMetadataReportProcessorTest
}
public void testValidSnapshotMetadata()
- throws ReportProcessorException
{
Artifact artifact =
artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
@@ -293,12 +312,11 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
assertFalse( "check there are no failures", failures.hasNext() );
}
public void testInvalidSnapshotMetadata()
- throws ReportProcessorException
{
Artifact artifact =
artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
@@ -311,16 +329,26 @@ public class BadMetadataReportProcessorTest
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ Iterator failures = reporter.getMetadataIterator();
assertTrue( "check there is a failure", failures.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
- assertEquals( "check metadata", metadata, result.getMetadata() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ Result result = (Result) failures.next();
+ assertMetadata( metadata, results );
// TODO: should be more robust
assertEquals( "check reason", "Snapshot artifact 1.0-alpha-1-20050611.202024-2 does not exist.",
result.getReason() );
assertFalse( "check no more failures", failures.hasNext() );
}
+ private static void assertMetadata( RepositoryMetadata metadata, MetadataResults results )
+ {
+ assertEquals( "check metadata", metadata.getGroupId(), results.getGroupId() );
+ assertEquals( "check metadata", metadata.getArtifactId(), results.getArtifactId() );
+ assertEquals( "check metadata", metadata.getBaseVersion(), results.getVersion() );
+ }
+
private Plugin createMetadataPlugin( String artifactId, String prefix )
{
Plugin plugin = new Plugin();
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 2a4740399..e92cf8ad0 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
@@ -17,15 +17,12 @@ package org.apache.maven.archiva.reporting;
*/
import org.apache.maven.archiva.digest.DigesterException;
+import org.apache.maven.archiva.reporting.model.MetadataResults;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
-import org.apache.maven.artifact.versioning.VersionRange;
import java.io.File;
import java.io.IOException;
@@ -40,7 +37,7 @@ public class ChecksumArtifactReporterTest
{
private ArtifactReportProcessor artifactReportProcessor;
- private ArtifactReporter reporter = new DefaultArtifactReporter();
+ private ReportingDatabase reporter = new ReportingDatabase();
private MetadataReportProcessor metadataReportProcessor;
@@ -56,33 +53,30 @@ public class ChecksumArtifactReporterTest
* Test the ChecksumArtifactReportProcessor when the checksum files are valid.
*/
public void testChecksumArtifactReporterSuccess()
- throws ReportProcessorException, IOException, DigesterException
+ throws DigesterException, IOException
{
createChecksumFile( "VALID" );
createChecksumFile( "INVALID" );
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0" );
- Artifact artifact =
- new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
+ Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
- artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
- assertEquals( 2, reporter.getNumSuccesses() );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
}
/**
* Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
*/
public void testChecksumArtifactReporterFailed()
- throws ReportProcessorException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0" );
- Artifact artifact =
- new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
+ String s = "invalidArtifact";
+ String s1 = "1.0";
+ Artifact artifact = createArtifact( "checksumTest", s, s1 );
- artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
- assertEquals( 2, reporter.getNumFailures() );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 1, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
}
/**
@@ -90,15 +84,12 @@ public class ChecksumArtifactReporterTest
* The reporter should report 2 success validation.
*/
public void testChecksumMetadataReporterSuccess()
- throws ReportProcessorException, DigesterException, IOException
+ throws DigesterException, IOException
{
createMetadataFile( "VALID" );
createMetadataFile( "INVALID" );
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0" );
- Artifact artifact =
- new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
+ Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
//Version level metadata
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
@@ -111,9 +102,6 @@ public class ChecksumArtifactReporterTest
//Group level metadata
metadata = new GroupRepositoryMetadata( "checksumTest" );
metadataReportProcessor.processMetadata( metadata, repository, reporter );
-
- Iterator iter = reporter.getRepositoryMetadataSuccessIterator();
- assertTrue( "check if there is a success", iter.hasNext() );
}
/**
@@ -121,43 +109,42 @@ public class ChecksumArtifactReporterTest
* The reporter must report 2 failures.
*/
public void testChecksumMetadataReporterFailure()
- throws ReportProcessorException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0" );
- Artifact artifact =
- new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
+ Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" );
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
metadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator iter = reporter.getRepositoryMetadataFailureIterator();
- assertTrue( "check if there is a failure", iter.hasNext() );
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
}
/**
* Test the conditional when the checksum files of the artifact & metadata do not exist.
*/
public void testChecksumFilesDoNotExist()
- throws ReportProcessorException, DigesterException, IOException
+ throws DigesterException, IOException
{
createChecksumFile( "VALID" );
createMetadataFile( "VALID" );
deleteChecksumFiles( "jar" );
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0" );
- Artifact artifact =
- new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
+ Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
- artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
- assertEquals( 2, reporter.getNumFailures() );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 1, reporter.getNumFailures() );
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
metadataReportProcessor.processMetadata( metadata, repository, reporter );
- Iterator iter = reporter.getRepositoryMetadataFailureIterator();
- assertTrue( "check if there is a failure", iter.hasNext() );
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );
}
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 7cd3b94bf..39cc0c0d9 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
@@ -16,6 +16,8 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
+import org.apache.maven.archiva.reporting.model.MetadataResults;
+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.ArtifactRepositoryMetadata;
@@ -30,9 +32,7 @@ import java.util.Iterator;
public class DefaultArtifactReporterTest
extends AbstractRepositoryReportsTestCase
{
- private ArtifactReporter reporter;
-
- private Artifact artifact;
+ private ReportingDatabase reporter;
private RepositoryMetadata metadata;
@@ -40,13 +40,8 @@ public class DefaultArtifactReporterTest
{
assertEquals( "No failures", 0, reporter.getNumFailures() );
assertEquals( "No warnings", 0, reporter.getNumWarnings() );
- assertEquals( "No successes", 0, reporter.getNumSuccesses() );
- assertFalse( "No artifact failures", reporter.getArtifactFailureIterator().hasNext() );
- assertFalse( "No artifact warnings", reporter.getArtifactWarningIterator().hasNext() );
- assertFalse( "No artifact successes", reporter.getArtifactSuccessIterator().hasNext() );
- assertFalse( "No metadata failures", reporter.getRepositoryMetadataFailureIterator().hasNext() );
- assertFalse( "No metadata warnings", reporter.getRepositoryMetadataWarningIterator().hasNext() );
- assertFalse( "No metadata successes", reporter.getRepositoryMetadataSuccessIterator().hasNext() );
+ assertFalse( "No artifact failures", reporter.getArtifactIterator().hasNext() );
+ assertFalse( "No metadata failures", reporter.getMetadataIterator().hasNext() );
}
public void testMetadataSingleFailure()
@@ -54,14 +49,23 @@ public class DefaultArtifactReporterTest
reporter.addFailure( metadata, "Single Failure Reason" );
assertEquals( "failures count", 1, reporter.getNumFailures() );
assertEquals( "warnings count", 0, reporter.getNumWarnings() );
- assertEquals( "successes count", 0, reporter.getNumSuccesses() );
- Iterator results = reporter.getRepositoryMetadataFailureIterator();
- assertTrue( "must have failures", results.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
- assertEquals( "check failure cause", metadata, result.getMetadata() );
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ Result result = (Result) failures.next();
+ assertMetadata( results );
assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
- assertFalse( "no more failures", results.hasNext() );
+ assertFalse( "no more failures", failures.hasNext() );
+ }
+
+ private void assertMetadata( MetadataResults result )
+ {
+ assertEquals( "check failure cause", metadata.getGroupId(), result.getGroupId() );
+ assertEquals( "check failure cause", metadata.getArtifactId(), result.getArtifactId() );
+ assertEquals( "check failure cause", metadata.getBaseVersion(), result.getVersion() );
}
public void testMetadataMultipleFailures()
@@ -70,93 +74,57 @@ public class DefaultArtifactReporterTest
reporter.addFailure( metadata, "Second Failure Reason" );
assertEquals( "failures count", 2, reporter.getNumFailures() );
assertEquals( "warnings count", 0, reporter.getNumWarnings() );
- assertEquals( "successes count", 0, reporter.getNumSuccesses() );
- Iterator results = reporter.getRepositoryMetadataFailureIterator();
- assertTrue( "must have failures", results.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
- assertEquals( "check failure cause", metadata, result.getMetadata() );
+ Iterator failures = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ MetadataResults results = (MetadataResults) failures.next();
+ failures = results.getFailures().iterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ Result result = (Result) failures.next();
+ assertMetadata( results );
assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
- assertTrue( "must have 2nd failure", results.hasNext() );
- result = (RepositoryMetadataResult) results.next();
- assertEquals( "check failure cause", metadata, result.getMetadata() );
+ assertTrue( "must have 2nd failure", failures.hasNext() );
+ result = (Result) failures.next();
assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
- assertFalse( "no more failures", results.hasNext() );
+ assertFalse( "no more failures", failures.hasNext() );
}
public void testMetadataSingleWarning()
{
reporter.addWarning( metadata, "Single Warning Message" );
- assertEquals( "failures count", 0, reporter.getNumFailures() );
+ assertEquals( "warnings count", 0, reporter.getNumFailures() );
assertEquals( "warnings count", 1, reporter.getNumWarnings() );
- assertEquals( "successes count", 0, reporter.getNumSuccesses() );
- Iterator results = reporter.getRepositoryMetadataWarningIterator();
- assertTrue( "must have failures", results.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
- assertEquals( "check failure cause", metadata, result.getMetadata() );
+ Iterator warnings = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", warnings.hasNext() );
+ MetadataResults results = (MetadataResults) warnings.next();
+ warnings = results.getWarnings().iterator();
+ assertTrue( "check there is a failure", warnings.hasNext() );
+ Result result = (Result) warnings.next();
+ assertMetadata( results );
assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
- assertFalse( "no more failures", results.hasNext() );
+ assertFalse( "no more warnings", warnings.hasNext() );
}
public void testMetadataMultipleWarnings()
{
reporter.addWarning( metadata, "First Warning" );
reporter.addWarning( metadata, "Second Warning" );
- assertEquals( "failures count", 0, reporter.getNumFailures() );
+ assertEquals( "warnings count", 0, reporter.getNumFailures() );
assertEquals( "warnings count", 2, reporter.getNumWarnings() );
- assertEquals( "successes count", 0, reporter.getNumSuccesses() );
- Iterator results = reporter.getRepositoryMetadataWarningIterator();
- assertTrue( "must have warnings", results.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
- assertEquals( "check failure cause", metadata, result.getMetadata() );
+ Iterator warnings = reporter.getMetadataIterator();
+ assertTrue( "check there is a failure", warnings.hasNext() );
+ MetadataResults results = (MetadataResults) warnings.next();
+ warnings = results.getWarnings().iterator();
+ assertTrue( "check there is a failure", warnings.hasNext() );
+ Result result = (Result) warnings.next();
+ assertMetadata( results );
assertEquals( "check failure reason", "First Warning", result.getReason() );
- assertTrue( "must have 2nd warning", results.hasNext() );
- result = (RepositoryMetadataResult) results.next();
- assertEquals( "check failure cause", metadata, result.getMetadata() );
+ assertTrue( "must have 2nd warning", warnings.hasNext() );
+ result = (Result) warnings.next();
assertEquals( "check failure reason", "Second Warning", result.getReason() );
- assertFalse( "no more failures", results.hasNext() );
- }
-
- public void testMetadataSingleSuccess()
- {
- reporter.addSuccess( metadata );
- assertEquals( "failures count", 0, reporter.getNumFailures() );
- assertEquals( "warnings count", 0, reporter.getNumWarnings() );
- assertEquals( "successes count", 1, reporter.getNumSuccesses() );
-
- Iterator results = reporter.getRepositoryMetadataSuccessIterator();
- assertTrue( "must have successes", results.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
- assertEquals( "check success metadata", metadata, result.getMetadata() );
- assertNull( "check no reason", result.getReason() );
- assertFalse( "no more failures", results.hasNext() );
- }
-
- public void testMetadataMultipleSuccesses()
- {
- Versioning versioning = new Versioning();
- versioning.addVersion( "1.0-beta-1" );
- versioning.addVersion( "1.0-beta-2" );
- RepositoryMetadata metadata2 = new ArtifactRepositoryMetadata( artifact, versioning );
-
- reporter.addSuccess( metadata );
- reporter.addSuccess( metadata2 );
- assertEquals( "failures count", 0, reporter.getNumFailures() );
- assertEquals( "warnings count", 0, reporter.getNumWarnings() );
- assertEquals( "successes count", 2, reporter.getNumSuccesses() );
-
- Iterator results = reporter.getRepositoryMetadataSuccessIterator();
- assertTrue( "must have successes", results.hasNext() );
- RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
- assertEquals( "check success metadata", metadata, result.getMetadata() );
- assertNull( "check no reason", result.getReason() );
- assertTrue( "must have 2nd success", results.hasNext() );
- result = (RepositoryMetadataResult) results.next();
- assertEquals( "check success metadata", metadata2, result.getMetadata() );
- assertNull( "check no reason", result.getReason() );
- assertFalse( "no more successes", results.hasNext() );
+ assertFalse( "no more warnings", warnings.hasNext() );
}
protected void setUp()
@@ -164,21 +132,14 @@ public class DefaultArtifactReporterTest
{
super.setUp();
- reporter = new DefaultArtifactReporter();
+ reporter = new ReportingDatabase();
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
- artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
+ Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
Versioning versioning = new Versioning();
versioning.addVersion( "1.0-alpha-1" );
versioning.addVersion( "1.0-alpha-2" );
- }
-
- protected void tearDown()
- throws Exception
- {
- super.tearDown();
- reporter = null;
- metadata = null;
+ metadata = new ArtifactRepositoryMetadata( artifact, versioning );
}
}
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 6a30c51fa..ddc88646e 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
@@ -16,6 +16,8 @@ package org.apache.maven.archiva.reporting;
* 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.model.Dependency;
@@ -35,7 +37,7 @@ public class DependencyArtifactReportProcessorTest
private static final String VALID_VERSION = "1.0-alpha-1";
- private ArtifactReporter reporter;
+ private ReportingDatabase reporter;
private Model model;
@@ -49,7 +51,7 @@ public class DependencyArtifactReportProcessorTest
throws Exception
{
super.setUp();
- reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
+ reporter = new ReportingDatabase();
model = new Model();
processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "dependency" );
@@ -57,43 +59,44 @@ public class DependencyArtifactReportProcessorTest
}
public void testArtifactFoundButNoDirectDependencies()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
private Artifact createValidArtifact()
{
- return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
+ Artifact projectArtifact =
+ artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
+ projectArtifact.setRepository( repository );
+ return projectArtifact;
}
public void testArtifactNotFound()
- throws ReportProcessorException
{
Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 0, reporter.getNumSuccesses() );
+ artifact.setRepository( repository );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() );
+ Iterator failures = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) failures.next();
+ assertFalse( failures.hasNext() );
+ failures = results.getFailures().iterator();
+ Result result = (Result) failures.next();
+ assertEquals( "Artifact does not exist in the repository", result.getReason() );
}
public void testValidArtifactWithNullDependency()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
Dependency dependency = createValidDependency();
model.addDependency( dependency );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 2, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
@@ -104,21 +107,18 @@ public class DependencyArtifactReportProcessorTest
}
public void testValidArtifactWithValidSingleDependency()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
Dependency dependency = createValidDependency();
model.addDependency( dependency );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 2, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithValidMultipleDependencies()
- throws ReportProcessorException
{
Dependency dependency = createValidDependency();
model.addDependency( dependency );
@@ -128,14 +128,12 @@ public class DependencyArtifactReportProcessorTest
model.addDependency( dependency );
Artifact artifact = createValidArtifact();
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 6, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithAnInvalidDependency()
- throws ReportProcessorException
{
Dependency dependency = createValidDependency();
model.addDependency( dependency );
@@ -145,32 +143,36 @@ public class DependencyArtifactReportProcessorTest
model.addDependency( createDependency( INVALID, INVALID, INVALID ) );
Artifact artifact = createValidArtifact();
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 5, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
+ Iterator failures = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) failures.next();
+ assertFalse( failures.hasNext() );
+ failures = results.getFailures().iterator();
+ Result result = (Result) failures.next();
+ assertEquals( getDependencyNotFoundMessage( createDependency( INVALID, INVALID, INVALID ) ),
+ result.getReason() );
}
public void testValidArtifactWithInvalidDependencyGroupId()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION );
model.addDependency( dependency );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
+ Iterator failures = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) failures.next();
+ assertFalse( failures.hasNext() );
+ failures = results.getFailures().iterator();
+ Result result = (Result) failures.next();
+ assertEquals( getDependencyNotFoundMessage( dependency ), result.getReason() );
}
private Dependency createDependency( String o, String valid, String s )
@@ -183,56 +185,69 @@ public class DependencyArtifactReportProcessorTest
}
public void testValidArtifactWithInvalidDependencyArtifactId()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION );
model.addDependency( dependency );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
+ Iterator failures = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) failures.next();
+ assertFalse( failures.hasNext() );
+ failures = results.getFailures().iterator();
+ Result result = (Result) failures.next();
+ assertEquals( getDependencyNotFoundMessage( dependency ), result.getReason() );
}
public void testValidArtifactWithIncorrectDependencyVersion()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID );
model.addDependency( dependency );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
+ Iterator failures = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) failures.next();
+ assertFalse( failures.hasNext() );
+ failures = results.getFailures().iterator();
+ Result result = (Result) failures.next();
+ assertEquals( getDependencyNotFoundMessage( dependency ), result.getReason() );
}
public void testValidArtifactWithInvalidDependencyVersion()
- throws ReportProcessorException
{
Artifact artifact = createValidArtifact();
Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" );
model.addDependency( dependency );
- processor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ processor.processArtifact( artifact, model, reporter );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() );
+ Iterator failures = reporter.getArtifactIterator();
+ ArtifactResults results = (ArtifactResults) failures.next();
+ assertFalse( failures.hasNext() );
+ failures = results.getFailures().iterator();
+ Result result = (Result) failures.next();
+ assertEquals( getDependencyVersionInvalidMessage( dependency, "[" ), result.getReason() );
+ }
+
+ private String getDependencyVersionInvalidMessage( Dependency dependency, String version )
+ {
+ return "Artifact's dependency " + dependency + " contains an invalid version " + version;
+ }
+
+ private String getDependencyNotFoundMessage( Dependency dependency )
+ {
+ return "Artifact's dependency " + dependency.toString() + " does not exist in the repository";
}
}
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 8e55976d9..902e32326 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 DefaultArtifactReporter reporter = new DefaultArtifactReporter();
+ private ReportingDatabase reportDatabase = new ReportingDatabase();
protected void setUp()
throws Exception
@@ -75,32 +75,29 @@ public class DuplicateArtifactFileReportProcessorTest
{
artifact.setFile( null );
- processor.processArtifact( model, artifact, reporter, repository );
+ processor.processArtifact( artifact, model, reportDatabase );
- assertEquals( "Check no successes", 0, reporter.getNumSuccesses() );
- assertEquals( "Check warnings", 1, reporter.getNumWarnings() );
- assertEquals( "Check no failures", 0, reporter.getNumFailures() );
+ assertEquals( "Check warnings", 1, reportDatabase.getNumWarnings() );
+ assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
}
public void testSuccessOnAlreadyIndexedArtifact()
throws Exception
{
- processor.processArtifact( model, artifact, reporter, repository );
+ processor.processArtifact( artifact, model, reportDatabase );
- assertEquals( "Check no successes", 1, reporter.getNumSuccesses() );
- assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
- assertEquals( "Check no failures", 0, reporter.getNumFailures() );
+ assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
+ assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
}
public void testSuccessOnDifferentGroupId()
throws Exception
{
artifact.setGroupId( "different.groupId" );
- processor.processArtifact( model, artifact, reporter, repository );
+ processor.processArtifact( artifact, model, reportDatabase );
- assertEquals( "Check no successes", 1, reporter.getNumSuccesses() );
- assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
- assertEquals( "Check no failures", 0, reporter.getNumFailures() );
+ assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
+ assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
}
public void testSuccessOnNewArtifact()
@@ -108,11 +105,10 @@ public class DuplicateArtifactFileReportProcessorTest
{
Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" );
- processor.processArtifact( model, newArtifact, reporter, repository );
+ processor.processArtifact( newArtifact, model, reportDatabase );
- assertEquals( "Check no successes", 1, reporter.getNumSuccesses() );
- assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
- assertEquals( "Check no failures", 0, reporter.getNumFailures() );
+ assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
+ assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
}
public void testFailure()
@@ -122,11 +118,10 @@ public class DuplicateArtifactFileReportProcessorTest
artifact.getVersion(), artifact.getType() );
duplicate.setFile( artifact.getFile() );
- processor.processArtifact( model, duplicate, reporter, repository );
+ processor.processArtifact( duplicate, model, reportDatabase );
- assertEquals( "Check no successes", 0, reporter.getNumSuccesses() );
- assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
- assertEquals( "Check no failures", 1, reporter.getNumFailures() );
+ assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
+ assertEquals( "Check no failures", 1, reportDatabase.getNumFailures() );
}
private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
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 511601d96..3351bc301 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
@@ -17,10 +17,6 @@ package org.apache.maven.archiva.reporting;
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.versioning.VersionRange;
/**
* This class tests the InvalidPomArtifactReportProcessor class.
@@ -30,7 +26,7 @@ public class InvalidPomArtifactReportProcessorTest
{
private ArtifactReportProcessor artifactReportProcessor;
- private ArtifactReporter reporter = new DefaultArtifactReporter();
+ private ReportingDatabase reporter = new ReportingDatabase();
public void setUp()
throws Exception
@@ -43,14 +39,10 @@ public class InvalidPomArtifactReportProcessorTest
* Test the InvalidPomArtifactReportProcessor when the artifact is an invalid pom.
*/
public void testInvalidPomArtifactReportProcessorFailure()
- throws ReportProcessorException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
- VersionRange version = VersionRange.createFromVersion( "1.0-alpha-3" );
- Artifact artifact =
- new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", handler );
+ Artifact artifact = createArtifact( "org.apache.maven", "artifactId", "1.0-alpha-3", "pom" );
- artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
assertEquals( 1, reporter.getNumFailures() );
}
@@ -59,14 +51,12 @@ public class InvalidPomArtifactReportProcessorTest
* Test the InvalidPomArtifactReportProcessor when the artifact is a valid pom.
*/
public void testInvalidPomArtifactReportProcessorSuccess()
- throws ReportProcessorException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
- VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" );
- Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", handler );
+ Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
- artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
}
@@ -74,13 +64,11 @@ public class InvalidPomArtifactReportProcessorTest
* Test the InvalidPomArtifactReportProcessor when the artifact is not a pom.
*/
public void testNotAPomArtifactReportProcessorSuccess()
- throws ReportProcessorException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" );
- Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
+ Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "jar" );
- artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
assertEquals( 1, reporter.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 38d1ef064..4d901b11d 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
@@ -17,10 +17,6 @@ package org.apache.maven.archiva.reporting;
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -38,7 +34,7 @@ public class LocationArtifactReportProcessorTest
{
private ArtifactReportProcessor artifactReportProcessor;
- private ArtifactReporter reporter = new DefaultArtifactReporter();
+ private ReportingDatabase reporter = new ReportingDatabase();
private MavenXpp3Reader pomReader;
@@ -63,18 +59,13 @@ public class LocationArtifactReportProcessorTest
* both in the file system pom and in the pom included in the package.
*/
public void testPackagedPomLocationArtifactReporterSuccess()
- throws ReportProcessorException, IOException, XmlPullParserException
+ throws IOException, XmlPullParserException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "2.0" );
- Artifact artifact =
- new DefaultArtifact( "org.apache.maven", "maven-model", version, "compile", "jar", "", handler );
-
- String path = "org/apache/maven/maven-model/2.0/maven-model-2.0.pom";
- Model model = readPom( path );
+ Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" );
- artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
}
/**
@@ -82,17 +73,13 @@ public class LocationArtifactReportProcessorTest
* file system pom (but the jar file does not have a pom included in its package).
*/
public void testLocationArtifactReporterSuccess()
- throws ReportProcessorException, IOException, XmlPullParserException
+ throws IOException, XmlPullParserException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" );
- Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
-
- String path = "groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom";
- Model model = readPom( path );
+ Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
- artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
- assertEquals( 1, reporter.getNumSuccesses() );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
+ assertEquals( 0, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumWarnings() );
}
/**
@@ -100,16 +87,11 @@ public class LocationArtifactReportProcessorTest
* in the file system pom.
*/
public void testLocationArtifactReporterFailure()
- throws IOException, XmlPullParserException, ReportProcessorException
+ throws IOException, XmlPullParserException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" );
- Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
-
- String path = "groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom";
- Model model = readPom( path );
+ Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
- artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
assertEquals( 1, reporter.getNumFailures() );
}
@@ -118,17 +100,13 @@ public class LocationArtifactReportProcessorTest
* location in the file system pom but instead matches the specified location in the packaged pom.
*/
public void testFsPomArtifactMatchFailure()
- throws IOException, ReportProcessorException, XmlPullParserException
+ throws IOException, XmlPullParserException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "2.0" );
- Artifact artifact =
- new DefaultArtifact( "org.apache.maven", "maven-archiver", version, "compile", "jar", "", handler );
+ Artifact artifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0" );
- String path = "org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom";
- Model model = readPom( path );
-
- artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ 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() );
}
@@ -154,17 +132,11 @@ public class LocationArtifactReportProcessorTest
* location specified in the packaged pom but matches the location specified in the file system pom.
*/
public void testPkgPomArtifactMatchFailure()
- throws IOException, XmlPullParserException, ReportProcessorException
+ throws IOException, XmlPullParserException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "2.1" );
- Artifact artifact =
- new DefaultArtifact( "org.apache.maven", "maven-monitor", version, "compile", "jar", "", handler );
-
- String path = "org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom";
- Model model = readPom( path );
+ Artifact artifact = createArtifact( "org.apache.maven", "maven-monitor", "2.1" );
- artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
assertEquals( 1, reporter.getNumFailures() );
}
@@ -173,17 +145,12 @@ public class LocationArtifactReportProcessorTest
* location specified in the packaged pom and the location specified in the file system pom.
*/
public void testBothPomArtifactMatchFailure()
- throws IOException, XmlPullParserException, ReportProcessorException
+ throws IOException, XmlPullParserException
{
- ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
- VersionRange version = VersionRange.createFromVersion( "2.1" );
- Artifact artifact =
- new DefaultArtifact( "org.apache.maven", "maven-project", version, "compile", "jar", "", handler );
-
- String path = "org/apache/maven/maven-project/2.1/maven-project-2.1.pom";
- Model model = readPom( path );
+ Artifact artifact = createArtifact( "org.apache.maven", "maven-project", "2.1" );
- artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ artifactReportProcessor.processArtifact( artifact, null, reporter );
assertEquals( 1, reporter.getNumFailures() );
}
+
}
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom
index e5cbe38fd..5d4f1f96f 100644
--- a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom
@@ -1,9 +1,5 @@
<project>
- <parent>
- <artifactId>maven</artifactId>
- <groupId>org.apache.maven</groupId>
- <version>2.1</version>
- </parent>
+ <groupId>org.apache.maven</groupId>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-archiver</artifactId>
<name>Maven Archiver</name>