1 package org.apache.maven.archiva.repository.scanner;
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.commons.collections.CollectionUtils;
24 import org.apache.commons.collections.functors.IfClosure;
25 import org.apache.maven.archiva.common.utils.BaseFile;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
29 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
30 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
31 import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
32 import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
33 import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure;
34 import org.codehaus.plexus.logging.AbstractLogEnabled;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
43 * RepositoryContentConsumerUtil
45 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
48 * @plexus.component role="org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers"
50 public class RepositoryContentConsumers
51 extends AbstractLogEnabled
56 private ArchivaConfiguration archivaConfiguration;
59 * @plexus.requirement role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
61 private List<KnownRepositoryContentConsumer> availableKnownConsumers;
64 * @plexus.requirement role="org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer"
66 private List<InvalidRepositoryContentConsumer> availableInvalidConsumers;
68 public List<String> getSelectedKnownConsumerIds()
70 RepositoryScanningConfiguration scanning = archivaConfiguration.getConfiguration().getRepositoryScanning();
71 return scanning.getKnownContentConsumers();
74 public List<String> getSelectedInvalidConsumerIds()
76 RepositoryScanningConfiguration scanning = archivaConfiguration.getConfiguration().getRepositoryScanning();
77 return scanning.getInvalidContentConsumers();
80 public Map<String, KnownRepositoryContentConsumer> getSelectedKnownConsumersMap()
82 Map<String, KnownRepositoryContentConsumer> consumerMap = new HashMap<String, KnownRepositoryContentConsumer>();
84 List<String> knownSelected = getSelectedKnownConsumerIds();
86 for ( KnownRepositoryContentConsumer consumer : availableKnownConsumers )
88 if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() )
90 consumerMap.put( consumer.getId(), consumer );
97 public Map<String, InvalidRepositoryContentConsumer> getSelectedInvalidConsumersMap()
99 Map<String, InvalidRepositoryContentConsumer> consumerMap = new HashMap<String, InvalidRepositoryContentConsumer>();
101 List<String> invalidSelected = getSelectedInvalidConsumerIds();
103 for ( InvalidRepositoryContentConsumer consumer : availableInvalidConsumers )
105 if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() )
107 consumerMap.put( consumer.getId(), consumer );
114 public List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
116 List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>();
118 List<String> knownSelected = getSelectedKnownConsumerIds();
120 for ( KnownRepositoryContentConsumer consumer : availableKnownConsumers )
122 if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() )
131 public List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
133 List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>();
135 List<String> invalidSelected = getSelectedInvalidConsumerIds();
137 for ( InvalidRepositoryContentConsumer consumer : availableInvalidConsumers )
139 if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() )
148 public List<KnownRepositoryContentConsumer> getAvailableKnownConsumers()
150 return availableKnownConsumers;
153 public List<InvalidRepositoryContentConsumer> getAvailableInvalidConsumers()
155 return availableInvalidConsumers;
158 public void setAvailableKnownConsumers( List<KnownRepositoryContentConsumer> availableKnownConsumers )
160 this.availableKnownConsumers = availableKnownConsumers;
163 public void setAvailableInvalidConsumers( List<InvalidRepositoryContentConsumer> availableInvalidConsumers )
165 this.availableInvalidConsumers = availableInvalidConsumers;
168 public void executeConsumers( ManagedRepositoryConfiguration repository, File localFile )
170 // Run the repository consumers
173 Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getLogger() );
175 CollectionUtils.forAllDo( availableKnownConsumers, triggerBeginScan );
176 CollectionUtils.forAllDo( availableInvalidConsumers, triggerBeginScan );
178 // yuck. In case you can't read this, it says
179 // "process the file if the consumer has it in the includes list, and not in the excludes list"
180 BaseFile baseFile = new BaseFile( repository.getLocation(), localFile );
181 ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
182 predicate.setBasefile( baseFile );
183 ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure( getLogger() );
184 closure.setBasefile( baseFile );
185 predicate.setCaseSensitive( false );
186 Closure processIfWanted = IfClosure.getInstance( predicate, closure );
188 CollectionUtils.forAllDo( availableKnownConsumers, processIfWanted );
190 if ( predicate.getWantedFileCount() <= 0 )
192 // Nothing known processed this file. It is invalid!
193 CollectionUtils.forAllDo( availableInvalidConsumers, closure );
198 /* TODO: This is never called by the repository scanner instance, so not calling here either - but it probably should be?
199 CollectionUtils.forAllDo( availableKnownConsumers, triggerCompleteScan );
200 CollectionUtils.forAllDo( availableInvalidConsumers, triggerCompleteScan );