aboutsummaryrefslogtreecommitdiff
path: root/src/shared/java/com/amadornes/artifactural
diff options
context:
space:
mode:
authorAmadornes <amadornes@gmail.com>2018-08-19 00:15:34 +0200
committerAmadornes <amadornes@gmail.com>2018-08-19 00:15:34 +0200
commit6fd0997b5ddcea041d488c7e02f165cf06b2a375 (patch)
tree38d57d22f846d87118e8c03a284cc0e81d78439d /src/shared/java/com/amadornes/artifactural
parent5bdc425b044246521849e902290ec8e65812f7be (diff)
downloadArtifactural-6fd0997b5ddcea041d488c7e02f165cf06b2a375.tar.gz
Artifactural-6fd0997b5ddcea041d488c7e02f165cf06b2a375.tar.bz2
Artifactural-6fd0997b5ddcea041d488c7e02f165cf06b2a375.zip
Added API-level support for cached artifacts
Diffstat (limited to 'src/shared/java/com/amadornes/artifactural')
-rw-r--r--src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactBase.java4
-rw-r--r--src/shared/java/com/amadornes/artifactural/base/cache/ArtifactCacheBase.java84
-rw-r--r--src/shared/java/com/amadornes/artifactural/base/cache/LocatedArtifactCache.java2
3 files changed, 82 insertions, 8 deletions
diff --git a/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactBase.java b/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactBase.java
index 4656285..e7dd0c2 100644
--- a/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactBase.java
+++ b/src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactBase.java
@@ -13,7 +13,7 @@ public abstract class ArtifactBase implements Artifact {
private final ArtifactType type;
private final ArtifactMetadata metadata;
- ArtifactBase(ArtifactIdentifier identifier, ArtifactType type, ArtifactMetadata metadata) {
+ public ArtifactBase(ArtifactIdentifier identifier, ArtifactType type, ArtifactMetadata metadata) {
this.identifier = identifier;
this.type = type;
this.metadata = metadata;
@@ -41,7 +41,7 @@ public abstract class ArtifactBase implements Artifact {
}
@Override
- public Artifact cache(ArtifactCache cache, String specifier) {
+ public Artifact.Cached cache(ArtifactCache cache, String specifier) {
return cache.store(this, specifier);
}
diff --git a/src/shared/java/com/amadornes/artifactural/base/cache/ArtifactCacheBase.java b/src/shared/java/com/amadornes/artifactural/base/cache/ArtifactCacheBase.java
index 5f1c240..93ca358 100644
--- a/src/shared/java/com/amadornes/artifactural/base/cache/ArtifactCacheBase.java
+++ b/src/shared/java/com/amadornes/artifactural/base/cache/ArtifactCacheBase.java
@@ -1,16 +1,31 @@
package com.amadornes.artifactural.base.cache;
import com.amadornes.artifactural.api.artifact.Artifact;
+import com.amadornes.artifactural.api.artifact.ArtifactIdentifier;
+import com.amadornes.artifactural.api.artifact.ArtifactMetadata;
+import com.amadornes.artifactural.api.artifact.ArtifactType;
+import com.amadornes.artifactural.api.artifact.MissingArtifactException;
import com.amadornes.artifactural.api.cache.ArtifactCache;
+import com.amadornes.artifactural.api.transform.ArtifactTransformer;
import com.amadornes.artifactural.base.artifact.StreamableArtifact;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
-abstract class ArtifactCacheBase implements ArtifactCache {
+public abstract class ArtifactCacheBase implements ArtifactCache {
- Artifact doStore(File path, Artifact artifact) {
- return StreamableArtifact.ofStreamable(artifact.getIdentifier(), artifact.getType(), () -> stream(path, artifact))
- .withMetadata(artifact.getMetadata());
+ Artifact.Cached doStore(File path, Artifact artifact) {
+ return wrap(
+ StreamableArtifact.ofStreamable(
+ artifact.getIdentifier(),
+ artifact.getType(),
+ () -> stream(path, artifact)
+ ).withMetadata(artifact.getMetadata()),
+ path
+ );
}
private InputStream stream(File path, Artifact artifact) throws IOException {
@@ -30,4 +45,63 @@ abstract class ArtifactCacheBase implements ArtifactCache {
return new FileInputStream(path);
}
+ public static Artifact.Cached wrap(Artifact artifact, File file) {
+ return new Artifact.Cached() {
+
+ @Override
+ public ArtifactIdentifier getIdentifier() {
+ return artifact.getIdentifier();
+ }
+
+ @Override
+ public ArtifactMetadata getMetadata() {
+ return artifact.getMetadata();
+ }
+
+ @Override
+ public ArtifactType getType() {
+ return artifact.getType();
+ }
+
+ @Override
+ public Artifact withMetadata(ArtifactMetadata metadata) {
+ return artifact.withMetadata(metadata);
+ }
+
+ @Override
+ public Artifact apply(ArtifactTransformer transformer) {
+ return artifact.apply(transformer);
+ }
+
+ @Override
+ public Artifact.Cached cache(ArtifactCache cache, String specifier) {
+ return artifact.cache(cache, specifier);
+ }
+
+ @Override
+ public boolean isPresent() {
+ return artifact.isPresent();
+ }
+
+ @Override
+ public InputStream openStream() throws IOException, MissingArtifactException {
+ return artifact.openStream();
+ }
+
+ @Override
+ public File asFile() throws IOException, MissingArtifactException {
+ if(!file.exists()) {
+ artifact.openStream().close();
+ }
+ return file;
+ }
+
+ @Override
+ public File getFileLocation() throws MissingArtifactException {
+ return file;
+ }
+
+ };
+ }
+
}
diff --git a/src/shared/java/com/amadornes/artifactural/base/cache/LocatedArtifactCache.java b/src/shared/java/com/amadornes/artifactural/base/cache/LocatedArtifactCache.java
index caa5de7..2afbff8 100644
--- a/src/shared/java/com/amadornes/artifactural/base/cache/LocatedArtifactCache.java
+++ b/src/shared/java/com/amadornes/artifactural/base/cache/LocatedArtifactCache.java
@@ -14,7 +14,7 @@ public class LocatedArtifactCache extends ArtifactCacheBase {
}
@Override
- public Artifact store(Artifact artifact, String specifier) {
+ public Artifact.Cached store(Artifact artifact, String specifier) {
ArtifactIdentifier identifier = artifact.getIdentifier();
File cachePath = new File(path.getAbsolutePath()
.replace("${GROUP}", identifier.getGroup())