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 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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
  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. * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
  218. *
  219. * @param remoteRepository the remote repository
  220. * @param configuration the configuration that is updated
  221. * @return the repository instance, that was created or updated
  222. * @throws RepositoryException if an error occurred while creating or updating the instance
  223. */
  224. RemoteRepository putRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException;
  225. /**
  226. * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
  227. * from the data of the given instance. Otherwise a new repository is created and updated by the data of the given instance.
  228. *
  229. * The archiva configuration is updated and saved after updating the registered repository instance.
  230. *
  231. * @param remoteRepository the remote repository
  232. * @return the repository instance, that was created or updated
  233. * @throws RepositoryException if an error occurred while creating or updating the instance
  234. */
  235. RemoteRepository putRepository( RemoteRepository remoteRepository ) throws RepositoryException;
  236. /**
  237. * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
  238. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  239. *
  240. * The archiva configuration is updated and saved after updating the registered repository instance.
  241. *
  242. * @param remoteRepositoryConfiguration the remote repository configuration
  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 ) throws RepositoryException;
  247. /**
  248. * Adds or updates the given remote repository. If a remote repository with the given id exists already, it is updated
  249. * from the data of the given configuration. Otherwise a new repository is created and updated by the data of the given configuration.
  250. *
  251. * This method can be used, if the archiva configuration should not be saved. It will only update the given configuration object.
  252. *
  253. * @param remoteRepositoryConfiguration the remote repository configuration
  254. * @param configuration the archiva configuration where the updated data is stored into
  255. * @return the repository instance, that was created or updated
  256. * @throws RepositoryException if an error occurred while creating or updating the instance
  257. */
  258. RemoteRepository putRepository( RemoteRepositoryConfiguration remoteRepositoryConfiguration, Configuration configuration ) throws RepositoryException;
  259. /**
  260. * Removes the repository or repository group with the given id, if it exists. Otherwise, it will do nothing.
  261. *
  262. * The configuration is updated and saved, if the deletion was successful
  263. *
  264. * @param repoId the id of the repository or repository group to delete
  265. * @throws RepositoryException if the repository deletion failed
  266. */
  267. void removeRepository( String repoId ) throws RepositoryException;
  268. /**
  269. * Removes the given repository.
  270. *
  271. * The configuration is updated and saved, if the deletion was successful
  272. *
  273. * @param repo the repository instance that should be deleted
  274. * @throws RepositoryException if the repository deletion failed
  275. */
  276. void removeRepository( Repository repo ) throws RepositoryException;
  277. /**
  278. * Removes the given managed repository.
  279. *
  280. * The configuration is updated and saved, if the deletion was successful
  281. *
  282. * @param managedRepository the managed repository to remove
  283. * @throws RepositoryException if the repository deletion failed
  284. */
  285. void removeRepository( ManagedRepository managedRepository ) throws RepositoryException;
  286. /**
  287. * Removes the given managed repository. The given configuration instance is updated, but the
  288. * archiva configuration is not saved.
  289. *
  290. * @param managedRepository the managed repository to remove
  291. * @param configuration the configuration instance to update
  292. * @throws RepositoryException if the repository deletion failed
  293. */
  294. void removeRepository( ManagedRepository managedRepository, Configuration configuration ) throws RepositoryException;
  295. /**
  296. * Removes the given repository group.
  297. *
  298. * The configuration is updated and saved, if the deletion was successful
  299. *
  300. * @param repositoryGroup the repository group to remove
  301. * @throws RepositoryException if the repository deletion failed
  302. */
  303. void removeRepositoryGroup( RepositoryGroup repositoryGroup ) throws RepositoryException;
  304. /**
  305. * Removes the given repository group. The given configuration instance is updated, but the
  306. * archiva configuration is not saved.
  307. *
  308. * @param repositoryGroup the repository group to remove
  309. * @param configuration the configuration instance to update
  310. * @throws RepositoryException if the repository deletion failed
  311. */
  312. void removeRepositoryGroup( RepositoryGroup repositoryGroup, Configuration configuration ) throws RepositoryException;
  313. /**
  314. * Removes the given remote repository.
  315. *
  316. * The configuration is updated and saved, if the deletion was successful
  317. *
  318. * @param remoteRepository the remote repository to remove
  319. * @throws RepositoryException if the repository deletion failed
  320. */
  321. void removeRepository( RemoteRepository remoteRepository ) throws RepositoryException;
  322. /**
  323. * Removes the given remote repository. The given configuration instance is updated, but the
  324. * archiva configuration is not saved.
  325. *
  326. * @param remoteRepository the remote repository to remove
  327. * @param configuration the configuration instance to update
  328. * @throws RepositoryException if the repository deletion failed
  329. */
  330. void removeRepository( RemoteRepository remoteRepository, Configuration configuration ) throws RepositoryException;
  331. /**
  332. * Reloads all repositories and groups from the configuration
  333. */
  334. void reload( );
  335. void resetIndexingContext( Repository repository ) throws IndexUpdateFailedException;
  336. /**
  337. * Creates a new repository based on the given repository and with the given new id.
  338. * @param repo the repository to copy from
  339. * @param newId the new repository id
  340. * @param <T> the type of the repository (Manage, Remote or RepositoryGroup)
  341. * @return the newly created repository
  342. * @throws RepositoryException if the repository could not be created
  343. */
  344. <T extends Repository> T clone( T repo, String newId ) throws RepositoryException;
  345. /**
  346. * Return the repository that stores the given asset.
  347. * @param asset the asset
  348. * @return the repository or <code>null</code> if no matching repository is found
  349. */
  350. Repository getRepositoryOfAsset( StorageAsset asset );
  351. /**
  352. * Validates the set attributes of the given repository instance and returns the validation result.
  353. * The repository registry uses all available validators and applies their validateRepository method to the given
  354. * repository. Validation results will be merged per field.
  355. *
  356. * @param repository the repository to validate against
  357. * @return the result of the validation.
  358. */
  359. <R extends Repository> ValidationResponse<R> validateRepository( R repository);
  360. /**
  361. * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
  362. * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
  363. * repository. Validation results will be merged per field.
  364. *
  365. * @param repository the repository to validate against
  366. * @return the result of the validation.
  367. */
  368. <R extends Repository> ValidationResponse<R> validateRepositoryForUpdate( R repository);
  369. }