123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600 |
- 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.Set;
- 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
- */
- public interface ManagedRepositoryContent extends RepositoryContent
- {
-
- /// ***************** New generation interface **********************
-
- /**
- * 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 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 deleted 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 delete.
- * <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 ItemNotFoundException 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 ItemNotFoundException 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;
-
-
- /**
- * 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;
-
-
- /**
- * 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 );
-
- /**
- * 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;
-
-
- /**
- * 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;
-
-
- /// ***************** 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 );
-
-
- /**
- * Returns the version reference that represents the generic version, which means that
- * snapshot versions are converted to <VERSION>-SNAPSHOT
- * @param artifactReference the artifact reference
- * @return the generic version
- */
- VersionedReference toGenericVersion( ArtifactReference artifactReference );
-
- /**
- * 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);
-
- /**
- * Returns a artifact reference for the given coordinates.
- * @param groupId the group id
- * @param artifactId the artifact id
- * @param version the version
- * @param type the type
- * @param classifier the classifier
- * @return a artifact reference object
- */
- ArtifactReference toArtifact( String groupId, String artifactId, String version, String type, String classifier);
-
-
-
-
- /**
- * 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>
- * 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.
- * If type and / or classifier of the reference is set, this returns only a list of artifacts that is directly
- * related to the given artifact, like checksums.
- * If type and classifier is <code>null</code> it will return the same artifacts as
- * {@link #getRelatedArtifacts(VersionedReference)}
- * </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.
- * @see #getRelatedArtifacts(VersionedReference)
- */
- List<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
- throws ContentNotFoundException, LayoutException, 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 the assets that belong to a given artifact type. The list returned contain
- * all the files that correspond to the given artifact reference.
- * This method is the same as {@link #getRelatedArtifacts(ArtifactReference)} but may also return
- * e.g. hash files.
- *
- * @param reference
- * @return
- */
- List<StorageAsset> getRelatedAssets(ArtifactReference 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();
-
- /**
- * Get the repository configuration associated with this
- * repository content.
- *
- * @return the repository that is associated with this repository content.
- */
- ManagedRepository getRepository();
-
- /**
- * Given a specific {@link ProjectReference}, return the list of available versions for
- * that project reference.
- *
- * @param reference the project reference to work off of.
- * @return the list of versions found for that project reference.
- * @throws ContentNotFoundException if the project reference does nto exist within the repository.
- * @throws LayoutException
- */
- Set<String> getVersions( ProjectReference reference )
- throws ContentNotFoundException, LayoutException, ContentAccessException;
-
-
-
- /**
- * <p>
- * Given a specific {@link VersionedReference}, return the list of available versions for that
- * versioned reference.
- * </p>
- * <p>
- * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
- * </p>
- *
- * @param reference the versioned reference to work off of.
- * @return the set of versions found.
- * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
- */
- Set<String> getVersions( VersionedReference reference )
- throws ContentNotFoundException, ContentAccessException, LayoutException;
-
- /**
- * 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 project referenced exists in the repository.
- *
- * @param reference the project reference to check for.
- * @return true it the project referenced exists.
- */
- boolean hasContent( ProjectReference 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.
- *
- * @param repo the repository to associate with this repository content.
- */
- 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.
- */
- 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 );
-
-
- }
|