From cfc586926328557e341768259ca9d84a220a75c3 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 7 May 2007 15:16:22 +0000 Subject: [PATCH] Adding ActiveManagedRepositories for non-webapp to use. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@535895 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/ActiveManagedRepositories.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java new file mode 100644 index 000000000..4e89e6a08 --- /dev/null +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java @@ -0,0 +1,92 @@ +package org.apache.maven.archiva.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.collections.CollectionUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.ConfigurationNames; +import org.apache.maven.archiva.configuration.util.LocalRepositoryPredicate; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.registry.Registry; +import org.codehaus.plexus.registry.RegistryListener; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * A component that provides a real-time listing of the active managed repositories within archiva. + * This object is internally consistent and will return maintain a consistent list of managed repositories internally. + * + * @author Joakim Erdfelt + * @version $Id$ + * + * @plexus.component role="org.apache.maven.archiva.repository.ActiveManagedRepositories" + */ +public class ActiveManagedRepositories + implements RegistryListener, Initializable +{ + /** + * @plexus.requirement + */ + private ArchivaConfiguration archivaConfiguration; + + private List allManagedRepositories = new ArrayList(); + + public List getAllManagedRepositories() + { + synchronized ( allManagedRepositories ) + { + return Collections.unmodifiableList( allManagedRepositories ); + } + } + + public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + if ( ConfigurationNames.isRepositories( propertyName ) ) + { + update(); + } + } + + public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) + { + /* nothing to do here */ + } + + public void initialize() + throws InitializationException + { + update(); + archivaConfiguration.addChangeListener( this ); + } + + private void update() + { + synchronized ( allManagedRepositories ) + { + allManagedRepositories.clear(); + + List configRepos = archivaConfiguration.getConfiguration().getRepositories(); + CollectionUtils.select( configRepos, LocalRepositoryPredicate.getInstance() ); + } + } +} -- 2.39.5