diff options
author | Amadornes <amadornes@gmail.com> | 2018-08-19 00:18:58 +0200 |
---|---|---|
committer | Amadornes <amadornes@gmail.com> | 2018-08-19 00:18:58 +0200 |
commit | 8f22509fd04c5b1124bda533cf276dd1a34c31bf (patch) | |
tree | 86e4d008fc585fd9b90f8597161d2f8209f130f5 /src | |
parent | 5176abfaebbefc33f4c4d242b8b02988cfaefc2f (diff) | |
download | Artifactural-8f22509fd04c5b1124bda533cf276dd1a34c31bf.tar.gz Artifactural-8f22509fd04c5b1124bda533cf276dd1a34c31bf.tar.bz2 Artifactural-8f22509fd04c5b1124bda533cf276dd1a34c31bf.zip |
Allow streamable artifacts to be considered as cached
Diffstat (limited to 'src')
-rw-r--r-- | src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java | 2 | ||||
-rw-r--r-- | src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java | 41 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java index 2e742ed..e02757b 100644 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java +++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java @@ -20,7 +20,7 @@ public class GradleArtifact { false ); if (files.isEmpty()) return Artifact.none(); - return StreamableArtifact.ofJar(identifier, type, files.iterator().next()); + return StreamableArtifact.ofFile(identifier, type, files.iterator().next()); } } diff --git a/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java b/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java index 4f3df7a..1b4377a 100644 --- a/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java +++ b/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java @@ -1,7 +1,13 @@ package com.amadornes.artifactural.base.artifact; -import com.amadornes.artifactural.api.artifact.*; +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.artifact.Streamable; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -10,12 +16,16 @@ import java.net.URL; public class StreamableArtifact extends ArtifactBase { - public static Artifact ofJar(ArtifactIdentifier identifier, ArtifactType type, File file) { - return ofStreamable(identifier, type, () -> new FileInputStream(file)); + public static Artifact ofFile(ArtifactIdentifier identifier, ArtifactType type, File file) { + return new StreamableFileArtifact(identifier, type, file); } public static Artifact ofURL(ArtifactIdentifier identifier, ArtifactType type, URL url) { - return ofStreamable(identifier, type, url::openStream); + return new StreamableArtifact(identifier, type, url::openStream); + } + + public static Artifact ofBytes(ArtifactIdentifier identifier, ArtifactType type, byte[] bytes) { + return new StreamableArtifact(identifier, type, () -> new ByteArrayInputStream(bytes)); } public static Artifact ofStreamable(ArtifactIdentifier identifier, ArtifactType type, Streamable streamable) { @@ -25,7 +35,7 @@ public class StreamableArtifact extends ArtifactBase { private final Streamable streamable; private StreamableArtifact(ArtifactIdentifier identifier, ArtifactType type, Streamable streamable) { - this(identifier, type, ArtifactMetadata.empty(), streamable); + this(identifier, type, new SimpleArtifactMetadata(), streamable); } private StreamableArtifact(ArtifactIdentifier identifier, ArtifactType type, ArtifactMetadata metadata, Streamable streamable) { @@ -53,4 +63,25 @@ public class StreamableArtifact extends ArtifactBase { return streamable.openStream(); } + private static class StreamableFileArtifact extends StreamableArtifact implements Artifact.Cached { + + private final File file; + + private StreamableFileArtifact(ArtifactIdentifier identifier, ArtifactType type, File file) { + super(identifier, type, () -> new FileInputStream(file)); + this.file = file; + } + + @Override + public File asFile() throws MissingArtifactException { + return file; + } + + @Override + public File getFileLocation() throws MissingArtifactException { + return file; + } + + } + } |