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 IllegalArgumentException 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 IllegalArgumentException 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 * Return the version reference that matches exactly the version string of the artifact
310 * @param artifactReference The artifact reference
311 * @return the version reference
313 VersionedReference toVersion( ArtifactReference artifactReference);
317 * Delete from the managed repository all files / directories associated with the
318 * provided version reference.
320 * @param reference the version reference to delete.
321 * @throws ContentNotFoundException
323 void deleteVersion( VersionedReference reference )
324 throws ContentNotFoundException, ContentAccessException;
329 * delete a specified artifact from the repository
331 * @param artifactReference
332 * @throws ContentNotFoundException
334 void deleteArtifact( ArtifactReference artifactReference )
335 throws ContentNotFoundException, ContentAccessException;
341 * @throws ContentNotFoundException
344 void deleteGroupId( String groupId )
345 throws ContentNotFoundException, ContentAccessException;
352 * @param namespace groupId for maven
353 * @param projectId artifactId for maven
354 * @throws ContentNotFoundException
356 void deleteProject( String namespace, String projectId )
357 throws ContentNotFoundException, ContentAccessException;
364 void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException;
371 * Convenience method to get the repository id.
374 * Equivalent to calling <code>.getRepository().getId()</code>
377 * @return the repository id.
383 * Gather up the list of related artifacts to the ArtifactReference provided.
384 * This typically includes the pom files, and those things with
385 * classifiers (such as doc, source code, test libs, etc...). Even if the classifier
386 * is set in the artifact reference, it may return artifacts with different classifiers.
389 * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
392 * @param reference the reference to work off of.
393 * @return the list of ArtifactReferences for related artifacts, if
394 * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
396 List<ArtifactReference> getRelatedArtifacts( VersionedReference reference )
397 throws ContentNotFoundException, LayoutException, ContentAccessException;
401 * Returns all artifacts that belong to a given version
402 * @param reference the version reference
403 * @return the list of artifacts or a empty list
405 List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException;
412 * Convenience method to get the repository (on disk) root directory.
415 * Equivalent to calling <code>.getRepository().getLocation()</code>
418 * @return the repository (on disk) root directory.
420 String getRepoRoot();
423 * Get the repository configuration associated with this
424 * repository content.
426 * @return the repository that is associated with this repository content.
428 ManagedRepository getRepository();
432 * Determines if the artifact referenced exists in the repository.
434 * @param reference the artifact reference to check for.
435 * @return true if the artifact referenced exists.
437 boolean hasContent( ArtifactReference reference ) throws ContentAccessException;
440 * Determines if the version reference exists in the repository.
442 * @param reference the version reference to check for.
443 * @return true if the version referenced exists.
445 boolean hasContent( VersionedReference reference ) throws ContentAccessException;
448 * Set the repository configuration to associate with this
449 * repository content.
451 * @param repo the repository to associate with this repository content.
453 void setRepository( ManagedRepository repo );
456 * Given an {@link ArtifactReference}, return the file reference to the artifact.
458 * @param reference the artifact reference to use.
459 * @return the relative path to the artifact.
461 StorageAsset toFile( VersionedReference reference );
464 * Given an {@link ArtifactReference}, return the file reference to the artifact.
466 * @param reference the artifact reference to use.
467 * @return the relative path to the artifact.
469 StorageAsset toFile( ArtifactReference reference );
472 * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
474 * @param reference the archiva artifact to use.
475 * @return the relative path to the artifact.
477 StorageAsset toFile( ArchivaArtifact reference );
480 * Given a {@link ProjectReference}, return the path to the metadata for
483 * @param reference the reference to use.
484 * @return the path to the metadata file, or null if no metadata is appropriate.
486 String toMetadataPath( ProjectReference reference );
489 * Given a {@link VersionedReference}, return the path to the metadata for
490 * the specific version of the project.
492 * @param reference the reference to use.
493 * @return the path to the metadata file, or null if no metadata is appropriate.
495 String toMetadataPath( VersionedReference reference );
498 * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
500 * @param reference the archiva artifact to use.
501 * @return the relative path to the artifact.
503 String toPath( ArchivaArtifact reference );