diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-05-30 19:58:46 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-05-30 20:00:22 +0200 |
commit | 6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5 (patch) | |
tree | 706add65520704a887961e65c5d2b7d31ac34e46 /archiva-modules/archiva-base/archiva-repository-api/src | |
parent | ac25c7a86fe77f5b0f005f03d9d28dc1f6f8580e (diff) | |
download | archiva-6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5.tar.gz archiva-6d7a510dea283ff8c4b1e6ae54a395dbe386e4a5.zip |
Refactoring of content interfaces. Adding layout for repository content.
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-api/src')
9 files changed, 569 insertions, 509 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java new file mode 100644 index 000000000..0d8e9029d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/BaseRepositoryContentLayout.java @@ -0,0 +1,440 @@ +package org.apache.archiva.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.model.ArchivaArtifact; +import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.model.ProjectReference; +import org.apache.archiva.model.VersionedReference; +import org.apache.archiva.repository.content.Artifact; +import org.apache.archiva.repository.content.ContentItem; +import org.apache.archiva.repository.content.ItemNotFoundException; +import org.apache.archiva.repository.content.ItemSelector; +import org.apache.archiva.repository.content.Namespace; +import org.apache.archiva.repository.content.Project; +import org.apache.archiva.repository.content.Version; +import org.apache.archiva.repository.storage.StorageAsset; + +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Stream; + +/** + * Layout interface for interacting with a managed repository in an abstract way, + * without the need for processing based on filesystem paths, or working with the database. + * + * + */ +public interface BaseRepositoryContentLayout extends RepositoryContent, ManagedRepositoryContent, ManagedRepositoryContentLayout +{ + + /// ***************** New generation interface ********************** + + + /** + * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other + * coordinates are ignored. + * The following coordinates must be set at the given selector: + * <ul> + * <li>namespace</li> + * </ul> + * If not, a {@link IllegalArgumentException} will be thrown. + * + * @param namespaceSelector the selectory with the namespace coordinates + * @return the namespace + * @throws ItemNotFoundException if the item does not exist + * @throws ContentAccessException if the item cannot be accessed + * @throws IllegalArgumentException if the selector has no namespace specified + */ + Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException; + + /** + * Returns the project for the given coordinates. + * The following coordinates must be set at the given selector: + * <ul> + * <li>namespace</li> + * <li>projectId</li> + * </ul> + * If not, a {@link IllegalArgumentException} will be thrown. + * Additional coordinates will be ignored. + * + * @param projectSelector + * @return the project instance + * @throws ItemNotFoundException if the project does not exist + * @throws ContentAccessException if the item cannot be accessed + * @throws IllegalArgumentException if the selector does not specify the required coordinates + */ + Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException; + + /** + * Returns the version for the given coordinates. + * The following coordinates must be set at the given selector: + * <ul> + * <li>namespace</li> + * <li>projectId</li> + * <li>version</li> + * </ul> + * If not, a {@link IllegalArgumentException} will be thrown. + * + * Additional coordinates will be ignored. + * + * @param versionCoordinates + * @return the version object + * @throws ItemNotFoundException + * @throws ContentAccessException + * @throws IllegalArgumentException + */ + Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException; + + + /** + * Returns the artifact object for the given coordinates. + * + * Normally the following coordinates should be set at the given selector: + * <ul> + * <li>namespace</li> + * <li>artifactVersion and or version</li> + * <li>artifactId or projectId</li> + * </ul> + * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown + * It depends on the repository type, what exactly is returned for a given set of coordinates. Some repository type + * may have different required and optional coordinates. For further information please check the documentation for the + * type specific implementations. + * + * The following coordinates are optional and may further specify the artifact to return. + * <ul> + * <li>classifier</li> + * <li>type</li> + * <li>extension</li> + * </ul> + * + * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact + * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code> + * method of the artifact. + * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact. + * + * + * @param selector the selector with the artifact coordinates + * @return a artifact object + * @throws IllegalArgumentException if the selector coordinates do not specify a artifact + * @throws ContentAccessException if the access to the underlying storage failed + */ + Artifact getArtifact(ItemSelector selector) throws ContentAccessException; + + + /** + * Returns the artifacts that match the given selector. It is up to the repository implementation + * what artifacts are returned for a given set of coordinates. + * + * @param selector the selector for the artifacts + * @return a list of artifacts. + * @throws IllegalArgumentException if the specified coordinates cannot be found in the repository + * @throws ContentAccessException if the access to the underlying storage failed + */ + List<? extends Artifact> getArtifacts( ItemSelector selector) throws ContentAccessException; + + /** + * Returns the artifacts that match the given selector. It is up to the repository implementation + * what artifacts are returned for a given set of coordinates. + * + * The returned stream is autoclosable and should always closed after using it. + * + * There is no guarantee about the order of the returned artifacts + * + * @param selector the selector for the artifacts + * @return a stream with artifact elements. + * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository + * @throws ContentAccessException if the access to the underlying storage failed + */ + Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException; + + + /** + * Return the projects that are part of the given namespace. + * + * @param namespace the namespace + * @return the list of projects or a empty list, if there are no projects for the given namespace. + */ + List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException; + + /** + * Returns the list of projects that match the given selector. The selector must at least specify a + * a namespace. + * + * @param selector the selector + * @return the list of projects that match the selector. A empty list of not project matches. + * @throws ContentAccessException if the access to the storage backend failed + * @throws IllegalArgumentException if the selector does not contain sufficient data for selecting projects + */ + List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; + + /** + * Return the existing versions of the given project. + * + * @param project the project + * @return a list of versions or a empty list, if not versions are available for the specified project + * @throws ContentAccessException if the access to the underlying storage failed + */ + List<? extends Version> getVersions( Project project) throws ContentAccessException; + + + /** + * Return the versions that match the given selector. The selector must at least specify a namespace and a projectId. + * + * @param selector the item selector. At least namespace and projectId must be set. + * @return the list of version or a empty list, if no version matches the selector + * @throws ContentAccessException if the access to the backend failed + * @throws IllegalArgumentException if the selector does not contain enough information for selecting versions + */ + List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; + + /** + * Returns all found artifact versions that can be found for the given selector. The selector must specify at least + * a project. + * + * @param selector the item selector that must specify at least a project + * @return the list of artifact versions + * @throws ContentAccessException if the access to the underlying storage failed + * @throws IllegalArgumentException if the selector does not have project information + */ + List<String> getArtifactVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; + + /** + * Return all the artifacts of a given content item (namespace, project, version) + * + * @param item the item + * @return a list of artifacts or a empty list, if no artifacts are available for the specified item + */ + List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException; + + /** + * Return a stream of artifacts that are part of the given content item. The returned stream is + * auto closable. There is no guarantee about the order of returned artifacts. + * + * As the stream may access IO resources, you should always use call this method inside try-with-resources or + * make sure, that the stream is closed after using it. + * + * @param item the item from where the artifacts should be returned + * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream + * is closed after use. + * @throws ContentAccessException if the access to the underlying storage failed + */ + Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException; + + + /** + * Copies the artifact to the given destination coordinates + * + * @param sourceFile the path to the source file + * @param destination the coordinates of the destination + * @throws IllegalArgumentException if the destination is not valid + */ + void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException; + + + /// ***************** End of new generation interface ********************** + + + + /** + * Returns the version reference for the given coordinates. + * @param groupId the group id + * @param artifactId the artifact id + * @param version the version number + * @return a version reference + */ + VersionedReference toVersion( String groupId, String artifactId, String version ); + + + /** + * Return the version reference that matches exactly the version string of the artifact + * + * @param artifactReference The artifact reference + * @return the version reference + */ + VersionedReference toVersion( ArtifactReference artifactReference); + + + /** + * Delete from the managed repository all files / directories associated with the + * provided version reference. + * + * @param reference the version reference to delete. + * @throws ContentNotFoundException + */ + void deleteVersion( VersionedReference reference ) + throws ContentNotFoundException, ContentAccessException; + + + + /** + * delete a specified artifact from the repository + * + * @param artifactReference + * @throws ContentNotFoundException + */ + void deleteArtifact( ArtifactReference artifactReference ) + throws ContentNotFoundException, ContentAccessException; + + + + /** + * @param groupId + * @throws ContentNotFoundException + * @since 1.4-M3 + */ + void deleteGroupId( String groupId ) + throws ContentNotFoundException, ContentAccessException; + + + + + /** + * + * @param namespace groupId for maven + * @param projectId artifactId for maven + * @throws ContentNotFoundException + */ + void deleteProject( String namespace, String projectId ) + throws ContentNotFoundException, ContentAccessException; + + + /** + * Deletes a project + * @param reference + */ + void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException; + + + + + + + /** + * <p> + * Gather up the list of related artifacts to the ArtifactReference provided. + * This typically includes the pom files, and those things with + * classifiers (such as doc, source code, test libs, etc...). Even if the classifier + * is set in the artifact reference, it may return artifacts with different classifiers. + * </p> + * <p> + * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query. + * </p> + * + * @param reference the reference to work off of. + * @return the list of ArtifactReferences for related artifacts, if + * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository. + */ + List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) + throws ContentNotFoundException, LayoutException, ContentAccessException; + + + /** + * Returns all artifacts that belong to a given version + * @param reference the version reference + * @return the list of artifacts or a empty list + */ + List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException; + + + + + /** + * <p> + * Convenience method to get the repository (on disk) root directory. + * </p> + * <p> + * Equivalent to calling <code>.getRepository().getLocation()</code> + * </p> + * + * @return the repository (on disk) root directory. + */ + String getRepoRoot(); + + /** + * Determines if the artifact referenced exists in the repository. + * + * @param reference the artifact reference to check for. + * @return true if the artifact referenced exists. + */ + boolean hasContent( ArtifactReference reference ) throws ContentAccessException; + + /** + * Determines if the version reference exists in the repository. + * + * @param reference the version reference to check for. + * @return true if the version referenced exists. + */ + boolean hasContent( VersionedReference reference ) throws ContentAccessException; + + + + /** + * Given an {@link ArtifactReference}, return the file reference to the artifact. + * + * @param reference the artifact reference to use. + * @return the relative path to the artifact. + */ + StorageAsset toFile( VersionedReference reference ); + + /** + * Given an {@link ArtifactReference}, return the file reference to the artifact. + * + * @param reference the artifact reference to use. + * @return the relative path to the artifact. + */ + StorageAsset toFile( ArtifactReference reference ); + + /** + * Given an {@link ArchivaArtifact}, return the file reference to the artifact. + * + * @param reference the archiva artifact to use. + * @return the relative path to the artifact. + */ + StorageAsset toFile( ArchivaArtifact reference ); + + /** + * Given a {@link ProjectReference}, return the path to the metadata for + * the project. + * + * @param reference the reference to use. + * @return the path to the metadata file, or null if no metadata is appropriate. + */ + String toMetadataPath( ProjectReference reference ); + + /** + * Given a {@link VersionedReference}, return the path to the metadata for + * the specific version of the project. + * + * @param reference the reference to use. + * @return the path to the metadata file, or null if no metadata is appropriate. + */ + String toMetadataPath( VersionedReference reference ); + + /** + * Given an {@link ArchivaArtifact}, return the relative path to the artifact. + * + * @param reference the archiva artifact to use. + * @return the relative path to the artifact. + */ + String toPath( ArchivaArtifact reference ); + + +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java index 4596201c8..54d565eb0 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/EditableManagedRepository.java @@ -34,7 +34,7 @@ public interface EditableManagedRepository extends EditableRepository, ManagedRe * Sets the content * @param content */ - void setContent(ManagedRepositoryContent content); + void setContent( ManagedRepositoryContent content); /** * Adds an active release scheme. Release schemes may be combined. diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java deleted file mode 100644 index 7242f5da9..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/GenericManagedRepositoryContent.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.apache.archiva.repository; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.repository.content.ContentItem; -import org.apache.archiva.repository.content.ItemNotFoundException; -import org.apache.archiva.repository.content.ItemSelector; -import org.apache.archiva.repository.storage.StorageAsset; - -import java.util.List; -import java.util.function.Consumer; -import java.util.stream.Stream; - -/** - * @author Martin Stockhammer <martin_s@apache.org> - */ -public interface GenericManagedRepositoryContent -{ - /** - * Delete all items that match the given selector. The type and number of deleted items - * depend on the specific selector: - * <ul> - * <li>namespace: the complete namespace is deleted (recursively if the recurse flag is set)</li> - * <li>project: the complete project and all contained versions are deleted</li> - * <li>version: the version inside the project is deleted (project is required)</li> - * <li>artifactId: all artifacts that match the id (project and version are required)</li> - * <li>artifactVersion: all artifacts that match the version (project and version are required)</li> - * <li></li> - * </ul> - * - * @param selector the item selector that selects the artifacts to delete - * @param consumer a consumer of the items that will be called after deletion - * @returns the list of items that are deleted - * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access - * to the artifacts failed - * @throws IllegalArgumentException if the selector does not specify valid artifacts to delete - */ - void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ) throws ContentAccessException, IllegalArgumentException; - - /** - * Removes the specified content item and if the item is a container or directory, - * all content stored under the given item. - * - * @param item the item. - * @throws ItemNotFoundException if the item cannot be found - * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access - * to the artifacts failed - */ - void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException; - - /** - * Returns a item for the given selector. The type of the returned item depends on the - * selector. - * - * @param selector the item selector - * @return the content item that matches the given selector - * @throws ContentAccessException if an error occured while accessing the backend - * @throws IllegalArgumentException if the selector does not select a valid content item - */ - ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; - - /** - * Returns a stream of items that match the given selector. It may return a stream of mixed types, - * like namespaces, projects, versions and artifacts. It will not select a specific type. - * The selector can specify the '*' pattern for all fields. - * The returned elements will be provided by depth first. - * - * @param selector the item selector that specifies the items - * @return the stream of content items - * @throws ContentAccessException if the access to the underlying storage failed - * @throws IllegalArgumentException if a illegal coordinate combination was provided - */ - Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ) throws ContentAccessException, IllegalArgumentException; - - /** - * Returns the item that matches the given path. The item at the path must not exist. - * - * @param path the path string that points to the item - * @return the content item if the path is a valid item path - * @throws LayoutException if the path is not valid for the repository layout - */ - ContentItem toItem( String path ) throws LayoutException; - - /** - * Returns the item that matches the given asset path. The asset must not exist. - * - * @param assetPath the path to the artifact or directory - * @return the item, if it is a valid path for the repository layout - * @throws LayoutException if the path is not valid for the repository - */ - ContentItem toItem( StorageAsset assetPath ) throws LayoutException; - - /** - * Returns true, if the selector coordinates point to a existing item in the repository. - * - * @param selector the item selector - * @return <code>true</code>, if there exists such a item, otherwise <code>false</code> - */ - boolean hasContent( ItemSelector selector ); - - /** - * Returns the parent of the item. - * @param item the current item - * @return the parent item, or <code>null</code> if no such item exists - */ - ContentItem getParent(ContentItem item); - - /** - * Returns the list of children items. - * @param item the current item - * @return the list of children, or a empty list, if no children exist - */ - List<? extends ContentItem> getChildren( ContentItem item); - - /** - * Tries to apply the given characteristic to the content item. If the layout does not allow this, - * it will throw a <code>LayoutException</code>. - * - * @param clazz the characteristic class to apply - * @param item the content item - * @param <T> The characteristic - * @return the applied characteristic - */ - <T extends ContentItem> T applyCharacteristic(Class<T> clazz, ContentItem item) throws LayoutException; -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java index 9b2b318b9..69364af1f 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java @@ -9,8 +9,7 @@ package org.apache.archiva.repository; * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -19,367 +18,125 @@ package org.apache.archiva.repository; * under the License. */ -import org.apache.archiva.model.ArchivaArtifact; -import org.apache.archiva.model.ArtifactReference; -import org.apache.archiva.model.ProjectReference; -import org.apache.archiva.model.VersionedReference; -import org.apache.archiva.repository.content.Artifact; import org.apache.archiva.repository.content.ContentItem; import org.apache.archiva.repository.content.ItemNotFoundException; import org.apache.archiva.repository.content.ItemSelector; -import org.apache.archiva.repository.content.Namespace; -import org.apache.archiva.repository.content.Project; -import org.apache.archiva.repository.content.Version; import org.apache.archiva.repository.storage.StorageAsset; -import java.nio.file.Path; -import java.util.BitSet; import java.util.List; -import java.util.Set; import java.util.function.Consumer; import java.util.stream.Stream; /** - * ManagedRepositoryContent interface for interacting with a managed repository in an abstract way, - * without the need for processing based on filesystem paths, or working with the database. - * - * This interface + * @author Martin Stockhammer <martin_s@apache.org> */ -public interface ManagedRepositoryContent extends RepositoryContent, GenericManagedRepositoryContent +public interface ManagedRepositoryContent { - /// ***************** New generation interface ********************** - /** - * Returns the namespace for the given selected coordinates. The selector must specify a namespace. All other - * coordinates are ignored. - * The following coordinates must be set at the given selector: - * <ul> - * <li>namespace</li> - * </ul> - * If not, a {@link IllegalArgumentException} will be thrown. + * Returns the path of the given item. * - * @param namespaceSelector the selectory with the namespace coordinates - * @return the namespace - * @throws ItemNotFoundException if the item does not exist - * @throws ContentAccessException if the item cannot be accessed - * @throws IllegalArgumentException if the selector has no namespace specified + * @param item + * @return */ - Namespace getNamespace( ItemSelector namespaceSelector ) throws ContentAccessException, IllegalArgumentException; + String toPath( ContentItem item ); + - /** - * Returns the project for the given coordinates. - * The following coordinates must be set at the given selector: - * <ul> - * <li>namespace</li> - * <li>projectId</li> - * </ul> - * If not, a {@link IllegalArgumentException} will be thrown. - * Additional coordinates will be ignored. - * - * @param projectSelector - * @return the project instance - * @throws ItemNotFoundException if the project does not exist - * @throws ContentAccessException if the item cannot be accessed - * @throws IllegalArgumentException if the selector does not specify the required coordinates - */ - Project getProject( ItemSelector projectSelector ) throws ContentAccessException, IllegalArgumentException; /** - * Returns the version for the given coordinates. - * The following coordinates must be set at the given selector: - * <ul> - * <li>namespace</li> - * <li>projectId</li> - * <li>version</li> - * </ul> - * If not, a {@link IllegalArgumentException} will be thrown. - * - * Additional coordinates will be ignored. + * <p> + * Convenience method to get the repository id. + * </p> + * <p> + * Equivalent to calling <code>.getRepository().getId()</code> + * </p> * - * @param versionCoordinates - * @return the version object - * @throws ItemNotFoundException - * @throws ContentAccessException - * @throws IllegalArgumentException + * @return the repository id. */ - Version getVersion(ItemSelector versionCoordinates) throws ContentAccessException, IllegalArgumentException; - + String getId(); /** - * Returns the artifact object for the given coordinates. - * - * Normally the following coordinates should be set at the given selector: - * <ul> - * <li>namespace</li> - * <li>artifactVersion and or version</li> - * <li>artifactId or projectId</li> - * </ul> - * If the coordinates do not provide enough information for selecting a artifact, a {@link IllegalArgumentException} will be thrown - * It depends on the repository type, what exactly is returned for a given set of coordinates. Some repository type - * may have different required and optional coordinates. For further information please check the documentation for the - * type specific implementations. - * - * The following coordinates are optional and may further specify the artifact to return. + * Delete all items that match the given selector. The type and number of deleted items + * depend on the specific selector: * <ul> - * <li>classifier</li> - * <li>type</li> - * <li>extension</li> + * <li>namespace: the complete namespace is deleted (recursively if the recurse flag is set)</li> + * <li>project: the complete project and all contained versions are deleted</li> + * <li>version: the version inside the project is deleted (project is required)</li> + * <li>artifactId: all artifacts that match the id (project and version are required)</li> + * <li>artifactVersion: all artifacts that match the version (project and version are required)</li> + * <li></li> * </ul> * - * The method always returns a artifact object, if the coordinates are valid. It does not guarantee that the artifact - * exists. To check if there is really a physical representation of the artifact, use the <code>{@link Artifact#exists()}</code> - * method of the artifact. - * For upload and data retrieval use the methods of the {@link StorageAsset} reference returned in the artifact. - * - * - * @param selector the selector with the artifact coordinates - * @return a artifact object - * @throws IllegalArgumentException if the selector coordinates do not specify a artifact - * @throws ContentAccessException if the access to the underlying storage failed + * @param selector the item selector that selects the artifacts to delete + * @param consumer a consumer of the items that will be called after deletion + * @returns the list of items that are deleted + * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access + * to the artifacts failed + * @throws IllegalArgumentException if the selector does not specify valid artifacts to delete */ - Artifact getArtifact(ItemSelector selector) throws ContentAccessException; - + void deleteAllItems( ItemSelector selector, Consumer<ItemDeleteStatus> consumer ) throws ContentAccessException, IllegalArgumentException; /** - * Returns the artifacts that match the given selector. It is up to the repository implementation - * what artifacts are returned for a given set of coordinates. + * Removes the specified content item and if the item is a container or directory, + * all content stored under the given item. * - * @param selector the selector for the artifacts - * @return a list of artifacts. - * @throws IllegalArgumentException if the specified coordinates cannot be found in the repository - * @throws ContentAccessException if the access to the underlying storage failed + * @param item the item. + * @throws ItemNotFoundException if the item cannot be found + * @throws ContentAccessException if the deletion was not possible or only partly successful, because the access + * to the artifacts failed */ - List<? extends Artifact> getArtifacts( ItemSelector selector) throws ContentAccessException; + void deleteItem( ContentItem item ) throws ItemNotFoundException, ContentAccessException; /** - * Returns the artifacts that match the given selector. It is up to the repository implementation - * what artifacts are returned for a given set of coordinates. - * - * The returned stream is autoclosable and should always closed after using it. + * Returns a item for the given selector. The type of the returned item depends on the + * selector. * - * There is no guarantee about the order of the returned artifacts - * - * @param selector the selector for the artifacts - * @return a stream with artifact elements. - * @throws ItemNotFoundException if the specified coordinates cannot be found in the repository - * @throws ContentAccessException if the access to the underlying storage failed + * @param selector the item selector + * @return the content item that matches the given selector + * @throws ContentAccessException if an error occured while accessing the backend + * @throws IllegalArgumentException if the selector does not select a valid content item */ - Stream<? extends Artifact> newArtifactStream( ItemSelector selector) throws ContentAccessException; - + ContentItem getItem( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; /** - * Return the projects that are part of the given namespace. + * Returns a stream of items that match the given selector. It may return a stream of mixed types, + * like namespaces, projects, versions and artifacts. It will not select a specific type. + * The selector can specify the '*' pattern for all fields. + * The returned elements will be provided by depth first. * - * @param namespace the namespace - * @return the list of projects or a empty list, if there are no projects for the given namespace. - */ - List<? extends Project> getProjects( Namespace namespace) throws ContentAccessException; - - /** - * Returns the list of projects that match the given selector. The selector must at least specify a - * a namespace. - * - * @param selector the selector - * @return the list of projects that match the selector. A empty list of not project matches. - * @throws ContentAccessException if the access to the storage backend failed - * @throws IllegalArgumentException if the selector does not contain sufficient data for selecting projects - */ - List<? extends Project> getProjects( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; - - /** - * Return the existing versions of the given project. - * - * @param project the project - * @return a list of versions or a empty list, if not versions are available for the specified project - * @throws ContentAccessException if the access to the underlying storage failed - */ - List<? extends Version> getVersions( Project project) throws ContentAccessException; - - - /** - * Return the versions that match the given selector. The selector must at least specify a namespace and a projectId. - * - * @param selector the item selector. At least namespace and projectId must be set. - * @return the list of version or a empty list, if no version matches the selector - * @throws ContentAccessException if the access to the backend failed - * @throws IllegalArgumentException if the selector does not contain enough information for selecting versions - */ - List<? extends Version> getVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; - - /** - * Returns all found artifact versions that can be found for the given selector. The selector must specify at least - * a project. - * - * @param selector the item selector that must specify at least a project - * @return the list of artifact versions - * @throws ContentAccessException if the access to the underlying storage failed - * @throws IllegalArgumentException if the selector does not have project information - */ - List<String> getArtifactVersions( ItemSelector selector ) throws ContentAccessException, IllegalArgumentException; - - /** - * Return all the artifacts of a given content item (namespace, project, version) - * - * @param item the item - * @return a list of artifacts or a empty list, if no artifacts are available for the specified item - */ - List<? extends Artifact> getArtifacts( ContentItem item) throws ContentAccessException; - - /** - * Return a stream of artifacts that are part of the given content item. The returned stream is - * auto closable. There is no guarantee about the order of returned artifacts. - * - * As the stream may access IO resources, you should always use call this method inside try-with-resources or - * make sure, that the stream is closed after using it. - * - * @param item the item from where the artifacts should be returned - * @return a stream of artifacts. The stream is auto closable. You should always make sure, that the stream - * is closed after use. + * @param selector the item selector that specifies the items + * @return the stream of content items * @throws ContentAccessException if the access to the underlying storage failed + * @throws IllegalArgumentException if a illegal coordinate combination was provided */ - Stream<? extends Artifact> newArtifactStream( ContentItem item ) throws ContentAccessException; - + Stream<? extends ContentItem> newItemStream( ItemSelector selector, boolean parallel ) throws ContentAccessException, IllegalArgumentException; /** - * Copies the artifact to the given destination coordinates + * Returns the item that matches the given path. The item at the path must not exist. * - * @param sourceFile the path to the source file - * @param destination the coordinates of the destination - * @throws IllegalArgumentException if the destination is not valid + * @param path the path string that points to the item + * @return the content item if the path is a valid item path + * @throws LayoutException if the path is not valid for the repository layout */ - void addArtifact( Path sourceFile, Artifact destination ) throws IllegalArgumentException, ContentAccessException; - - - /// ***************** End of new generation interface ********************** - - - - /** - * Returns the version reference for the given coordinates. - * @param groupId the group id - * @param artifactId the artifact id - * @param version the version number - * @return a version reference - */ - VersionedReference toVersion( String groupId, String artifactId, String version ); - + ContentItem toItem( String path ) throws LayoutException; /** - * Return the version reference that matches exactly the version string of the artifact + * Returns the item that matches the given asset path. The asset must not exist. * - * @param artifactReference The artifact reference - * @return the version reference + * @param assetPath the path to the artifact or directory + * @return the item, if it is a valid path for the repository layout + * @throws LayoutException if the path is not valid for the repository */ - VersionedReference toVersion( ArtifactReference artifactReference); - + ContentItem toItem( StorageAsset assetPath ) throws LayoutException; /** - * Delete from the managed repository all files / directories associated with the - * provided version reference. + * Returns true, if the selector coordinates point to a existing item in the repository. * - * @param reference the version reference to delete. - * @throws ContentNotFoundException + * @param selector the item selector + * @return <code>true</code>, if there exists such a item, otherwise <code>false</code> */ - void deleteVersion( VersionedReference reference ) - throws ContentNotFoundException, ContentAccessException; - - - - /** - * delete a specified artifact from the repository - * - * @param artifactReference - * @throws ContentNotFoundException - */ - void deleteArtifact( ArtifactReference artifactReference ) - throws ContentNotFoundException, ContentAccessException; - - - - /** - * @param groupId - * @throws ContentNotFoundException - * @since 1.4-M3 - */ - void deleteGroupId( String groupId ) - throws ContentNotFoundException, ContentAccessException; - - - - - /** - * - * @param namespace groupId for maven - * @param projectId artifactId for maven - * @throws ContentNotFoundException - */ - void deleteProject( String namespace, String projectId ) - throws ContentNotFoundException, ContentAccessException; - - - /** - * Deletes a project - * @param reference - */ - void deleteProject(ProjectReference reference) throws ContentNotFoundException, ContentAccessException; - - - - - /** - * <p> - * Convenience method to get the repository id. - * </p> - * <p> - * Equivalent to calling <code>.getRepository().getId()</code> - * </p> - * - * @return the repository id. - */ - String getId(); - - /** - * <p> - * Gather up the list of related artifacts to the ArtifactReference provided. - * This typically includes the pom files, and those things with - * classifiers (such as doc, source code, test libs, etc...). Even if the classifier - * is set in the artifact reference, it may return artifacts with different classifiers. - * </p> - * <p> - * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query. - * </p> - * - * @param reference the reference to work off of. - * @return the list of ArtifactReferences for related artifacts, if - * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository. - */ - List<ArtifactReference> getRelatedArtifacts( VersionedReference reference ) - throws ContentNotFoundException, LayoutException, ContentAccessException; - - - /** - * Returns all artifacts that belong to a given version - * @param reference the version reference - * @return the list of artifacts or a empty list - */ - List<ArtifactReference> getArtifacts(VersionedReference reference) throws ContentNotFoundException, LayoutException, ContentAccessException; - - - - - /** - * <p> - * Convenience method to get the repository (on disk) root directory. - * </p> - * <p> - * Equivalent to calling <code>.getRepository().getLocation()</code> - * </p> - * - * @return the repository (on disk) root directory. - */ - String getRepoRoot(); + boolean hasContent( ItemSelector selector ); /** * Get the repository configuration associated with this @@ -389,23 +146,6 @@ public interface ManagedRepositoryContent extends RepositoryContent, GenericMana */ ManagedRepository getRepository(); - - /** - * Determines if the artifact referenced exists in the repository. - * - * @param reference the artifact reference to check for. - * @return true if the artifact referenced exists. - */ - boolean hasContent( ArtifactReference reference ) throws ContentAccessException; - - /** - * Determines if the version reference exists in the repository. - * - * @param reference the version reference to check for. - * @return true if the version referenced exists. - */ - boolean hasContent( VersionedReference reference ) throws ContentAccessException; - /** * Set the repository configuration to associate with this * repository content. @@ -415,54 +155,43 @@ public interface ManagedRepositoryContent extends RepositoryContent, GenericMana void setRepository( ManagedRepository repo ); /** - * Given an {@link ArtifactReference}, return the file reference to the artifact. - * - * @param reference the artifact reference to use. - * @return the relative path to the artifact. + * Returns the parent of the item. + * @param item the current item + * @return the parent item, or <code>null</code> if no such item exists */ - StorageAsset toFile( VersionedReference reference ); + ContentItem getParent(ContentItem item); /** - * Given an {@link ArtifactReference}, return the file reference to the artifact. - * - * @param reference the artifact reference to use. - * @return the relative path to the artifact. + * Returns the list of children items. + * @param item the current item + * @return the list of children, or a empty list, if no children exist */ - StorageAsset toFile( ArtifactReference reference ); + List<? extends ContentItem> getChildren( ContentItem item); /** - * Given an {@link ArchivaArtifact}, return the file reference to the artifact. + * Tries to apply the given characteristic to the content item. If the layout does not allow this, + * it will throw a <code>LayoutException</code>. * - * @param reference the archiva artifact to use. - * @return the relative path to the artifact. + * @param clazz the characteristic class to apply + * @param item the content item + * @param <T> The characteristic + * @return the applied characteristic */ - StorageAsset toFile( ArchivaArtifact reference ); + <T extends ContentItem> T applyCharacteristic(Class<T> clazz, ContentItem item) throws LayoutException; /** - * Given a {@link ProjectReference}, return the path to the metadata for - * the project. - * - * @param reference the reference to use. - * @return the path to the metadata file, or null if no metadata is appropriate. + * Returns the given layout from the content. + * @param clazz The layout class + * @param <T> the layout class + * @return the specific layout + * @throws LayoutException if the repository does not support this layout type */ - String toMetadataPath( ProjectReference reference ); + <T extends ManagedRepositoryContentLayout> T getLayout(Class<T> clazz) throws LayoutException; /** - * Given a {@link VersionedReference}, return the path to the metadata for - * the specific version of the project. - * - * @param reference the reference to use. - * @return the path to the metadata file, or null if no metadata is appropriate. + * Returns <code>true</code>, if the specific layout is supported by this content. + * @param clazz the layout class + * @return <code>true</code>, if the layout is supported, otherwise <code>false</code> */ - String toMetadataPath( VersionedReference reference ); - - /** - * Given an {@link ArchivaArtifact}, return the relative path to the artifact. - * - * @param reference the archiva artifact to use. - * @return the relative path to the artifact. - */ - String toPath( ArchivaArtifact reference ); - - + <T extends ManagedRepositoryContentLayout> boolean supportsLayout(Class<T> clazz); } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContentLayout.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContentLayout.java new file mode 100644 index 000000000..e64f8b2ac --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContentLayout.java @@ -0,0 +1,32 @@ +package org.apache.archiva.repository; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * + * Basic interface for content layouts. + * A content layout provides specific content item instances for the content structure like Namespace, + * Project, Version and their relationships. + * + * @author Martin Stockhammer <martin_s@apache.org> + */ +public interface ManagedRepositoryContentLayout +{ + ManagedRepositoryContent getGenericContent(); +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java index 4e062fcb9..5de655d9f 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContent.java @@ -21,6 +21,7 @@ package org.apache.archiva.repository; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.VersionedReference; +import org.apache.archiva.repository.content.ContentItem; import org.apache.archiva.repository.content.ItemSelector; diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContentProvider.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContentProvider.java index 823444925..66e3caef8 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContentProvider.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryContentProvider.java @@ -66,7 +66,7 @@ public interface RepositoryContentProvider * @return a new instance * @throws RepositoryException if the layout is not supported, or a error occured during initialization */ - ManagedRepositoryContent createManagedContent(ManagedRepository repository) throws RepositoryException; + ManagedRepositoryContent createManagedContent( ManagedRepository repository) throws RepositoryException; /** * Creates a generic content object. diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java index ecc97b844..04700e76b 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java @@ -112,7 +112,7 @@ public interface RepositoryRequestInfo String getLayout( String requestPath ); /** - * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}. + * Adjust the requestedPath to conform to the native layout of the provided {@link BaseRepositoryContentLayout}. * * @param requestPath the incoming requested path. * @return the adjusted (to native) path. diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java index 68aca2d8b..447712bd5 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/ContentItem.java @@ -19,9 +19,8 @@ package org.apache.archiva.repository.content; * under the License. */ -import org.apache.archiva.repository.ItemConversionException; import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.UnsupportedConversionException; +import org.apache.archiva.repository.ItemConversionException; import org.apache.archiva.repository.storage.StorageAsset; import java.util.Map; |