1 package org.apache.archiva.repository;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.model.ArchivaArtifact;
23 import org.apache.archiva.model.ArtifactReference;
24 import org.apache.archiva.model.ProjectReference;
25 import org.apache.archiva.model.VersionedReference;
26 import org.apache.archiva.repository.content.Artifact;
27 import org.apache.archiva.repository.content.ContentItem;
28 import org.apache.archiva.repository.content.DataItem;
29 import org.apache.archiva.repository.content.ItemNotFoundException;
30 import org.apache.archiva.repository.content.ItemSelector;
31 import org.apache.archiva.repository.content.Namespace;
32 import org.apache.archiva.repository.content.Project;
33 import org.apache.archiva.repository.content.Version;
34 import org.apache.archiva.repository.storage.StorageAsset;
36 import java.nio.file.Path;
37 import java.util.List;
38 import java.util.stream.Stream;
41 * Layout interface for interacting with a managed repository in an abstract way,
42 * without the need for processing based on filesystem paths, or working with the database.
46 public interface BaseRepositoryContentLayout extends ManagedRepositoryContentLayout
49 /// ***************** New generation interface **********************
54 * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other
55 * coordinates are ignored.
56 * The following coordinates must be set at the given selector:
60 * If not, a {@link IllegalArgumentException} will be thrown.
62 * @param namespaceSelector the selectory with the namespace coordinates
63 * @return the namespace
64 * @throws ItemNotFoundException if the item does not exist
65 * @throws ContentAccessException if the item cannot be accessed
66 * @throws IllegalArgumentException if the selector has no namespace specified
68 Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException;
71 * Returns the project for the given coordinates.
72 * The following coordinates must be set at the given selector:
77 * If not, a {@link IllegalArgumentException} will be thrown.
78 * Additional coordinates will be ignored.
80 * @param projectSelector
81 * @return the project instance
82 * @throws ItemNotFoundException if the project does not exist
83 * @throws ContentAccessException if the item cannot be accessed
84 * @throws IllegalArgumentException if the selector does not specify the required coordinates
86 Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException;
89 * Returns the version for the given coordinates.
90 * The following coordinates must be set at the given selector:
96 * If not, a {@link IllegalArgumentException} will be thrown.
98 * Additional coordinates will be ignored.
100 * @param versionCoordinates
101 * @return the version object
102 * @throws ItemNotFoundException
103 * @throws ContentAccessException
104 * @throws IllegalArgumentException
106 Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException;
110 * Returns the artifact object for the given coordinates.
112 * Normally the following coordinates should be set at the given selector:
115 * <li>artifactVersion and or version</li>
116 * <li>artifactId or projectId</li>
118 * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown
119 * It depends on the repository type, what exactly is returned for a given set of coordinates. Some repository type
120 * may have different required and optional coordinates. For further information please check the documentation for the
121 * type specific implementations.
123 * The following coordinates are optional and may further specify the artifact to return.
125 * <li>classifier</li>
130 * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact
131 * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code>
132 * method of the artifact.
133 * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact.
136 * @param selector the selector with the artifact coordinates
137 * @return a artifact object
138 * @throws IllegalArgumentException if the selector coordinates do not specify a artifact
139 * @throws ContentAccessException if the access to the underlying storage failed
141 Artifact getArtifact(ItemSelector selector) throws ContentAccessException;
145 * Returns the artifacts that match the given selector. It is up to the repository implementation
146 * what artifacts are returned for a given set of coordinates.
148 * @param selector the selector for the artifacts
149 * @return a list of artifacts.
150 * @throws IllegalArgumentException if the specified coordinates cannot be found in the repository
151 * @throws ContentAccessException if the access to the underlying storage failed
153 List<? extends Artifact> getArtifacts( ItemSelector selector) throws ContentAccessException;
156 * Returns the artifacts that match the given selector. It is up to the repository implementation
157 * what artifacts are returned for a given set of coordinates.
159 * The returned stream is autoclosable and should always closed after using it.
161 * There is no guarantee about the order of the returned artifacts
163 * @param selector the selector for the artifacts
164 * @return a stream with artifact elements.
165 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
166 * @throws ContentAccessException if the access to the underlying storage failed
168 Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException;
172 * Return the projects that are part of the given namespace.
174 * @param namespace the namespace
175 * @return the list of projects or a empty list, if there are no projects for the given namespace.
177 List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException;
180 * Returns the list of projects that match the given selector. The selector must at least specify a
183 * @param selector the selector
184 * @return the list of projects that match the selector. A empty list of not project matches.
185 * @throws ContentAccessException if the access to the storage backend failed
186 * @throws IllegalArgumentException if the selector does not contain sufficient data for selecting projects
188 List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
191 * Return the existing versions of the given project.
193 * @param project the project
194 * @return a list of versions or a empty list, if not versions are available for the specified project
195 * @throws ContentAccessException if the access to the underlying storage failed
197 List<? extends Version> getVersions( Project project) throws ContentAccessException;
201 * Return the versions that match the given selector. The selector must at least specify a namespace and a projectId.
203 * @param selector the item selector. At least namespace and projectId must be set.
204 * @return the list of version or a empty list, if no version matches the selector
205 * @throws ContentAccessException if the access to the backend failed
206 * @throws IllegalArgumentException if the selector does not contain enough information for selecting versions
208 List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
211 * Returns all found artifact versions that can be found for the given selector. The selector must specify at least
214 * @param selector the item selector that must specify at least a project
215 * @return the list of artifact versions
216 * @throws ContentAccessException if the access to the underlying storage failed
217 * @throws IllegalArgumentException if the selector does not have project information
219 List<String> getArtifactVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
222 * Return all the artifacts of a given content item (namespace, project, version)
224 * @param item the item
225 * @return a list of artifacts or a empty list, if no artifacts are available for the specified item
227 List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException;
230 * Return a stream of artifacts that are part of the given content item. The returned stream is
231 * auto closable. There is no guarantee about the order of returned artifacts.
233 * As the stream may access IO resources, you should always use call this method inside try-with-resources or
234 * make sure, that the stream is closed after using it.
236 * @param item the item from where the artifacts should be returned
237 * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
238 * is closed after use.
239 * @throws ContentAccessException if the access to the underlying storage failed
241 Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException;
245 * Copies the artifact to the given destination coordinates
247 * @param sourceFile the path to the source file
248 * @param destination the coordinates of the destination
249 * @throws IllegalArgumentException if the destination is not valid
251 void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException;
254 * Returns the metadata file for the given version.
256 * @param version the version
257 * @return the metadata file
259 DataItem getMetadataItem( Version version );
262 * Returns the metadata file for the given project
264 * @param project the project
265 * @return the metadata file
267 DataItem getMetadataItem( Project project );
270 /// ***************** End of new generation interface **********************
275 * Returns the version reference for the given coordinates.
276 * @param groupId the group id
277 * @param artifactId the artifact id
278 * @param version the version number
279 * @return a version reference
281 VersionedReference toVersion( String groupId, String artifactId, String version );
285 * Return the version reference that matches exactly the version string of the artifact
287 * @param artifactReference The artifact reference
288 * @return the version reference
290 VersionedReference toVersion( ArtifactReference artifactReference);
294 * Delete from the managed repository all files / directories associated with the
295 * provided version reference.
297 * @param reference the version reference to delete.
298 * @throws ContentNotFoundException
300 void deleteVersion( VersionedReference reference )
301 throws ContentNotFoundException, ContentAccessException;
306 * delete a specified artifact from the repository
308 * @param artifactReference
309 * @throws ContentNotFoundException
311 void deleteArtifact( ArtifactReference artifactReference )
312 throws ContentNotFoundException, ContentAccessException;
318 * @throws ContentNotFoundException
321 void deleteGroupId( String groupId )
322 throws ContentNotFoundException, ContentAccessException;
329 * @param namespace groupId for maven
330 * @param projectId artifactId for maven
331 * @throws ContentNotFoundException
333 void deleteProject( String namespace, String projectId )
334 throws ContentNotFoundException, ContentAccessException;
341 void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
350 * Gather up the list of related artifacts to the ArtifactReference provided.
351 * This typically includes the pom files, and those things with
352 * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
353 * is set in the artifact reference, it may return artifacts with different classifiers.
356 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
359 * @param reference the reference to work off of.
360 * @return the list of ArtifactReferences for related artifacts, if
361 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
363 List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
364 throws ContentNotFoundException, LayoutException, ContentAccessException;
368 * Returns all artifacts that belong to a given version
369 * @param reference the version reference
370 * @return the list of artifacts or a empty list
372 List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
379 * Convenience method to get the repository (on disk) root directory.
382 * Equivalent to calling <code>.getRepository().getLocation()</code>
385 * @return the repository (on disk) root directory.
387 String getRepoRoot();
391 * Given an {@link ArtifactReference}, return the file reference to the artifact.
393 * @param reference the artifact reference to use.
394 * @return the relative path to the artifact.
396 StorageAsset toFile( VersionedReference reference );
399 * Given an {@link ArtifactReference}, return the file reference to the artifact.
401 * @param reference the artifact reference to use.
402 * @return the relative path to the artifact.
404 StorageAsset toFile( ArtifactReference reference );