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 all content stored under the given item.
54 * @param item the item.
55 * @throws ItemNotFoundException if the item cannot be found
56 * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access
57 * to the artifacts failed
59 void deleteItem( ContentItem item) throws ItemNotFoundException, ContentAccessException;
62 * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other
63 * coordinates are ignored.
64 * The following coordinates must be set at the given selector:
68 * If not, a {@link IllegalArgumentException} will be thrown.
70 * @param namespaceSelector the selectory with the namespace coordinates
71 * @return the namespace
72 * @throws ItemNotFoundException if the item does not exist
73 * @throws ContentAccessException if the item cannot be accessed
74 * @throws IllegalArgumentException if the selector has no namespace specified
76 Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException;
79 * Returns the project for the given coordinates.
80 * The following coordinates must be set at the given selector:
85 * If not, a {@link IllegalArgumentException} will be thrown.
86 * Additional coordinates will be ignored.
88 * @param projectSelector
89 * @return the project instance
90 * @throws ItemNotFoundException if the project does not exist
91 * @throws ContentAccessException if the item cannot be accessed
92 * @throws IllegalArgumentException if the selector does not specify the required coordinates
94 Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException;
97 * Returns the version for the given coordinates.
98 * The following coordinates must be set at the given selector:
104 * If not, a {@link IllegalArgumentException} will be thrown.
106 * Additional coordinates will be ignored.
108 * @param versionCoordinates
109 * @return the version object
110 * @throws ItemNotFoundException
111 * @throws ContentAccessException
112 * @throws IllegalArgumentException
114 Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException;
117 * Returns the artifact object for the given coordinates.
119 * Normally the following coordinates should be set at the given selector:
122 * <li>artifactVersion and or version</li>
123 * <li>artifactId or projectId</li>
125 * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown
126 * It depends on the repository type, what exactly is deleted for a given set of coordinates. Some repository type
127 * may have different required and optional coordinates. For further information please check the documentation for the
128 * type specific implementations.
130 * The following coordinates are optional and may further specify the artifact to delete.
132 * <li>classifier</li>
137 * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact
138 * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code>
139 * method of the artifact.
140 * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact.
143 * @param selector the selector with the artifact coordinates
144 * @return a artifact object
145 * @throws ItemNotFoundException if the selector coordinates do not specify a artifact
146 * @throws ContentAccessException if the access to the underlying storage failed
148 Artifact getArtifact(ItemSelector selector) throws ContentAccessException;
152 * Returns the artifacts that match the given selector. It is up to the repository implementation
153 * what artifacts are returned for a given set of coordinates.
155 * @param selector the selector for the artifacts
156 * @return a list of artifacts.
157 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
158 * @throws ContentAccessException if the access to the underlying storage failed
160 List<? extends Artifact> getAllArtifacts( ItemSelector selector) throws ContentAccessException;
163 * Returns the artifacts that match the given selector. It is up to the repository implementation
164 * what artifacts are returned for a given set of coordinates.
166 * The returned stream is autoclosable and should always closed after using it.
168 * There is no guarantee about the order of the returned artifacts
170 * @param selector the selector for the artifacts
171 * @return a stream with artifact elements.
172 * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository
173 * @throws ContentAccessException if the access to the underlying storage failed
175 Stream<? extends Artifact> getAllArtifactStream( ItemSelector selector) throws ContentAccessException;
179 * Return the projects that are part of the given namespace.
181 * @param namespace the namespace
182 * @return the list of projects or a empty list, if there are no projects for the given namespace.
184 List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException;
187 * Return the existing versions of the given project.
189 * @param project the project
190 * @return a list of versions or a empty list, if not versions are available for the specified project
192 List<? extends Version> getVersions( Project project) throws ContentAccessException;
195 * Return all the artifacts of a given content item (namespace, project, version)
197 * @param item the item
198 * @return a list of artifacts or a empty list, if no artifacts are available for the specified item
200 List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException;
203 * Return all the artifacts of a given namespace and all sub namespaces that are defined under the
206 * @param namespace the namespace, which is the parent namespace
207 * @return a list of artifacts or a empty list, if no artifacts are available for the specified namespace
209 List<? extends Artifact> getArtifactsStartingWith( Namespace namespace ) throws ContentAccessException;
213 * Return a stream of artifacts that are part of the given content item. The returned stream is
214 * auto closable. There is no guarantee about the order of returned artifacts.
216 * As the stream may access IO resources, you should always use call this method inside try-with-resources or
217 * make sure, that the stream is closed after using it.
219 * @param item the item from where the artifacts should be returned
220 * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
221 * is closed after use.
223 Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException;
227 * Return a stream of all artifacts that are available for the given namespace and its sub namespaces. The artifacts
228 * are retrieved recursively. There is no guarantee about the order of returned artifacts.
230 * As the stream may access IO resources, you should always use call this method inside try-with-resources or
231 * make sure, that the stream is closed after using it.
233 * @param namespace the namespace from where the artifacts should be returned
234 * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream
235 * is closed after use.
237 Stream<? extends Artifact> getArtifactStreamStartingWith( Namespace namespace ) throws ContentAccessException;
241 * Returns true, if the selector coordinates point to a existing item in the repository.
243 * @param selector the item selector
244 * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
246 boolean hasContent( ItemSelector selector );
249 * Copies the artifact to the given destination coordinates
251 * @param sourceFile the path to the source file
252 * @param destination the coordinates of the destination
253 * @throws IllegalArgumentException if the destination is not valid
255 void copyArtifact( Path sourceFile, ItemSelector destination ) throws IllegalArgumentException;
261 /// ***************** End of new generation interface **********************
266 * Returns the version reference for the given coordinates.
267 * @param groupId the group id
268 * @param artifactId the artifact id
269 * @param version the version number
270 * @return a version reference
272 VersionedReference toVersion( String groupId, String artifactId, String version );
276 * Returns the version reference that represents the generic version, which means that
277 * snapshot versions are converted to <VERSION>-SNAPSHOT
278 * @param artifactReference the artifact reference
279 * @return the generic version
281 VersionedReference toGenericVersion( ArtifactReference artifactReference );
284 * Return the version reference that matches exactly the version string of the artifact
286 * @param artifactReference The artifact reference
287 * @return the version reference
289 VersionedReference toVersion( ArtifactReference artifactReference);
292 * Returns a artifact reference for the given coordinates.
293 * @param groupId the group id
294 * @param artifactId the artifact id
295 * @param version the version
296 * @param type the type
297 * @param classifier the classifier
298 * @return a artifact reference object
300 ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
306 * Delete from the managed repository all files / directories associated with the
307 * provided version reference.
309 * @param reference the version reference to delete.
310 * @throws ContentNotFoundException
312 void deleteVersion( VersionedReference reference )
313 throws ContentNotFoundException, ContentAccessException;
318 * delete a specified artifact from the repository
320 * @param artifactReference
321 * @throws ContentNotFoundException
323 void deleteArtifact( ArtifactReference artifactReference )
324 throws ContentNotFoundException, ContentAccessException;
330 * @throws ContentNotFoundException
333 void deleteGroupId( String groupId )
334 throws ContentNotFoundException, ContentAccessException;
341 * @param namespace groupId for maven
342 * @param projectId artifactId for maven
343 * @throws ContentNotFoundException
345 void deleteProject( String namespace, String projectId )
346 throws ContentNotFoundException, ContentAccessException;
353 void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
360 * Convenience method to get the repository id.
363 * Equivalent to calling <code>.getRepository().getId()</code>
366 * @return the repository id.
372 * Gather up the list of related artifacts to the ArtifactReference provided.
373 * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
374 * related to the given artifact, like checksums.
375 * If type and classifier is <code>null</code> it will return the same artifacts as
376 * {@link #getRelatedArtifacts(VersionedReference)}
379 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
382 * @param reference the reference to work off of.
383 * @return the list of ArtifactReferences for related artifacts, if
384 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
385 * @see #getRelatedArtifacts(VersionedReference)
387 List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
388 throws ContentNotFoundException, LayoutException, ContentAccessException;
392 * Gather up the list of related artifacts to the ArtifactReference provided.
393 * This typically includes the pom files, and those things with
394 * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
395 * is set in the artifact reference, it may return artifacts with different classifiers.
398 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
401 * @param reference the reference to work off of.
402 * @return the list of ArtifactReferences for related artifacts, if
403 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
405 List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
406 throws ContentNotFoundException, LayoutException, ContentAccessException;
415 * Returns all the assets that belong to a given artifact type. The list returned contain
416 * all the files that correspond to the given artifact reference.
417 * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
423 List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
426 * Returns all artifacts that belong to a given version
427 * @param reference the version reference
428 * @return the list of artifacts or a empty list
430 List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
437 * Convenience method to get the repository (on disk) root directory.
440 * Equivalent to calling <code>.getRepository().getLocation()</code>
443 * @return the repository (on disk) root directory.
445 String getRepoRoot();
448 * Get the repository configuration associated with this
449 * repository content.
451 * @return the repository that is associated with this repository content.
453 ManagedRepository getRepository();
456 * Given a specific {@link ProjectReference}, return the list of available versions for
457 * that project reference.
459 * @param reference the project reference to work off of.
460 * @return the list of versions found for that project reference.
461 * @throws ContentNotFoundException if the project reference does nto exist within the repository.
462 * @throws LayoutException
464 Set<String> getVersions( ProjectReference reference )
465 throws ContentNotFoundException, LayoutException, ContentAccessException;
471 * Given a specific {@link VersionedReference}, return the list of available versions for that
472 * versioned reference.
475 * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
478 * @param reference the versioned reference to work off of.
479 * @return the set of versions found.
480 * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
482 Set<String> getVersions( VersionedReference reference )
483 throws ContentNotFoundException, ContentAccessException, LayoutException;
486 * Determines if the artifact referenced exists in the repository.
488 * @param reference the artifact reference to check for.
489 * @return true if the artifact referenced exists.
491 boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
494 * Determines if the project referenced exists in the repository.
496 * @param reference the project reference to check for.
497 * @return true it the project referenced exists.
499 boolean hasContent( ProjectReference reference ) throws ContentAccessException;
502 * Determines if the version reference exists in the repository.
504 * @param reference the version reference to check for.
505 * @return true if the version referenced exists.
507 boolean hasContent( VersionedReference reference ) throws ContentAccessException;
510 * Set the repository configuration to associate with this
511 * repository content.
513 * @param repo the repository to associate with this repository content.
515 void setRepository( ManagedRepository repo );
518 * Given an {@link ArtifactReference}, return the file reference to the artifact.
520 * @param reference the artifact reference to use.
521 * @return the relative path to the artifact.
523 StorageAsset toFile( VersionedReference reference );
526 * Given an {@link ArtifactReference}, return the file reference to the artifact.
528 * @param reference the artifact reference to use.
529 * @return the relative path to the artifact.
531 StorageAsset toFile( ArtifactReference reference );
534 * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
536 * @param reference the archiva artifact to use.
537 * @return the relative path to the artifact.
539 StorageAsset toFile( ArchivaArtifact reference );
542 * Given a {@link ProjectReference}, return the path to the metadata for
545 * @param reference the reference to use.
546 * @return the path to the metadata file, or null if no metadata is appropriate.
548 String toMetadataPath( ProjectReference reference );
551 * Given a {@link VersionedReference}, return the path to the metadata for
552 * the specific version of the project.
554 * @param reference the reference to use.
555 * @return the path to the metadata file, or null if no metadata is appropriate.
557 String toMetadataPath( VersionedReference reference );
560 * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
562 * @param reference the archiva artifact to use.
563 * @return the relative path to the artifact.
565 String toPath( ArchivaArtifact reference );