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> getArtifactStream( 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.
251 Stream<? extends Artifact> getArtifactStream( ContentItem item ) throws ContentAccessException;
255 * Returns true, if the selector coordinates point to a existing item in the repository.
257 * @param selector the item selector
258 * @return <code>true</code>, if there exists such a item, otherwise <code>false</code>
260 boolean hasContent( ItemSelector selector );
263 * Copies the artifact to the given destination coordinates
265 * @param sourceFile the path to the source file
266 * @param destination the coordinates of the destination
267 * @throws IllegalArgumentException if the destination is not valid
269 void copyArtifact( Path sourceFile, ContentItem destination ) throws IllegalArgumentException;
273 * Returns the item that matches the given path. The item at the path must not exist.
275 * @param path the path string that points to the item
276 * @return the content item if the path is a valid item path
277 * @throws LayoutException if the path is not valid for the repository layout
279 ContentItem toItem(String path) throws LayoutException;
283 * Returns the item that matches the given asset path. The asset must not exist.
285 * @param assetPath the path to the artifact or directory
286 * @return the item, if it is a valid path for the repository layout
287 * @throws LayoutException if the path is not valid for the repository
289 ContentItem toItem(StorageAsset assetPath) throws LayoutException;
292 /// ***************** End of new generation interface **********************
297 * Returns the version reference for the given coordinates.
298 * @param groupId the group id
299 * @param artifactId the artifact id
300 * @param version the version number
301 * @return a version reference
303 VersionedReference toVersion( String groupId, String artifactId, String version );
307 * Returns the version reference that represents the generic version, which means that
308 * snapshot versions are converted to <VERSION>-SNAPSHOT
309 * @param artifactReference the artifact reference
310 * @return the generic version
312 VersionedReference toGenericVersion( ArtifactReference artifactReference );
315 * Return the version reference that matches exactly the version string of the artifact
317 * @param artifactReference The artifact reference
318 * @return the version reference
320 VersionedReference toVersion( ArtifactReference artifactReference);
323 * Returns a artifact reference for the given coordinates.
324 * @param groupId the group id
325 * @param artifactId the artifact id
326 * @param version the version
327 * @param type the type
328 * @param classifier the classifier
329 * @return a artifact reference object
331 ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
337 * Delete from the managed repository all files / directories associated with the
338 * provided version reference.
340 * @param reference the version reference to delete.
341 * @throws ContentNotFoundException
343 void deleteVersion( VersionedReference reference )
344 throws ContentNotFoundException, ContentAccessException;
349 * delete a specified artifact from the repository
351 * @param artifactReference
352 * @throws ContentNotFoundException
354 void deleteArtifact( ArtifactReference artifactReference )
355 throws ContentNotFoundException, ContentAccessException;
361 * @throws ContentNotFoundException
364 void deleteGroupId( String groupId )
365 throws ContentNotFoundException, ContentAccessException;
372 * @param namespace groupId for maven
373 * @param projectId artifactId for maven
374 * @throws ContentNotFoundException
376 void deleteProject( String namespace, String projectId )
377 throws ContentNotFoundException, ContentAccessException;
384 void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
391 * Convenience method to get the repository id.
394 * Equivalent to calling <code>.getRepository().getId()</code>
397 * @return the repository id.
403 * Gather up the list of related artifacts to the ArtifactReference provided.
404 * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
405 * related to the given artifact, like checksums.
406 * If type and classifier is <code>null</code> it will return the same artifacts as
407 * {@link #getRelatedArtifacts(VersionedReference)}
410 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
413 * @param reference the reference to work off of.
414 * @return the list of ArtifactReferences for related artifacts, if
415 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
416 * @see #getRelatedArtifacts(VersionedReference)
418 List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
419 throws ContentNotFoundException, LayoutException, ContentAccessException;
423 * Gather up the list of related artifacts to the ArtifactReference provided.
424 * This typically includes the pom files, and those things with
425 * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
426 * is set in the artifact reference, it may return artifacts with different classifiers.
429 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
432 * @param reference the reference to work off of.
433 * @return the list of ArtifactReferences for related artifacts, if
434 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
436 List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
437 throws ContentNotFoundException, LayoutException, ContentAccessException;
446 * Returns all the assets that belong to a given artifact type. The list returned contain
447 * all the files that correspond to the given artifact reference.
448 * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
454 List<StorageAsset> getRelatedAssets(ArtifactReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
457 * Returns all artifacts that belong to a given version
458 * @param reference the version reference
459 * @return the list of artifacts or a empty list
461 List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
468 * Convenience method to get the repository (on disk) root directory.
471 * Equivalent to calling <code>.getRepository().getLocation()</code>
474 * @return the repository (on disk) root directory.
476 String getRepoRoot();
479 * Get the repository configuration associated with this
480 * repository content.
482 * @return the repository that is associated with this repository content.
484 ManagedRepository getRepository();
487 * Given a specific {@link ProjectReference}, return the list of available versions for
488 * that project reference.
490 * @param reference the project reference to work off of.
491 * @return the list of versions found for that project reference.
492 * @throws ContentNotFoundException if the project reference does nto exist within the repository.
493 * @throws LayoutException
495 Set<String> getVersions( ProjectReference reference )
496 throws ContentNotFoundException, LayoutException, ContentAccessException;
502 * Given a specific {@link VersionedReference}, return the list of available versions for that
503 * versioned reference.
506 * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
509 * @param reference the versioned reference to work off of.
510 * @return the set of versions found.
511 * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
513 Set<String> getVersions( VersionedReference reference )
514 throws ContentNotFoundException, ContentAccessException, LayoutException;
517 * Determines if the artifact referenced exists in the repository.
519 * @param reference the artifact reference to check for.
520 * @return true if the artifact referenced exists.
522 boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
525 * Determines if the project referenced exists in the repository.
527 * @param reference the project reference to check for.
528 * @return true it the project referenced exists.
530 boolean hasContent( ProjectReference reference ) throws ContentAccessException;
533 * Determines if the version reference exists in the repository.
535 * @param reference the version reference to check for.
536 * @return true if the version referenced exists.
538 boolean hasContent( VersionedReference reference ) throws ContentAccessException;
541 * Set the repository configuration to associate with this
542 * repository content.
544 * @param repo the repository to associate with this repository content.
546 void setRepository( ManagedRepository repo );
549 * Given an {@link ArtifactReference}, return the file reference to the artifact.
551 * @param reference the artifact reference to use.
552 * @return the relative path to the artifact.
554 StorageAsset toFile( VersionedReference reference );
557 * Given an {@link ArtifactReference}, return the file reference to the artifact.
559 * @param reference the artifact reference to use.
560 * @return the relative path to the artifact.
562 StorageAsset toFile( ArtifactReference reference );
565 * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
567 * @param reference the archiva artifact to use.
568 * @return the relative path to the artifact.
570 StorageAsset toFile( ArchivaArtifact reference );
573 * Given a {@link ProjectReference}, return the path to the metadata for
576 * @param reference the reference to use.
577 * @return the path to the metadata file, or null if no metadata is appropriate.
579 String toMetadataPath( ProjectReference reference );
582 * Given a {@link VersionedReference}, return the path to the metadata for
583 * the specific version of the project.
585 * @param reference the reference to use.
586 * @return the path to the metadata file, or null if no metadata is appropriate.
588 String toMetadataPath( VersionedReference reference );
591 * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
593 * @param reference the archiva artifact to use.
594 * @return the relative path to the artifact.
596 String toPath( ArchivaArtifact reference );