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.ValidationResponse;
26 import java.util.Collection;
31 * This is the generic interface that handles different repository flavours.
33 * @author Martin Stockhammer <martin_s@apache.org>
35 public interface RepositoryHandler<R extends Repository, C>
39 * Creates instances from the archiva configuration. The instances are not registered in the registry.
41 * @return A map of (repository id, Repository) pairs
43 Map<String, R> newInstancesFromConfig();
46 * Creates a new instance without registering and without updating the archiva configuration
48 * @param type the repository type
49 * @param id the repository identifier
50 * @return the repository instance
51 * @throws RepositoryException if the creation failed
53 R newInstance(RepositoryType type, String id) throws RepositoryException;
56 * Creates a new instance and updates the given configuration object.
58 * @param repositoryConfiguration the configuration instance
59 * @return a newly created instance
60 * @throws RepositoryException if the creation failed
62 R newInstance( C repositoryConfiguration ) throws RepositoryException;
65 * Adds the given repository to the registry or replaces a already existing repository in the registry.
66 * If an error occurred during the update, it will revert to the old repository status.
68 * @param repository the repository
69 * @return the created or updated repository instance
70 * @throws RepositoryException if the update or creation failed
72 R put( R repository ) throws RepositoryException;
75 * Adds the repository to the registry, based on the given configuration.
76 * If there is a repository registered with the given id, it is updated.
77 * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
78 * The repository instance is registered and initialized if no error occurs
80 * @param repositoryConfiguration the repository configuration
81 * @return the updated or created repository instance
82 * @throws RepositoryException if the update or creation failed
84 R put( C repositoryConfiguration ) throws RepositoryException;
87 * Adds a repository from the given repository configuration. The changes are stored in
88 * the configuration object. The archiva registry is not updated.
89 * The returned repository instance is a clone of the registered repository instance. It is not registered
90 * and not initialized. References are not updated.
92 * @param repositoryConfiguration the repository configuration
93 * @param configuration the configuration instance
94 * @return the repository instance that was created or updated
95 * @throws RepositoryException if the update or creation failed
97 R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
100 * Adds or updates a repository from the given configuration data. The resulting repository is
101 * checked by the repository checker and the result is returned.
102 * If the checker returns a valid result, the registry is updated and configuration is saved.
104 * @param repositoryConfiguration the repository configuration
105 * @param checker the checker that validates the repository data
106 * @return the repository and the check result
107 * @throws RepositoryException if the creation or update failed
109 <D> CheckedResult<R, D>
110 putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker) throws RepositoryException;
113 * Removes the given repository from the registry and updates references and saves the new configuration.
115 * @param id The repository identifier
116 * @throws RepositoryException if the repository could not be removed
118 void remove( final String id ) throws RepositoryException;
121 * Removes the given repository from the registry and updates only the given configuration instance.
122 * The archiva registry is not updated
124 * @param id the repository identifier
125 * @param configuration the configuration to update
126 * @throws RepositoryException if the repository could not be removed
128 void remove( String id, Configuration configuration ) throws RepositoryException;
131 * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
133 * @param id the repository id
134 * @return if the retrieval failed
139 * Clones a given repository without registering.
141 * @param repo the repository that should be cloned
142 * @return a newly created instance with the same repository data
144 R clone(R repo) throws RepositoryException;
147 * Updates the references and stores updates in the given <code>configuration</code> instance.
148 * The references that are updated depend on the concrete repository subclass <code>R</code>.
149 * This method may register/unregister repositories depending on the implementation. That means there is no simple
150 * way to roll back, if an error occurs.
152 * @param repo the repository for which references are updated
153 * @param repositoryConfiguration the repository configuration
155 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
158 * Returns all registered repositories.
160 * @return the list of repositories
162 Collection<R> getAll();
165 * Returns a validator that can be used to validate repository data
166 * @return a validator instance
168 RepositoryValidator<R> getValidator( );
171 * Validates the set attributes of the given repository instance and returns the validation result.
172 * The repository registry uses all available validators and applies their validateRepository method to the given
173 * repository. Validation results will be merged per field.
175 * @param repository the repository to validate against
176 * @return the result of the validation.
178 ValidationResponse<R> validateRepository( R repository);
181 * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
182 * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
183 * repository. Validation results will be merged per field.
185 * @param repository the repository to validate against
186 * @return the result of the validation.
188 ValidationResponse<R> validateRepositoryForUpdate( R repository);
193 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
194 * @param id the repository identifier
195 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
197 boolean has(String id);