1 package org.apache.maven.archiva.reporting;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.archiva.digest.Digester;
20 import org.apache.maven.archiva.digest.DigesterException;
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.repository.ArtifactRepository;
23 import org.apache.maven.model.Model;
24 import org.codehaus.plexus.util.FileUtils;
27 import java.io.IOException;
30 * This class reports invalid and mismatched checksums of artifacts and metadata files.
31 * It validates MD5 and SHA-1 checksums.
33 * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReportProcessor" role-hint="checksum"
35 public class ChecksumArtifactReporter
36 implements ArtifactReportProcessor
39 * @plexus.requirement role-hint="sha1"
41 private Digester sha1Digester;
44 * @plexus.requirement role-hint="md5"
46 private Digester md5Digester;
49 * Validate the checksum of the specified artifact.
56 public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
57 ArtifactRepository repository )
59 if ( !"file".equals( repository.getProtocol() ) )
61 // We can't check other types of URLs yet. Need to use Wagon, with an exists() method.
62 throw new UnsupportedOperationException(
63 "Can't process repository '" + repository.getUrl() + "'. Only file based repositories are supported" );
66 //check if checksum files exist
67 String path = repository.pathOf( artifact );
68 File file = new File( repository.getBasedir(), path );
70 verifyChecksum( repository, path + ".md5", file, md5Digester, reporter, artifact );
71 verifyChecksum( repository, path + ".sha1", file, sha1Digester, reporter, artifact );
74 private void verifyChecksum( ArtifactRepository repository, String path, File file, Digester digester,
75 ArtifactReporter reporter, Artifact artifact )
77 File checksumFile = new File( repository.getBasedir(), path );
78 if ( checksumFile.exists() )
82 digester.verify( file, FileUtils.fileRead( checksumFile ) );
84 reporter.addSuccess( artifact );
86 catch ( DigesterException e )
88 reporter.addFailure( artifact, e.getMessage() );
90 catch ( IOException e )
92 reporter.addFailure( artifact, "Read file error: " + e.getMessage() );
97 reporter.addFailure( artifact, digester.getAlgorithm() + " checksum file does not exist." );