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;
23 import java.util.Collection;
28 * This is the generic interface that handles different repository flavours.
30 * @author Martin Stockhammer <martin_s@apache.org>
32 public interface RepositoryHandler<R extends Repository, C>
36 * Creates instances from the archiva configuration. The instances are not registered in the registry.
38 * @return A map of (repository id, Repository) pairs
40 Map<String, R> newInstancesFromConfig();
43 * Creates a new instance without registering and without updating the archiva configuration
45 * @param type the repository type
46 * @param id the repository identifier
47 * @return the repository instance
48 * @throws RepositoryException if the creation failed
50 R newInstance(RepositoryType type, String id) throws RepositoryException;
53 * Creates a new instance and updates the given configuration object.
55 * @param repositoryConfiguration the configuration instance
56 * @return a newly created instance
57 * @throws RepositoryException if the creation failed
59 R newInstance( C repositoryConfiguration ) throws RepositoryException;
62 * Adds the given repository to the registry or replaces a already existing repository in the registry.
63 * If an error occurred during the update, it will revert to the old repository status.
65 * @param repository the repository
66 * @return the created or updated repository instance
67 * @throws RepositoryException if the update or creation failed
69 R put( R repository ) throws RepositoryException;
72 * Adds the repository to the registry, based on the given configuration.
73 * If there is a repository registered with the given id, it is updated.
74 * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
75 * The repository instance is registered and initialized if no error occurs
77 * @param repositoryConfiguration the repository configuration
78 * @return the updated or created repository instance
79 * @throws RepositoryException if the update or creation failed
81 R put( C repositoryConfiguration ) throws RepositoryException;
84 * Adds a repository from the given repository configuration. The changes are stored in
85 * the configuration object. The archiva registry is not updated.
86 * The returned repository instance is a clone of the registered repository instance. It is not registered
87 * and not initialized. References are not updated.
89 * @param repositoryConfiguration the repository configuration
90 * @param configuration the configuration instance
91 * @return the repository instance that was created or updated
92 * @throws RepositoryException if the update or creation failed
94 R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
97 * Adds or updates a repository from the given configuration data. The resulting repository is
98 * checked by the repository checker and the result is returned.
99 * If the checker returns a valid result, the registry is updated and configuration is saved.
101 * @param repositoryConfiguration the repository configuration
102 * @param checker the checker that validates the repository data
103 * @return the repository and the check result
104 * @throws RepositoryException if the creation or update failed
106 <D> CheckedResult<R, D>
107 putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker) throws RepositoryException;
110 * Removes the given repository from the registry and updates references and saves the new configuration.
112 * @param id The repository identifier
113 * @throws RepositoryException if the repository could not be removed
115 void remove( final String id ) throws RepositoryException;
118 * Removes the given repository from the registry and updates only the given configuration instance.
119 * The archiva registry is not updated
121 * @param id the repository identifier
122 * @param configuration the configuration to update
123 * @throws RepositoryException if the repository could not be removed
125 void remove( String id, Configuration configuration ) throws RepositoryException;
128 * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
130 * @param id the repository id
131 * @return if the retrieval failed
136 * Clones a given repository without registering.
138 * @param repo the repository that should be cloned
139 * @return a newly created instance with the same repository data
141 R clone(R repo) throws RepositoryException;
144 * Updates the references and stores updates in the given <code>configuration</code> instance.
145 * The references that are updated depend on the concrete repository subclass <code>R</code>.
146 * This method may register/unregister repositories depending on the implementation. That means there is no simple
147 * way to roll back, if an error occurs.
149 * @param repo the repository for which references are updated
150 * @param repositoryConfiguration the repository configuration
152 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
155 * Returns all registered repositories.
157 * @return the list of repositories
159 Collection<R> getAll();
162 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
163 * @param id the repository identifier
164 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
166 boolean has(String id);