From: Brett Porter Date: Wed, 6 Sep 2006 02:38:02 +0000 (+0000) Subject: [MRM-161] rename some classes X-Git-Tag: archiva-0.9-alpha-1~599 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1b940da8671bb5d0ee49fe4881edf86bcb95aaf4;p=archiva.git [MRM-161] rename some classes git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@440577 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java index 7ba79b61a..ec55ad6e5 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java @@ -291,14 +291,12 @@ public class BadMetadataReportProcessor return hasFailures; } - private Artifact createArtifact( RepositoryMetadata metadata, Snapshot snapshot ) - { - String version = metadata.getBaseVersion(); - return artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version ); - } - /** - * Used to gather artifactIds from a groupId directory + * Used to gather artifactIds from a groupId directory. + * + * @param groupIdDir the directory of the group + * @return the list of artifact ID File objects for each directory + * @throws IOException if there was a failure to read the directories */ private List getArtifactIdFiles( File groupIdDir ) throws IOException diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java new file mode 100644 index 000000000..896fd35bd --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReportProcessor.java @@ -0,0 +1,92 @@ +package org.apache.maven.archiva.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.archiva.digest.Digester; +import org.apache.maven.archiva.digest.DigesterException; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * This class reports invalid and mismatched checksums of artifacts and metadata files. + * It validates MD5 and SHA-1 checksums. + * + * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="checksum" + */ +public class ChecksumArtifactReportProcessor + implements ArtifactReportProcessor +{ + /** + * @plexus.requirement role-hint="sha1" + */ + private Digester sha1Digester; + + /** + * @plexus.requirement role-hint="md5" + */ + private Digester md5Digester; + + 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/archiva/reporting/ChecksumArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporter.java deleted file mode 100644 index ef23c9226..000000000 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporter.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.apache.maven.archiva.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.archiva.digest.Digester; -import org.apache.maven.archiva.digest.DigesterException; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * This class reports invalid and mismatched checksums of artifacts and metadata files. - * It validates MD5 and SHA-1 checksums. - * - * @plexus.component role="org.apache.maven.archiva.reporting.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/archiva/reporting/ChecksumMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java new file mode 100644 index 000000000..18abad1ec --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReportProcessor.java @@ -0,0 +1,95 @@ +package org.apache.maven.archiva.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.archiva.digest.Digester; +import org.apache.maven.archiva.digest.DigesterException; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * This class reports invalid and mismatched checksums of artifacts and metadata files. + * It validates MD5 and SHA-1 checksums. + * + * @plexus.component role="org.apache.maven.archiva.reporting.MetadataReportProcessor" role-hint="checksum-metadata" + */ +public class ChecksumMetadataReportProcessor + implements MetadataReportProcessor +{ + /** + * @plexus.requirement role-hint="sha1" + */ + private Digester sha1Digester; + + /** + * @plexus.requirement role-hint="md5" + */ + private Digester md5Digester; + + /** + * Validate the checksums of the metadata. Get the metadata file from the + * repository then validate the checksum. + */ + public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) + { + if ( !"file".equals( repository.getProtocol() ) ) + { + // We can't check other types of URLs yet. Need to use Wagon, with an exists() method. + throw new UnsupportedOperationException( + "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" ); + } + + //check if checksum files exist + String path = repository.pathOfRemoteRepositoryMetadata( metadata ); + File file = new File( repository.getBasedir(), path ); + + verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, metadata ); + verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, metadata ); + } + + private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester, + ArtifactReporter reporter, RepositoryMetadata metadata ) + { + File checksumFile = new File( repository.getBasedir(), path ); + if ( checksumFile.exists() ) + { + try + { + digester.verify( file, FileUtils.fileRead( checksumFile ) ); + + reporter.addSuccess( metadata ); + } + catch ( DigesterException e ) + { + reporter.addFailure( metadata, e.getMessage() ); + } + catch ( IOException e ) + { + reporter.addFailure( metadata, "Read file error: " + e.getMessage() ); + } + } + else + { + reporter.addFailure( metadata, digester.getAlgorithm() + " checksum file does not exist." ); + } + } + +} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java index 2e2f41a04..ef926c725 100644 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ChecksumMetadataReporter.java @@ -63,7 +63,6 @@ public class ChecksumMetadataReporter 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, diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java deleted file mode 100644 index b9fd36dd7..000000000 --- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.apache.maven.archiva.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.archiva.layer.RepositoryQueryLayer; -import org.apache.maven.archiva.layer.RepositoryQueryLayerFactory; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; - -import java.util.Iterator; -import java.util.List; - -/** - * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="default" - */ -public class DefaultArtifactReportProcessor - implements ArtifactReportProcessor -{ - /** - * @plexus.requirement - */ - private ArtifactFactory artifactFactory; - - /** - * @plexus.requirement - */ - private RepositoryQueryLayerFactory layerFactory; - - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) - { - RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository ); - processArtifact( artifact, reporter, queryLayer ); - - List dependencies = model.getDependencies(); - processDependencies( dependencies, reporter, queryLayer ); - } - - private void processArtifact( Artifact artifact, ArtifactReporter reporter, - RepositoryQueryLayer repositoryQueryLayer ) - { - if ( repositoryQueryLayer.containsArtifact( artifact ) ) - { - reporter.addSuccess( artifact ); - } - else - { - reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND ); - } - } - - private void processDependencies( List dependencies, ArtifactReporter reporter, - RepositoryQueryLayer repositoryQueryLayer ) - { - if ( dependencies.size() > 0 ) - { - Iterator iterator = dependencies.iterator(); - while ( iterator.hasNext() ) - { - Dependency dependency = (Dependency) iterator.next(); - - Artifact artifact = null; - try - { - artifact = createArtifact( dependency ); - - if ( repositoryQueryLayer.containsArtifact( artifact ) ) - { - reporter.addSuccess( artifact ); - } - else - { - reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND ); - } - } - catch ( InvalidVersionSpecificationException e ) - { - reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION ); - } - } - } - } - - private Artifact createArtifact( Dependency dependency ) - throws InvalidVersionSpecificationException - { - return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), - VersionRange.createFromVersionSpec( dependency.getVersion() ), - dependency.getType(), dependency.getClassifier(), - dependency.getScope() ); - } -} diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java new file mode 100644 index 000000000..ded3d586d --- /dev/null +++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessor.java @@ -0,0 +1,111 @@ +package org.apache.maven.archiva.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.archiva.layer.RepositoryQueryLayer; +import org.apache.maven.archiva.layer.RepositoryQueryLayerFactory; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; + +import java.util.Iterator; +import java.util.List; + +/** + * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="dependency" + */ +public class DependencyArtifactReportProcessor + implements ArtifactReportProcessor +{ + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private RepositoryQueryLayerFactory layerFactory; + + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository repository ) + { + RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository ); + processArtifact( artifact, reporter, queryLayer ); + + List dependencies = model.getDependencies(); + processDependencies( dependencies, reporter, queryLayer ); + } + + private void processArtifact( Artifact artifact, ArtifactReporter reporter, + RepositoryQueryLayer repositoryQueryLayer ) + { + if ( repositoryQueryLayer.containsArtifact( artifact ) ) + { + reporter.addSuccess( artifact ); + } + else + { + reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND ); + } + } + + private void processDependencies( List dependencies, ArtifactReporter reporter, + RepositoryQueryLayer repositoryQueryLayer ) + { + if ( dependencies.size() > 0 ) + { + Iterator iterator = dependencies.iterator(); + while ( iterator.hasNext() ) + { + Dependency dependency = (Dependency) iterator.next(); + + Artifact artifact = null; + try + { + artifact = createArtifact( dependency ); + + if ( repositoryQueryLayer.containsArtifact( artifact ) ) + { + reporter.addSuccess( artifact ); + } + else + { + reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND ); + } + } + catch ( InvalidVersionSpecificationException e ) + { + reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION ); + } + } + } + } + + private Artifact createArtifact( Dependency dependency ) + throws InvalidVersionSpecificationException + { + return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), + VersionRange.createFromVersionSpec( dependency.getVersion() ), + dependency.getType(), dependency.getClassifier(), + dependency.getScope() ); + } +} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java index a7e6a764f..bed4097ef 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractChecksumArtifactReporterTestCase.java @@ -33,7 +33,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; /** - * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter. + * This class creates the artifact and metadata files used for testing the ChecksumArtifactReportProcessor. * It is extended by ChecksumArtifactReporterTest class. */ public abstract class AbstractChecksumArtifactReporterTestCase diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java deleted file mode 100644 index 1b3d60759..000000000 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java +++ /dev/null @@ -1,238 +0,0 @@ -package org.apache.maven.archiva.reporting; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -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 VALID_GROUP_ID = "groupId"; - - private static final String VALID_ARTIFACT_ID = "artifactId"; - - private static final String VALID_VERSION = "1.0-alpha-1"; - - private ArtifactReporter reporter; - - private Model model; - - private ArtifactReportProcessor processor; - - private ArtifactFactory artifactFactory; - - private static final String INVALID = "invalid"; - - protected void setUp() - throws Exception - { - super.setUp(); - reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE ); - model = new Model(); - processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "default" ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); - } - - public void testArtifactFoundButNoDirectDependencies() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getNumSuccesses() ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - } - - private Artifact createValidArtifact() - { - return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION ); - } - - public void testArtifactNotFound() - throws ReportProcessorException - { - Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID ); - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 0, reporter.getNumSuccesses() ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() ); - } - - public void testValidArtifactWithNullDependency() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - - Dependency dependency = createValidDependency(); - model.addDependency( dependency ); - - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 2, reporter.getNumSuccesses() ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - } - - private Dependency createValidDependency() - { - return createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION ); - } - - public void testValidArtifactWithValidSingleDependency() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - - Dependency dependency = createValidDependency(); - model.addDependency( dependency ); - - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 2, reporter.getNumSuccesses() ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - } - - public void testValidArtifactWithValidMultipleDependencies() - throws ReportProcessorException - { - Dependency dependency = createValidDependency(); - model.addDependency( dependency ); - model.addDependency( dependency ); - model.addDependency( dependency ); - model.addDependency( dependency ); - model.addDependency( dependency ); - - Artifact artifact = createValidArtifact(); - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 6, reporter.getNumSuccesses() ); - assertEquals( 0, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - } - - public void testValidArtifactWithAnInvalidDependency() - throws ReportProcessorException - { - Dependency dependency = createValidDependency(); - model.addDependency( dependency ); - model.addDependency( dependency ); - model.addDependency( dependency ); - model.addDependency( dependency ); - model.addDependency( createDependency( INVALID, INVALID, INVALID ) ); - - Artifact artifact = createValidArtifact(); - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 5, reporter.getNumSuccesses() ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); - } - - public void testValidArtifactWithInvalidDependencyGroupId() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - - Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION ); - model.addDependency( dependency ); - - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getNumSuccesses() ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); - } - - private Dependency createDependency( String o, String valid, String s ) - { - Dependency dependency = new Dependency(); - dependency.setGroupId( o ); - dependency.setArtifactId( valid ); - dependency.setVersion( s ); - return dependency; - } - - public void testValidArtifactWithInvalidDependencyArtifactId() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - - Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION ); - model.addDependency( dependency ); - - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getNumSuccesses() ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); - } - - public void testValidArtifactWithIncorrectDependencyVersion() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - - Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID ); - model.addDependency( dependency ); - - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getNumSuccesses() ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); - } - - public void testValidArtifactWithInvalidDependencyVersion() - throws ReportProcessorException - { - Artifact artifact = createValidArtifact(); - - Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" ); - model.addDependency( dependency ); - - processor.processArtifact( model, artifact, reporter, repository ); - assertEquals( 1, reporter.getNumSuccesses() ); - assertEquals( 1, reporter.getNumFailures() ); - assertEquals( 0, reporter.getNumWarnings() ); - - Iterator failures = reporter.getArtifactFailureIterator(); - ArtifactResult result = (ArtifactResult) failures.next(); - assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() ); - } -} diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java index 6132204db..2a4740399 100644 --- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ChecksumArtifactReporterTest.java @@ -32,7 +32,7 @@ import java.io.IOException; import java.util.Iterator; /** - * This class tests the ChecksumArtifactReporter. + * This class tests the ChecksumArtifactReportProcessor. * It extends the AbstractChecksumArtifactReporterTestCase class. */ public class ChecksumArtifactReporterTest @@ -53,7 +53,7 @@ public class ChecksumArtifactReporterTest } /** - * Test the ChecksumArtifactReporter when the checksum files are valid. + * Test the ChecksumArtifactReportProcessor when the checksum files are valid. */ public void testChecksumArtifactReporterSuccess() throws ReportProcessorException, IOException, DigesterException @@ -71,7 +71,7 @@ public class ChecksumArtifactReporterTest } /** - * Test the ChecksumArtifactReporter when the checksum files are invalid. + * Test the ChecksumArtifactReportProcessor when the checksum files are invalid. */ public void testChecksumArtifactReporterFailed() throws ReportProcessorException diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java new file mode 100644 index 000000000..6a30c51fa --- /dev/null +++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/DependencyArtifactReportProcessorTest.java @@ -0,0 +1,238 @@ +package org.apache.maven.archiva.reporting; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; + +import java.util.Iterator; + +/** + * + */ +public class DependencyArtifactReportProcessorTest + extends AbstractRepositoryReportsTestCase +{ + private static final String VALID_GROUP_ID = "groupId"; + + private static final String VALID_ARTIFACT_ID = "artifactId"; + + private static final String VALID_VERSION = "1.0-alpha-1"; + + private ArtifactReporter reporter; + + private Model model; + + private ArtifactReportProcessor processor; + + private ArtifactFactory artifactFactory; + + private static final String INVALID = "invalid"; + + protected void setUp() + throws Exception + { + super.setUp(); + reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE ); + model = new Model(); + processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "dependency" ); + + artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + } + + public void testArtifactFoundButNoDirectDependencies() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getNumSuccesses() ); + assertEquals( 0, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + } + + private Artifact createValidArtifact() + { + return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION ); + } + + public void testArtifactNotFound() + throws ReportProcessorException + { + Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID ); + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 0, reporter.getNumSuccesses() ); + assertEquals( 1, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() ); + } + + public void testValidArtifactWithNullDependency() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + + Dependency dependency = createValidDependency(); + model.addDependency( dependency ); + + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 2, reporter.getNumSuccesses() ); + assertEquals( 0, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + } + + private Dependency createValidDependency() + { + return createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION ); + } + + public void testValidArtifactWithValidSingleDependency() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + + Dependency dependency = createValidDependency(); + model.addDependency( dependency ); + + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 2, reporter.getNumSuccesses() ); + assertEquals( 0, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + } + + public void testValidArtifactWithValidMultipleDependencies() + throws ReportProcessorException + { + Dependency dependency = createValidDependency(); + model.addDependency( dependency ); + model.addDependency( dependency ); + model.addDependency( dependency ); + model.addDependency( dependency ); + model.addDependency( dependency ); + + Artifact artifact = createValidArtifact(); + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 6, reporter.getNumSuccesses() ); + assertEquals( 0, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + } + + public void testValidArtifactWithAnInvalidDependency() + throws ReportProcessorException + { + Dependency dependency = createValidDependency(); + model.addDependency( dependency ); + model.addDependency( dependency ); + model.addDependency( dependency ); + model.addDependency( dependency ); + model.addDependency( createDependency( INVALID, INVALID, INVALID ) ); + + Artifact artifact = createValidArtifact(); + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 5, reporter.getNumSuccesses() ); + assertEquals( 1, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); + } + + public void testValidArtifactWithInvalidDependencyGroupId() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + + Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION ); + model.addDependency( dependency ); + + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getNumSuccesses() ); + assertEquals( 1, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); + } + + private Dependency createDependency( String o, String valid, String s ) + { + Dependency dependency = new Dependency(); + dependency.setGroupId( o ); + dependency.setArtifactId( valid ); + dependency.setVersion( s ); + return dependency; + } + + public void testValidArtifactWithInvalidDependencyArtifactId() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + + Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION ); + model.addDependency( dependency ); + + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getNumSuccesses() ); + assertEquals( 1, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); + } + + public void testValidArtifactWithIncorrectDependencyVersion() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + + Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID ); + model.addDependency( dependency ); + + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getNumSuccesses() ); + assertEquals( 1, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() ); + } + + public void testValidArtifactWithInvalidDependencyVersion() + throws ReportProcessorException + { + Artifact artifact = createValidArtifact(); + + Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" ); + model.addDependency( dependency ); + + processor.processArtifact( model, artifact, reporter, repository ); + assertEquals( 1, reporter.getNumSuccesses() ); + assertEquals( 1, reporter.getNumFailures() ); + assertEquals( 0, reporter.getNumWarnings() ); + + Iterator failures = reporter.getArtifactFailureIterator(); + ArtifactResult result = (ArtifactResult) failures.next(); + assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() ); + } +}