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
51 * Returns the version reference for the given coordinates.
52 * @param groupId the group id
53 * @param artifactId the artifact id
54 * @param version the version number
55 * @return a version reference
57 VersionedReference toVersion( String groupId, String artifactId, String version );
61 * Returns the version reference that represents the generic version, which means that
62 * snapshot versions are converted to <VERSION>-SNAPSHOT
63 * @param artifactReference the artifact reference
64 * @return the generic version
66 VersionedReference toGenericVersion( ArtifactReference artifactReference );
69 * Return the version reference that matches exactly the version string of the artifact
71 * @param artifactReference The artifact reference
72 * @return the version reference
74 VersionedReference toVersion( ArtifactReference artifactReference);
77 * Returns a artifact reference for the given coordinates.
78 * @param groupId the group id
79 * @param artifactId the artifact id
80 * @param version the version
81 * @param type the type
82 * @param classifier the classifier
83 * @return a artifact reference object
85 ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
88 * Removes the specified content item and all content stored under the given item.
90 * @param item the item.
91 * @throws ItemNotFoundException if the item cannot be found
92 * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
93 * to the artifacts failed
95 void deleteItem( ContentItem item) throws ItemNotFoundException, ContentAccessException;
98 * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other
99 * coordinates are ignored.
100 * The following coordinates must be set at the given selector:
104 * If not, a {@link IllegalArgumentException} will be thrown.
106 * @param namespaceSelector the selectory with the namespace coordinates
107 * @return the namespace
108 * @throws ItemNotFoundException if the item does not exist
109 * @throws ContentAccessException if the item cannot be accessed
110 * @throws IllegalArgumentException if the selector has no namespace specified
112 Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException;
115 * Returns the project for the given coordinates.
116 * The following coordinates must be set at the given selector:
121 * If not, a {@link IllegalArgumentException} will be thrown.
122 * Additional coordinates will be ignored.
124 * @param projectSelector
125 * @return the project instance
126 * @throws ItemNotFoundException if the project does not exist
127 * @throws ContentAccessException if the item cannot be accessed
128 * @throws IllegalArgumentException if the selector does not specify the required coordinates
130 Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException;
133 * Returns the version for the given coordinates.
134 * The following coordinates must be set at the given selector:
140 * If not, a {@link IllegalArgumentException} will be thrown.
142 * Additional coordinates will be ignored.
144 * @param versionCoordinates
145 * @return the version object
146 * @throws ItemNotFoundException
147 * @throws ContentAccessException
148 * @throws IllegalArgumentException
150 Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException;
153 * Returns the artifact object for the given coordinates.
155 * Normally the following coordinates should be set at the given selector:
158 * <li>artifactVersion and or version</li>
159 * <li>artifactId or projectId</li>
161 * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown
162 * It depends on the repository type, what exactly is deleted for a given set of coordinates. Some repository type
163 * may have different required and optional coordinates. For further information please check the documentation for the
164 * type specific implementations.
166 * The following coordinates are optional and may further specify the artifact to delete.
168 * <li>classifier</li>
173 * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact
174 * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code>
175 * method of the artifact.
176 * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact.
179 * @param selector the selector with the artifact coordinates
180 * @return a artifact object
181 * @throws ItemNotFoundException if the selector coordinates do not specify a artifact
182 * @throws ContentAccessException if the access to the underlying storage failed
184 Artifact getArtifact(ItemSelector selector) throws ContentAccessException;
188 * Returns the artifacts that match the given selector. It is up to the repository implementation
189 * what artifacts are returned for a given set of coordinates.
191 * @param selector the selector for the artifacts
192 * @return a list of artifacts.
193 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
194 * @throws ContentAccessException if the access to the underlying storage failed
196 List<? extends Artifact> getAllArtifacts( ItemSelector selector) throws ContentAccessException;
199 * Returns the artifacts that match the given selector. It is up to the repository implementation
200 * what artifacts are returned for a given set of coordinates.
202 * The returned stream is autoclosable and should always closed after using it.
204 * There is no guarantee about the order of the returned artifacts
206 * @param selector the selector for the artifacts
207 * @return a stream with artifact elements.
208 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
209 * @throws ContentAccessException if the access to the underlying storage failed
211 Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector) throws ContentAccessException;
215 * Return the projects that are part of the given namespace.
217 * @param namespace the namespace
218 * @return the list of projects or a empty list, if there are no projects for the given namespace.
220 List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException;
223 * Return the existing versions of the given project.
225 * @param project the project
226 * @return a list of versions or a empty list, if not versions are available for the specified project
228 List<? extends Version> getVersions( Project project) throws ContentAccessException;
231 * Return all the artifacts of a given content item (namespace, project, version)
233 * @param item the item
234 * @return a list of artifacts or a empty list, if no artifacts are available for the specified item
236 List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException;
239 * Return all the artifacts of a given namespace and all sub namespaces that are defined under the
242 * @param namespace the namespace, which is the parent namespace
243 * @return a list of artifacts or a empty list, if no artifacts are available for the specified namespace
245 List<? extends Artifact> getArtifactsStartingWith( Namespace namespace ) throws ContentAccessException;
249 * Return a stream of artifacts that are part of the given content item. The returned stream is
250 * auto closable. There is no guarantee about the order of returned artifacts.
252 * As the stream may access IO resources, you should always use call this method inside try-with-resources or
253 * make sure, that the stream is closed after using it.
255 * @param item the item from where the artifacts should be returned
256 * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
257 * is closed after use.
259 Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException;
263 * Return a stream of all artifacts that are available for the given namespace and its sub namespaces. The artifacts
264 * are retrieved recursively. There is no guarantee about the order of returned artifacts.
266 * As the stream may access IO resources, you should always use call this method inside try-with-resources or
267 * make sure, that the stream is closed after using it.
269 * @param namespace the namespace from where the artifacts should be returned
270 * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
271 * is closed after use.
273 Stream<? extends Artifact> getArtifactStreamStartingWith( Namespace namespace ) throws ContentAccessException;
277 * Returns true, if the selector coordinates point to a existing item in the repository.
279 * @param selector the item selector
280 * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
282 boolean hasContent( ItemSelector selector );
285 * Copies the artifact to the given destination coordinates
287 * @param sourceFile the path to the source file
288 * @param destination the coordinates of the destination
289 * @throws IllegalArgumentException if the destination is not valid
291 void copyArtifact( Path sourceFile, ItemSelector destination ) throws IllegalArgumentException;
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;
348 * Convenience method to get the repository id.
351 * Equivalent to calling <code>.getRepository().getId()</code>
354 * @return the repository id.
360 * Gather up the list of related artifacts to the ArtifactReference provided.
361 * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
362 * related to the given artifact, like checksums.
363 * If type and classifier is <code>null</code> it will return the same artifacts as
364 * {@link #getRelatedArtifacts(VersionedReference)}
367 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
370 * @param reference the reference to work off of.
371 * @return the list of ArtifactReferences for related artifacts, if
372 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
373 * @see #getRelatedArtifacts(VersionedReference)
375 List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
376 throws ContentNotFoundException, LayoutException, ContentAccessException;
380 * Gather up the list of related artifacts to the ArtifactReference provided.
381 * This typically includes the pom files, and those things with
382 * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
383 * is set in the artifact reference, it may return artifacts with different classifiers.
386 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
389 * @param reference the reference to work off of.
390 * @return the list of ArtifactReferences for related artifacts, if
391 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
393 List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
394 throws ContentNotFoundException, LayoutException, ContentAccessException;
403 * Returns all the assets that belong to a given artifact type. The list returned contain
404 * all the files that correspond to the given artifact reference.
405 * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
411 List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
414 * Returns all artifacts that belong to a given version
415 * @param reference the version reference
416 * @return the list of artifacts or a empty list
418 List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
425 * Convenience method to get the repository (on disk) root directory.
428 * Equivalent to calling <code>.getRepository().getLocation()</code>
431 * @return the repository (on disk) root directory.
433 String getRepoRoot();
436 * Get the repository configuration associated with this
437 * repository content.
439 * @return the repository that is associated with this repository content.
441 ManagedRepository getRepository();
444 * Given a specific {@link ProjectReference}, return the list of available versions for
445 * that project reference.
447 * @param reference the project reference to work off of.
448 * @return the list of versions found for that project reference.
449 * @throws ContentNotFoundException if the project reference does nto exist within the repository.
450 * @throws LayoutException
452 Set<String> getVersions( ProjectReference reference )
453 throws ContentNotFoundException, LayoutException, ContentAccessException;
459 * Given a specific {@link VersionedReference}, return the list of available versions for that
460 * versioned reference.
463 * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
466 * @param reference the versioned reference to work off of.
467 * @return the set of versions found.
468 * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
470 Set<String> getVersions( VersionedReference reference )
471 throws ContentNotFoundException, ContentAccessException, LayoutException;
474 * Determines if the artifact referenced exists in the repository.
476 * @param reference the artifact reference to check for.
477 * @return true if the artifact referenced exists.
479 boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
482 * Determines if the project referenced exists in the repository.
484 * @param reference the project reference to check for.
485 * @return true it the project referenced exists.
487 boolean hasContent( ProjectReference reference ) throws ContentAccessException;
490 * Determines if the version reference exists in the repository.
492 * @param reference the version reference to check for.
493 * @return true if the version referenced exists.
495 boolean hasContent( VersionedReference reference ) throws ContentAccessException;
498 * Set the repository configuration to associate with this
499 * repository content.
501 * @param repo the repository to associate with this repository content.
503 void setRepository( ManagedRepository repo );
506 * Given an {@link ArtifactReference}, return the file reference to the artifact.
508 * @param reference the artifact reference to use.
509 * @return the relative path to the artifact.
511 StorageAsset toFile( VersionedReference reference );
514 * Given an {@link ArtifactReference}, return the file reference to the artifact.
516 * @param reference the artifact reference to use.
517 * @return the relative path to the artifact.
519 StorageAsset toFile( ArtifactReference reference );
522 * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
524 * @param reference the archiva artifact to use.
525 * @return the relative path to the artifact.
527 StorageAsset toFile( ArchivaArtifact reference );
530 * Given a {@link ProjectReference}, return the path to the metadata for
533 * @param reference the reference to use.
534 * @return the path to the metadata file, or null if no metadata is appropriate.
536 String toMetadataPath( ProjectReference reference );
539 * Given a {@link VersionedReference}, return the path to the metadata for
540 * the specific version of the project.
542 * @param reference the reference to use.
543 * @return the path to the metadata file, or null if no metadata is appropriate.
545 String toMetadataPath( VersionedReference reference );
548 * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
550 * @param reference the archiva artifact to use.
551 * @return the relative path to the artifact.
553 String toPath( ArchivaArtifact reference );