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.ItemNotFoundException;
29 import org.apache.archiva.repository.content.ItemSelector;
30 import org.apache.archiva.repository.content.Namespace;
31 import org.apache.archiva.repository.content.Project;
32 import org.apache.archiva.repository.content.Version;
33 import org.apache.archiva.repository.storage.StorageAsset;
35 import java.nio.file.Path;
36 import java.util.List;
38 import java.util.stream.Stream;
41 * ManagedRepositoryContent 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 ManagedRepositoryContent extends RepositoryContent
49 /// ***************** New generation interface **********************
52 * Removes the specified content item and if the item is a container or directory,
53 * all content stored under the given item.
55 * @param item the item.
56 * @throws ItemNotFoundException if the item cannot be found
57 * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
58 * to the artifacts failed
60 void deleteItem( ContentItem item) throws ItemNotFoundException, ContentAccessException;
64 * Returns a item for the given selector. The type of the returned item depends on the
67 * @param selector the item selector
68 * @return the content item that matches the given selector
69 * @throws ContentAccessException if an error occured while accessing the backend
70 * @throws IllegalArgumentException if the selector does not select a valid content item
72 ContentItem getItem(ItemSelector selector) throws ContentAccessException, IllegalArgumentException;
75 * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other
76 * coordinates are ignored.
77 * The following coordinates must be set at the given selector:
81 * If not, a {@link IllegalArgumentException} will be thrown.
83 * @param namespaceSelector the selectory with the namespace coordinates
84 * @return the namespace
85 * @throws ItemNotFoundException if the item does not exist
86 * @throws ContentAccessException if the item cannot be accessed
87 * @throws IllegalArgumentException if the selector has no namespace specified
89 Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException;
92 * Returns the project for the given coordinates.
93 * The following coordinates must be set at the given selector:
98 * If not, a {@link IllegalArgumentException} will be thrown.
99 * Additional coordinates will be ignored.
101 * @param projectSelector
102 * @return the project instance
103 * @throws ItemNotFoundException if the project does not exist
104 * @throws ContentAccessException if the item cannot be accessed
105 * @throws IllegalArgumentException if the selector does not specify the required coordinates
107 Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException;
110 * Returns the version for the given coordinates.
111 * The following coordinates must be set at the given selector:
117 * If not, a {@link IllegalArgumentException} will be thrown.
119 * Additional coordinates will be ignored.
121 * @param versionCoordinates
122 * @return the version object
123 * @throws ItemNotFoundException
124 * @throws ContentAccessException
125 * @throws IllegalArgumentException
127 Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException;
131 * Returns the artifact object for the given coordinates.
133 * Normally the following coordinates should be set at the given selector:
136 * <li>artifactVersion and or version</li>
137 * <li>artifactId or projectId</li>
139 * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown
140 * It depends on the repository type, what exactly is deleted for a given set of coordinates. Some repository type
141 * may have different required and optional coordinates. For further information please check the documentation for the
142 * type specific implementations.
144 * The following coordinates are optional and may further specify the artifact to delete.
146 * <li>classifier</li>
151 * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact
152 * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code>
153 * method of the artifact.
154 * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact.
157 * @param selector the selector with the artifact coordinates
158 * @return a artifact object
159 * @throws ItemNotFoundException if the selector coordinates do not specify a artifact
160 * @throws ContentAccessException if the access to the underlying storage failed
162 Artifact getArtifact(ItemSelector selector) throws ContentAccessException;
166 * Returns the artifacts that match the given selector. It is up to the repository implementation
167 * what artifacts are returned for a given set of coordinates.
169 * @param selector the selector for the artifacts
170 * @return a list of artifacts.
171 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
172 * @throws ContentAccessException if the access to the underlying storage failed
174 List<? extends Artifact> getArtifacts( ItemSelector selector) throws ContentAccessException;
177 * Returns the artifacts that match the given selector. It is up to the repository implementation
178 * what artifacts are returned for a given set of coordinates.
180 * The returned stream is autoclosable and should always closed after using it.
182 * There is no guarantee about the order of the returned artifacts
184 * @param selector the selector for the artifacts
185 * @return a stream with artifact elements.
186 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
187 * @throws ContentAccessException if the access to the underlying storage failed
189 Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException;
193 * Return the projects that are part of the given namespace.
195 * @param namespace the namespace
196 * @return the list of projects or a empty list, if there are no projects for the given namespace.
198 List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException;
201 * Returns the list of projects that match the given selector. The selector must at least specify a
204 * @param selector the selector
205 * @return the list of projects that match the selector. A empty list of not project matches.
206 * @throws ContentAccessException if the access to the storage backend failed
207 * @throws IllegalArgumentException if the selector does not contain sufficient data for selecting projects
209 List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
212 * Return the existing versions of the given project.
214 * @param project the project
215 * @return a list of versions or a empty list, if not versions are available for the specified project
216 * @throws ContentAccessException if the access to the underlying storage failed
218 List<? extends Version> getVersions( Project project) throws ContentAccessException;
222 * Return the versions that match the given selector. The selector must at least specify a namespace and a projectId.
224 * @param selector the item selector. At least namespace and projectId must be set.
225 * @return the list of version or a empty list, if no version matches the selector
226 * @throws ContentAccessException if the access to the backend failed
227 * @throws IllegalArgumentException if the selector does not contain enough information for selecting versions
229 List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException;
233 * Return all the artifacts of a given content item (namespace, project, version)
235 * @param item the item
236 * @return a list of artifacts or a empty list, if no artifacts are available for the specified item
238 List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException;
241 * Return a stream of artifacts that are part of the given content item. The returned stream is
242 * auto closable. There is no guarantee about the order of returned artifacts.
244 * As the stream may access IO resources, you should always use call this method inside try-with-resources or
245 * make sure, that the stream is closed after using it.
247 * @param item the item from where the artifacts should be returned
248 * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
249 * is closed after use.
250 * @throws ContentAccessException if the access to the underlying storage failed
252 Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException;
256 * Returns true, if the selector coordinates point to a existing item in the repository.
258 * @param selector the item selector
259 * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
261 boolean hasContent( ItemSelector selector );
264 * Copies the artifact to the given destination coordinates
266 * @param sourceFile the path to the source file
267 * @param destination the coordinates of the destination
268 * @throws IllegalArgumentException if the destination is not valid
270 void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException;
274 * Returns the item that matches the given path. The item at the path must not exist.
276 * @param path the path string that points to the item
277 * @return the content item if the path is a valid item path
278 * @throws LayoutException if the path is not valid for the repository layout
280 ContentItem toItem(String path) throws LayoutException;
284 * Returns the item that matches the given asset path. The asset must not exist.
286 * @param assetPath the path to the artifact or directory
287 * @return the item, if it is a valid path for the repository layout
288 * @throws LayoutException if the path is not valid for the repository
290 ContentItem toItem(StorageAsset assetPath) throws LayoutException;
293 /// ***************** End of new generation interface **********************
298 * Returns the version reference for the given coordinates.
299 * @param groupId the group id
300 * @param artifactId the artifact id
301 * @param version the version number
302 * @return a version reference
304 VersionedReference toVersion( String groupId, String artifactId, String version );
308 * Returns the version reference that represents the generic version, which means that
309 * snapshot versions are converted to <VERSION>-SNAPSHOT
310 * @param artifactReference the artifact reference
311 * @return the generic version
313 VersionedReference toGenericVersion( ArtifactReference artifactReference );
316 * Return the version reference that matches exactly the version string of the artifact
318 * @param artifactReference The artifact reference
319 * @return the version reference
321 VersionedReference toVersion( ArtifactReference artifactReference);
324 * Returns a artifact reference for the given coordinates.
325 * @param groupId the group id
326 * @param artifactId the artifact id
327 * @param version the version
328 * @param type the type
329 * @param classifier the classifier
330 * @return a artifact reference object
332 ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
338 * Delete from the managed repository all files / directories associated with the
339 * provided version reference.
341 * @param reference the version reference to delete.
342 * @throws ContentNotFoundException
344 void deleteVersion( VersionedReference reference )
345 throws ContentNotFoundException, ContentAccessException;
350 * delete a specified artifact from the repository
352 * @param artifactReference
353 * @throws ContentNotFoundException
355 void deleteArtifact( ArtifactReference artifactReference )
356 throws ContentNotFoundException, ContentAccessException;
362 * @throws ContentNotFoundException
365 void deleteGroupId( String groupId )
366 throws ContentNotFoundException, ContentAccessException;
373 * @param namespace groupId for maven
374 * @param projectId artifactId for maven
375 * @throws ContentNotFoundException
377 void deleteProject( String namespace, String projectId )
378 throws ContentNotFoundException, ContentAccessException;
385 void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
392 * Convenience method to get the repository id.
395 * Equivalent to calling <code>.getRepository().getId()</code>
398 * @return the repository id.
404 * Gather up the list of related artifacts to the ArtifactReference provided.
405 * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
406 * related to the given artifact, like checksums.
407 * If type and classifier is <code>null</code> it will return the same artifacts as
408 * {@link #getRelatedArtifacts(VersionedReference)}
411 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
414 * @param reference the reference to work off of.
415 * @return the list of ArtifactReferences for related artifacts, if
416 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
417 * @see #getRelatedArtifacts(VersionedReference)
419 List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
420 throws ContentNotFoundException, LayoutException, ContentAccessException;
424 * Gather up the list of related artifacts to the ArtifactReference provided.
425 * This typically includes the pom files, and those things with
426 * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
427 * is set in the artifact reference, it may return artifacts with different classifiers.
430 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
433 * @param reference the reference to work off of.
434 * @return the list of ArtifactReferences for related artifacts, if
435 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
437 List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
438 throws ContentNotFoundException, LayoutException, ContentAccessException;
447 * Returns all the assets that belong to a given artifact type. The list returned contain
448 * all the files that correspond to the given artifact reference.
449 * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
455 List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
458 * Returns all artifacts that belong to a given version
459 * @param reference the version reference
460 * @return the list of artifacts or a empty list
462 List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
469 * Convenience method to get the repository (on disk) root directory.
472 * Equivalent to calling <code>.getRepository().getLocation()</code>
475 * @return the repository (on disk) root directory.
477 String getRepoRoot();
480 * Get the repository configuration associated with this
481 * repository content.
483 * @return the repository that is associated with this repository content.
485 ManagedRepository getRepository();
490 * Given a specific {@link VersionedReference}, return the list of available versions for that
491 * versioned reference.
494 * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
497 * @param reference the versioned reference to work off of.
498 * @return the set of versions found.
499 * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
501 Set<String> getVersions( VersionedReference reference )
502 throws ContentNotFoundException, ContentAccessException, LayoutException;
505 * Determines if the artifact referenced exists in the repository.
507 * @param reference the artifact reference to check for.
508 * @return true if the artifact referenced exists.
510 boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
513 * Determines if the version reference exists in the repository.
515 * @param reference the version reference to check for.
516 * @return true if the version referenced exists.
518 boolean hasContent( VersionedReference reference ) throws ContentAccessException;
521 * Set the repository configuration to associate with this
522 * repository content.
524 * @param repo the repository to associate with this repository content.
526 void setRepository( ManagedRepository repo );
529 * Given an {@link ArtifactReference}, return the file reference to the artifact.
531 * @param reference the artifact reference to use.
532 * @return the relative path to the artifact.
534 StorageAsset toFile( VersionedReference reference );
537 * Given an {@link ArtifactReference}, return the file reference to the artifact.
539 * @param reference the artifact reference to use.
540 * @return the relative path to the artifact.
542 StorageAsset toFile( ArtifactReference reference );
545 * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
547 * @param reference the archiva artifact to use.
548 * @return the relative path to the artifact.
550 StorageAsset toFile( ArchivaArtifact reference );
553 * Given a {@link ProjectReference}, return the path to the metadata for
556 * @param reference the reference to use.
557 * @return the path to the metadata file, or null if no metadata is appropriate.
559 String toMetadataPath( ProjectReference reference );
562 * Given a {@link VersionedReference}, return the path to the metadata for
563 * the specific version of the project.
565 * @param reference the reference to use.
566 * @return the path to the metadata file, or null if no metadata is appropriate.
568 String toMetadataPath( VersionedReference reference );
571 * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
573 * @param reference the archiva artifact to use.
574 * @return the relative path to the artifact.
576 String toPath( ArchivaArtifact reference );