aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-repository-api
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-07-19 19:29:01 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-07-19 19:29:01 +0200
commit8e4acdc82a875ca32e39eb216b879c002d228de3 (patch)
tree0c255f334dd886636ae1d1343430c89b7f1e630a /archiva-modules/archiva-base/archiva-repository-api
parentd599b89e3d259266373717897f8b7fd24fc7fb8e (diff)
downloadarchiva-8e4acdc82a875ca32e39eb216b879c002d228de3.tar.gz
archiva-8e4acdc82a875ca32e39eb216b879c002d228de3.zip
Migrating to storage API
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-api')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java13
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/RepositoryStorage.java81
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java51
3 files changed, 115 insertions, 30 deletions
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 1bab4a8ff..c50a89cf2 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
@@ -23,18 +23,9 @@ 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.RepositoryStorage;
import org.apache.archiva.repository.content.StorageAsset;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.file.Path;
-import java.time.Instant;
-import java.util.List;
import java.util.Set;
-import java.util.function.Consumer;
-import java.util.function.Function;
/**
* ManagedRepositoryContent interface for interacting with a managed repository in an abstract way,
@@ -198,7 +189,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
* @param reference the artifact reference to use.
* @return the relative path to the artifact.
*/
- Path toFile( ArtifactReference reference );
+ StorageAsset toFile( ArtifactReference reference );
/**
* Given an {@link ArchivaArtifact}, return the file reference to the artifact.
@@ -206,7 +197,7 @@ public interface ManagedRepositoryContent extends RepositoryContent
* @param reference the archiva artifact to use.
* @return the relative path to the artifact.
*/
- Path toFile( ArchivaArtifact reference );
+ StorageAsset toFile( ArchivaArtifact reference );
/**
* Given a {@link ProjectReference}, return the path to the metadata for
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/RepositoryStorage.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/RepositoryStorage.java
index 82b40b2ce..3dea0b294 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/RepositoryStorage.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/RepositoryStorage.java
@@ -21,6 +21,10 @@ package org.apache.archiva.repository.content;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.file.CopyOption;
import java.util.function.Consumer;
/**
@@ -47,14 +51,43 @@ public interface RepositoryStorage {
/**
* Consumes the data and sets a lock for the file during the operation.
*
- * @param asset
- * @param consumerFunction
- * @param readLock
+ * @param asset The asset from which the data is consumed.
+ * @param consumerFunction The consumer that reads the data
+ * @param readLock If true, a read lock is acquired on the asset.
* @throws IOException
*/
void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException;
/**
+ * Consumes the data and sets a lock for the file during the operation.
+ *
+ * @param asset The asset from which the data is consumed.
+ * @param consumerFunction The consumer that reads the data
+ * @param readLock If true, a read lock is acquired on the asset.
+ * @throws IOException
+ */
+ void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock) throws IOException;
+
+ /**
+ * Writes data to the asset using a write lock.
+ *
+ * @param asset The asset to which the data is written.
+ * @param consumerFunction The function that provides the data.
+ * @param writeLock If true, a write lock is acquired on the destination.
+ */
+ void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock) throws IOException;;
+
+ /**
+ * Writes data and sets a lock during the operation.
+ *
+ * @param asset The asset to which the data is written.
+ * @param consumerFunction The function that provides the data.
+ * @param writeLock If true, a write lock is acquired on the destination.
+ * @throws IOException
+ */
+ void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock) throws IOException;
+
+ /**
* Adds a new asset to the underlying storage.
* @param path The path to the asset.
* @param container True, if the asset should be a container, false, if it is a file.
@@ -73,19 +106,43 @@ public interface RepositoryStorage {
/**
* Moves the asset to the given location and returns the asset object for the destination.
*
- * @param origin
- * @param destination
- * @return
+ * @param origin The original asset
+ * @param destination The destination path pointing to the new asset.
+ * @param copyOptions The copy options.
+ * @return The asset representation of the moved object.
+ */
+ StorageAsset moveAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException;
+
+ /**
+ * Moves the asset to the new path.
+ *
+ * @param origin The original asset
+ * @param destination The destination asset.
+ * @param copyOptions The copy options (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
+ * @throws IOException If it was not possible to copy the asset.
*/
- StorageAsset moveAsset(StorageAsset origin, String destination) throws IOException;
+ void moveAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
/**
* Copies the given asset to the new destination.
*
- * @param origin
- * @param destination
- * @return
- * @throws IOException
+ * @param origin The original asset
+ * @param destination The path to the new asset
+ * @param copyOptions The copy options, e.g. (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
+ * @return The asset representation of the copied object
+ * @throws IOException If it was not possible to copy the asset
*/
- StorageAsset copyAsset(StorageAsset origin, String destination) throws IOException;
+ StorageAsset copyAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException;
+
+ /**
+ * Copies the given asset to the new destination.
+ *
+ * @param origin The original asset
+ * @param destination The path to the new asset
+ * @param copyOptions The copy options, e.g. (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
+ * @throws IOException If it was not possible to copy the asset
+ */
+ void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
+
+
}
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java
index 16e70859d..38ef2a895 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java
@@ -22,6 +22,8 @@ package org.apache.archiva.repository.content;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
import java.nio.file.Path;
import java.time.Instant;
import java.util.List;
@@ -39,6 +41,13 @@ import java.util.function.Consumer;
*/
public interface StorageAsset
{
+
+ /**
+ * Returns the storage this asset belongs to.
+ * @return
+ */
+ RepositoryStorage getStorage();
+
/**
* Returns the complete path relative to the repository to the given asset.
*
@@ -68,7 +77,7 @@ public interface StorageAsset
/**
* List the child assets.
*
- * @return The list of children. If there are no children, a empty list will be returned.
+ * @return The list of children. If there are no children and if the asset is not a container, a empty list will be returned.
*/
List<StorageAsset> list();
@@ -82,22 +91,41 @@ public interface StorageAsset
/**
* Returns the input stream of the artifact content.
* It will throw a IOException, if the stream could not be created.
- * Implementations should create a new stream instance for each invocation.
+ * Implementations should create a new stream instance for each invocation and make sure that the
+ * stream is proper closed after usage.
*
* @return The InputStream representing the content of the artifact.
* @throws IOException
*/
- InputStream getData() throws IOException;
+ InputStream getReadStream() throws IOException;
+
+ /**
+ * Returns a NIO representation of the data.
+ *
+ * @return A channel to the asset data.
+ * @throws IOException
+ */
+ ReadableByteChannel getReadChannel() throws IOException;
/**
*
- * Returns an output stream where you can write data to the asset.
+ * Returns an output stream where you can write data to the asset. The operation is not locked or synchronized.
+ * User of this method have to make sure, that the stream is proper closed after usage.
*
* @param replace If true, the original data will be replaced, otherwise the data will be appended.
* @return The OutputStream where the data can be written.
* @throws IOException
*/
- OutputStream writeData( boolean replace) throws IOException;
+ OutputStream getWriteStream( boolean replace) throws IOException;
+
+ /**
+ * Returns a NIO representation of the asset where you can write the data.
+ *
+ * @param replace True, if the content should be replaced by the data written to the stream.
+ * @return The Channel for writing the data.
+ * @throws IOException
+ */
+ WritableByteChannel getWriteChannel( boolean replace) throws IOException;
/**
* Replaces the content. The implementation may do an atomic move operation, or keep a backup. If
@@ -107,7 +135,7 @@ public interface StorageAsset
*
* @param newData Replaces the data by the content of the given file.
*/
- boolean storeDataFile( Path newData) throws IOException;
+ boolean replaceDataFromFile( Path newData) throws IOException;
/**
* Returns true, if the asset exists.
@@ -123,13 +151,22 @@ public interface StorageAsset
/**
* Returns the real path to the asset, if it exist. Not all implementations may implement this method.
+ * The method throws {@link UnsupportedOperationException}, if and only if {@link #isFileBased()} returns false.
*
* @return The filesystem path to the asset.
- * @throws UnsupportedOperationException
+ * @throws UnsupportedOperationException If the underlying storage is not file based.
*/
Path getFilePath() throws UnsupportedOperationException;
/**
+ * Returns true, if the asset can return a file path for the given asset. If this is true, the {@link #getFilePath()}
+ * will not throw a {@link UnsupportedOperationException}
+ *
+ * @return
+ */
+ boolean isFileBased();
+
+ /**
* Returns true, if there is a parent to this asset.
* @return
*/