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.configuration.ArchivaConfiguration;
23 import org.apache.archiva.configuration.Configuration;
24 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
26 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
27 import org.apache.archiva.event.EventSource;
28 import org.apache.archiva.indexer.ArchivaIndexManager;
29 import org.apache.archiva.indexer.IndexUpdateFailedException;
30 import org.apache.archiva.repository.metadata.MetadataReader;
31 import org.apache.archiva.repository.storage.StorageAsset;
32 import org.apache.archiva.repository.validation.CheckedResult;
33 import org.apache.archiva.repository.validation.ValidationError;
34 import org.apache.archiva.repository.validation.ValidationResponse;
36 import java.util.Collection;
37 import java.util.List;
41 * Registry for repositories. This is the central entry point for repositories. It provides methods for
42 * retrieving, adding and removing repositories.
44 * The modification methods putXX and removeXX without configuration object persist the changes immediately to the archiva configuration. If the
45 * configuration save fails the changes are rolled back.
48 * The modification methods with configuration object do only update the given configuration. The configuration is not saved.
50 * @author Martin Stockhammer <martin_s@apache.org>
52 @SuppressWarnings( "UnusedReturnValue" )
53 public interface RepositoryRegistry extends EventSource, RepositoryHandlerManager
56 * Set the configuration for the registry
57 * @param archivaConfiguration the archiva configuration instance
59 void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration );
62 * Return the index manager for the given repository type
63 * @param type the repository type
64 * @return the index manager, if it exists
66 ArchivaIndexManager getIndexManager( RepositoryType type );
69 * Returns the metadata reader for the given repository type
70 * @param type the repository type
71 * @return the metadata reader instance
73 MetadataReader getMetadataReader(RepositoryType type) throws UnsupportedRepositoryTypeException;
76 * Returns all registered repositories
77 * @return the list of repositories
79 Collection<Repository> getRepositories( );
82 * Returns all managed repositories
83 * @return the list of managed repositories
85 Collection<ManagedRepository> getManagedRepositories( );
88 * Returns a collection of all registered remote repositories
89 * @return the collection of remote repositories
91 Collection<RemoteRepository> getRemoteRepositories( );
94 * Returns a collection of all registered repository groups.
96 * @return the collection of repository groups
98 Collection<RepositoryGroup> getRepositoryGroups( );
101 * Returns the repository (managed, remote, group) with the given id
102 * @param repoId the id of the repository
103 * @return the repository or <code>null</code> if no repository with this ID is registered.
105 Repository getRepository( String repoId );
108 * Returns the managed repository with the given id
109 * @param repoId the id of the repository
110 * @return the managed repository instance or <code>null</code>, if no managed repository with this ID is registered.
112 ManagedRepository getManagedRepository( String repoId );
115 * Returns the remote repository with the given id
116 * @param repoId the id of the repository
117 * @return the remote repository instance or <code>null</code>, if no remote repository with this ID is registered.
119 RemoteRepository getRemoteRepository( String repoId );
122 * Returns the repository group with the given id
123 * @param groupId the id of the repository group
124 * @return the repository group instance or <code>null</code>, if no repository group with this ID is registered.
126 RepositoryGroup getRepositoryGroup( String groupId );
129 * Returns <code>true</code>, if a repository with the given ID is registered, otherwise <code>false</code>
130 * @param repoId the ID of the repository
131 * @return <code>true</code>, if a repository with the given ID is registered, otherwise <code>false</code>
133 boolean hasRepository(String repoId);
136 * Returns <code>true</code>, if a managed repository with the given ID is registered, otherwise <code>false</code>
137 * @param repoId the id of the managed repository
138 * @return <code>true</code>, if a managed repository with the given ID is registered, otherwise <code>false</code>
140 boolean hasManagedRepository(String repoId);
143 * Returns <code>true</code>, if a remote repository with the given ID is registered, otherwise <code>false</code>
144 * @param repoId the id of the remote repository
145 * @return <code>true</code>, if a remote repository with the given ID is registered, otherwise <code>false</code>
147 boolean hasRemoteRepository(String repoId);
150 * Returns <code>true</code>, if a repository group with the given ID is registered, otherwise <code>false</code>
151 * @param groupId the id of the repository group
152 * @return <code>true</code>, if a repository group with the given ID is registered, otherwise <code>false</code>
154 boolean hasRepositoryGroup( String groupId );
157 * Adds or updates the given managed repository. If a managed repository with the given id exists already, it is updated
158 * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
160 * The archiva configuration is updated and saved after updating the registered repository instance.
162 * @param managedRepository the managed repository
163 * @return the repository instance, that was created or updated
164 * @throws RepositoryException if an error occurred while creating or updating the instance
166 ManagedRepository putRepository( ManagedRepository managedRepository ) throws RepositoryException;
169 * Adds or updates the given managed repository. If a managed repository with the given id exists already, it is updated
170 * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
172 * The archiva configuration is updated and saved after updating the registered repository instance.
174 * @param managedRepositoryConfiguration the managed repository configuration
175 * @return the repository instance, that was created or updated
176 * @throws RepositoryException if an error occurred while creating or updating the instance
178 ManagedRepository putRepository( ManagedRepositoryConfiguration managedRepositoryConfiguration ) throws RepositoryException;
181 * Adds or updates the given managed repository. If a managed repository with the given id exists already, it is updated
182 * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
184 * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
186 * @param managedRepositoryConfiguration the managed repository configuration
187 * @param configuration the archiva configuration that is updated
188 * @return the repository instance, that was created or updated
189 * @throws RepositoryException if an error occurred while creating or updating the instance
191 ManagedRepository putRepository( ManagedRepositoryConfiguration managedRepositoryConfiguration, Configuration configuration ) throws RepositoryException;
194 * Adds or updates the given repository group. If a repository group with the given id exists already, it is updated
195 * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
197 * The archiva configuration is updated and saved after updating the registered repository instance.
199 * @param repositoryGroup the repository group
200 * @return the repository instance, that was created or updated
201 * @throws RepositoryException if an error occurred while creating or updating the instance
203 RepositoryGroup putRepositoryGroup( RepositoryGroup repositoryGroup ) throws RepositoryException;
206 * Adds or updates the given repository group. If a repository group with the given id exists already, it is updated
207 * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
209 * The archiva configuration is updated and saved after updating the registered repository instance.
211 * @param repositoryGroupConfiguration the repository group configuration
212 * @return the repository instance, that was created or updated
213 * @throws RepositoryException if an error occurred while creating or updating the instance
215 RepositoryGroup putRepositoryGroup( RepositoryGroupConfiguration repositoryGroupConfiguration ) throws RepositoryException;
219 * This method creates or updates a repository by the given configuration. It uses the <code>validator</code> to check the
220 * result. If the validation is not successful, the repository will not be saved.
222 * @param configuration the repository configuration
225 CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> putRepositoryGroupAndValidate( RepositoryGroupConfiguration configuration) throws RepositoryException;
228 * Adds or updates the given repository group. If a repository group with the given id exists already, it is updated
229 * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
231 * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
233 * @param repositoryGroupConfiguration the repository group configuration
234 * @param configuration the archiva configuration that is updated
235 * @return the repository instance, that was created or updated
236 * @throws RepositoryException if an error occurred while creating or updating the instance
238 RepositoryGroup putRepositoryGroup( RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration ) throws RepositoryException;
241 * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
242 * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
244 * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
246 * @param remoteRepository the remote repository
247 * @param configuration the configuration that is updated
248 * @return the repository instance, that was created or updated
249 * @throws RepositoryException if an error occurred while creating or updating the instance
251 RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException;
254 * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
255 * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
257 * The archiva configuration is updated and saved after updating the registered repository instance.
259 * @param remoteRepository the remote repository
260 * @return the repository instance, that was created or updated
261 * @throws RepositoryException if an error occurred while creating or updating the instance
263 RemoteRepository putRepository( RemoteRepository remoteRepository ) throws RepositoryException;
266 * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
267 * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
269 * The archiva configuration is updated and saved after updating the registered repository instance.
271 * @param remoteRepositoryConfiguration the remote repository configuration
272 * @return the repository instance, that was created or updated
273 * @throws RepositoryException if an error occurred while creating or updating the instance
275 RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration ) throws RepositoryException;
278 * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
279 * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
281 * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
283 * @param remoteRepositoryConfiguration the remote repository configuration
284 * @param configuration the archiva configuration where the updated data is stored into
285 * @return the repository instance, that was created or updated
286 * @throws RepositoryException if an error occurred while creating or updating the instance
288 RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration ) throws RepositoryException;
291 * Removes the repository or repository group with the given id, if it exists. Otherwise, it will do nothing.
293 * The configuration is updated and saved, if the deletion was successful
295 * @param repoId the id of the repository or repository group to delete
296 * @throws RepositoryException if the repository deletion failed
298 void removeRepository( String repoId ) throws RepositoryException;
301 * Removes the given repository.
303 * The configuration is updated and saved, if the deletion was successful
305 * @param repo the repository instance that should be deleted
306 * @throws RepositoryException if the repository deletion failed
308 void removeRepository( Repository repo ) throws RepositoryException;
311 * Removes the given managed repository.
313 * The configuration is updated and saved, if the deletion was successful
315 * @param managedRepository the managed repository to remove
316 * @throws RepositoryException if the repository deletion failed
318 void removeRepository( ManagedRepository managedRepository ) throws RepositoryException;
321 * Removes the given managed repository. The given configuration instance is updated, but the
322 * archiva configuration is not saved.
324 * @param managedRepository the managed repository to remove
325 * @param configuration the configuration instance to update
326 * @throws RepositoryException if the repository deletion failed
328 void removeRepository( ManagedRepository managedRepository, Configuration configuration ) throws RepositoryException;
331 * Removes the given repository group.
333 * The configuration is updated and saved, if the deletion was successful
335 * @param repositoryGroup the repository group to remove
336 * @throws RepositoryException if the repository deletion failed
338 void removeRepositoryGroup( RepositoryGroup repositoryGroup ) throws RepositoryException;
341 * Removes the given repository group. The given configuration instance is updated, but the
342 * archiva configuration is not saved.
344 * @param repositoryGroup the repository group to remove
345 * @param configuration the configuration instance to update
346 * @throws RepositoryException if the repository deletion failed
348 void removeRepositoryGroup( RepositoryGroup repositoryGroup, Configuration configuration ) throws RepositoryException;
351 * Removes the given remote repository.
353 * The configuration is updated and saved, if the deletion was successful
355 * @param remoteRepository the remote repository to remove
356 * @throws RepositoryException if the repository deletion failed
358 void removeRepository( RemoteRepository remoteRepository ) throws RepositoryException;
361 * Removes the given remote repository. The given configuration instance is updated, but the
362 * archiva configuration is not saved.
364 * @param remoteRepository the remote repository to remove
365 * @param configuration the configuration instance to update
366 * @throws RepositoryException if the repository deletion failed
368 void removeRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException;
371 * Reloads all repositories and groups from the configuration
375 void resetIndexingContext( Repository repository ) throws IndexUpdateFailedException;
378 * Creates a new repository based on the given repository and with the given new id.
379 * @param repo the repository to copy from
380 * @param newId the new repository id
381 * @param <T> the type of the repository (Manage, Remote or RepositoryGroup)
382 * @return the newly created repository
383 * @throws RepositoryException if the repository could not be created
385 <T extends Repository> T clone( T repo, String newId ) throws RepositoryException;
388 * Return the repository that stores the given asset.
389 * @param asset the asset
390 * @return the repository or <code>null</code> if no matching repository is found
392 Repository getRepositoryOfAsset( StorageAsset asset );
395 * Validates the set attributes of the given repository instance and returns the validation result.
396 * The repository registry uses all available validators and applies their validateRepository method to the given
397 * repository. Validation results will be merged per field.
399 * @param repository the repository to validate against
400 * @return the result of the validation.
402 <R extends Repository> ValidationResponse<R> validateRepository( R repository);
405 * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
406 * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
407 * repository. Validation results will be merged per field.
409 * @param repository the repository to validate against
410 * @return the result of the validation.
412 <R extends Repository> ValidationResponse<R> validateRepositoryForUpdate( R repository);