001package org.apache.archiva.repository.scanner.functors; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.admin.model.beans.ManagedRepository; 023import org.apache.commons.collections.Closure; 024import org.apache.archiva.consumers.ConsumerException; 025import org.apache.archiva.consumers.RepositoryContentConsumer; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028 029import java.util.Date; 030 031/** 032 * TriggerBeginScanClosure 033 * 034 * 035 */ 036public class TriggerBeginScanClosure 037 implements Closure 038{ 039 private Logger log = LoggerFactory.getLogger( TriggerBeginScanClosure.class ); 040 041 private ManagedRepository repository; 042 043 private Date whenGathered; 044 045 private boolean executeOnEntireRepo = true; 046 047 public TriggerBeginScanClosure( ManagedRepository repository ) 048 { 049 this.repository = repository; 050 } 051 052 public TriggerBeginScanClosure( ManagedRepository repository, Date whenGathered ) 053 { 054 this( repository ); 055 this.whenGathered = whenGathered; 056 } 057 058 public TriggerBeginScanClosure( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo ) 059 { 060 this( repository, whenGathered ); 061 this.executeOnEntireRepo = executeOnEntireRepo; 062 } 063 064 @Override 065 public void execute( Object input ) 066 { 067 if ( input instanceof RepositoryContentConsumer ) 068 { 069 RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; 070 071 try 072 { 073 consumer.beginScan( repository, whenGathered, executeOnEntireRepo ); 074 } 075 catch ( ConsumerException e ) 076 { 077 log.warn( "Consumer [{}] cannot begin: {}",consumer.getId(), e.getMessage(), e ); 078 } 079 } 080 } 081}