1 package org.apache.archiva.repository;
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.archiva.repository.content.RepositoryStorage;
23 import org.apache.archiva.repository.content.StorageAsset;
24 import org.apache.commons.collections4.map.ListOrderedMap;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.nio.file.Path;
29 import java.util.List;
30 import java.util.Locale;
31 import java.util.concurrent.locks.ReadWriteLock;
32 import java.util.concurrent.locks.ReentrantReadWriteLock;
33 import java.util.function.Consumer;
36 * Abstract repository group implementation.
39 public class AbstractRepositoryGroup extends AbstractRepository implements EditableRepositoryGroup {
41 private ListOrderedMap<String, ManagedRepository> repositories = new ListOrderedMap<>();
43 private int mergedIndexTTL;
45 private final ReadWriteLock rwl = new ReentrantReadWriteLock();
47 private RepositoryCapabilities capabilities;
49 public AbstractRepositoryGroup(RepositoryType type, String id, String name, RepositoryStorage storage) {
50 super(type, id, name, storage);
53 public AbstractRepositoryGroup(Locale primaryLocale, RepositoryType type, String id, String name, RepositoryStorage storage) {
54 super(primaryLocale, type, id, name, storage);
58 public boolean hasIndex() {
63 public RepositoryCapabilities getCapabilities() {
69 public void clearRepositories() {
70 rwl.writeLock().lock();
74 rwl.writeLock().unlock();
79 public void setRepositories(List<ManagedRepository> newRepositories) {
80 rwl.writeLock().lock();
83 for(ManagedRepository repo : newRepositories) {
85 repositories.put(repo.getId(), repo);
88 rwl.writeLock().unlock();
93 public void addRepository(ManagedRepository repository) {
94 rwl.writeLock().lock();
97 repositories.put(repository.getId(), repository);
99 rwl.writeLock().unlock();
104 public void addRepository(int index, ManagedRepository repository) {
105 rwl.writeLock().lock();
107 if (repository!=null)
108 repositories.put(index, repository.getId(), repository);
110 rwl.writeLock().unlock();
115 public boolean removeRepository(ManagedRepository repository) {
116 rwl.writeLock().lock();
118 return repositories.remove(repository.getId(), repository);
120 rwl.writeLock().unlock();
125 public ManagedRepository removeRepository(String repoId) {
126 rwl.writeLock().lock();
128 return repositories.remove(repoId);
130 rwl.writeLock().unlock();
135 public void setMergedIndexTTL(int timeInSeconds) {
136 this.mergedIndexTTL = timeInSeconds;
140 public List<ManagedRepository> getRepositories() {
141 rwl.readLock().lock();
143 return repositories.valueList();
145 rwl.readLock().unlock();
150 public boolean contains(ManagedRepository repository) {
151 rwl.readLock().lock();
153 return repositories.containsValue(repository);
155 rwl.readLock().unlock();
160 public boolean contains(String id) {
161 rwl.readLock().lock();
163 return repositories.containsKey(id);
165 rwl.readLock().unlock();
170 public int getMergedIndexTTL() {
171 return mergedIndexTTL;
174 protected void setCapabilities(RepositoryCapabilities capabilities) {
175 this.capabilities = capabilities;