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.configuration.ManagedRepositoryConfiguration;
23 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
24 import org.apache.maven.archiva.consumers.ConsumerException;
25 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
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.Date;
37 import java.util.Iterator;
38 import java.util.List;
41 * ValidateChecksumConsumer - validate the provided checksum against the file it represents.
44 * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
45 * role-hint="validate-checksum"
46 * instantiation-strategy="per-lookup"
48 public class ValidateChecksumConsumer
49 extends AbstractMonitoredConsumer
50 implements KnownRepositoryContentConsumer, 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<Digester> digesterList;
80 private File repositoryDir;
82 private List<String> includes = new ArrayList<String>();
89 public String getDescription()
91 return this.description;
94 public boolean isPermanent()
99 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
100 throws ConsumerException
102 this.repositoryDir = new File( repository.getLocation() );
105 public void completeScan()
110 public List<String> getExcludes()
115 public List<String> getIncludes()
117 return this.includes;
120 public void processFile( String path )
121 throws ConsumerException
123 File checksumFile = new File( this.repositoryDir, path );
126 if ( !checksum.isValidChecksum( checksumFile ) )
128 triggerConsumerWarning( NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid." );
131 catch ( FileNotFoundException e )
133 triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() );
135 catch ( DigesterException e )
137 triggerConsumerError( CHECKSUM_DIGESTER_FAILURE,
138 "Digester failure during checksum validation on " + checksumFile );
140 catch ( IOException e )
142 triggerConsumerError( CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile );
146 public void initialize()
147 throws InitializationException
149 for ( Iterator<Digester> itDigesters = digesterList.iterator(); itDigesters.hasNext(); )
151 Digester digester = itDigesters.next();
152 includes.add( "**/*" + digester.getFilenameExtension() );