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.AbstractRepositoryConfiguration;
21 import org.apache.archiva.configuration.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 * Removes the given repository from the registry and updates references and saves the new configuration.
146 * @param id The repository identifier
147 * @throws RepositoryException if the repository could not be removed
149 void remove( final String id ) throws RepositoryException;
152 * Removes the given repository from the registry and updates only the given configuration instance.
153 * The archiva registry is not updated
155 * @param id the repository identifier
156 * @param configuration the configuration to update
157 * @throws RepositoryException if the repository could not be removed
159 void remove( String id, Configuration configuration ) throws RepositoryException;
162 * Returns the repository with the given identifier or <code>null</code>, if no repository is registered
165 * @param id the repository id
166 * @return the repository instance or <code>null</code>
171 * Clones a given repository without registering.
173 * @param repo the repository that should be cloned
174 * @param newId the new identifier of the cloned instance
175 * @return a newly created instance with the same repository data
177 R clone( R repo, String newId ) throws RepositoryException;
180 * Updates the references and stores updates in the given <code>configuration</code> instance.
181 * The references that are updated depend on the concrete repository subclass <code>R</code>.
182 * This method may register/unregister repositories depending on the implementation. That means there is no simple
183 * way to roll back, if an error occurs.
185 * @param repo the repository for which references are updated
186 * @param repositoryConfiguration the repository configuration
188 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
191 * Returns all registered repositories.
193 * @return the list of repositories
195 Collection<R> getAll( );
198 * Returns a validator that can be used to validate repository data
200 * @return a validator instance
202 RepositoryValidator<R> getValidator( );
205 * Validates the set attributes of the given repository instance and returns the validation result.
206 * The repository registry uses all available validators and applies their validateRepository method to the given
207 * repository. Validation results will be merged per field.
209 * @param repository the repository to validate against
210 * @return the result of the validation.
212 CheckedResult<R,Map<String, List<ValidationError>>> validateRepository( R repository );
215 * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
216 * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
217 * repository. Validation results will be merged per field.
219 * @param repository the repository to validate against
220 * @return the result of the validation.
222 CheckedResult<R,Map<String, List<ValidationError>>> validateRepositoryForUpdate( R repository );
226 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
228 * @param id the repository identifier
229 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
231 boolean hasRepository( String id );
234 * This is called, when another variant repository was removed. This is needed only for certain variants.
238 void processOtherVariantRemoval( Repository repository );
241 * Initializes the handler. This method must be called before using the repository handler.
246 * Closes the handler. After closing, the repository handler instance is not usable anymore.
252 * Sets the repository provider list
255 void setRepositoryProviders( List<RepositoryProvider> providers );
258 * Sets the list of repository validators
259 * @param repositoryValidatorList
261 void setRepositoryValidator( List<RepositoryValidator<? extends Repository>> repositoryValidatorList );
264 * Returns the repository variant, this handler manages.
265 * @return the concrete variant class
267 Class<R> getVariant();
270 * Returns the repository configuration variant, this handler manages.
271 * @return the concrete configuration variant class
273 Class<C> getConfigurationVariant();