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.Configuration;
21 import org.apache.archiva.repository.validation.CheckedResult;
22 import org.apache.archiva.repository.validation.RepositoryChecker;
23 import org.apache.archiva.repository.validation.RepositoryValidator;
24 import org.apache.archiva.repository.validation.ValidationError;
26 import java.util.Collection;
27 import java.util.List;
31 * This is the generic interface that handles different repository flavours, currently for
32 * ManagedRepository, RemoteRepository and RepositoryGroup
34 * Lifecycle/states of a repository:
36 * <li>Instance created: This state is reached by the newInstance-methods. The instance is created, filled with the
37 * corresponding attribute data and references are updated. References are object references to other repositories, if they exist.
38 * The instance is not registered on the registry (stored) and configuration is not updated.</li>
39 * <li>Instance registered: Instances added/updated by the put()-methods are created and registered on the registry.
40 * If all goes well, the configuration is updated.</li>
41 * <li>Instance initialized: </li>
45 * @author Martin Stockhammer <martin_s@apache.org>
47 public interface RepositoryHandler<R extends Repository, C>
51 * Initializes the current state from the configuration
53 void initializeFromConfig( );
56 * Initializes the repository. E.g. starts scheduling and activate additional processes.
57 * @param repository the repository to initialize
59 void activateRepository( R repository );
62 * Creates new instances from the archiva configuration. The instances are not registered in the registry.
64 * @return A map of (repository id, Repository) pairs
66 Map<String, R> newInstancesFromConfig( );
69 * Creates a new instance without registering and without updating the archiva configuration
71 * @param type the repository type
72 * @param id the repository identifier
73 * @return the repository instance
74 * @throws RepositoryException if the creation failed
76 R newInstance( RepositoryType type, String id ) throws RepositoryException;
79 * Creates a new instance based on the given configuration instance. The instance is not activated and not registered.
81 * @param repositoryConfiguration the configuration instance
82 * @return a newly created instance
83 * @throws RepositoryException if the creation failed
85 R newInstance( C repositoryConfiguration ) throws RepositoryException;
88 * Adds the given repository to the registry or replaces a already existing repository in the registry.
89 * If an error occurred during the update, it will revert to the old repository status.
91 * @param repository the repository
92 * @return the created or updated repository instance
93 * @throws RepositoryException if the update or creation failed
95 R put( R repository ) throws RepositoryException;
98 * Adds the repository to the registry, based on the given configuration.
99 * If there is a repository registered with the given id, it is updated.
100 * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
101 * The repository instance is registered and initialized if no error occurs
103 * @param repositoryConfiguration the repository configuration
104 * @return the updated or created repository instance
105 * @throws RepositoryException if the update or creation failed
107 R put( C repositoryConfiguration ) throws RepositoryException;
110 * Adds a repository from the given repository configuration. The changes are stored in
111 * the configuration object. The archiva registry is not updated.
112 * The returned repository instance is a clone of the registered repository instance. It is not registered
113 * and not initialized. References are not updated.
115 * @param repositoryConfiguration the repository configuration
116 * @param configuration the configuration instance
117 * @return the repository instance that was created or updated
118 * @throws RepositoryException if the update or creation failed
120 R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
123 * Adds or updates a repository from the given configuration data. The resulting repository is
124 * checked by the repository checker and the result is returned.
125 * If the checker returns a valid result, the registry is updated and configuration is saved.
127 * @param repositoryConfiguration the repository configuration
128 * @param checker the checker that validates the repository data
129 * @return the repository and the check result
130 * @throws RepositoryException if the creation or update failed
132 <D> CheckedResult<R, D>
133 putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker ) throws RepositoryException;
136 * Removes the given repository from the registry and updates references and saves the new configuration.
138 * @param id The repository identifier
139 * @throws RepositoryException if the repository could not be removed
141 void remove( final String id ) throws RepositoryException;
144 * Removes the given repository from the registry and updates only the given configuration instance.
145 * The archiva registry is not updated
147 * @param id the repository identifier
148 * @param configuration the configuration to update
149 * @throws RepositoryException if the repository could not be removed
151 void remove( String id, Configuration configuration ) throws RepositoryException;
154 * Returns the repository with the given identifier or <code>null</code>, if no repository is registered
157 * @param id the repository id
158 * @return the repository instance or <code>null</code>
163 * Clones a given repository without registering.
165 * @param repo the repository that should be cloned
166 * @return a newly created instance with the same repository data
168 R clone( R repo ) throws RepositoryException;
171 * Updates the references and stores updates in the given <code>configuration</code> instance.
172 * The references that are updated depend on the concrete repository subclass <code>R</code>.
173 * This method may register/unregister repositories depending on the implementation. That means there is no simple
174 * way to roll back, if an error occurs.
176 * @param repo the repository for which references are updated
177 * @param repositoryConfiguration the repository configuration
179 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
182 * Returns all registered repositories.
184 * @return the list of repositories
186 Collection<R> getAll( );
189 * Returns a validator that can be used to validate repository data
191 * @return a validator instance
193 RepositoryValidator<R> getValidator( );
196 * Validates the set attributes of the given repository instance and returns the validation result.
197 * The repository registry uses all available validators and applies their validateRepository method to the given
198 * repository. Validation results will be merged per field.
200 * @param repository the repository to validate against
201 * @return the result of the validation.
203 CheckedResult<R,Map<String, List<ValidationError>>> validateRepository( R repository );
206 * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
207 * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
208 * repository. Validation results will be merged per field.
210 * @param repository the repository to validate against
211 * @return the result of the validation.
213 CheckedResult<R,Map<String, List<ValidationError>>> validateRepositoryForUpdate( R repository );
217 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
219 * @param id the repository identifier
220 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
222 boolean has( String id );
225 * Initializes the handler. This method must be called before using the repository handler.
230 * Closes the handler. After closing, the repository handler instance is not usable anymore.