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
--- /dev/null
+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." );
+ }
+ }
+}
+++ /dev/null
-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." );
- }
- }
-}
--- /dev/null
+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." );
+ }
+ }
+
+}
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,
+++ /dev/null
-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() );
- }
-}
--- /dev/null
+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() );
+ }
+}
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
+++ /dev/null
-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() );
- }
-}
import java.util.Iterator;
/**
- * This class tests the ChecksumArtifactReporter.
+ * This class tests the ChecksumArtifactReportProcessor.
* It extends the AbstractChecksumArtifactReporterTestCase class.
*/
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
}
/**
- * Test the ChecksumArtifactReporter when the checksum files are invalid.
+ * Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
*/
public void testChecksumArtifactReporterFailed()
throws ReportProcessorException
--- /dev/null
+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() );
+ }
+}