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.RepositoryChecker;
22 import org.apache.archiva.repository.validation.RepositoryValidator;
24 import java.util.Collection;
29 * This is the generic interface that handles different repository flavours.
31 * @author Martin Stockhammer <martin_s@apache.org>
33 public interface RepositoryHandler<R extends Repository, C>
37 * Creates instances from the archiva configuration. The instances are not registered in the registry.
39 * @return A map of (repository id, Repository) pairs
41 Map<String, R> newInstancesFromConfig();
44 * Creates a new instance without registering and without updating the archiva configuration
46 * @param type the repository type
47 * @param id the repository identifier
48 * @return the repository instance
49 * @throws RepositoryException if the creation failed
51 R newInstance(RepositoryType type, String id) throws RepositoryException;
54 * Creates a new instance and updates the given configuration object.
56 * @param repositoryConfiguration the configuration instance
57 * @return a newly created instance
58 * @throws RepositoryException if the creation failed
60 R newInstance( C repositoryConfiguration ) throws RepositoryException;
63 * Adds the given repository to the registry or replaces a already existing repository in the registry.
64 * If an error occurred during the update, it will revert to the old repository status.
66 * @param repository the repository
67 * @return the created or updated repository instance
68 * @throws RepositoryException if the update or creation failed
70 R put( R repository ) throws RepositoryException;
73 * Adds the repository to the registry, based on the given configuration.
74 * If there is a repository registered with the given id, it is updated.
75 * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
76 * The repository instance is registered and initialized if no error occurs
78 * @param repositoryConfiguration the repository configuration
79 * @return the updated or created repository instance
80 * @throws RepositoryException if the update or creation failed
82 R put( C repositoryConfiguration ) throws RepositoryException;
85 * Adds a repository from the given repository configuration. The changes are stored in
86 * the configuration object. The archiva registry is not updated.
87 * The returned repository instance is a clone of the registered repository instance. It is not registered
88 * and not initialized. References are not updated.
90 * @param repositoryConfiguration the repository configuration
91 * @param configuration the configuration instance
92 * @return the repository instance that was created or updated
93 * @throws RepositoryException if the update or creation failed
95 R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
98 * Adds or updates a repository from the given configuration data. The resulting repository is
99 * checked by the repository checker and the result is returned.
100 * If the checker returns a valid result, the registry is updated and configuration is saved.
102 * @param repositoryConfiguration the repository configuration
103 * @param checker the checker that validates the repository data
104 * @return the repository and the check result
105 * @throws RepositoryException if the creation or update failed
107 <D> CheckedResult<R, D>
108 putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker) throws RepositoryException;
111 * Removes the given repository from the registry and updates references and saves the new configuration.
113 * @param id The repository identifier
114 * @throws RepositoryException if the repository could not be removed
116 void remove( final String id ) throws RepositoryException;
119 * Removes the given repository from the registry and updates only the given configuration instance.
120 * The archiva registry is not updated
122 * @param id the repository identifier
123 * @param configuration the configuration to update
124 * @throws RepositoryException if the repository could not be removed
126 void remove( String id, Configuration configuration ) throws RepositoryException;
129 * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
131 * @param id the repository id
132 * @return if the retrieval failed
137 * Clones a given repository without registering.
139 * @param repo the repository that should be cloned
140 * @return a newly created instance with the same repository data
142 R clone(R repo) throws RepositoryException;
145 * Updates the references and stores updates in the given <code>configuration</code> instance.
146 * The references that are updated depend on the concrete repository subclass <code>R</code>.
147 * This method may register/unregister repositories depending on the implementation. That means there is no simple
148 * way to roll back, if an error occurs.
150 * @param repo the repository for which references are updated
151 * @param repositoryConfiguration the repository configuration
153 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
156 * Returns all registered repositories.
158 * @return the list of repositories
160 Collection<R> getAll();
163 * Returns a validator that can be used to validate repository data
164 * @return a validator instance
166 RepositoryValidator<R> getValidator( );
169 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
170 * @param id the repository identifier
171 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
173 boolean has(String id);