1 package org.apache.maven.archiva.consumers.core;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
23 import org.apache.maven.archiva.consumers.ConsumerException;
24 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
25 import org.apache.maven.archiva.model.ArchivaRepository;
26 import org.codehaus.plexus.digest.ChecksumFile;
27 import org.codehaus.plexus.digest.Digester;
28 import org.codehaus.plexus.digest.DigesterException;
29 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
30 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
33 import java.io.FileNotFoundException;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.Iterator;
37 import java.util.List;
40 * ValidateChecksumConsumer - validate the provided checksum against the file it represents.
42 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
45 * @plexus.component role="org.apache.maven.archiva.consumers.RepositoryContentConsumer"
46 * role-hint="validate-checksums"
47 * instantiation-strategy="per-lookup"
49 public class ValidateChecksumConsumer extends AbstractMonitoredConsumer
50 implements RepositoryContentConsumer, Initializable
52 private static final String NOT_VALID_CHECKSUM = "checksum-not-valid";
54 private static final String CHECKSUM_NOT_FOUND = "checksum-not-found";
56 private static final String CHECKSUM_DIGESTER_FAILURE = "checksum-digester-failure";
58 private static final String CHECKSUM_IO_ERROR = "checksum-io-error";
61 * @plexus.configuration default-value="validate-checksums"
66 * @plexus.configuration default-value="Validate checksums against file."
68 private String description;
73 private ChecksumFile checksum;
76 * @plexus.requirement role="org.codehaus.plexus.digest.Digester"
78 private List digesterList;
80 private ArchivaRepository repository;
82 private File repositoryDir;
84 private List includes = new ArrayList();
91 public String getDescription()
93 return this.description;
96 public boolean isPermanent()
101 public void beginScan( ArchivaRepository repository ) throws ConsumerException
103 if ( !repository.isManaged() )
105 throw new ConsumerException( "Consumer requires managed repository." );
108 this.repository = repository;
109 this.repositoryDir = new File( repository.getUrl().getPath() );
112 public void completeScan()
117 public List getExcludes()
122 public List getIncludes()
124 return this.includes;
127 public void processFile( String path ) throws ConsumerException
129 File checksumFile = new File( this.repositoryDir, path );
132 if ( !checksum.isValidChecksum( checksumFile ) )
134 triggerConsumerWarning( NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid." );
137 catch ( FileNotFoundException e )
139 triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() );
141 catch ( DigesterException e )
143 triggerConsumerError( CHECKSUM_DIGESTER_FAILURE, "Digester failure during checksum validation on " + checksumFile );
145 catch ( IOException e )
147 triggerConsumerError( CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile );
151 public void initialize() throws InitializationException
153 for ( Iterator itDigesters = digesterList.iterator(); itDigesters.hasNext(); )
155 Digester digester = (Digester) itDigesters.next();
156 includes.add( "**/*" + digester.getFilenameExtension() );