1 package org.apache.maven.archiva.database.updater;
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.CollectionUtils;
23 import org.apache.commons.collections.Predicate;
24 import org.apache.commons.collections.functors.OrPredicate;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
27 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
28 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
29 import org.apache.maven.archiva.consumers.functors.PermanentConsumerPredicate;
30 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
31 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
42 * @plexus.component role="org.apache.maven.archiva.database.updater.DatabaseConsumers"
44 public class DatabaseConsumers
45 implements Initializable
50 private ArchivaConfiguration archivaConfiguration;
53 * @plexus.requirement role="org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer"
55 private List availableUnprocessedConsumers;
58 * @plexus.requirement role="org.apache.maven.archiva.consumers.DatabaseCleanupConsumer"
60 private List availableCleanupConsumers;
62 private Predicate selectedCleanupConsumers;
64 private Predicate selectedUnprocessedConsumers;
66 class SelectedUnprocessedConsumersPredicate
69 public boolean evaluate( Object object )
71 boolean satisfies = false;
73 if ( object instanceof DatabaseUnprocessedArtifactConsumer )
75 DatabaseUnprocessedArtifactConsumer consumer = (DatabaseUnprocessedArtifactConsumer) object;
76 DatabaseScanningConfiguration config = archivaConfiguration.getConfiguration().getDatabaseScanning();
78 return config.getUnprocessedConsumers().contains( consumer.getId() );
85 class SelectedCleanupConsumersPredicate
88 public boolean evaluate( Object object )
90 boolean satisfies = false;
92 if ( object instanceof DatabaseCleanupConsumer )
94 DatabaseCleanupConsumer consumer = (DatabaseCleanupConsumer) object;
95 DatabaseScanningConfiguration config = archivaConfiguration.getConfiguration().getDatabaseScanning();
97 return config.getCleanupConsumers().contains( consumer.getId() );
104 public void initialize()
105 throws InitializationException
107 Predicate permanentConsumers = new PermanentConsumerPredicate();
109 selectedCleanupConsumers = new OrPredicate( permanentConsumers, new SelectedCleanupConsumersPredicate() );
110 selectedUnprocessedConsumers = new OrPredicate( permanentConsumers, new SelectedUnprocessedConsumersPredicate() );
114 * Get the {@link List} of {@link DatabaseUnprocessedArtifactConsumer} objects
115 * for those consumers selected due to the configuration.
117 * @return the list of selected {@link DatabaseUnprocessedArtifactConsumer} objects.
119 public List getSelectedUnprocessedConsumers()
121 List ret = new ArrayList();
122 ret.addAll( CollectionUtils.select( availableUnprocessedConsumers, selectedUnprocessedConsumers ) );
127 * Get the {@link List} of {@link DatabaseCleanupConsumer} objects for those
128 * consumers selected due to the configuration.
130 * @return the list of selected {@link DatabaseCleanupConsumer} objects.
132 public List getSelectedCleanupConsumers()
134 List ret = new ArrayList();
135 ret.addAll( CollectionUtils.select( availableCleanupConsumers, selectedCleanupConsumers ) );
140 * Get the complete {@link List} of {@link DatabaseUnprocessedArtifactConsumer} objects
141 * that are available in the system, regardless of configuration.
143 * @return the list of all available {@link DatabaseUnprocessedArtifactConsumer} objects.
145 public List getAvailableUnprocessedConsumers()
147 return Collections.unmodifiableList( this.availableUnprocessedConsumers );
151 * Get the complete {@link List} of {@link DatabaseCleanupConsumer} objects
152 * that are available in the system, regardless of configuration.
154 * @return the list of all available {@link DatabaseCleanupConsumer} objects.
156 public List getAvailableCleanupConsumers()
158 return Collections.unmodifiableList( this.availableCleanupConsumers );