1 package org.apache.archiva.repository.base.group;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.common.filelock.DefaultFileLockManager;
21 import org.apache.archiva.common.filelock.FileLockManager;
22 import org.apache.archiva.repository.EditableRepositoryGroup;
23 import org.apache.archiva.repository.ManagedRepository;
24 import org.apache.archiva.repository.ReleaseScheme;
25 import org.apache.archiva.repository.RepositoryCapabilities;
26 import org.apache.archiva.repository.RepositoryGroup;
27 import org.apache.archiva.repository.RepositoryType;
28 import org.apache.archiva.repository.StandardCapabilities;
29 import org.apache.archiva.repository.base.AbstractRepository;
30 import org.apache.archiva.repository.base.managed.BasicManagedRepository;
31 import org.apache.archiva.repository.features.IndexCreationFeature;
32 import org.apache.archiva.repository.storage.RepositoryStorage;
33 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import java.io.IOException;
38 import java.nio.file.Path;
39 import java.util.ArrayList;
40 import java.util.List;
43 * @author Martin Stockhammer <martin_s@apache.org>
45 public class BasicRepositoryGroup extends AbstractRepository implements EditableRepositoryGroup
47 private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
48 new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
51 new String[] {IndexCreationFeature.class.getName()},
59 private int mergedIndexTtl = 0;
60 private boolean hasIndex = false;
62 private final Logger log = LoggerFactory.getLogger(BasicRepositoryGroup.class);
64 private List<ManagedRepository> repositories = new ArrayList<>( );
66 public BasicRepositoryGroup( String id, String name, RepositoryStorage repositoryStorage )
68 super( RepositoryType.MAVEN, id, name, repositoryStorage );
69 IndexCreationFeature feature = new IndexCreationFeature( this, null );
70 feature.setLocalIndexPath( repositoryStorage.getRoot( ).resolve(".indexer") );
71 feature.setLocalPackedIndexPath( repositoryStorage.getRoot( ).resolve(".index") );
72 addFeature( feature );
76 public List<ManagedRepository> getRepositories( )
82 public boolean contains( ManagedRepository repository )
84 return repositories.contains( repository );
88 public boolean contains( String id )
90 return repositories.stream( ).anyMatch( v -> id.equals( v.getId( ) ) );
94 public int getMergedIndexTTL( )
96 return mergedIndexTtl;
100 public boolean hasIndex( )
106 public RepositoryCapabilities getCapabilities( )
112 public void clearRepositories( )
114 this.repositories.clear( );
118 public void setRepositories( List<ManagedRepository> repositories )
120 this.repositories.clear();
121 this.repositories.addAll( repositories );
125 public void addRepository( ManagedRepository repository )
127 if ( !this.repositories.contains( repository ) )
129 this.repositories.add( repository );
134 public void addRepository( int index, ManagedRepository repository )
136 if (!this.repositories.contains( repository )) {
137 this.repositories.add( index, repository );
142 public boolean removeRepository( ManagedRepository repository )
144 return this.repositories.remove( repository );
148 public ManagedRepository removeRepository( String repoId )
150 for (ManagedRepository repo : this.repositories) {
152 if (repoId.equals( repo.getId() )) {
153 this.repositories.remove( repo );
161 public void setMergedIndexTTL( int timeInSeconds )
163 this.mergedIndexTtl = timeInSeconds;
167 * Creates a filesystem based repository instance. The path is built by basePath/repository-id
169 * @param id The repository id
170 * @param name The name of the repository
171 * @param repositoryPath The path to the repository
172 * @return The repository instance
173 * @throws IOException
175 public static BasicRepositoryGroup newFilesystemInstance( String id, String name, Path repositoryPath) throws IOException {
176 FileLockManager lockManager = new DefaultFileLockManager();
177 FilesystemStorage storage = new FilesystemStorage(repositoryPath, lockManager);
178 return new BasicRepositoryGroup(id, name, storage);