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.

RepositoryHandler.java 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. * 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
  17. * under the License.
  18. */
  19. import org.apache.archiva.configuration.Configuration;
  20. import org.apache.archiva.repository.validation.CheckedResult;
  21. import org.apache.archiva.repository.validation.RepositoryChecker;
  22. import org.apache.archiva.repository.validation.RepositoryValidator;
  23. import org.apache.archiva.repository.validation.ValidationResponse;
  24. import java.util.Collection;
  25. import java.util.Map;
  26. /**
  27. *
  28. * This is the generic interface that handles different repository flavours.
  29. *
  30. * @author Martin Stockhammer <martin_s@apache.org>
  31. */
  32. public interface RepositoryHandler<R extends Repository, C>
  33. {
  34. /**
  35. * Creates instances from the archiva configuration. The instances are not registered in the registry.
  36. *
  37. * @return A map of (repository id, Repository) pairs
  38. */
  39. Map<String, R> newInstancesFromConfig();
  40. /**
  41. * Creates a new instance without registering and without updating the archiva configuration
  42. *
  43. * @param type the repository type
  44. * @param id the repository identifier
  45. * @return the repository instance
  46. * @throws RepositoryException if the creation failed
  47. */
  48. R newInstance(RepositoryType type, String id) throws RepositoryException;
  49. /**
  50. * Creates a new instance and updates the given configuration object.
  51. *
  52. * @param repositoryConfiguration the configuration instance
  53. * @return a newly created instance
  54. * @throws RepositoryException if the creation failed
  55. */
  56. R newInstance( C repositoryConfiguration ) throws RepositoryException;
  57. /**
  58. * Adds the given repository to the registry or replaces a already existing repository in the registry.
  59. * If an error occurred during the update, it will revert to the old repository status.
  60. *
  61. * @param repository the repository
  62. * @return the created or updated repository instance
  63. * @throws RepositoryException if the update or creation failed
  64. */
  65. R put( R repository ) throws RepositoryException;
  66. /**
  67. * Adds the repository to the registry, based on the given configuration.
  68. * If there is a repository registered with the given id, it is updated.
  69. * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
  70. * The repository instance is registered and initialized if no error occurs
  71. *
  72. * @param repositoryConfiguration the repository configuration
  73. * @return the updated or created repository instance
  74. * @throws RepositoryException if the update or creation failed
  75. */
  76. R put( C repositoryConfiguration ) throws RepositoryException;
  77. /**
  78. * Adds a repository from the given repository configuration. The changes are stored in
  79. * the configuration object. The archiva registry is not updated.
  80. * The returned repository instance is a clone of the registered repository instance. It is not registered
  81. * and not initialized. References are not updated.
  82. *
  83. * @param repositoryConfiguration the repository configuration
  84. * @param configuration the configuration instance
  85. * @return the repository instance that was created or updated
  86. * @throws RepositoryException if the update or creation failed
  87. */
  88. R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
  89. /**
  90. * Adds or updates a repository from the given configuration data. The resulting repository is
  91. * checked by the repository checker and the result is returned.
  92. * If the checker returns a valid result, the registry is updated and configuration is saved.
  93. *
  94. * @param repositoryConfiguration the repository configuration
  95. * @param checker the checker that validates the repository data
  96. * @return the repository and the check result
  97. * @throws RepositoryException if the creation or update failed
  98. */
  99. <D> CheckedResult<R, D>
  100. putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker) throws RepositoryException;
  101. /**
  102. * Removes the given repository from the registry and updates references and saves the new configuration.
  103. *
  104. * @param id The repository identifier
  105. * @throws RepositoryException if the repository could not be removed
  106. */
  107. void remove( final String id ) throws RepositoryException;
  108. /**
  109. * Removes the given repository from the registry and updates only the given configuration instance.
  110. * The archiva registry is not updated
  111. *
  112. * @param id the repository identifier
  113. * @param configuration the configuration to update
  114. * @throws RepositoryException if the repository could not be removed
  115. */
  116. void remove( String id, Configuration configuration ) throws RepositoryException;
  117. /**
  118. * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
  119. *
  120. * @param id the repository id
  121. * @return if the retrieval failed
  122. */
  123. R get( String id );
  124. /**
  125. * Clones a given repository without registering.
  126. *
  127. * @param repo the repository that should be cloned
  128. * @return a newly created instance with the same repository data
  129. */
  130. R clone(R repo) throws RepositoryException;
  131. /**
  132. * Updates the references and stores updates in the given <code>configuration</code> instance.
  133. * The references that are updated depend on the concrete repository subclass <code>R</code>.
  134. * This method may register/unregister repositories depending on the implementation. That means there is no simple
  135. * way to roll back, if an error occurs.
  136. *
  137. * @param repo the repository for which references are updated
  138. * @param repositoryConfiguration the repository configuration
  139. */
  140. void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
  141. /**
  142. * Returns all registered repositories.
  143. *
  144. * @return the list of repositories
  145. */
  146. Collection<R> getAll();
  147. /**
  148. * Returns a validator that can be used to validate repository data
  149. * @return a validator instance
  150. */
  151. RepositoryValidator<R> getValidator( );
  152. /**
  153. * Validates the set attributes of the given repository instance and returns the validation result.
  154. * The repository registry uses all available validators and applies their validateRepository method to the given
  155. * repository. Validation results will be merged per field.
  156. *
  157. * @param repository the repository to validate against
  158. * @return the result of the validation.
  159. */
  160. ValidationResponse<R> validateRepository( R repository);
  161. /**
  162. * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
  163. * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
  164. * repository. Validation results will be merged per field.
  165. *
  166. * @param repository the repository to validate against
  167. * @return the result of the validation.
  168. */
  169. ValidationResponse<R> validateRepositoryForUpdate( R repository);
  170. /**
  171. * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
  172. * @param id the repository identifier
  173. * @return <code>true</code>, if it is registered, otherwise <code>false</code>
  174. */
  175. boolean has(String id);
  176. /**
  177. * Initializes
  178. */
  179. void init();
  180. /**
  181. * Closes the handler
  182. */
  183. void close();
  184. }