]> source.dussan.org Git - archiva.git/commitdiff
Adding ActiveManagedRepositories for non-webapp to use.
authorJoakim Erdfelt <joakime@apache.org>
Mon, 7 May 2007 15:16:22 +0000 (15:16 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 7 May 2007 15:16:22 +0000 (15:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@535895 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/ActiveManagedRepositories.java [new file with mode: 0644]

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 (file)
index 0000000..4e89e6a
--- /dev/null
@@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @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() );
+        }
+    }
+}