1 package org.apache.archiva.repository;
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.configuration.model.AbstractRepositoryConfiguration;
21 import org.apache.archiva.configuration.model.Configuration;
22 import org.apache.archiva.repository.validation.CheckedResult;
23 import org.apache.archiva.repository.validation.RepositoryChecker;
24 import org.apache.archiva.repository.validation.RepositoryValidator;
25 import org.apache.archiva.repository.validation.ValidationError;
27 import java.util.Collection;
28 import java.util.List;
32 * This is the generic interface that handles different repository flavours, currently for
33 * ManagedRepository, RemoteRepository and RepositoryGroup
35 * Lifecycle/states of a repository:
37 * <li>Instance created: This state is reached by the newInstance-methods. The instance is created, filled with the
38 * corresponding attribute data and references are updated. References are object references to other repositories, if they exist.
39 * The instance is not registered on the registry (stored) and configuration is not updated.</li>
40 * <li>Instance registered: Instances added/updated by the put()-methods are created and registered on the registry.
41 * If all goes well, the configuration is updated.</li>
42 * <li>Instance initialized: </li>
45 * The repository handler are not thread safe. Synchronization is done by registry if necessary.
47 * @author Martin Stockhammer <martin_s@apache.org>
49 public interface RepositoryHandler<R extends Repository, C extends AbstractRepositoryConfiguration>
53 * Initializes the current state from the configuration
55 void initializeFromConfig( );
58 * Initializes the repository. E.g. starts scheduling and activate additional processes.
59 * @param repository the repository to initialize
61 void activateRepository( R repository );
64 * Reset the repository. E.g. stops scheduling.
67 void deactivateRepository( R repository );
70 * Creates new instances from the archiva configuration. The instances are not registered in the registry.
72 * @return A map of (repository id, Repository) pairs
74 Map<String, R> newInstancesFromConfig( );
77 * Creates a new instance without registering and without updating the archiva configuration
79 * @param type the repository type
80 * @param id the repository identifier
81 * @return the repository instance
82 * @throws RepositoryException if the creation failed
84 R newInstance( RepositoryType type, String id ) throws RepositoryException;
87 * Creates a new instance based on the given configuration instance. The instance is not activated and not registered.
89 * @param repositoryConfiguration the configuration instance
90 * @return a newly created instance
91 * @throws RepositoryException if the creation failed
93 R newInstance( C repositoryConfiguration ) throws RepositoryException;
96 * Adds the given repository to the registry or replaces a already existing repository in the registry.
97 * If an error occurred during the update, it will revert to the old repository status.
99 * @param repository the repository
100 * @return the created or updated repository instance
101 * @throws RepositoryException if the update or creation failed
103 R put( R repository ) throws RepositoryException;
106 * Adds the repository to the registry, based on the given configuration.
107 * If there is a repository registered with the given id, it is updated.
108 * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
109 * The repository instance is registered and initialized if no error occurs
111 * @param repositoryConfiguration the repository configuration
112 * @return the updated or created repository instance
113 * @throws RepositoryException if the update or creation failed
115 R put( C repositoryConfiguration ) throws RepositoryException;
118 * Adds a repository from the given repository configuration. The changes are stored in
119 * the configuration object. The archiva registry is not updated.
120 * The returned repository instance is a clone of the registered repository instance. It is not registered
121 * and not initialized. References are not updated.
123 * @param repositoryConfiguration the repository configuration
124 * @param configuration the configuration instance
125 * @return the repository instance that was created or updated
126 * @throws RepositoryException if the update or creation failed
128 R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
131 * Adds or updates a repository from the given configuration data. The resulting repository is
132 * checked by the repository checker and the result is returned.
133 * If the checker returns a valid result, the registry is updated and configuration is saved.
135 * @param repositoryConfiguration the repository configuration
136 * @param checker the checker that validates the repository data
137 * @return the repository and the check result
138 * @throws RepositoryException if the creation or update failed
140 <D> CheckedResult<R, D>
141 putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker ) throws RepositoryException;
144 * Adds or updates a repository from the given configuration data. The resulting repository is
145 * checked by the default repository checker of the handler instance and the result is returned.
146 * If the checker returns a valid result, the registry is updated and configuration is saved.
148 * @param repositoryConfiguration the repository configuration
149 * @return the repository and the check result as map of attributes -> list of validation errors
150 * @throws RepositoryException if the creation or update failed
152 CheckedResult<R, Map<String, List<ValidationError>>>
153 putWithCheck( C repositoryConfiguration ) throws RepositoryException;
157 * Removes the given repository from the registry and updates references and saves the new configuration.
159 * @param id The repository identifier
160 * @throws RepositoryException if the repository could not be removed
162 void remove( final String id ) throws RepositoryException;
165 * Removes the given repository from the registry and updates only the given configuration instance.
166 * The archiva registry is not updated
168 * @param id the repository identifier
169 * @param configuration the configuration to update
170 * @throws RepositoryException if the repository could not be removed
172 void remove( String id, Configuration configuration ) throws RepositoryException;
175 * Returns the repository with the given identifier or <code>null</code>, if no repository is registered
178 * @param id the repository id
179 * @return the repository instance or <code>null</code>
184 * Clones a given repository without registering.
186 * @param repo the repository that should be cloned
187 * @param newId the new identifier of the cloned instance
188 * @return a newly created instance with the same repository data
190 R clone( R repo, String newId ) throws RepositoryException;
193 * Updates the references and stores updates in the given <code>configuration</code> instance.
194 * The references that are updated depend on the concrete repository subclass <code>R</code>.
195 * This method may register/unregister repositories depending on the implementation. That means there is no simple
196 * way to roll back, if an error occurs.
198 * @param repo the repository for which references are updated
199 * @param repositoryConfiguration the repository configuration
201 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
204 * Returns all registered repositories.
206 * @return the list of repositories
208 Collection<R> getAll( );
211 * Returns a validator that can be used to validate repository data
213 * @return a validator instance
215 RepositoryValidator<R> getValidator( );
218 * Validates the set attributes of the given repository instance and returns the validation result.
219 * The repository registry uses all available validators and applies their validateRepository method to the given
220 * repository. Validation results will be merged per field.
222 * @param repository the repository to validate against
223 * @return the result of the validation.
225 CheckedResult<R,Map<String, List<ValidationError>>> validateRepository( R repository );
228 * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
229 * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
230 * repository. Validation results will be merged per field.
232 * @param repository the repository to validate against
233 * @return the result of the validation.
235 CheckedResult<R,Map<String, List<ValidationError>>> validateRepositoryForUpdate( R repository );
239 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
241 * @param id the repository identifier
242 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
244 boolean hasRepository( String id );
247 * This is called, when another variant repository was removed. This is needed only for certain variants.
251 void processOtherVariantRemoval( Repository repository );
254 * Initializes the handler. This method must be called before using the repository handler.
259 * Closes the handler. After closing, the repository handler instance is not usable anymore.
265 * Sets the repository provider list
268 void setRepositoryProviders( List<RepositoryProvider> providers );
271 * Sets the list of repository validators
272 * @param repositoryValidatorList
274 void setRepositoryValidator( List<RepositoryValidator<? extends Repository>> repositoryValidatorList );
277 * Returns the repository variant, this handler manages.
278 * @return the concrete variant class
280 Class<R> getVariant();
283 * Returns the repository configuration variant, this handler manages.
284 * @return the concrete configuration variant class
286 Class<C> getConfigurationVariant();