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 String mergedIndexPath;
45 private int mergedIndexTTL;
47 private final ReadWriteLock rwl = new ReentrantReadWriteLock();
49 private RepositoryStorage storage;
51 private RepositoryCapabilities capabilities;
53 public AbstractRepositoryGroup(RepositoryType type, String id, String name, Path repositoryBase) {
54 super(type, id, name, repositoryBase);
57 public AbstractRepositoryGroup(Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase) {
58 super(primaryLocale, type, id, name, repositoryBase);
62 public boolean hasIndex() {
67 public RepositoryCapabilities getCapabilities() {
73 public void clearRepositories() {
74 rwl.writeLock().lock();
78 rwl.writeLock().unlock();
83 public void setRepositories(List<ManagedRepository> repositories) {
84 rwl.writeLock().lock();
87 repositories.addAll(repositories);
89 rwl.writeLock().unlock();
94 public void addRepository(ManagedRepository repository) {
95 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 repositories.put(index, repository.getId(), repository);
109 rwl.writeLock().unlock();
114 public boolean removeRepository(ManagedRepository repository) {
115 rwl.writeLock().lock();
117 return repositories.remove(repository.getId(), repository);
119 rwl.writeLock().unlock();
124 public ManagedRepository removeRepository(String repoId) {
125 rwl.writeLock().lock();
127 return repositories.remove(repoId);
129 rwl.writeLock().unlock();
134 public void setMergedIndexPath(String path) {
135 this.mergedIndexPath = path;
139 public void setMergedIndexTTL(int timeInSeconds) {
140 this.mergedIndexTTL = timeInSeconds;
144 public List<ManagedRepository> getRepositories() {
145 rwl.readLock().lock();
147 return repositories.valueList();
149 rwl.readLock().unlock();
154 public boolean contains(ManagedRepository repository) {
155 rwl.readLock().lock();
157 return repositories.containsValue(repository);
159 rwl.readLock().unlock();
164 public boolean contains(String id) {
165 rwl.readLock().lock();
167 return repositories.containsKey(id);
169 rwl.readLock().unlock();
174 public StorageAsset getMergedIndexPath() {
175 return storage.getAsset(mergedIndexPath);
179 public int getMergedIndexTTL() {
180 return mergedIndexTTL;
184 public StorageAsset getAsset(String path) {
185 return storage.getAsset(path);
189 public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException {
190 storage.consumeData(asset, consumerFunction, readLock);
194 public StorageAsset addAsset(String path, boolean container) {
195 return storage.addAsset(path, container);
199 public void removeAsset(StorageAsset asset) throws IOException {
200 storage.removeAsset(asset);
204 public StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException {
205 return storage.moveAsset(origin, destination);
209 public StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException {
210 return storage.copyAsset(origin, destination);
213 protected void setStorage(RepositoryStorage storage) {
214 this.storage = storage;
217 protected void setCapabilities(RepositoryCapabilities capabilities) {
218 this.capabilities = capabilities;