Coverage Report - org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure
 
Classes in this File Line Coverage Branch Coverage Complexity
ConsumerProcessFileClosure
0%
0/32
0%
0/10
0
 
 1  
 package org.apache.maven.archiva.repository.scanner.functors;
 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.commons.collections.Closure;
 23  
 import org.apache.maven.archiva.common.utils.BaseFile;
 24  
 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
 25  
 import org.slf4j.Logger;
 26  
 import org.slf4j.LoggerFactory;
 27  
 
 28  
 import java.util.HashMap;
 29  
 import java.util.Map;
 30  
 
 31  
 /**
 32  
  * ConsumerProcessFileClosure 
 33  
  *
 34  
  * @version $Id: ConsumerProcessFileClosure.java 1042689 2010-12-06 15:56:35Z brett $
 35  
  */
 36  0
 public class ConsumerProcessFileClosure
 37  
     implements Closure
 38  
 {
 39  0
     private Logger log = LoggerFactory.getLogger( ConsumerProcessFileClosure.class );
 40  
     
 41  
     private BaseFile basefile;
 42  
 
 43  
     private boolean executeOnEntireRepo;
 44  
 
 45  
     private Map<String,Long> consumerTimings;
 46  
     
 47  
     private Map<String,Long> consumerCounts;
 48  
 
 49  
     public void execute( Object input )
 50  
     {
 51  0
         if ( input instanceof RepositoryContentConsumer )
 52  
         {
 53  0
             RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
 54  
 
 55  0
             String id = consumer.getId();
 56  
             try
 57  
             {
 58  0
                 log.debug( "Sending to consumer: " + id );
 59  
 
 60  0
                 long startTime = System.currentTimeMillis();
 61  0
                 consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo );
 62  0
                 long endTime = System.currentTimeMillis();
 63  
 
 64  0
                 if ( consumerTimings != null )
 65  
                 {
 66  0
                     Long value = consumerTimings.get( id );
 67  0
                     consumerTimings.put( id, ( value != null ? value : 0 ) + endTime - startTime );
 68  
                 }
 69  
 
 70  0
                 if ( consumerCounts != null )
 71  
                 {
 72  0
                     Long value = consumerCounts.get( id );
 73  0
                     consumerCounts.put( id, ( value != null ? value : 0 ) + 1 );
 74  
                 }
 75  
             }
 76  0
             catch ( Exception e )
 77  
             {
 78  
                 /* Intentionally Catch all exceptions.
 79  
                  * So that the discoverer processing can continue.
 80  
                  */
 81  0
                 log.error( "Consumer [" + id + "] had an error when processing file ["
 82  
                     + basefile.getAbsolutePath() + "]: " + e.getMessage(), e );
 83  0
             }
 84  
         }
 85  0
     }
 86  
 
 87  
     public BaseFile getBasefile()
 88  
     {
 89  0
         return basefile;
 90  
     }
 91  
 
 92  
     public void setBasefile( BaseFile basefile )
 93  
     {
 94  0
         this.basefile = basefile;
 95  0
     }
 96  
 
 97  
     public boolean isExecuteOnEntireRepo()
 98  
     {
 99  0
         return executeOnEntireRepo;
 100  
     }
 101  
 
 102  
     public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
 103  
     {
 104  0
         this.executeOnEntireRepo = executeOnEntireRepo;
 105  0
     }
 106  
 
 107  
     public void setConsumerTimings( Map<String, Long> consumerTimings )
 108  
     {
 109  0
         this.consumerTimings = consumerTimings;
 110  0
     }
 111  
 
 112  
     public void setConsumerCounts( Map<String, Long> consumerCounts )
 113  
     {
 114  0
         this.consumerCounts = consumerCounts;
 115  0
     }
 116  
 
 117  
     public Logger getLogger()
 118  
     {
 119  0
         return log;
 120  
     }
 121  
 
 122  
     public void setLogger( Logger logger )
 123  
     {
 124  0
         this.log = logger;
 125  0
     }
 126  
 }