aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-reports-standard
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-08-26 05:47:59 +0000
committerBrett Porter <brett@apache.org>2006-08-26 05:47:59 +0000
commit209ef5ca84ee8de9e5ee61952e0d380749c3074b (patch)
tree1f64a28aa8f3bfab1ab17cb8715fe6eb0485391e /archiva-reports-standard
parent72cbf8748f2f0cb7dad3b45cd5668461aa4a76b2 (diff)
downloadarchiva-209ef5ca84ee8de9e5ee61952e0d380749c3074b.tar.gz
archiva-209ef5ca84ee8de9e5ee61952e0d380749c3074b.zip
rename archiva artifacts
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437088 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-reports-standard')
-rwxr-xr-xarchiva-reports-standard/pom.xml69
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java106
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java34
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java88
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java54
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java330
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java221
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java99
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java100
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java96
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java161
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java118
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java31
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java35
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java124
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java101
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java196
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java31
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java32
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java54
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java38
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java34
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java38
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java283
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java142
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java64
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java463
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java187
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java358
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java143
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java58
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java220
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java184
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java149
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java62
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java109
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java224
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java258
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java92
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java80
-rwxr-xr-xarchiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java121
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java79
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java74
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jarbin0 -> 45568 bytes
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom6
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom6
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml27
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom0
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom0
-rw-r--r--archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml17
-rw-r--r--archiva-reports-standard/src/test/repository/maven-metadata.xml21
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom9
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jarbin0 -> 11720 bytes
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom31
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt4
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jarbin0 -> 78476 bytes
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom86
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt3
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jarbin0 -> 7591 bytes
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom15
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt4
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jarbin0 -> 104615 bytes
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom52
-rw-r--r--archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt4
-rw-r--r--archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml21
65 files changed, 5846 insertions, 0 deletions
diff --git a/archiva-reports-standard/pom.xml b/archiva-reports-standard/pom.xml
new file mode 100755
index 000000000..f6d85a9ba
--- /dev/null
+++ b/archiva-reports-standard/pom.xml
@@ -0,0 +1,69 @@
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>archiva-reports-standard</artifactId>
+ <name>Archiva Standard Reports</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-repository-metadata</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-provider-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.archiva</groupId>
+ <artifactId>archiva-indexer</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
new file mode 100644
index 000000000..997597c77
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java
@@ -0,0 +1,106 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ *
+ */
+public abstract class AbstractRepositoryQueryLayer
+ implements RepositoryQueryLayer
+{
+ protected ArtifactRepository repository;
+
+ public boolean containsArtifact( Artifact artifact )
+ {
+ File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
+ return f.exists();
+ }
+
+ public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
+ {
+ String artifactPath = getSnapshotArtifactRepositoryPath( artifact, snapshot );
+ File artifactFile = new File( artifactPath );
+ return artifactFile.exists();
+ }
+
+ public List getVersions( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata = getMetadata( artifact );
+
+ return metadata.getVersioning().getVersions();
+ }
+
+ protected String getSnapshotArtifactRepositoryPath( Artifact artifact, Snapshot snapshot )
+ {
+ File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
+ String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" +
+ snapshot.getBuildNumber() + ".pom" );
+ File snapshotFile = new File( f.getParentFile(), artifact.getArtifactId() + "-" + snapshotInfo );
+ return snapshotFile.getAbsolutePath();
+ }
+
+ protected Metadata getMetadata( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata;
+
+ ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
+ String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
+ File metadataFile = new File( repository.getBasedir(), path );
+ if ( metadataFile.exists() )
+ {
+ MetadataXpp3Reader reader = new MetadataXpp3Reader();
+ try
+ {
+ metadata = reader.read( new FileReader( metadataFile ) );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ }
+ else
+ {
+ throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() );
+ }
+
+ return metadata;
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java
new file mode 100644
index 000000000..773b2c7f5
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java
@@ -0,0 +1,34 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+
+/**
+ * This interface will be called by the main system for each artifact as it is discovered. This is how each of the
+ * different types of reports are implemented.
+ */
+public interface ArtifactReportProcessor
+{
+ String ROLE = ArtifactReportProcessor.class.getName();
+
+ void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository repository )
+ throws ReportProcessorException;
+
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java
new file mode 100644
index 000000000..a48476491
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java
@@ -0,0 +1,88 @@
+package org.apache.maven.repository.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
+ */
+public interface ArtifactReporter
+{
+ String ROLE = ArtifactReporter.class.getName();
+
+ String NULL_MODEL = "Provided model was null";
+
+ String NULL_ARTIFACT = "Provided artifact was null";
+
+ String EMPTY_GROUP_ID = "Group id was empty or null";
+
+ String EMPTY_ARTIFACT_ID = "Artifact id was empty or null";
+
+ String EMPTY_VERSION = "Version was empty or null";
+
+ String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null";
+
+ String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null";
+
+ String EMPTY_DEPENDENCY_VERSION = "Version was empty or null";
+
+ String NO_DEPENDENCIES = "Artifact has no dependencies";
+
+ String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository";
+
+ String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository";
+
+ 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 getFailures();
+
+ int getSuccesses();
+
+ int getWarnings();
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java
new file mode 100644
index 000000000..6c0aba900
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java
@@ -0,0 +1,54 @@
+package org.apache.maven.repository.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/repository/reporting/BadMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java
new file mode 100644
index 000000000..fdba18d39
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java
@@ -0,0 +1,330 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.Plugin;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class will report on bad metadata files. These include invalid version declarations and incomplete version
+ * information inside the metadata file. Plugin metadata will be checked for validity of the latest plugin artifacts.
+ *
+ * @plexus.component role="org.apache.maven.repository.reporting.MetadataReportProcessor" role-hint="bad-metadata"
+ */
+public class BadMetadataReportProcessor
+ implements MetadataReportProcessor
+{
+ /**
+ * @plexus.requirement
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryQueryLayerFactory repositoryQueryLayerFactory;
+
+ /**
+ * Process the metadata encountered in the repository and report all errors found, if any.
+ *
+ * @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
+ */
+ public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
+ throws ReportProcessorException
+ {
+ boolean hasFailures = false;
+
+ if ( metadata.storedInGroupDirectory() )
+ {
+ try
+ {
+ hasFailures = checkPluginMetadata( metadata, repository, reporter );
+ }
+ catch ( IOException e )
+ {
+ throw new ReportProcessorException( "Error getting plugin artifact directories versions", e );
+ }
+ }
+ else
+ {
+ String lastUpdated = metadata.getMetadata().getVersioning().getLastUpdated();
+ 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 );
+ }
+ else
+ {
+ if ( !checkMetadataVersions( metadata, repository, reporter ) )
+ {
+ hasFailures = true;
+ }
+
+ try
+ {
+ if ( checkRepositoryVersions( metadata, repository, reporter ) )
+ {
+ hasFailures = true;
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new ReportProcessorException( "Error getting versions", e );
+ }
+ }
+ }
+
+ if ( !hasFailures )
+ {
+ reporter.addSuccess( metadata );
+ }
+ }
+
+ /**
+ * Method for processing a GroupRepositoryMetadata
+ *
+ * @param metadata the metadata to be processed.
+ * @param repository the repository where the metadata was encountered
+ * @param reporter the ArtifactReporter to receive processing results
+ */
+ private boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
+ throws IOException
+ {
+ boolean hasFailures = false;
+
+ File metadataDir =
+ new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
+ List pluginDirs = getArtifactIdFiles( metadataDir );
+
+ Map prefixes = new HashMap();
+ for ( Iterator plugins = metadata.getMetadata().getPlugins().iterator(); plugins.hasNext(); )
+ {
+ Plugin plugin = (Plugin) plugins.next();
+
+ String artifactId = plugin.getArtifactId();
+ if ( artifactId == null || artifactId.length() == 0 )
+ {
+ reporter.addFailure( metadata, "Missing or empty artifactId in group metadata." );
+ hasFailures = true;
+ }
+
+ 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
+ {
+ prefixes.put( prefix, plugin );
+ }
+ }
+
+ if ( artifactId != null && artifactId.length() > 0 )
+ {
+ File pluginDir = new File( metadataDir, artifactId );
+ if ( !pluginDirs.contains( pluginDir ) )
+ {
+ reporter.addFailure( metadata, "Metadata plugin " + artifactId + " not found in the repository" );
+ hasFailures = true;
+ }
+ else
+ {
+ pluginDirs.remove( pluginDir );
+ }
+ }
+ }
+
+ if ( pluginDirs.size() > 0 )
+ {
+ for ( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); )
+ {
+ File plugin = (File) plugins.next();
+ reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " +
+ "missing in the metadata." );
+ }
+ hasFailures = true;
+ }
+
+ return hasFailures;
+ }
+
+ /**
+ * Method for processing a SnapshotArtifactRepository
+ *
+ * @param metadata the metadata to be processed.
+ * @param repository the repository where the metadata was encountered
+ * @param reporter the ArtifactReporter to receive processing results
+ */
+ private boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
+ {
+ RepositoryQueryLayer repositoryQueryLayer =
+ repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
+
+ boolean hasFailures = false;
+
+ Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
+ String timestamp = snapshot.getTimestamp();
+ String buildNumber = String.valueOf( snapshot.getBuildNumber() );
+
+ Artifact artifact = createArtifact( metadata );
+ if ( !repositoryQueryLayer.containsArtifact( artifact, snapshot ) )
+ {
+ reporter.addFailure( metadata, "Snapshot artifact " + timestamp + "-" + buildNumber + " does not exist." );
+ hasFailures = true;
+ }
+
+ return hasFailures;
+ }
+
+ /**
+ * Method for validating the versions declared inside an ArtifactRepositoryMetadata
+ *
+ * @param metadata the metadata to be processed.
+ * @param repository the repository where the metadata was encountered
+ * @param reporter the ArtifactReporter to receive processing results
+ */
+ private boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
+ {
+ RepositoryQueryLayer repositoryQueryLayer =
+ repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
+
+ boolean hasFailures = false;
+ Versioning versioning = metadata.getMetadata().getVersioning();
+ for ( Iterator versions = versioning.getVersions().iterator(); versions.hasNext(); )
+ {
+ String version = (String) versions.next();
+
+ Artifact artifact = createArtifact( metadata, version );
+
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
+ {
+ reporter.addFailure( metadata, "Artifact version " + version + " is present in metadata but " +
+ "missing in the repository." );
+ hasFailures = true;
+ }
+ }
+ return hasFailures;
+ }
+
+ /**
+ * Searches the artifact repository directory for all versions and verifies that all of them are listed in the
+ * ArtifactRepositoryMetadata
+ *
+ * @param metadata the metadata to be processed.
+ * @param repository the repository where the metadata was encountered
+ * @param reporter the ArtifactReporter to receive processing results
+ */
+ private boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository,
+ ArtifactReporter reporter )
+ throws IOException
+ {
+ boolean hasFailures = false;
+ Versioning versioning = metadata.getMetadata().getVersioning();
+ File versionsDir =
+ new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( metadata ) ).getParentFile();
+ List versions = FileUtils.getFileNames( versionsDir, "*/*.pom", null, false );
+ for ( Iterator i = versions.iterator(); i.hasNext(); )
+ {
+ File path = new File( (String) i.next() );
+ String version = path.getParentFile().getName();
+ if ( !versioning.getVersions().contains( version ) )
+ {
+ reporter.addFailure( metadata, "Artifact version " + version + " found in the repository but " +
+ "missing in the metadata." );
+ hasFailures = true;
+ }
+ }
+ return hasFailures;
+ }
+
+ /**
+ * Used to create an artifact object from a metadata base version
+ */
+ private Artifact createArtifact( RepositoryMetadata metadata )
+ {
+ return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(),
+ metadata.getBaseVersion(), "pom" );
+ }
+
+ /**
+ * Used to create an artifact object with a specified version
+ */
+ private Artifact createArtifact( RepositoryMetadata metadata, String version )
+ {
+ return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), version, "pom" );
+ }
+
+ /**
+ * Used to gather artifactIds from a groupId directory
+ */
+ private List getArtifactIdFiles( File groupIdDir )
+ throws IOException
+ {
+ List artifactIdFiles = new ArrayList();
+
+ List fileArray = new ArrayList( Arrays.asList( groupIdDir.listFiles() ) );
+ for ( Iterator files = fileArray.iterator(); files.hasNext(); )
+ {
+ File artifactDir = (File) files.next();
+
+ if ( artifactDir.isDirectory() )
+ {
+ List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false );
+ if ( versions.size() > 0 )
+ {
+ artifactIdFiles.add( artifactDir );
+ }
+ }
+ }
+
+ return artifactIdFiles;
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java
new file mode 100644
index 000000000..8f695f91d
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java
@@ -0,0 +1,221 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Class to implement caching.
+ */
+public class Cache
+{
+ private final Map cache;
+
+ private final double cacheHitRatio;
+
+ private final int cacheMaxSize;
+
+ private long cacheHits;
+
+ private long cacheMiss;
+
+ /**
+ * Caches all data and expires only the oldest data when the specified cache hit rate is reached.
+ */
+ public Cache( double cacheHitRatio )
+ {
+ this( cacheHitRatio, 0 );
+ }
+
+ /**
+ * Caches all data and expires only the oldest data when the maximum cache size is reached
+ */
+ public Cache( int cacheMaxSize )
+ {
+ this( (double) 1, cacheMaxSize );
+ }
+
+ /**
+ * Caches all data and expires only the oldest data when either the specified cache hit rate is reached
+ * or the maximum cache size is reached.
+ */
+ public Cache( double cacheHitRatio, int cacheMaxSize )
+ {
+ this.cacheHitRatio = cacheHitRatio;
+ this.cacheMaxSize = cacheMaxSize;
+
+ if ( cacheMaxSize > 0 )
+ {
+ cache = new LinkedHashMap( cacheMaxSize );
+ }
+ else
+ {
+ cache = new LinkedHashMap();
+ }
+ }
+
+ /**
+ * Check if the specified key is already mapped to an object.
+ *
+ * @param key the key used to map the cached object
+ * @return true if the cache contains an object associated with the given key
+ */
+ public boolean containsKey( Object key )
+ {
+ boolean contains;
+ synchronized ( cache )
+ {
+ contains = cache.containsKey( key );
+
+ if ( contains )
+ {
+ cacheHits++;
+ }
+ else
+ {
+ cacheMiss++;
+ }
+ }
+
+ return contains;
+ }
+
+ /**
+ * Check for a cached object and return it if it exists. Returns null when the keyed object is not found
+ *
+ * @param key the key used to map the cached object
+ * @return the object mapped to the given key, or null if no cache object is mapped to the given key
+ */
+ public Object get( Object key )
+ {
+ Object retValue = null;
+
+ synchronized ( cache )
+ {
+ if ( cache.containsKey( key ) )
+ {
+ // remove and put: this promotes it to the top since we use a linked hash map
+ retValue = cache.remove( key );
+
+ cache.put( key, retValue );
+
+ cacheHits++;
+ }
+ else
+ {
+ cacheMiss++;
+ }
+ }
+
+ return retValue;
+ }
+
+ /**
+ * Cache the given value and map it using the given key
+ *
+ * @param key the object to map the valued object
+ * @param value the object to cache
+ */
+ public void put( Object key, Object value )
+ {
+ // remove and put: this promotes it to the top since we use a linked hash map
+ synchronized ( cache )
+ {
+ if ( cache.containsKey( key ) )
+ {
+ cache.remove( key );
+ }
+
+ cache.put( key, value );
+ }
+
+ manageCache();
+ }
+
+ /**
+ * Compute for the efficiency of this cache.
+ *
+ * @return the ratio of cache hits to the cache misses to queries for cache objects
+ */
+ public double getHitRate()
+ {
+ synchronized ( cache )
+ {
+ return cacheHits == 0 && cacheMiss == 0 ? 0 : (double) cacheHits / (double) ( cacheHits + cacheMiss );
+ }
+ }
+
+ /**
+ * Get the total number of cache objects currently cached.
+ */
+ public int size()
+ {
+ return cache.size();
+ }
+
+ /**
+ * Empty the cache and reset the cache hit rate
+ */
+ public void clear()
+ {
+ synchronized ( cache )
+ {
+ cacheHits = 0;
+ cacheMiss = 0;
+ cache.clear();
+ }
+ }
+
+ private void manageCache()
+ {
+ synchronized ( cache )
+ {
+ Iterator iterator = cache.entrySet().iterator();
+ if ( cacheMaxSize == 0 )
+ {
+ //desired HitRatio is reached, we can trim the cache to conserve memory
+ if ( cacheHitRatio <= getHitRate() )
+ {
+ iterator.next();
+ iterator.remove();
+ }
+ }
+ else if ( cache.size() > cacheMaxSize )
+ {
+ // maximum cache size is reached
+ while ( cache.size() > cacheMaxSize )
+ {
+ iterator.next();
+ iterator.remove();
+ }
+ }
+ else
+ {
+ //even though the max has not been reached, the desired HitRatio is already reached,
+ // so we can trim the cache to conserve memory
+ if ( cacheHitRatio <= getHitRate() )
+ {
+ iterator.next();
+ iterator.remove();
+ }
+ }
+ }
+ }
+
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java
new file mode 100644
index 000000000..b0c1eac27
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java
@@ -0,0 +1,99 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+
+
+/**
+ *
+ */
+public class CachedRepositoryQueryLayer
+ extends AbstractRepositoryQueryLayer
+{
+ private Cache cache;
+
+ public static final double CACHE_HIT_RATIO = 0.5;
+
+ public CachedRepositoryQueryLayer( ArtifactRepository repository )
+ {
+ this.repository = repository;
+
+ cache = new Cache( CACHE_HIT_RATIO );
+ }
+
+ public double getCacheHitRate()
+ {
+ return cache.getHitRate();
+ }
+
+ public boolean containsArtifact( Artifact artifact )
+ {
+ boolean artifactFound = true;
+
+ String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact );
+
+ if ( cache.get( artifactPath ) == null )
+ {
+ artifactFound = super.containsArtifact( artifact );
+ if ( artifactFound )
+ {
+ cache.put( artifactPath, artifactPath );
+ }
+ }
+
+ return artifactFound;
+ }
+
+ public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
+ {
+ boolean artifactFound = true;
+
+ String path = getSnapshotArtifactRepositoryPath( artifact, snapshot );
+
+ if ( cache.get( path ) == null )
+ {
+ artifactFound = super.containsArtifact( artifact, snapshot );
+ if ( artifactFound )
+ {
+ cache.put( path, path );
+ }
+ }
+
+ return artifactFound;
+ }
+
+ /**
+ * Override method to utilize the cache
+ */
+ protected Metadata getMetadata( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata = (Metadata) cache.get( artifact.getId() );
+
+ if ( metadata == null )
+ {
+ metadata = super.getMetadata( artifact );
+ cache.put( artifact.getId(), metadata );
+ }
+
+ return metadata;
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
new file mode 100644
index 000000000..51b4a8772
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java
@@ -0,0 +1,100 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
+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.repository.reporting.ArtifactReportProcessor" role-hint="checksum"
+ */
+public class ChecksumArtifactReporter
+ implements ArtifactReportProcessor
+{
+ /**
+ * @plexus.requirement role-hint="sha1"
+ */
+ private Digester sha1Digester;
+
+ /**
+ * @plexus.requirement role-hint="md5"
+ */
+ private Digester md5Digester;
+
+ /**
+ * Validate the checksum of the specified artifact.
+ *
+ * @param model
+ * @param artifact
+ * @param reporter
+ * @param repository
+ */
+ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
+ ArtifactRepository repository )
+ {
+ 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.pathOf( artifact );
+ File file = new File( repository.getBasedir(), path );
+
+ 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 )
+ {
+ File checksumFile = new File( repository.getBasedir(), path );
+ if ( checksumFile.exists() )
+ {
+ try
+ {
+ digester.verify( file, FileUtils.fileRead( checksumFile ) );
+
+ reporter.addSuccess( artifact );
+ }
+ catch ( DigesterException e )
+ {
+ reporter.addFailure( artifact, e.getMessage() );
+ }
+ catch ( IOException e )
+ {
+ reporter.addFailure( artifact, "Read file error: " + e.getMessage() );
+ }
+ }
+ else
+ {
+ reporter.addFailure( artifact, digester.getAlgorithm() + " checksum file does not exist." );
+ }
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java
new file mode 100644
index 000000000..df732f656
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumMetadataReporter.java
@@ -0,0 +1,96 @@
+package org.apache.maven.repository.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;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
+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.repository.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/repository/reporting/DefaultArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java
new file mode 100644
index 000000000..b869e7e49
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java
@@ -0,0 +1,161 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="default"
+ */
+public class DefaultArtifactReportProcessor
+ implements ArtifactReportProcessor
+{
+ private static final String EMPTY_STRING = "";
+
+ // plexus components
+ private ArtifactFactory artifactFactory;
+
+ private RepositoryQueryLayer repositoryQueryLayer;
+
+ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
+ ArtifactRepository repository )
+ {
+ if ( artifact == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT );
+ }
+ else
+ {
+ processArtifact( artifact, reporter );
+ }
+
+ if ( model == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL );
+ }
+ else
+ {
+ List dependencies = model.getDependencies();
+ processDependencies( dependencies, reporter );
+ }
+ }
+
+ private void processArtifact( Artifact artifact, ArtifactReporter reporter )
+ {
+ boolean hasFailed = false;
+ if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID );
+ hasFailed = true;
+ }
+ if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID );
+ hasFailed = true;
+ }
+ if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION );
+ hasFailed = true;
+ }
+ if ( !hasFailed )
+ {
+ if ( repositoryQueryLayer.containsArtifact( artifact ) )
+ {
+ reporter.addSuccess( artifact );
+ }
+ else
+ {
+ reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
+ }
+ }
+ }
+
+ private void processDependencies( List dependencies, ArtifactReporter reporter )
+ {
+ if ( dependencies.size() > 0 )
+ {
+ Iterator iterator = dependencies.iterator();
+ while ( iterator.hasNext() )
+ {
+ boolean hasFailed = false;
+ Dependency dependency = (Dependency) iterator.next();
+ Artifact artifact = createArtifact( dependency );
+ if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID );
+ hasFailed = true;
+ }
+ if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID );
+ hasFailed = true;
+ }
+ if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION );
+ hasFailed = true;
+ }
+ if ( !hasFailed )
+ {
+ if ( repositoryQueryLayer.containsArtifact( artifact ) )
+ {
+ reporter.addSuccess( artifact );
+ }
+ else
+ {
+ reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Only used for passing a mock object when unit testing
+ *
+ * @param repositoryQueryLayer
+ */
+ protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer )
+ {
+ this.repositoryQueryLayer = repositoryQueryLayer;
+ }
+
+ /**
+ * Only used for passing a mock object when unit testing
+ *
+ * @param artifactFactory
+ */
+ protected void setArtifactFactory( ArtifactFactory artifactFactory )
+ {
+ this.artifactFactory = artifactFactory;
+ }
+
+ private Artifact createArtifact( Dependency dependency )
+ {
+ return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(),
+ dependency.getVersion(), "pom" );
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java
new file mode 100644
index 000000000..32b4cd755
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java
@@ -0,0 +1,118 @@
+package org.apache.maven.repository.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.repository.reporting.ArtifactReporter" role-hint="default"
+ */
+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 getFailures()
+ {
+ return artifactFailures.size() + metadataFailures.size();
+ }
+
+ public int getSuccesses()
+ {
+ return artifactSuccesses.size() + metadataSuccesses.size();
+ }
+
+ public int getWarnings()
+ {
+ return artifactWarnings.size() + metadataWarnings.size();
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java
new file mode 100644
index 000000000..5570666dd
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java
@@ -0,0 +1,31 @@
+package org.apache.maven.repository.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;
+
+/**
+ *
+ */
+public class DefaultRepositoryQueryLayer
+ extends AbstractRepositoryQueryLayer
+{
+ public DefaultRepositoryQueryLayer( ArtifactRepository repository )
+ {
+ this.repository = repository;
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java
new file mode 100644
index 000000000..56f9826dc
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java
@@ -0,0 +1,35 @@
+package org.apache.maven.repository.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;
+
+/**
+ * Gets the default implementation of a repository query layer for the given repository.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.repository.reporting.RepositoryQueryLayerFactory"
+ */
+public class DefaultRepositoryQueryLayerFactory
+ implements RepositoryQueryLayerFactory
+{
+ public RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository )
+ {
+ return new DefaultRepositoryQueryLayer( repository );
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
new file mode 100644
index 000000000..df8c81a85
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessor.java
@@ -0,0 +1,124 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
+import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
+import org.apache.maven.repository.indexing.lucene.LuceneQuery;
+import org.apache.maven.repository.indexing.record.StandardArtifactIndexRecord;
+import org.apache.maven.repository.indexing.record.StandardIndexRecordFields;
+
+/**
+ * Validates an artifact file for duplicates within the same groupId based from what's available in a repository index.
+ *
+ * @author Edwin Punzalan
+ * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="duplicate"
+ */
+public class DuplicateArtifactFileReportProcessor
+ implements ArtifactReportProcessor
+{
+ /**
+ * @plexus.requirement role-hint="md5"
+ */
+ private Digester digester;
+
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryArtifactIndexFactory indexFactory;
+
+ /**
+ * @plexus.configuration
+ */
+ private String indexDirectory;
+
+ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
+ ArtifactRepository repository )
+ throws ReportProcessorException
+ {
+ if ( artifact.getFile() != null )
+ {
+ RepositoryArtifactIndex index = indexFactory.createStandardIndex( new File( indexDirectory ) );
+
+ String checksum;
+ try
+ {
+ checksum = digester.calc( artifact.getFile() );
+ }
+ catch ( DigesterException e )
+ {
+ throw new ReportProcessorException( "Failed to generate checksum", e );
+ }
+
+ try
+ {
+ List results = index.search( new LuceneQuery(
+ new TermQuery( new Term( StandardIndexRecordFields.MD5, checksum.toLowerCase() ) ) ) );
+
+ if ( results.isEmpty() )
+ {
+ reporter.addSuccess( artifact );
+ }
+ else
+ {
+ boolean hasDuplicates = false;
+ for ( Iterator i = results.iterator(); i.hasNext(); )
+ {
+ StandardArtifactIndexRecord result = (StandardArtifactIndexRecord) i.next();
+
+ //make sure it is not the same artifact
+ if ( !result.getFilename().equals( repository.pathOf( artifact ) ) )
+ {
+ //report only duplicates from the same groupId
+ String groupId = artifact.getGroupId();
+ if ( groupId.equals( result.getGroupId() ) )
+ {
+ hasDuplicates = true;
+ 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 );
+ }
+ }
+ else
+ {
+ reporter.addWarning( artifact, "Artifact file is null" );
+ }
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java
new file mode 100644
index 000000000..a11f35754
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java
@@ -0,0 +1,101 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * This class validates well-formedness of pom xml file.
+ *
+ * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="invalid-pom"
+ */
+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.
+ */
+ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
+ ArtifactRepository repository )
+ {
+ 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" );
+ }
+
+ if ( "pom".equals( artifact.getType().toLowerCase() ) )
+ {
+ File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
+
+ if ( !f.exists() )
+ {
+ reporter.addFailure( artifact, "Artifact not found." );
+ }
+ else
+ {
+ Reader reader = null;
+
+ MavenXpp3Reader pomReader = new MavenXpp3Reader();
+
+ try
+ {
+ reader = new FileReader( f );
+ pomReader.read( reader );
+ reporter.addSuccess( artifact );
+ }
+ catch ( XmlPullParserException e )
+ {
+ reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing: " +
+ e.getMessage() );
+ }
+ catch ( FileNotFoundException e )
+ {
+ reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
+ }
+ catch ( IOException e )
+ {
+ reporter.addFailure( artifact, "Error while reading the pom xml file: " + e.getMessage() );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+ }
+ }
+ else
+ {
+ reporter.addWarning( artifact, "The artifact is not a pom xml file." );
+ }
+ }
+
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java
new file mode 100644
index 000000000..140425656
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java
@@ -0,0 +1,196 @@
+package org.apache.maven.repository.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.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.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Validate the location of the artifact based on the values indicated
+ * in its pom (both the pom packaged with the artifact & the pom in the
+ * file system).
+ * @plexus.component role="org.apache.maven.repository.reporting.ArtifactReportProcessor" role-hint="artifact-location"
+ */
+public class LocationArtifactReportProcessor
+ implements ArtifactReportProcessor
+{
+ /** @plexus.requirement */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * 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
+ * object (pom in the file system). Then unpack the artifact (jar file) and get the model (pom)
+ * 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
+ {
+ 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 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 ) )
+ {
+ //get the location of the artifact itself
+ File file = new File( repository.getBasedir(), artifactPath );
+
+ if ( file.exists() )
+ {
+ //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() );
+
+ if ( extractedModel != null )
+ {
+ Artifact extractedArtifact = artifactFactory.createBuildArtifact( extractedModel.getGroupId(),
+ extractedModel.getArtifactId(),
+ extractedModel.getVersion(),
+ extractedModel.getPackaging() );
+ if ( !repository.pathOf( extractedArtifact ).equals( artifactPath ) )
+ {
+ reporter.addFailure( artifact,
+ "The artifact is out of place. It does not match the specified location in the packaged pom." );
+ 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 );
+ }
+ }
+
+ /**
+ * 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
+ {
+ Model model = null;
+
+ JarFile jar = null;
+ try
+ {
+ jar = new JarFile( file );
+
+ //Get the entry and its input stream.
+ JarEntry entry = jar.getJarEntry( "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
+
+ // If the entry is not null, extract it.
+ if ( entry != null )
+ {
+ model = readModel( jar.getInputStream( entry ) );
+ }
+ }
+ catch ( IOException e )
+ {
+ // TODO: should just warn and continue?
+ throw new ReportProcessorException( "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 );
+ }
+ finally
+ {
+ if ( jar != null )
+ {
+ //noinspection UnusedCatchParameter
+ try
+ {
+ jar.close();
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+ }
+ return model;
+ }
+
+ private Model readModel( InputStream entryStream )
+ throws IOException, XmlPullParserException
+ {
+ Reader isReader = new InputStreamReader( entryStream );
+
+ Model model;
+ try
+ {
+ MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ model = pomReader.read( isReader );
+ }
+ finally
+ {
+ IOUtil.close( isReader );
+ }
+ return model;
+ }
+
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java
new file mode 100644
index 000000000..0431a8adf
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java
@@ -0,0 +1,31 @@
+package org.apache.maven.repository.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;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+
+/**
+ * This interface is called by the main system for each piece of metadata as it is discovered.
+ */
+public interface MetadataReportProcessor
+{
+ String ROLE = MetadataReportProcessor.class.getName();
+
+ void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter )
+ throws ReportProcessorException;
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java
new file mode 100644
index 000000000..5f73dbdc0
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java
@@ -0,0 +1,32 @@
+package org.apache.maven.repository.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.
+ */
+
+/**
+ * Exception occurring during reporting.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class ReportProcessorException
+ extends Exception
+{
+ public ReportProcessorException( String msg, Throwable cause )
+ {
+ super( msg, cause );
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java
new file mode 100644
index 000000000..4c962986a
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java
@@ -0,0 +1,54 @@
+package org.apache.maven.repository.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$
+ */
+public class RepositoryMetadataResult
+{
+ 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/repository/reporting/RepositoryQueryLayer.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java
new file mode 100644
index 000000000..950f7a252
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java
@@ -0,0 +1,38 @@
+package org.apache.maven.repository.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.Snapshot;
+
+import java.util.List;
+
+/**
+ * The transitive and metadata validation reports will need to query the repository for artifacts.
+ */
+public interface RepositoryQueryLayer
+{
+ String ROLE = RepositoryQueryLayer.class.getName();
+
+ boolean containsArtifact( Artifact artifact );
+
+ /** @todo I believe we can remove this [BP] - artifact should contain all the necessary version info */
+ boolean containsArtifact( Artifact artifact, Snapshot snapshot );
+
+ List getVersions( Artifact artifact )
+ throws RepositoryQueryLayerException;
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java
new file mode 100644
index 000000000..ae7f77947
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java
@@ -0,0 +1,34 @@
+package org.apache.maven.repository.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.
+ */
+
+/**
+ *
+ */
+public class RepositoryQueryLayerException
+ extends Exception
+{
+ public RepositoryQueryLayerException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public RepositoryQueryLayerException( String message )
+ {
+ super( message );
+ }
+}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java
new file mode 100644
index 000000000..00f42b30d
--- /dev/null
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java
@@ -0,0 +1,38 @@
+package org.apache.maven.repository.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;
+
+/**
+ * Gets the preferred implementation of a repository query layer for the given repository.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public interface RepositoryQueryLayerFactory
+{
+ String ROLE = RepositoryQueryLayerFactory.class.getName();
+
+ /**
+ * Create or obtain a query interface.
+ *
+ * @param repository the repository to query
+ * @return the obtained query layer
+ */
+ RepositoryQueryLayer createRepositoryQueryLayer( ArtifactRepository repository );
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java
new file mode 100644
index 000000000..93b9b2e6e
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTestCase.java
@@ -0,0 +1,283 @@
+package org.apache.maven.repository.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.repository.digest.Digester;
+import org.apache.maven.repository.digest.DigesterException;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+
+/**
+ * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter.
+ * It is extended by ChecksumArtifactReporterTest class.
+ */
+public abstract class AbstractChecksumArtifactReporterTestCase
+ extends AbstractRepositoryReportsTestCase
+{
+ private static final String[] validArtifactChecksumJars = {"validArtifact-1.0"};
+
+ private static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"};
+
+ private static final String metadataChecksumFilename = "maven-metadata";
+
+ private Digester sha1Digest;
+
+ private Digester md5Digest;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ sha1Digest = (Digester) lookup( Digester.ROLE, "sha1" );
+ md5Digest = (Digester) lookup( Digester.ROLE, "md5" );
+ }
+
+ /**
+ * Create checksum files.
+ *
+ * @param type The type of checksum file to be created.
+ */
+ protected void createChecksumFile( String type )
+ throws DigesterException, IOException
+ {
+ //loop through the valid artifact names..
+ if ( "VALID".equals( type ) )
+ {
+ for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+ {
+ writeChecksumFile( "checksumTest/", validArtifactChecksumJars[i], "jar", true );
+ }
+ }
+ else if ( "INVALID".equals( type ) )
+ {
+ for ( int i = 0; i < invalidArtifactChecksumJars.length; i++ )
+ {
+ writeChecksumFile( "checksumTest/", invalidArtifactChecksumJars[i], "jar", false );
+ }
+ }
+ }
+
+ /**
+ * Create checksum files for metadata.
+ *
+ * @param type The type of checksum to be created. (Valid or invalid)
+ */
+ protected void createMetadataFile( String type )
+ throws DigesterException, IOException
+ {
+ //loop through the valid artifact names..
+ if ( "VALID".equals( type ) )
+ {
+ writeMetadataFile( "checksumTest/validArtifact/1.0/", metadataChecksumFilename, "xml", true );
+ writeMetadataFile( "checksumTest/validArtifact/", metadataChecksumFilename, "xml", true );
+ writeMetadataFile( "checksumTest/", metadataChecksumFilename, "xml", true );
+ }
+ else if ( "INVALID".equals( type ) )
+ {
+ writeMetadataFile( "checksumTest/invalidArtifact/1.0/", metadataChecksumFilename, "xml", false );
+ }
+ }
+
+ /**
+ * Create artifact together with its checksums.
+ *
+ * @param relativePath The groupId
+ * @param filename The filename of the artifact to be created.
+ * @param type The file type (JAR)
+ * @param isValid Indicates whether the checksum to be created is valid or not.
+ */
+ private void writeChecksumFile( String relativePath, String filename, String type, boolean isValid )
+ throws IOException, DigesterException
+ {
+ //Initialize variables for creating jar files
+ String repoUrl = repository.getBasedir();
+
+ String dirs = filename.replace( '-', '/' );
+ //create the group level directory of the artifact
+ File dirFiles = new File( repoUrl + relativePath + dirs );
+
+ if ( dirFiles.mkdirs() )
+ {
+ // create a jar file
+ String path = repoUrl + relativePath + dirs + "/" + filename + "." + type;
+ FileOutputStream f = new FileOutputStream( path );
+ JarOutputStream out = new JarOutputStream( new BufferedOutputStream( f ) );
+
+ // jar sample.txt
+ String filename1 = repoUrl + relativePath + dirs + "/sample.txt";
+ createSampleFile( filename1 );
+
+ BufferedReader in = new BufferedReader( new FileReader( filename1 ) );
+ out.putNextEntry( new JarEntry( filename1 ) );
+ IOUtil.copy( in, out );
+ in.close();
+ out.close();
+
+ //Create md5 and sha-1 checksum files..
+
+ File file = new File( path + ".md5" );
+ OutputStream os = new FileOutputStream( file );
+ OutputStreamWriter osw = new OutputStreamWriter( os );
+ String sum = md5Digest.calc( new File( path ) );
+ if ( !isValid )
+ {
+ osw.write( sum + "1" );
+ }
+ else
+ {
+ osw.write( sum );
+ }
+ osw.close();
+
+ file = new File( path + ".sha1" );
+ os = new FileOutputStream( file );
+ osw = new OutputStreamWriter( os );
+ String sha1sum = sha1Digest.calc( new File( path ) );
+ if ( !isValid )
+ {
+ osw.write( sha1sum + "2" );
+ }
+ else
+ {
+ osw.write( sha1sum );
+ }
+ osw.close();
+ }
+ }
+
+ /**
+ * Create metadata file together with its checksums.
+ *
+ * @param relativePath The groupId
+ * @param filename The filename of the artifact to be created.
+ * @param type The file type (JAR)
+ * @param isValid Indicates whether the checksum to be created is valid or not.
+ */
+ private void writeMetadataFile( String relativePath, String filename, String type, boolean isValid )
+ throws IOException, DigesterException
+ {
+ //create checksum for the metadata file..
+ String repoUrl = repository.getBasedir();
+ String url = repository.getBasedir() + "/" + filename + "." + type;
+
+ String path = repoUrl + relativePath + filename + "." + type;
+ FileUtils.copyFile( new File( url ), new File( path ) );
+
+ //Create md5 and sha-1 checksum files..
+ File file = new File( path + ".md5" );
+ OutputStream os = new FileOutputStream( file );
+ OutputStreamWriter osw = new OutputStreamWriter( os );
+ String md5sum = md5Digest.calc( new File( path ) );
+ if ( !isValid )
+ {
+ osw.write( md5sum + "1" );
+ }
+ else
+ {
+ osw.write( md5sum );
+ }
+ osw.close();
+
+ file = new File( path + ".sha1" );
+ os = new FileOutputStream( file );
+ osw = new OutputStreamWriter( os );
+ String sha1sum = sha1Digest.calc( new File( path ) );
+ if ( !isValid )
+ {
+ osw.write( sha1sum + "2" );
+ }
+ else
+ {
+ osw.write( sha1sum );
+ }
+ osw.close();
+ }
+
+ /**
+ * Create the sample file that will be included in the jar.
+ *
+ * @param filename
+ */
+ private void createSampleFile( String filename )
+ throws IOException
+ {
+ File file = new File( filename );
+ OutputStream os = new FileOutputStream( file );
+ OutputStreamWriter osw = new OutputStreamWriter( os );
+ osw.write( "This is the content of the sample file that will be included in the jar file." );
+ osw.close();
+ }
+
+ /**
+ * Delete the test directory created in the repository.
+ *
+ * @param dir The directory to be deleted.
+ */
+ protected void deleteTestDirectory( File dir )
+ {
+ try
+ {
+ FileUtils.deleteDirectory( dir );
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+
+ private void deleteFile( String filename )
+ {
+ File f = new File( filename );
+ f.delete();
+ }
+
+ protected void deleteChecksumFiles( String type )
+ {
+ //delete valid checksum files of artifacts created
+ for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+ {
+ deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+ "/" + validArtifactChecksumJars[i] + "." + type + ".md5" );
+
+ deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+ "/" + validArtifactChecksumJars[i] + "." + type + ".sha1" );
+ }
+
+ //delete valid checksum files of metadata file
+ for ( int i = 0; i < validArtifactChecksumJars.length; i++ )
+ {
+ deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+ "/" + metadataChecksumFilename + ".xml.md5" );
+
+ deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) +
+ "/" + metadataChecksumFilename + ".xml.sha1" );
+ }
+ }
+
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java
new file mode 100644
index 000000000..6de998c8f
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTestCase.java
@@ -0,0 +1,142 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ *
+ */
+public abstract class AbstractRepositoryQueryLayerTestCase
+ extends PlexusTestCase
+{
+ private ArtifactFactory artifactFactory;
+
+ protected ArtifactRepository repository;
+
+ protected CachedRepositoryQueryLayer queryLayer;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ File repositoryDirectory = getTestFile( "src/test/repository" );
+
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+
+ repository =
+ factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
+ }
+
+ public void testContainsArtifactTrue()
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
+
+ assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
+ }
+
+ public void testContainsArtifactFalse()
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
+
+ assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
+ }
+
+ public void testContainsSnapshotArtifactTrue()
+ {
+ Snapshot snapshot = new Snapshot();
+ snapshot.setTimestamp( "20050611.202024" );
+ snapshot.setBuildNumber( 1 );
+
+ Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
+ assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
+ }
+
+ public void testContainsSnapshotArtifactFalse()
+ {
+ Snapshot snapshot = new Snapshot();
+ snapshot.setTimestamp( "20050611.202024" );
+ snapshot.setBuildNumber( 2 );
+
+ Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
+ assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
+ }
+
+ public void testArtifactVersionsTrue()
+ throws Exception
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
+
+ List versions = queryLayer.getVersions( artifact );
+
+ assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
+ assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
+ assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
+ }
+
+ public void testArtifactVersionsFalse()
+ throws Exception
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
+
+ List versions = queryLayer.getVersions( artifact );
+
+ assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
+ assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
+ assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
+ }
+
+ public void testArtifactVersionsError()
+ {
+ Artifact artifact = getArtifact( "groupId", "none", "ignored" );
+
+ try
+ {
+ queryLayer.getVersions( artifact );
+ fail( "expected error not thrown" );
+ }
+ catch ( RepositoryQueryLayerException e )
+ {
+ //expected
+ }
+ }
+
+ private Artifact getArtifact( String groupId, String artifactId, String version )
+ {
+ return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ release( artifactFactory );
+ super.tearDown();
+ artifactFactory = null;
+ repository = null;
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java
new file mode 100644
index 000000000..45f12964e
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java
@@ -0,0 +1,64 @@
+package org.apache.maven.repository.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;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+
+/**
+ *
+ */
+public abstract class AbstractRepositoryReportsTestCase
+ extends PlexusTestCase
+{
+ /**
+ * This should only be used for the few that can't use the query layer.
+ */
+ protected ArtifactRepository repository;
+
+ protected static final String remoteRepoUrl = "http://public.planetmirror.com/pub/maven2/";
+
+ protected static final String remoteArtifactGroup = "HTTPClient";
+
+ protected static final String remoteArtifactId = "HTTPClient";
+
+ protected static final String remoteArtifactVersion = "0.3-3";
+
+ protected static final String remoteArtifactScope = "compile";
+
+ protected static final String remoteArtifactType = "jar";
+
+ protected static final String remoteRepoId = "remote-repo";
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ File repositoryDirectory = getTestFile( "src/test/repository" );
+
+ ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+
+ repository = factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout,
+ null, null );
+ }
+
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java
new file mode 100644
index 000000000..4d6c697f3
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java
@@ -0,0 +1,463 @@
+package org.apache.maven.repository.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.model.Dependency;
+import org.apache.maven.model.Model;
+
+import java.util.Iterator;
+
+/**
+ *
+ */
+public class ArtifactReportProcessorTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private static final String EMPTY_STRING = "";
+
+ private static final String VALID = "temp";
+
+ private MockArtifactReporter reporter;
+
+ private Artifact artifact;
+
+ private Model model;
+
+ private DefaultArtifactReportProcessor processor;
+
+ private static final boolean ARTIFACT_FOUND = true;
+
+ private static final boolean ARTIFACT_NOT_FOUND = false;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ reporter = new MockArtifactReporter();
+ artifact = new MockArtifact();
+ model = new Model();
+ processor = new DefaultArtifactReportProcessor();
+ }
+
+ public void testNullArtifact()
+ {
+ processor.processArtifact( model, null, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.NULL_ARTIFACT, result.getReason() );
+ }
+
+ public void testNoProjectDescriptor()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ processor.processArtifact( null, artifact, reporter, null );
+ assertEquals( 1, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.NULL_MODEL, result.getReason() );
+ }
+
+ public void testArtifactFoundButNoDirectDependencies()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 1, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testArtifactNotFound()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_NOT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() );
+ }
+
+ public void testValidArtifactWithNullDependency()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, VALID, VALID, VALID );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 2, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testValidArtifactWithValidSingleDependency()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, VALID, VALID, VALID );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 2, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testValidArtifactWithValidMultipleDependencies()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, VALID, VALID, VALID );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 6, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testValidArtifactWithAnInvalidDependency()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, VALID, VALID, VALID );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_NOT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 5, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
+ }
+
+ public void testEmptyGroupId()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, EMPTY_STRING, VALID, VALID );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
+ }
+
+ public void testEmptyArtifactId()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, VALID, EMPTY_STRING, VALID );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
+ }
+
+ public void testEmptyVersion()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, VALID, VALID, EMPTY_STRING );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
+ }
+
+ public void testNullGroupId()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, null, VALID, VALID );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
+ }
+
+ public void testNullArtifactId()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, VALID, null, VALID );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
+ }
+
+ public void testNullVersion()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, VALID, VALID, null );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
+ }
+
+ public void testMultipleFailures()
+ {
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+ processor.setRepositoryQueryLayer( queryLayer );
+
+ setRequiredElements( artifact, null, null, null );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 3, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
+ result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
+ result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
+ }
+
+ public void testValidArtifactWithInvalidDependencyGroupId()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, null, VALID, VALID );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 1, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
+ }
+
+ public void testValidArtifactWithInvalidDependencyArtifactId()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, VALID, null, VALID );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 1, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
+ }
+
+ public void testValidArtifactWithInvalidDependencyVersion()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, VALID, VALID, null );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 1, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
+ }
+
+ public void testValidArtifactWithInvalidDependencyRequiredElements()
+ {
+ MockArtifactFactory artifactFactory = new MockArtifactFactory();
+ processor.setArtifactFactory( artifactFactory );
+
+ setRequiredElements( artifact, VALID, VALID, VALID );
+ MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ Dependency dependency = new Dependency();
+ setRequiredElements( dependency, null, null, null );
+ model.addDependency( dependency );
+ queryLayer.addReturnValue( ARTIFACT_FOUND );
+
+ processor.setRepositoryQueryLayer( queryLayer );
+ processor.processArtifact( model, artifact, reporter, null );
+ assertEquals( 1, reporter.getSuccesses() );
+ assertEquals( 3, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+
+ Iterator failures = reporter.getArtifactFailureIterator();
+ ArtifactResult result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
+ result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
+ result = (ArtifactResult) failures.next();
+ assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ model = null;
+ artifact = null;
+ reporter = null;
+ super.tearDown();
+ }
+
+ private void setRequiredElements( Artifact artifact, String groupId, String artifactId, String version )
+ {
+ artifact.setGroupId( groupId );
+ artifact.setArtifactId( artifactId );
+ artifact.setVersion( version );
+ }
+
+ private void setRequiredElements( Dependency dependency, String groupId, String artifactId, String version )
+ {
+ dependency.setGroupId( groupId );
+ dependency.setArtifactId( artifactId );
+ dependency.setVersion( version );
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java
new file mode 100644
index 000000000..e3fc97f6b
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java
@@ -0,0 +1,187 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+import org.apache.maven.model.Model;
+
+import java.util.Iterator;
+
+/**
+ *
+ */
+public class ArtifactReporterTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private ArtifactReporter reporter;
+
+ private Artifact artifact;
+
+ private MockArtifactReportProcessor processor;
+
+ private Model model;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ reporter = new DefaultArtifactReporter();
+ ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
+ processor = new MockArtifactReportProcessor();
+ Versioning versioning = new Versioning();
+ versioning.addVersion( "1.0-alpha-1" );
+ versioning.setLastUpdated( "20050611.202020" );
+ model = new Model();
+ }
+
+ public void testArtifactReporterSingleSuccess()
+ {
+ processor.addReturnValue( ReportCondition.SUCCESS, artifact, "all is good" );
+ processor.processArtifact( model, artifact, reporter, null );
+ Iterator success = reporter.getArtifactSuccessIterator();
+ assertTrue( success.hasNext() );
+ assertEquals( 1, reporter.getSuccesses() );
+ Artifact result = ( (ArtifactResult) success.next() ).getArtifact();
+ assertEquals( "groupId", result.getGroupId() );
+ assertEquals( "artifactId", result.getArtifactId() );
+ assertEquals( "1.0-alpha-1", result.getVersion() );
+ assertFalse( success.hasNext() );
+ }
+
+ public void testArtifactReporterMultipleSuccess()
+ {
+ processor.clearList();
+ processor.addReturnValue( ReportCondition.SUCCESS, artifact, "one" );
+ processor.addReturnValue( ReportCondition.SUCCESS, artifact, "two" );
+ processor.addReturnValue( ReportCondition.SUCCESS, artifact, "three" );
+ reporter = new DefaultArtifactReporter();
+ processor.processArtifact( model, artifact, reporter, null );
+ Iterator success = reporter.getArtifactSuccessIterator();
+ assertTrue( success.hasNext() );
+ int i;
+ for ( i = 0; success.hasNext(); i++ )
+ {
+ success.next();
+ }
+ assertEquals( 3, i );
+ assertEquals( 3, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testArtifactReporterSingleFailure()
+ {
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
+ processor.processArtifact( model, artifact, reporter, null );
+ Iterator failure = reporter.getArtifactFailureIterator();
+ assertTrue( failure.hasNext() );
+ failure.next();
+ assertFalse( failure.hasNext() );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 1, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testArtifactReporterMultipleFailure()
+ {
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
+ processor.processArtifact( model, artifact, reporter, null );
+ Iterator failure = reporter.getArtifactFailureIterator();
+ assertTrue( failure.hasNext() );
+ int i;
+ for ( i = 0; failure.hasNext(); i++ )
+ {
+ failure.next();
+ }
+ assertEquals( 3, i );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 3, reporter.getFailures() );
+ assertEquals( 0, reporter.getWarnings() );
+ }
+
+ public void testFailureMessages()
+ {
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
+ processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
+ processor.processArtifact( model, artifact, reporter, null );
+ 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() );
+ }
+
+ public void testArtifactReporterSingleWarning()
+ {
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "you've been warned" );
+ processor.processArtifact( model, artifact, reporter, null );
+ Iterator warning = reporter.getArtifactWarningIterator();
+ assertTrue( warning.hasNext() );
+ warning.next();
+ assertFalse( warning.hasNext() );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 1, reporter.getWarnings() );
+ }
+
+ public void testArtifactReporterMultipleWarning()
+ {
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
+ processor.processArtifact( model, artifact, reporter, null );
+ Iterator warning = reporter.getArtifactWarningIterator();
+ assertTrue( warning.hasNext() );
+ int i;
+ for ( i = 0; warning.hasNext(); i++ )
+ {
+ warning.next();
+ }
+ assertEquals( 3, i );
+ assertEquals( 0, reporter.getSuccesses() );
+ assertEquals( 0, reporter.getFailures() );
+ assertEquals( 3, reporter.getWarnings() );
+ }
+
+ public void testWarningMessages()
+ {
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
+ processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
+ processor.processArtifact( model, artifact, reporter, null );
+ 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() );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ model = null;
+ processor.clearList();
+ processor = null;
+ reporter = null;
+ super.tearDown();
+ }
+
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java
new file mode 100644
index 000000000..828b27274
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java
@@ -0,0 +1,358 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Plugin;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+
+import java.util.Iterator;
+
+/**
+ * @todo??? should use MetadataXpp3Reader instead ?
+ */
+public class BadMetadataReportProcessorTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private ArtifactFactory artifactFactory;
+
+ private MetadataReportProcessor badMetadataReportProcessor;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+
+ badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE );
+ }
+
+ public void testMetadataMissingLastUpdated()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ 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" );
+
+ RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ assertEquals( "check metadata", metadata, result.getMetadata() );
+ assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testMetadataValidVersions()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ 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" );
+ versioning.setLastUpdated( "20050611.202020" );
+
+ RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertFalse( "check there are no failures", failures.hasNext() );
+ }
+
+ public void testMetadataMissingADirectory()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
+
+ Versioning versioning = new Versioning();
+ versioning.addVersion( "1.0-alpha-1" );
+ versioning.setLastUpdated( "20050611.202020" );
+
+ RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ assertEquals( "check metadata", metadata, result.getMetadata() );
+ // TODO: should be more robust
+ assertEquals( "check reason",
+ "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.",
+ result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testMetadataInvalidArtifactVersion()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ 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" );
+ versioning.addVersion( "1.0-alpha-3" );
+ versioning.setLastUpdated( "20050611.202020" );
+
+ RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ assertEquals( "check metadata", metadata, result.getMetadata() );
+ // 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() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testMoreThanOneMetadataVersionErrors()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ 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-3" );
+ versioning.setLastUpdated( "20050611.202020" );
+
+ RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ assertEquals( "check metadata", metadata, result.getMetadata() );
+ // 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();
+ // TODO: should be more robust
+ assertEquals( "check reason",
+ "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.",
+ result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testValidPluginMetadata()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertFalse( "check there are no failures", failures.hasNext() );
+ }
+
+ public void testMissingMetadataPlugin()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository",
+ result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testIncompletePluginMetadata()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason",
+ "Plugin snapshot-artifact is present in the repository but " + "missing in the metadata.",
+ result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testInvalidPluginArtifactId()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() );
+ assertTrue( "check there is a 2nd failure", failures.hasNext() );
+ result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testInvalidPluginPrefix()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "" ) );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason", "Missing or empty plugin prefix for artifactId artifactId.", result.getReason() );
+ assertTrue( "check there is a 2nd failure", failures.hasNext() );
+ result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason", "Missing or empty plugin prefix for artifactId snapshot-artifact.",
+ result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testDuplicatePluginPrefixes()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
+ metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default" ) );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ // TODO: should be more robust
+ assertEquals( "check reason", "Duplicate plugin prefix found: default.", result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ public void testValidSnapshotMetadata()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ Artifact artifact =
+ artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
+
+ Snapshot snapshot = new Snapshot();
+ snapshot.setBuildNumber( 1 );
+ snapshot.setTimestamp( "20050611.202024" );
+
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertFalse( "check there are no failures", failures.hasNext() );
+ }
+
+ public void testInvalidSnapshotMetadata()
+ throws ReportProcessorException
+ {
+ ArtifactReporter reporter = new MockArtifactReporter();
+
+ Artifact artifact =
+ artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
+
+ Snapshot snapshot = new Snapshot();
+ snapshot.setBuildNumber( 2 );
+ snapshot.setTimestamp( "20050611.202024" );
+
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
+
+ badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator failures = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check there is a failure", failures.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
+ assertEquals( "check metadata", metadata, result.getMetadata() );
+ // TODO: should be more robust
+ assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() );
+ assertFalse( "check no more failures", failures.hasNext() );
+ }
+
+ private Plugin createMetadataPlugin( String artifactId, String prefix )
+ {
+ Plugin plugin = new Plugin();
+ plugin.setArtifactId( artifactId );
+ plugin.setName( artifactId );
+ plugin.setPrefix( prefix );
+ return plugin;
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java
new file mode 100644
index 000000000..cfc83b309
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java
@@ -0,0 +1,143 @@
+package org.apache.maven.repository.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 junit.framework.TestCase;
+
+/**
+ *
+ */
+public class CacheTest
+ extends TestCase
+{
+ private Cache cache;
+
+ private static final double CACHE_HIT_RATIO = 0.5;
+
+ private static final double CACHE_HIT_RATIO_THRESHOLD = 0.75;
+
+ public void testCacheManagementBasedOnHitsRatio()
+ {
+ cache = new Cache( CACHE_HIT_RATIO );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD )
+ {
+ cache.get( "key2" );
+ }
+ cache.put( "key10", "value10" );
+ assertNull( "first key must be expired", cache.get( "key1" ) );
+ }
+
+ public void testCacheManagementBasedOnCacheSize()
+ {
+ cache = new Cache( 9 );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ cache.put( "key10", "value10" );
+ assertNull( "first key must be expired", cache.get( "key1" ) );
+ assertEquals( "check cache size to be max size", 9, cache.size() );
+ }
+
+ public void testCacheManagementBasedOnCacheSizeAndHitRate()
+ {
+ cache = new Cache( CACHE_HIT_RATIO, 9 );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 5; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ while ( cache.getHitRate() < CACHE_HIT_RATIO )
+ {
+ cache.get( "key3" );
+ }
+
+ cache.put( "key10", "value10" );
+ assertNull( "first key must be expired", cache.get( "key1" ) );
+
+ while ( cache.getHitRate() >= CACHE_HIT_RATIO )
+ {
+ cache.get( "key11" );
+ }
+
+ for ( int ctr = 5; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ cache.put( "key11", "value11" );
+ assertNull( "second key must be expired", cache.get( "key2" ) );
+ assertEquals( "check cache size to be max size", 9, cache.size() );
+ }
+
+ public void testCacheOnRedundantData()
+ {
+ cache = new Cache( CACHE_HIT_RATIO, 9 );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ cache.put( "key1", "value1" );
+ cache.put( "key10", "value10" );
+ assertNull( "second key must be gone", cache.get( "key2" ) );
+ assertEquals( "check cache size to be max size", 9, cache.size() );
+ }
+
+ private void newCacheObjectTests()
+ {
+ assertEquals( (double) 0, cache.getHitRate(), 0 );
+ assertEquals( "check cache size", 0, cache.size() );
+
+ String value = "value";
+ String key = "key";
+
+ cache.put( key, value );
+ assertEquals( "check cache hit", value, cache.get( key ) );
+ assertEquals( (double) 1, cache.getHitRate(), 0 );
+ assertEquals( "check cache size", 1, cache.size() );
+ assertNull( "check cache miss", cache.get( "none" ) );
+ assertEquals( CACHE_HIT_RATIO, cache.getHitRate(), 0 );
+ cache.clear();
+ assertNull( "check flushed object", cache.get( "key" ) );
+ assertEquals( (double) 0, cache.getHitRate(), 0 );
+ assertEquals( "check flushed cache size", 0, cache.size() );
+ cache.clear();
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java
new file mode 100644
index 000000000..11c0b8e95
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java
@@ -0,0 +1,58 @@
+package org.apache.maven.repository.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.
+ */
+
+/**
+ *
+ */
+public class CachedRepositoryQueryLayerTest
+ extends AbstractRepositoryQueryLayerTestCase
+{
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ queryLayer = new CachedRepositoryQueryLayer( repository );
+ }
+
+ public void testUseFileCache()
+ {
+ testContainsArtifactTrue();
+ assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
+ testContainsArtifactTrue();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
+ }
+
+ public void testUseMetadataCache()
+ throws Exception
+ {
+ testArtifactVersionsTrue();
+ assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
+ testArtifactVersionsTrue();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
+ }
+
+ public void testUseFileCacheOnSnapshot()
+ {
+ testContainsSnapshotArtifactTrue();
+ assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
+ testContainsSnapshotArtifactTrue();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
new file mode 100644
index 000000000..64585c52d
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java
@@ -0,0 +1,220 @@
+package org.apache.maven.repository.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.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 org.apache.maven.repository.digest.DigesterException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * This class tests the ChecksumArtifactReporter.
+ * It extends the AbstractChecksumArtifactReporterTestCase class.
+ */
+public class ChecksumArtifactReporterTest
+ extends AbstractChecksumArtifactReporterTestCase
+{
+ private ArtifactReportProcessor artifactReportProcessor;
+
+ private ArtifactReporter reporter = new MockArtifactReporter();
+
+ private MetadataReportProcessor metadataReportProcessor;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
+ metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
+ }
+
+ /**
+ * Test the ChecksumArtifactReporter when the checksum files are valid.
+ */
+ public void testChecksumArtifactReporterSuccess()
+ throws ReportProcessorException, IOException, DigesterException
+ {
+ 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 );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ assertEquals( 2, reporter.getSuccesses() );
+ }
+
+ /**
+ * Test the ChecksumArtifactReporter 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 );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ assertEquals( 2, reporter.getFailures() );
+ }
+
+ /**
+ * Test the valid checksum of a metadata file.
+ * The reporter should report 2 success validation.
+ */
+ public void testChecksumMetadataReporterSuccess()
+ throws ReportProcessorException, 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 );
+
+ //Version level metadata
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+ metadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ //Artifact level metadata
+ metadata = new ArtifactRepositoryMetadata( artifact );
+ metadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ //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() );
+ }
+
+ /**
+ * Test the corrupted checksum of a metadata file.
+ * 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 );
+
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+ metadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator iter = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check if there is a failure", iter.hasNext() );
+ }
+
+ /**
+ * Test the checksum of an artifact located in a remote location.
+ */
+ /* public void testChecksumArtifactRemote()
+ {
+ ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
+ VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
+ Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope,
+ remoteArtifactType, "", handler );
+ ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
+ new DefaultRepositoryLayout() );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ if ( reporter.getFailures() == 2 )
+ assertTrue( reporter.getFailures() == 2 );
+
+ if ( reporter.getSuccesses() == 2 )
+ assertTrue( reporter.getSuccesses() == 2 );
+
+ }
+ */
+
+ /**
+ * Test the checksum of a metadata file located in a remote location.
+ */
+ /* public void testChecksumMetadataRemote()
+ {
+
+ try
+ {
+ ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
+ VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
+ Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version,
+ remoteArtifactScope, remoteArtifactType, "", handler );
+ ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
+ new DefaultRepositoryLayout() );
+
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+
+ metadataReportProcessor.processMetadata( metadata, repository, reporter );
+ Iterator iter = reporter.getRepositoryMetadataFailureIterator();
+ if ( iter.hasNext() )
+ assertTrue( "check if there is a failure", iter.hasNext() );
+
+ iter = reporter.getRepositoryMetadataSuccessIterator();
+ if ( iter.hasNext() )
+ assertTrue( "check if there is a success", iter.hasNext() );
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+ */
+
+ /**
+ * Test the conditional when the checksum files of the artifact & metadata do not exist.
+ */
+ public void testChecksumFilesDoNotExist()
+ throws ReportProcessorException, 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 );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ assertEquals( 2, reporter.getFailures() );
+
+ RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
+ metadataReportProcessor.processMetadata( metadata, repository, reporter );
+
+ Iterator iter = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "check if there is a failure", iter.hasNext() );
+
+ deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java
new file mode 100644
index 000000000..ac19ab3e0
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java
@@ -0,0 +1,184 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+
+import java.util.Iterator;
+
+/**
+ *
+ */
+public class DefaultArtifactReporterTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private ArtifactReporter reporter;
+
+ private Artifact artifact;
+
+ private RepositoryMetadata metadata;
+
+ public void testEmptyArtifactReporter()
+ {
+ assertEquals( "No failures", 0, reporter.getFailures() );
+ assertEquals( "No warnings", 0, reporter.getWarnings() );
+ assertEquals( "No successes", 0, reporter.getSuccesses() );
+ 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() );
+ }
+
+ public void testMetadataSingleFailure()
+ {
+ reporter.addFailure( metadata, "Single Failure Reason" );
+ assertEquals( "failures count", 1, reporter.getFailures() );
+ assertEquals( "warnings count", 0, reporter.getWarnings() );
+ assertEquals( "successes count", 0, reporter.getSuccesses() );
+
+ Iterator results = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "must have failures", results.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
+ assertEquals( "check failure cause", metadata, result.getMetadata() );
+ assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
+ assertFalse( "no more failures", results.hasNext() );
+ }
+
+ public void testMetadataMultipleFailures()
+ {
+ reporter.addFailure( metadata, "First Failure Reason" );
+ reporter.addFailure( metadata, "Second Failure Reason" );
+ assertEquals( "failures count", 2, reporter.getFailures() );
+ assertEquals( "warnings count", 0, reporter.getWarnings() );
+ assertEquals( "successes count", 0, reporter.getSuccesses() );
+
+ Iterator results = reporter.getRepositoryMetadataFailureIterator();
+ assertTrue( "must have failures", results.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
+ assertEquals( "check failure cause", metadata, result.getMetadata() );
+ 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() );
+ assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
+ assertFalse( "no more failures", results.hasNext() );
+ }
+
+ public void testMetadataSingleWarning()
+ {
+ reporter.addWarning( metadata, "Single Warning Message" );
+ assertEquals( "failures count", 0, reporter.getFailures() );
+ assertEquals( "warnings count", 1, reporter.getWarnings() );
+ assertEquals( "successes count", 0, reporter.getSuccesses() );
+
+ Iterator results = reporter.getRepositoryMetadataWarningIterator();
+ assertTrue( "must have failures", results.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
+ assertEquals( "check failure cause", metadata, result.getMetadata() );
+ assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
+ assertFalse( "no more failures", results.hasNext() );
+ }
+
+ public void testMetadataMultipleWarnings()
+ {
+ reporter.addWarning( metadata, "First Warning" );
+ reporter.addWarning( metadata, "Second Warning" );
+ assertEquals( "failures count", 0, reporter.getFailures() );
+ assertEquals( "warnings count", 2, reporter.getWarnings() );
+ assertEquals( "successes count", 0, reporter.getSuccesses() );
+
+ Iterator results = reporter.getRepositoryMetadataWarningIterator();
+ assertTrue( "must have warnings", results.hasNext() );
+ RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
+ assertEquals( "check failure cause", metadata, result.getMetadata() );
+ 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() );
+ 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.getFailures() );
+ assertEquals( "warnings count", 0, reporter.getWarnings() );
+ assertEquals( "successes count", 1, reporter.getSuccesses() );
+
+ 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.getFailures() );
+ assertEquals( "warnings count", 0, reporter.getWarnings() );
+ assertEquals( "successes count", 2, reporter.getSuccesses() );
+
+ 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() );
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ reporter = new DefaultArtifactReporter();
+ 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.addVersion( "1.0-alpha-2" );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+
+ reporter = null;
+ metadata = null;
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
new file mode 100644
index 000000000..31dec3015
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.java
@@ -0,0 +1,149 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.model.Model;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndex;
+import org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory;
+import org.apache.maven.repository.indexing.record.RepositoryIndexRecordFactory;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.Collections;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class DuplicateArtifactFileReportProcessorTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private Artifact artifact;
+
+ private Model model;
+
+ private ArtifactReportProcessor processor;
+
+ private ArtifactFactory artifactFactory;
+
+ File indexDirectory;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ indexDirectory = getTestFile( "target/indexDirectory" );
+ FileUtils.deleteDirectory( indexDirectory );
+
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
+ model = new Model();
+
+ RepositoryArtifactIndexFactory factory =
+ (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" );
+
+ RepositoryArtifactIndex index = factory.createStandardIndex( indexDirectory );
+
+ RepositoryIndexRecordFactory recordFactory =
+ (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" );
+
+ index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact ) ) );
+
+ processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
+ }
+
+ public void testNullArtifactFile()
+ throws Exception
+ {
+ artifact.setFile( null );
+
+ MockArtifactReporter reporter = new MockArtifactReporter();
+
+ processor.processArtifact( model, artifact, reporter, repository );
+
+ assertEquals( "Check no successes", 0, reporter.getSuccesses() );
+ assertEquals( "Check warnings", 1, reporter.getWarnings() );
+ assertEquals( "Check no failures", 0, reporter.getFailures() );
+ }
+
+ public void testSuccessOnAlreadyIndexedArtifact()
+ throws Exception
+ {
+ MockArtifactReporter reporter = new MockArtifactReporter();
+
+ processor.processArtifact( model, artifact, reporter, repository );
+
+ assertEquals( "Check no successes", 1, reporter.getSuccesses() );
+ assertEquals( "Check warnings", 0, reporter.getWarnings() );
+ assertEquals( "Check no failures", 0, reporter.getFailures() );
+ }
+
+ public void testSuccessOnDifferentGroupId()
+ throws Exception
+ {
+ MockArtifactReporter reporter = new MockArtifactReporter();
+
+ artifact.setGroupId( "different.groupId" );
+ processor.processArtifact( model, artifact, reporter, repository );
+
+ assertEquals( "Check no successes", 1, reporter.getSuccesses() );
+ assertEquals( "Check warnings", 0, reporter.getWarnings() );
+ assertEquals( "Check no failures", 0, reporter.getFailures() );
+ }
+
+ public void testSuccessOnNewArtifact()
+ throws Exception
+ {
+ Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" );
+
+ MockArtifactReporter reporter = new MockArtifactReporter();
+
+ processor.processArtifact( model, newArtifact, reporter, repository );
+
+ assertEquals( "Check no successes", 1, reporter.getSuccesses() );
+ assertEquals( "Check warnings", 0, reporter.getWarnings() );
+ assertEquals( "Check no failures", 0, reporter.getFailures() );
+ }
+
+ public void testFailure()
+ throws Exception
+ {
+ Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT",
+ artifact.getVersion(), artifact.getType() );
+ duplicate.setFile( artifact.getFile() );
+
+ MockArtifactReporter reporter = new MockArtifactReporter();
+
+ processor.processArtifact( model, duplicate, reporter, repository );
+
+ assertEquals( "Check no successes", 0, reporter.getSuccesses() );
+ assertEquals( "Check warnings", 0, reporter.getWarnings() );
+ assertEquals( "Check no failures", 1, reporter.getFailures() );
+ }
+
+ private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
+ String type )
+ {
+ Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
+ artifact.setBaseVersion( baseVersion );
+ artifact.setRepository( repository );
+ artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
+ return artifact;
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java
new file mode 100644
index 000000000..7ab3de250
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java
@@ -0,0 +1,62 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class GenericMockObject
+ implements InvocationHandler
+{
+ private Map invocations = new HashMap();
+
+ public GenericMockObject()
+ {
+ //default constructor
+ }
+
+ public GenericMockObject( Map returnMap )
+ {
+ invocations = new HashMap( returnMap );
+ }
+
+ public void setExpectedReturns( Method method, List returnList )
+ {
+ invocations.put( method, returnList );
+ }
+
+ public Object invoke( Object proxy, Method method, Object[] args )
+ {
+ if ( !invocations.containsKey( method ) )
+ {
+ throw new UnsupportedOperationException( "No expected return values defined." );
+ }
+
+ List returnList = (List) invocations.get( method );
+ if ( returnList.size() < 1 )
+ {
+ throw new UnsupportedOperationException( "Too few expected return values defined." );
+ }
+ return returnList.remove( 0 );
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java
new file mode 100644
index 000000000..71c53d8bd
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java
@@ -0,0 +1,109 @@
+package org.apache.maven.repository.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.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.
+ */
+public class InvalidPomArtifactReportProcessorTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private ArtifactReportProcessor artifactReportProcessor;
+
+ private ArtifactReporter reporter = new MockArtifactReporter();
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "invalid-pom" );
+ }
+
+ /**
+ * 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 );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ assertEquals( 1, reporter.getFailures() );
+ }
+
+
+ /**
+ * 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 );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ assertEquals( 1, reporter.getSuccesses() );
+ }
+
+
+ /**
+ * 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 );
+
+ artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
+ assertEquals( 1, reporter.getWarnings() );
+ }
+
+ /**
+ * Test the InvalidPomArtifactReportProcessor when the pom is located in
+ * a remote repository.
+ */
+ /* public void testRemotePomArtifactReportProcessorSuccess(){
+ try{
+ ArtifactHandler handler = new DefaultArtifactHandler( "pom" );
+ VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
+ Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope,
+ "pom", "", handler );
+ ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
+ new DefaultRepositoryLayout() );
+
+ artifactReportProcessor.processArtifact(null, artifact, reporter, repository);
+ if(reporter.getSuccesses() == 1)
+ assertTrue(reporter.getSuccesses() == 1);
+
+ }catch(Exception e){
+
+ }
+ }
+ */
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java
new file mode 100644
index 000000000..d892dd3a6
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java
@@ -0,0 +1,224 @@
+package org.apache.maven.repository.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.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;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * This class tests the LocationArtifactReportProcessor.
+ */
+public class LocationArtifactReportProcessorTest
+ extends AbstractRepositoryReportsTestCase
+{
+ private ArtifactReportProcessor artifactReportProcessor;
+
+ private ArtifactReporter reporter = new MockArtifactReporter();
+
+ private MavenXpp3Reader pomReader;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" );
+ pomReader = new MavenXpp3Reader();
+ }
+
+ public void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ artifactReportProcessor = null;
+ pomReader = null;
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact's physical location matches the location specified
+ * both in the file system pom and in the pom included in the package.
+ */
+ public void testPackagedPomLocationArtifactReporterSuccess()
+ throws ReportProcessorException, 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 );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getSuccesses() );
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact is in the location specified in the
+ * file system pom (but the jar file does not have a pom included in its package).
+ */
+ public void testLocationArtifactReporterSuccess()
+ throws ReportProcessorException, 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 );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getSuccesses() );
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact is not in the location specified
+ * in the file system pom.
+ */
+ public void testLocationArtifactReporterFailure()
+ throws IOException, XmlPullParserException, ReportProcessorException
+ {
+ 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 );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getFailures() );
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact's physical location does not match the
+ * location in the file system pom but instead matches the specified location in the packaged pom.
+ */
+ public void testFsPomArtifactMatchFailure()
+ throws IOException, ReportProcessorException, 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 );
+
+ String path = "org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom";
+ Model model = readPom( path );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getFailures() );
+ }
+
+ private Model readPom( String path )
+ throws IOException, XmlPullParserException
+ {
+ Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
+ Model model = pomReader.read( reader );
+ // hokey inheritence to avoid some errors right now
+ if ( model.getGroupId() == null )
+ {
+ model.setGroupId( model.getParent().getGroupId() );
+ }
+ if ( model.getVersion() == null )
+ {
+ model.setVersion( model.getParent().getVersion() );
+ }
+ return model;
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact's physical location does not match the
+ * location specified in the packaged pom but matches the location specified in the file system pom.
+ */
+ public void testPkgPomArtifactMatchFailure()
+ throws IOException, XmlPullParserException, ReportProcessorException
+ {
+ 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 );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getFailures() );
+ }
+
+ /**
+ * Test the LocationArtifactReporter when the artifact's physical location does not match both the
+ * location specified in the packaged pom and the location specified in the file system pom.
+ */
+ public void testBothPomArtifactMatchFailure()
+ throws IOException, XmlPullParserException, ReportProcessorException
+ {
+ 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 );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getFailures() );
+ }
+
+ /**
+ * Test the LocationArtifactReportProcessor when the artifact is located in the remote repository.
+ */
+ /* public void testRemoteArtifactReportProcessorFailure()
+ {
+
+ ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
+ VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
+ Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope,
+ remoteArtifactType, "", handler );
+ ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
+ new DefaultRepositoryLayout() );
+ try
+ {
+ URL url = new URL( remoteRepoUrl + remoteArtifactGroup + "/" + remoteArtifactId + "/"
+ + remoteArtifactVersion + "/" + remoteArtifactId + "-" + remoteArtifactVersion + ".pom" );
+ InputStream is = url.openStream();
+ Reader reader = new InputStreamReader( is );
+ Model model = pomReader.read( reader );
+
+ artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
+ if ( reporter.getFailures() > 0 )
+ assertTrue( reporter.getFailures() == 1 );
+
+ if ( reporter.getSuccesses() > 0 )
+ assertTrue( reporter.getSuccesses() == 1 );
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+ */
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java
new file mode 100644
index 000000000..a9f3cd3f2
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java
@@ -0,0 +1,258 @@
+package org.apache.maven.repository.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.handler.ArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.artifact.versioning.ArtifactVersion;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @noinspection ReturnOfNull
+ */
+public class MockArtifact
+ implements Artifact
+{
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String s )
+ {
+ version = s;
+ }
+
+ public String getScope()
+ {
+ return null;
+ }
+
+ public String getType()
+ {
+ return null;
+ }
+
+ public String getClassifier()
+ {
+ return null;
+ }
+
+ public boolean hasClassifier()
+ {
+ return false;
+ }
+
+ public File getFile()
+ {
+ return null;
+ }
+
+ public void setFile( File file )
+ {
+ }
+
+ public String getBaseVersion()
+ {
+ return null;
+ }
+
+ public void setBaseVersion( String s )
+ {
+ }
+
+ public String getId()
+ {
+ return null;
+ }
+
+ public String getDependencyConflictId()
+ {
+ return null;
+ }
+
+ public void addMetadata( ArtifactMetadata artifactMetadata )
+ {
+ }
+
+ public Collection getMetadataList()
+ {
+ return null;
+ }
+
+ public void setRepository( ArtifactRepository artifactRepository )
+ {
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return null;
+ }
+
+ public void updateVersion( String s, ArtifactRepository artifactRepository )
+ {
+ }
+
+ public String getDownloadUrl()
+ {
+ return null;
+ }
+
+ public void setDownloadUrl( String s )
+ {
+ }
+
+ public ArtifactFilter getDependencyFilter()
+ {
+ return null;
+ }
+
+ public void setDependencyFilter( ArtifactFilter artifactFilter )
+ {
+ }
+
+ public ArtifactHandler getArtifactHandler()
+ {
+ return null;
+ }
+
+ public List getDependencyTrail()
+ {
+ return null;
+ }
+
+ public void setDependencyTrail( List list )
+ {
+ }
+
+ public void setScope( String s )
+ {
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return null;
+ }
+
+ public void setVersionRange( VersionRange versionRange )
+ {
+ }
+
+ public void selectVersion( String s )
+ {
+ }
+
+ public void setGroupId( String s )
+ {
+ groupId = s;
+ }
+
+ public void setArtifactId( String s )
+ {
+ artifactId = s;
+ }
+
+ public boolean isSnapshot()
+ {
+ return false;
+ }
+
+ public void setResolved( boolean b )
+ {
+ }
+
+ public boolean isResolved()
+ {
+ return false;
+ }
+
+ public void setResolvedVersion( String s )
+ {
+ }
+
+ public void setArtifactHandler( ArtifactHandler artifactHandler )
+ {
+ }
+
+ public boolean isRelease()
+ {
+ return false;
+ }
+
+ public void setRelease( boolean b )
+ {
+ }
+
+ public List getAvailableVersions()
+ {
+ return null;
+ }
+
+ public void setAvailableVersions( List list )
+ {
+ }
+
+ public boolean isOptional()
+ {
+ return false;
+ }
+
+ public ArtifactVersion getSelectedVersion()
+ throws OverConstrainedVersionException
+ {
+ return null;
+ }
+
+ public boolean isSelectedVersionKnown()
+ throws OverConstrainedVersionException
+ {
+ return false;
+ }
+
+ public int compareTo( Object o )
+ {
+ return 0;
+ }
+
+ public void setOptional( boolean b )
+ {
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java
new file mode 100644
index 000000000..7bdc708a9
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java
@@ -0,0 +1,92 @@
+package org.apache.maven.repository.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.factory.ArtifactFactory;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+/**
+ * @noinspection ReturnOfNull
+ */
+public class MockArtifactFactory
+ implements ArtifactFactory
+{
+ public Artifact createArtifact( String s, String s1, String s2, String s3, String s4 )
+ {
+ return null;
+ }
+
+ public Artifact createArtifactWithClassifier( String s, String s1, String s2, String s3, String s4 )
+ {
+ return null;
+ }
+
+ public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
+ String s4 )
+ {
+ return null;
+ }
+
+ public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
+ String s4, String s5 )
+ {
+ return null;
+ }
+
+ public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
+ String s4, String s5, boolean b )
+ {
+ return null;
+ }
+
+ public Artifact createBuildArtifact( String s, String s1, String s2, String s3 )
+ {
+ return null;
+ }
+
+ public Artifact createProjectArtifact( String s, String s1, String s2 )
+ {
+ return null;
+ }
+
+ public Artifact createParentArtifact( String s, String s1, String s2 )
+ {
+ return null;
+ }
+
+ public Artifact createPluginArtifact( String s, String s1, VersionRange versionRange )
+ {
+ return null;
+ }
+
+ public Artifact createProjectArtifact( String s, String s1, String s2, String s3 )
+ {
+ return null;
+ }
+
+ public Artifact createExtensionArtifact( String s, String s1, VersionRange versionRange )
+ {
+ return null;
+ }
+
+ public Artifact createDependencyArtifact( String string, String string1, VersionRange versionRange, String string2,
+ String string3, String string4, boolean b )
+ {
+ return null;
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java
new file mode 100644
index 000000000..00bdc23ae
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java
@@ -0,0 +1,80 @@
+package org.apache.maven.repository.reporting;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ */
+public class MockArtifactReportProcessor
+ implements ArtifactReportProcessor
+{
+ private List reportConditions;
+
+ private Iterator iterator;
+
+ public MockArtifactReportProcessor()
+ {
+ reportConditions = new ArrayList();
+ }
+
+ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
+ ArtifactRepository repository )
+ {
+ if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
+ {
+ iterator = reportConditions.iterator();
+ }
+ if ( !reportConditions.isEmpty() )
+ {
+ while ( iterator.hasNext() )
+ {
+ ReportCondition reportCondition = (ReportCondition) iterator.next();
+ int i = reportCondition.getResult();
+ if ( i == ReportCondition.SUCCESS )
+ {
+ reporter.addSuccess( reportCondition.getArtifact() );
+ }
+ else if ( i == ReportCondition.WARNING )
+ {
+ reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() );
+ }
+ else if ( i == ReportCondition.FAILURE )
+ {
+ reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() );
+ }
+ }
+ }
+ }
+
+ public void addReturnValue( int result, Artifact artifact, String reason )
+ {
+ reportConditions.add( new ReportCondition( result, artifact, reason ) );
+ }
+
+ public void clearList()
+ {
+ reportConditions.clear();
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java
new file mode 100755
index 000000000..f13e660cf
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java
@@ -0,0 +1,121 @@
+package org.apache.maven.repository.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;
+
+/**
+ * Mock implementation of the artifact reporter.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class MockArtifactReporter
+ 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 getFailures()
+ {
+ return artifactFailures.size();
+ }
+
+ public int getSuccesses()
+ {
+ return artifactSuccesses.size();
+ }
+
+ public int getWarnings()
+ {
+ return artifactWarnings.size();
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java
new file mode 100644
index 000000000..e6ec4eef3
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java
@@ -0,0 +1,79 @@
+package org.apache.maven.repository.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.Snapshot;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ */
+public class MockRepositoryQueryLayer
+ implements RepositoryQueryLayer
+{
+ private List queryConditions;
+
+ private Iterator iterator;
+
+ public MockRepositoryQueryLayer()
+ {
+ queryConditions = new ArrayList();
+ }
+
+ public boolean containsArtifact( Artifact artifact )
+ {
+ if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
+ {
+ iterator = queryConditions.iterator();
+ }
+ boolean b;
+ if ( queryConditions.isEmpty() )
+ {
+ b = false;
+ }
+ else
+ {
+ b = ( (Boolean) iterator.next() ).booleanValue();
+ }
+ return b;
+ }
+
+ public void addReturnValue( boolean queryCondition )
+ {
+ queryConditions.add( Boolean.valueOf( queryCondition ) );
+ }
+
+ public void clearList()
+ {
+ queryConditions.clear();
+ }
+
+ public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
+ {
+ return containsArtifact( artifact );
+ }
+
+ public List getVersions( Artifact artifact )
+ {
+ return Collections.EMPTY_LIST;
+ }
+}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java
new file mode 100644
index 000000000..98df89646
--- /dev/null
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java
@@ -0,0 +1,74 @@
+package org.apache.maven.repository.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;
+
+/**
+ *
+ */
+public class ReportCondition
+{
+ public static final int SUCCESS = 0;
+
+ public static final int FAILURE = -1;
+
+ public static final int WARNING = 1;
+
+ private int result;
+
+ private Artifact artifact;
+
+ private String reason;
+
+ public ReportCondition( int result, Artifact artifact, String reason )
+ {
+ this.result = result;
+ this.artifact = artifact;
+ this.reason = reason;
+ }
+
+ public int getResult()
+ {
+ return result;
+ }
+
+ public void setResult( int result )
+ {
+ this.result = result;
+ }
+
+ public Artifact getArtifact()
+ {
+ return artifact;
+ }
+
+ public void setArtifact( Artifact artifact )
+ {
+ this.artifact = artifact;
+ }
+
+ public String getReason()
+ {
+ return reason;
+ }
+
+ public void setReason( String reason )
+ {
+ this.reason = reason;
+ }
+}
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar
new file mode 100644
index 000000000..c2ea777c1
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar
Binary files differ
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom
new file mode 100644
index 000000000..24bca8028
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom
@@ -0,0 +1,6 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-1</version>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom
new file mode 100644
index 000000000..fd07c6f14
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom
@@ -0,0 +1,6 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-2</version>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml b/archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml
new file mode 100644
index 000000000..a8ea6e7e0
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml
@@ -0,0 +1,27 @@
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-1</version>
+ <versioning>
+ <versions>
+ <version>1.0-alpha-1</version>
+ <version>1.0-alpha-2</version>
+ </versions>
+ </versioning>
+</metadata>
diff --git a/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom b/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom
diff --git a/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom b/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-SNAPSHOT.pom
diff --git a/archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml b/archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml
new file mode 100644
index 000000000..44c9d51ff
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/groupId/unexpectedfile.xml
@@ -0,0 +1,17 @@
+This file is here to make sure that it will not be processed during unit <!--
+ ~ 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.
+ -->
+
+ test. \ No newline at end of file
diff --git a/archiva-reports-standard/src/test/repository/maven-metadata.xml b/archiva-reports-standard/src/test/repository/maven-metadata.xml
new file mode 100644
index 000000000..9efaee38c
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/maven-metadata.xml
@@ -0,0 +1,21 @@
+<!--
+ ~ 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.
+ -->
+
+<metadata>
+ <groupId>checksumTest</groupId>
+ <artifactId>invalidArtifact</artifactId>
+ <version>1.0</version>
+</metadata>
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom
new file mode 100644
index 000000000..31d626277
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/artifactId/1.0-alpha-3/artifactId-1.0-alpha-3.pom
@@ -0,0 +1,9 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-3</version>
+ <build>
+ <plugins>
+ </build>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar
new file mode 100644
index 000000000..2acfe605d
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.jar
Binary files differ
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
new file mode 100644
index 000000000..e5cbe38fd
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom
@@ -0,0 +1,31 @@
+<project>
+ <parent>
+ <artifactId>maven</artifactId>
+ <groupId>org.apache.maven</groupId>
+ <version>2.1</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>maven-archiver</artifactId>
+ <name>Maven Archiver</name>
+ <version>2.1</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-archiver</artifactId>
+ <version>1.0-alpha-3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0</version>
+ </dependency>
+ </dependencies>
+ <distributionManagement>
+ <status>deployed</status>
+ </distributionManagement>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt
new file mode 100644
index 000000000..bc218ba95
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-archiver/2.0/note.txt
@@ -0,0 +1,4 @@
+- The artifact location does not match the location specified in the file system, but
+ matches the location specified in the pom included in the package.
+- The groupId, artifactId and version of the pom in the file system does not match
+ the groupId, artifactId and version of the pom included in the package.
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar
new file mode 100644
index 000000000..d6820d6fe
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.jar
Binary files differ
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom
new file mode 100644
index 000000000..17bc67891
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/maven-model-2.0.pom
@@ -0,0 +1,86 @@
+<project>
+ <parent>
+ <artifactId>maven</artifactId>
+ <groupId>org.apache.maven</groupId>
+ <version>2.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <name>Maven Model</name>
+ <version>2.0</version>
+ <description>Maven Model</description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>xpp3-writer</goal>
+ <goal>java</goal>
+ <goal>xpp3-reader</goal>
+ <goal>xsd</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <version>4.0.0</version>
+ <model>maven.mdo</model>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>all-models</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>v3</id>
+ <goals>
+ <goal>xpp3-writer</goal>
+ <goal>java</goal>
+ <goal>xpp3-reader</goal>
+ <goal>xsd</goal>
+ </goals>
+ <configuration>
+ <version>3.0.0</version>
+ <packageWithVersion>true</packageWithVersion>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>all</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ </dependencies>
+ <distributionManagement>
+ <status>deployed</status>
+ </distributionManagement>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt
new file mode 100644
index 000000000..13b46ec93
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-model/2.0/note.txt
@@ -0,0 +1,3 @@
+- The artifact is located in the proper location.
+- The groupId, artifactId and version of the pom in the file system matches
+ the groupId, artifactId and version of the pom included in the package.
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar
new file mode 100644
index 000000000..c499d94ff
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.jar
Binary files differ
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom
new file mode 100644
index 000000000..44ba7ed4e
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom
@@ -0,0 +1,15 @@
+<project>
+ <parent>
+ <artifactId>maven</artifactId>
+ <groupId>org.apache.maven</groupId>
+ <version>2.1</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-monitor</artifactId>
+ <name>Maven Monitor</name>
+ <version>2.1</version>
+ <distributionManagement>
+ <status>deployed</status>
+ </distributionManagement>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt
new file mode 100644
index 000000000..796d100b0
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-monitor/2.1/note.txt
@@ -0,0 +1,4 @@
+- The artifact location matches the location specified in the file system, but
+ does not match the location specified in the pom included in the package.
+- The groupId, artifactId and version of the pom in the file system does not match
+ the groupId, artifactId and version of the pom included in the package.
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar
new file mode 100644
index 000000000..efeb8d456
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.jar
Binary files differ
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom
new file mode 100644
index 000000000..8993ed385
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/maven-project-2.1.pom
@@ -0,0 +1,52 @@
+<project>
+ <parent>
+ <artifactId>maven</artifactId>
+ <groupId>org.apache.maven</groupId>
+ <version>2.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>maven-project</artifactId>
+ <name>Maven Project Builder</name>
+ <version>2.0</version>
+ <description>This library is used to not only read Maven project object model files, but to assemble inheritence
+ and to retrieve remote models as required.</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-test</artifactId>
+ <version>2.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-profile</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact-manager</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+ </dependencies>
+ <distributionManagement>
+ <status>deployed</status>
+ </distributionManagement>
+</project>
diff --git a/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt
new file mode 100644
index 000000000..38aefadac
--- /dev/null
+++ b/archiva-reports-standard/src/test/repository/org/apache/maven/maven-project/2.1/note.txt
@@ -0,0 +1,4 @@
+- The artifact location does not match both the location specified in the file system pom
+ and in the pom included in the package.
+- The groupId, artifactId and version of the pom in the file system does not match
+ the groupId, artifactId and version of the pom included in the package.
diff --git a/archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml b/archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml
new file mode 100644
index 000000000..d8b910c2e
--- /dev/null
+++ b/archiva-reports-standard/src/test/resources/org/apache/maven/repository/reporting/DuplicateArtifactFileReportProcessorTest.xml
@@ -0,0 +1,21 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.repository.reporting.ArtifactReportProcessor</role>
+ <role-hint>duplicate</role-hint>
+ <implementation>org.apache.maven.repository.reporting.DuplicateArtifactFileReportProcessor</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.repository.digest.Digester</role>
+ <role-hint>md5</role-hint>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.repository.indexing.RepositoryArtifactIndexFactory</role>
+ </requirement>
+ </requirements>
+ <configuration>
+ <indexDirectory>${basedir}/target/indexDirectory</indexDirectory>
+ </configuration>
+ </component>
+ </components>
+</component-set> \ No newline at end of file