You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryRegistry.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. package org.apache.archiva.repository;
  2. /*
  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
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.configuration.ArchivaConfiguration;
  21. import org.apache.archiva.configuration.Configuration;
  22. import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
  23. import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
  24. import org.apache.archiva.configuration.RepositoryGroupConfiguration;
  25. import org.apache.archiva.event.EventSource;
  26. import org.apache.archiva.indexer.ArchivaIndexManager;
  27. import org.apache.archiva.indexer.IndexUpdateFailedException;
  28. import org.apache.archiva.repository.metadata.MetadataReader;
  29. import org.apache.archiva.repository.storage.StorageAsset;
  30. import org.apache.archiva.repository.validation.CheckedResult;
  31. import org.apache.archiva.repository.validation.ValidationError;
  32. import org.apache.archiva.repository.validation.ValidationResponse;
  33. import java.util.Collection;
  34. import java.util.List;
  35. import java.util.Map;
  36. /**
  37. * Registry for repositories. This is the central entry point for repositories. It provides methods for
  38. * retrieving, adding and removing repositories.
  39. * <p>
  40. * The modification methods putXX and removeXX without configuration object persist the changes immediately to the archiva configuration. If the
  41. * configuration save fails the changes are rolled back.
  42. * </p>
  43. * <p>
  44. * The modification methods with configuration object do only update the given configuration. The configuration is not saved.
  45. * </p>
  46. * @author Martin Stockhammer <martin_s@apache.org>
  47. */
  48. @SuppressWarnings( "UnusedReturnValue" )
  49. public interface RepositoryRegistry extends EventSource, RepositoryHandlerManager
  50. {
  51. /**
  52. * Set the configuration for the registry
  53. * @param archivaConfiguration the archiva configuration instance
  54. */
  55. void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration );
  56. /**
  57. * Return the index manager for the given repository type
  58. * @param type the repository type
  59. * @return the index manager, if it exists
  60. */
  61. ArchivaIndexManager getIndexManager( RepositoryType type );
  62. /**
  63. * Returns the metadata reader for the given repository type
  64. * @param type the repository type
  65. * @return the metadata reader instance
  66. */
  67. MetadataReader getMetadataReader(RepositoryType type) throws UnsupportedRepositoryTypeException;
  68. /**
  69. * Returns all registered repositories
  70. * @return the list of repositories
  71. */
  72. Collection<Repository> getRepositories( );
  73. /**
  74. * Returns all managed repositories
  75. * @return the list of managed repositories
  76. */
  77. Collection<ManagedRepository> getManagedRepositories( );
  78. /**
  79. * Returns a collection of all registered remote repositories
  80. * @return the collection of remote repositories
  81. */
  82. Collection<RemoteRepository> getRemoteRepositories( );
  83. /**
  84. * Returns a collection of all registered repository groups.
  85. *
  86. * @return the collection of repository groups
  87. */
  88. Collection<RepositoryGroup> getRepositoryGroups( );
  89. /**
  90. * Returns the repository (managed, remote, group) with the given id
  91. * @param repoId the id of the repository
  92. * @return the repository or <code>null</code> if no repository with this ID is registered.
  93. */
  94. Repository getRepository( String repoId );
  95. /**
  96. * Returns the managed repository with the given id
  97. * @param repoId the id of the repository
  98. * @return the managed repository instance or <code>null</code>, if no managed repository with this ID is registered.
  99. */
  100. ManagedRepository getManagedRepository( String repoId );
  101. /**
  102. * Returns the remote repository with the given id
  103. * @param repoId the id of the repository
  104. * @return the remote repository instance or <code>null</code>, if no remote repository with this ID is registered.
  105. */
  106. RemoteRepository getRemoteRepository( String repoId );
  107. /**
  108. * Returns the repository group with the given id
  109. * @param groupId the id of the repository group
  110. * @return the repository group instance or <code>null</code>, if no repository group with this ID is registered.
  111. */
  112. RepositoryGroup getRepositoryGroup( String groupId );
  113. /**
  114. * Returns <code>true</code>, if a repository with the given ID is registered, otherwise <code>false</code>
  115. * @param repoId the ID of the repository
  116. * @return <code>true</code>, if a repository with the given ID is registered, otherwise <code>false</code>
  117. */
  118. boolean hasRepository(String repoId);
  119. /**
  120. * Returns <code>true</code>, if a managed repository with the given ID is registered, otherwise <code>false</code>
  121. * @param repoId the id of the managed repository
  122. * @return <code>true</code>, if a managed repository with the given ID is registered, otherwise <code>false</code>
  123. */
  124. boolean hasManagedRepository(String repoId);
  125. /**
  126. * Returns <code>true</code>, if a remote repository with the given ID is registered, otherwise <code>false</code>
  127. * @param repoId the id of the remote repository
  128. * @return <code>true</code>, if a remote repository with the given ID is registered, otherwise <code>false</code>
  129. */
  130. boolean hasRemoteRepository(String repoId);
  131. /**
  132. * Returns <code>true</code>, if a repository group with the given ID is registered, otherwise <code>false</code>
  133. * @param groupId the id of the repository group
  134. * @return <code>true</code>, if a repository group with the given ID is registered, otherwise <code>false</code>
  135. */
  136. boolean hasRepositoryGroup( String groupId );
  137. /**
  138. * Adds or updates the given managed repository. If a managed repository with the given id exists already, it is updated
  139. * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
  140. *
  141. * The archiva configuration is updated and saved after updating the registered repository instance.
  142. *
  143. * @param managedRepository the managed repository
  144. * @return the repository instance, that was created or updated
  145. * @throws RepositoryException if an error occurred while creating or updating the instance
  146. */
  147. ManagedRepository putRepository( ManagedRepository managedRepository ) throws RepositoryException;
  148. /**
  149. * Adds or updates the given managed repository. If a managed repository with the given id exists already, it is updated
  150. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  151. *
  152. * The archiva configuration is updated and saved after updating the registered repository instance.
  153. *
  154. * @param managedRepositoryConfiguration the managed repository configuration
  155. * @return the repository instance, that was created or updated
  156. * @throws RepositoryException if an error occurred while creating or updating the instance
  157. */
  158. ManagedRepository putRepository( ManagedRepositoryConfiguration managedRepositoryConfiguration ) throws RepositoryException;
  159. /**
  160. * Adds or updates the given managed repository. If a managed repository with the given id exists already, it is updated
  161. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  162. *
  163. * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
  164. *
  165. * @param managedRepositoryConfiguration the managed repository configuration
  166. * @param configuration the archiva configuration that is updated
  167. * @return the repository instance, that was created or updated
  168. * @throws RepositoryException if an error occurred while creating or updating the instance
  169. */
  170. ManagedRepository putRepository( ManagedRepositoryConfiguration managedRepositoryConfiguration, Configuration configuration ) throws RepositoryException;
  171. /**
  172. * Adds or updates the given repository group. If a repository group with the given id exists already, it is updated
  173. * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
  174. *
  175. * The archiva configuration is updated and saved after updating the registered repository instance.
  176. *
  177. * @param repositoryGroup the repository group
  178. * @return the repository instance, that was created or updated
  179. * @throws RepositoryException if an error occurred while creating or updating the instance
  180. */
  181. RepositoryGroup putRepositoryGroup( RepositoryGroup repositoryGroup ) throws RepositoryException;
  182. /**
  183. * Adds or updates the given repository group. If a repository group with the given id exists already, it is updated
  184. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  185. *
  186. * The archiva configuration is updated and saved after updating the registered repository instance.
  187. *
  188. * @param repositoryGroupConfiguration the repository group configuration
  189. * @return the repository instance, that was created or updated
  190. * @throws RepositoryException if an error occurred while creating or updating the instance
  191. */
  192. RepositoryGroup putRepositoryGroup( RepositoryGroupConfiguration repositoryGroupConfiguration ) throws RepositoryException;
  193. /**
  194. * This method creates or updates a repository by the given configuration. It uses the <code>validator</code> to check the
  195. * result. If the validation is not successful, the repository will not be saved.
  196. *
  197. * @param configuration the repository configuration
  198. * @return the result
  199. */
  200. CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> putRepositoryGroupAndValidate( RepositoryGroupConfiguration configuration) throws RepositoryException;
  201. /**
  202. * Adds or updates the given repository group. If a repository group with the given id exists already, it is updated
  203. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  204. *
  205. * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
  206. *
  207. * @param repositoryGroupConfiguration the repository group configuration
  208. * @param configuration the archiva configuration that is updated
  209. * @return the repository instance, that was created or updated
  210. * @throws RepositoryException if an error occurred while creating or updating the instance
  211. */
  212. RepositoryGroup putRepositoryGroup( RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration ) throws RepositoryException;
  213. /**
  214. * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
  215. * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
  216. *
  217. * The archiva configuration is updated and saved after updating the registered repository instance.
  218. *
  219. * @param remoteRepository the remote repository
  220. * @return the repository instance, that was created or updated
  221. * @throws RepositoryException if an error occurred while creating or updating the instance
  222. */
  223. RemoteRepository putRepository( RemoteRepository remoteRepository ) throws RepositoryException;
  224. /**
  225. * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
  226. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  227. *
  228. * The archiva configuration is updated and saved after updating the registered repository instance.
  229. *
  230. * @param remoteRepositoryConfiguration the remote repository configuration
  231. * @return the repository instance, that was created or updated
  232. * @throws RepositoryException if an error occurred while creating or updating the instance
  233. */
  234. RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration ) throws RepositoryException;
  235. /**
  236. * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
  237. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  238. *
  239. * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
  240. *
  241. * @param remoteRepositoryConfiguration the remote repository configuration
  242. * @param configuration the archiva configuration where the updated data is stored into
  243. * @return the repository instance, that was created or updated
  244. * @throws RepositoryException if an error occurred while creating or updating the instance
  245. */
  246. RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration ) throws RepositoryException;
  247. /**
  248. * Removes the repository or repository group with the given id, if it exists. Otherwise, it will do nothing.
  249. *
  250. * The configuration is updated and saved, if the deletion was successful
  251. *
  252. * @param repoId the id of the repository or repository group to delete
  253. * @throws RepositoryException if the repository deletion failed
  254. */
  255. void removeRepository( String repoId ) throws RepositoryException;
  256. /**
  257. * Removes the given repository.
  258. *
  259. * The configuration is updated and saved, if the deletion was successful
  260. *
  261. * @param repo the repository instance that should be deleted
  262. * @throws RepositoryException if the repository deletion failed
  263. */
  264. void removeRepository( Repository repo ) throws RepositoryException;
  265. /**
  266. * Removes the given managed repository.
  267. *
  268. * The configuration is updated and saved, if the deletion was successful
  269. *
  270. * @param managedRepository the managed repository to remove
  271. * @throws RepositoryException if the repository deletion failed
  272. */
  273. void removeRepository( ManagedRepository managedRepository ) throws RepositoryException;
  274. /**
  275. * Removes the given managed repository. The given configuration instance is updated, but the
  276. * archiva configuration is not saved.
  277. *
  278. * @param managedRepository the managed repository to remove
  279. * @param configuration the configuration instance to update
  280. * @throws RepositoryException if the repository deletion failed
  281. */
  282. void removeRepository( ManagedRepository managedRepository, Configuration configuration ) throws RepositoryException;
  283. /**
  284. * Removes the given repository group.
  285. *
  286. * The configuration is updated and saved, if the deletion was successful
  287. *
  288. * @param repositoryGroup the repository group to remove
  289. * @throws RepositoryException if the repository deletion failed
  290. */
  291. void removeRepositoryGroup( RepositoryGroup repositoryGroup ) throws RepositoryException;
  292. /**
  293. * Removes the given repository group. The given configuration instance is updated, but the
  294. * archiva configuration is not saved.
  295. *
  296. * @param repositoryGroup the repository group to remove
  297. * @param configuration the configuration instance to update
  298. * @throws RepositoryException if the repository deletion failed
  299. */
  300. void removeRepositoryGroup( RepositoryGroup repositoryGroup, Configuration configuration ) throws RepositoryException;
  301. /**
  302. * Removes the given remote repository.
  303. *
  304. * The configuration is updated and saved, if the deletion was successful
  305. *
  306. * @param remoteRepository the remote repository to remove
  307. * @throws RepositoryException if the repository deletion failed
  308. */
  309. void removeRepository( RemoteRepository remoteRepository ) throws RepositoryException;
  310. /**
  311. * Removes the given remote repository. The given configuration instance is updated, but the
  312. * archiva configuration is not saved.
  313. *
  314. * @param remoteRepository the remote repository to remove
  315. * @param configuration the configuration instance to update
  316. * @throws RepositoryException if the repository deletion failed
  317. */
  318. void removeRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException;
  319. /**
  320. * Reloads all repositories and groups from the configuration
  321. */
  322. void reload( );
  323. void resetIndexingContext( Repository repository ) throws IndexUpdateFailedException;
  324. /**
  325. * Creates a new repository based on the given repository and with the given new id.
  326. * @param repo the repository to copy from
  327. * @param newId the new repository id
  328. * @param <T> the type of the repository (Manage, Remote or RepositoryGroup)
  329. * @return the newly created repository
  330. * @throws RepositoryException if the repository could not be created
  331. */
  332. <T extends Repository> T clone( T repo, String newId ) throws RepositoryException;
  333. /**
  334. * Return the repository that stores the given asset.
  335. * @param asset the asset
  336. * @return the repository or <code>null</code> if no matching repository is found
  337. */
  338. Repository getRepositoryOfAsset( StorageAsset asset );
  339. /**
  340. * Validates the set attributes of the given repository instance and returns the validation result.
  341. * The repository registry uses all available validators and applies their validateRepository method to the given
  342. * repository. Validation results will be merged per field.
  343. *
  344. * @param repository the repository to validate against
  345. * @return the result of the validation.
  346. */
  347. <R extends Repository> ValidationResponse<R> validateRepository( R repository);
  348. /**
  349. * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
  350. * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
  351. * repository. Validation results will be merged per field.
  352. *
  353. * @param repository the repository to validate against
  354. * @return the result of the validation.
  355. */
  356. <R extends Repository> ValidationResponse<R> validateRepositoryForUpdate( R repository);
  357. }