diff options
Diffstat (limited to 'src/api/java')
3 files changed, 28 insertions, 9 deletions
diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java b/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java index c82bbd9..7e797fb 100644 --- a/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java +++ b/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java @@ -4,11 +4,8 @@ import com.amadornes.artifactural.api.cache.ArtifactCache; import com.amadornes.artifactural.api.transform.ArtifactTransformer; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; -import java.util.function.UnaryOperator; public interface Artifact { @@ -26,10 +23,22 @@ public interface Artifact { Artifact apply(ArtifactTransformer transformer); - Artifact cache(ArtifactCache cache, String specifier); + Artifact.Cached cache(ArtifactCache cache, String specifier); + + default Artifact.Cached optionallyCache(ArtifactCache cache, String specifier) { + return this instanceof Artifact.Cached ? (Artifact.Cached) this : cache(cache, specifier); + } boolean isPresent(); InputStream openStream() throws IOException, MissingArtifactException; + interface Cached extends Artifact { + + File asFile() throws IOException, MissingArtifactException; + + File getFileLocation() throws IOException, MissingArtifactException; + + } + } diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java b/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java index 41201df..9401b00 100644 --- a/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java +++ b/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java @@ -3,10 +3,10 @@ package com.amadornes.artifactural.api.artifact; import com.amadornes.artifactural.api.cache.ArtifactCache; import com.amadornes.artifactural.api.transform.ArtifactTransformer; -import java.io.IOException; +import java.io.File; import java.io.InputStream; -class Internal { +final class Internal { static final ArtifactIdentifier NO_IDENTIFIER = new ArtifactIdentifier() { @@ -37,7 +37,7 @@ class Internal { }; - static final Artifact NO_ARTIFACT = new Artifact() { + static final Artifact NO_ARTIFACT = new Artifact.Cached() { @Override public ArtifactIdentifier getIdentifier() { @@ -65,7 +65,7 @@ class Internal { } @Override - public Artifact cache(ArtifactCache cache, String specifier) { + public Artifact.Cached cache(ArtifactCache cache, String specifier) { return this; } @@ -79,6 +79,16 @@ class Internal { throw new MissingArtifactException(getIdentifier()); } + @Override + public File asFile() throws MissingArtifactException { + throw new MissingArtifactException(getIdentifier()); + } + + @Override + public File getFileLocation() throws MissingArtifactException { + throw new MissingArtifactException(getIdentifier()); + } + }; } diff --git a/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java b/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java index 4f86798..3209656 100644 --- a/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java +++ b/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java @@ -4,6 +4,6 @@ import com.amadornes.artifactural.api.artifact.Artifact; public interface ArtifactCache { - Artifact store(Artifact artifact, String specifier); + Artifact.Cached store(Artifact artifact, String specifier); } |