Coverage Report - org.apache.maven.archiva.consumers.core.ValidateChecksumConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidateChecksumConsumer
0%
0/32
0%
0/4
0
 
 1  
 package org.apache.maven.archiva.consumers.core;
 2  
 
 3  
 /*
 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
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 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
 19  
  * under the License.
 20  
  */
 21  
 
 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;
 31  
 
 32  
 import java.io.File;
 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;
 39  
 
 40  
 /**
 41  
  * ValidateChecksumConsumer - validate the provided checksum against the file it represents.
 42  
  *
 43  
  * @version $Id: ValidateChecksumConsumer.java 1041824 2010-12-03 14:11:05Z brett $
 44  
  * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
 45  
  * role-hint="validate-checksum"
 46  
  * instantiation-strategy="per-lookup"
 47  
  */
 48  0
 public class ValidateChecksumConsumer
 49  
     extends AbstractMonitoredConsumer
 50  
     implements KnownRepositoryContentConsumer, Initializable
 51  
 {
 52  
     private static final String NOT_VALID_CHECKSUM = "checksum-not-valid";
 53  
 
 54  
     private static final String CHECKSUM_NOT_FOUND = "checksum-not-found";
 55  
 
 56  
     private static final String CHECKSUM_DIGESTER_FAILURE = "checksum-digester-failure";
 57  
 
 58  
     private static final String CHECKSUM_IO_ERROR = "checksum-io-error";
 59  
 
 60  
     /**
 61  
      * @plexus.configuration default-value="validate-checksums"
 62  
      */
 63  
     private String id;
 64  
 
 65  
     /**
 66  
      * @plexus.configuration default-value="Validate checksums against file."
 67  
      */
 68  
     private String description;
 69  
 
 70  
     /**
 71  
      * @plexus.requirement
 72  
      */
 73  
     private ChecksumFile checksum;
 74  
 
 75  
     /**
 76  
      * @plexus.requirement role="org.codehaus.plexus.digest.Digester"
 77  
      */
 78  
     private List<Digester> digesterList;
 79  
 
 80  
     private File repositoryDir;
 81  
 
 82  0
     private List<String> includes = new ArrayList<String>();
 83  
 
 84  
     public String getId()
 85  
     {
 86  0
         return this.id;
 87  
     }
 88  
 
 89  
     public String getDescription()
 90  
     {
 91  0
         return this.description;
 92  
     }
 93  
 
 94  
     public boolean isPermanent()
 95  
     {
 96  0
         return false;
 97  
     }
 98  
 
 99  
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
 100  
         throws ConsumerException
 101  
     {
 102  0
         this.repositoryDir = new File( repository.getLocation() );
 103  0
     }
 104  
 
 105  
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
 106  
         throws ConsumerException
 107  
     {
 108  0
         beginScan( repository, whenGathered );
 109  0
     }
 110  
 
 111  
     public void completeScan()
 112  
     {
 113  
         /* nothing to do */
 114  0
     }
 115  
 
 116  
     public void completeScan( boolean executeOnEntireRepo )
 117  
     {
 118  0
         completeScan();
 119  0
     }
 120  
 
 121  
     public List<String> getExcludes()
 122  
     {
 123  0
         return null;
 124  
     }
 125  
 
 126  
     public List<String> getIncludes()
 127  
     {
 128  0
         return this.includes;
 129  
     }
 130  
 
 131  
     public void processFile( String path )
 132  
         throws ConsumerException
 133  
     {
 134  0
         File checksumFile = new File( this.repositoryDir, path );
 135  
         try
 136  
         {
 137  0
             if ( !checksum.isValidChecksum( checksumFile ) )
 138  
             {
 139  0
                 triggerConsumerWarning( NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid." );
 140  
             }
 141  
         }
 142  0
         catch ( FileNotFoundException e )
 143  
         {
 144  0
             triggerConsumerError( CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage() );
 145  
         }
 146  0
         catch ( DigesterException e )
 147  
         {
 148  0
             triggerConsumerError( CHECKSUM_DIGESTER_FAILURE,
 149  
                                   "Digester failure during checksum validation on " + checksumFile );
 150  
         }
 151  0
         catch ( IOException e )
 152  
         {
 153  0
             triggerConsumerError( CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile );
 154  0
         }
 155  0
     }
 156  
 
 157  
     public void processFile( String path, boolean executeOnEntireRepo )
 158  
         throws Exception
 159  
     {
 160  0
         processFile( path );
 161  0
     }
 162  
 
 163  
     public void initialize()
 164  
         throws InitializationException
 165  
     {
 166  0
         for ( Iterator<Digester> itDigesters = digesterList.iterator(); itDigesters.hasNext(); )
 167  
         {
 168  0
             Digester digester = itDigesters.next();
 169  0
             includes.add( "**/*" + digester.getFilenameExtension() );
 170  0
         }
 171  0
     }
 172  
 }