1 package org.apache.archiva.repository.scanner.functors;
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.commons.collections.Closure;
23 import org.apache.archiva.common.utils.BaseFile;
24 import org.apache.archiva.consumers.RepositoryContentConsumer;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
31 * ConsumerProcessFileClosure
35 public class ConsumerProcessFileClosure
38 private Logger log = LoggerFactory.getLogger( ConsumerProcessFileClosure.class );
40 private BaseFile basefile;
42 private boolean executeOnEntireRepo;
44 private Map<String,Long> consumerTimings;
46 private Map<String,Long> consumerCounts;
48 public void execute( Object input )
50 if ( input instanceof RepositoryContentConsumer )
52 RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
54 String id = consumer.getId();
57 log.debug( "Sending to consumer: {}", id );
59 long startTime = System.currentTimeMillis();
60 consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo );
61 long endTime = System.currentTimeMillis();
63 if ( consumerTimings != null )
65 Long value = consumerTimings.get( id );
66 consumerTimings.put( id, ( value != null ? value : 0 ) + endTime - startTime );
69 if ( consumerCounts != null )
71 Long value = consumerCounts.get( id );
72 consumerCounts.put( id, ( value != null ? value : 0 ) + 1 );
77 /* Intentionally Catch all exceptions.
78 * So that the discoverer processing can continue.
80 log.error( "Consumer [" + id + "] had an error when processing file ["
81 + basefile.getAbsolutePath() + "]: " + e.getMessage(), e );
86 public BaseFile getBasefile()
91 public void setBasefile( BaseFile basefile )
93 this.basefile = basefile;
96 public boolean isExecuteOnEntireRepo()
98 return executeOnEntireRepo;
101 public void setExecuteOnEntireRepo( boolean executeOnEntireRepo )
103 this.executeOnEntireRepo = executeOnEntireRepo;
106 public void setConsumerTimings( Map<String, Long> consumerTimings )
108 this.consumerTimings = consumerTimings;
111 public void setConsumerCounts( Map<String, Long> consumerCounts )
113 this.consumerCounts = consumerCounts;
116 public Logger getLogger()
121 public void setLogger( Logger logger )