From dcf33551be719282d7569e6c0c48011a8275b543 Mon Sep 17 00:00:00 2001 From: Amadornes Date: Sun, 19 Aug 2018 00:16:53 +0200 Subject: Remove artifact pipelines and exclusive transformers --- .../api/transform/ArtifactPipeline.java | 11 ---- .../api/transform/ArtifactTransformer.java | 5 -- .../base/transform/ExclusiveTransformer.java | 77 ---------------------- .../base/transform/SimpleArtifactPipeline.java | 46 ------------- 4 files changed, 139 deletions(-) delete mode 100644 src/api/java/com/amadornes/artifactural/api/transform/ArtifactPipeline.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/transform/ExclusiveTransformer.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/transform/SimpleArtifactPipeline.java (limited to 'src') diff --git a/src/api/java/com/amadornes/artifactural/api/transform/ArtifactPipeline.java b/src/api/java/com/amadornes/artifactural/api/transform/ArtifactPipeline.java deleted file mode 100644 index 014046f..0000000 --- a/src/api/java/com/amadornes/artifactural/api/transform/ArtifactPipeline.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.amadornes.artifactural.api.transform; - -import com.amadornes.artifactural.api.cache.ArtifactCache; - -public interface ArtifactPipeline extends ArtifactTransformer { - - ArtifactPipeline apply(ArtifactTransformer transformer); - - ArtifactPipeline cache(ArtifactCache cache, String specifier); - -} diff --git a/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java b/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java index e24e790..bfbb965 100644 --- a/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java +++ b/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java @@ -3,7 +3,6 @@ package com.amadornes.artifactural.api.transform; import com.amadornes.artifactural.api.artifact.Artifact; import com.amadornes.artifactural.api.artifact.ArtifactMetadata; -import java.util.Set; import java.util.function.UnaryOperator; public interface ArtifactTransformer { @@ -22,10 +21,6 @@ public interface ArtifactTransformer { }; } - static ArtifactTransformer exclude(Set filters) { - return (ArtifactTransformer) new Object(); - } - default boolean appliesTo(Artifact artifact) { return true; } diff --git a/src/shared/java/com/amadornes/artifactural/base/transform/ExclusiveTransformer.java b/src/shared/java/com/amadornes/artifactural/base/transform/ExclusiveTransformer.java deleted file mode 100644 index e16be1f..0000000 --- a/src/shared/java/com/amadornes/artifactural/base/transform/ExclusiveTransformer.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.amadornes.artifactural.base.transform; - -import com.amadornes.artifactural.api.artifact.Artifact; -import com.amadornes.artifactural.api.artifact.ArtifactMetadata; -import com.amadornes.artifactural.api.artifact.ArtifactType; -import com.amadornes.artifactural.api.transform.ArtifactTransformer; -import com.amadornes.artifactural.base.artifact.StreamableArtifact; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Predicate; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class ExclusiveTransformer implements ArtifactTransformer { - - public static ExclusiveTransformer of(boolean whitelist, String... filters) { - return new ExclusiveTransformer(whitelist, filters); - } - - private final Set filters = new HashSet<>(); - private final boolean whitelist; - - private ExclusiveTransformer(boolean whitelist, String... filters) { - this.whitelist = whitelist; - for (String s : filters) { - String regex = s - .replaceAll("(?:(^|[^\\w\\*])\\*\\*([^\\w\\*]|$))", "$1.*$2") // ** matches anything - .replaceAll("(?:(^|[^\\w\\*])\\*([^\\w\\*]|$))", "$1[^\\/]*$2"); // * matches anything but / - this.filters.add(Pattern.compile(regex)); - } - } - - @Override - public Artifact transform(Artifact artifact) { - if (!artifact.isPresent()) return Artifact.none(); - - if (artifact.getType() == ArtifactType.BINARY || artifact.getType() == ArtifactType.SOURCE) { - return exclude(artifact); - } else { - return Artifact.none(); - } - } - - @Override - public ArtifactMetadata withInfo(ArtifactMetadata metadata) { - return metadata.with("EXCLUDE", filters.stream().map(Pattern::pattern).collect(Collectors.joining(";"))); - } - - private Artifact exclude(Artifact artifact) { - return StreamableArtifact.ofStreamable(artifact.getIdentifier(), artifact.getType(), - () -> new ZipInputStream(artifact.openStream()) { - @Override - public ZipEntry getNextEntry() throws IOException { - ZipEntry next; - while ((next = super.getNextEntry()) != null) { - if (isAllowed(next.getName())) { - return next; - } - } - return null; - } - }); - } - - private boolean isAllowed(String name) { - if (whitelist) { - return filters.stream().anyMatch(p -> p.asPredicate().test(name)); - } else { - return filters.stream().noneMatch(p -> p.asPredicate().test(name)); - } - } - -} diff --git a/src/shared/java/com/amadornes/artifactural/base/transform/SimpleArtifactPipeline.java b/src/shared/java/com/amadornes/artifactural/base/transform/SimpleArtifactPipeline.java deleted file mode 100644 index 625b2e9..0000000 --- a/src/shared/java/com/amadornes/artifactural/base/transform/SimpleArtifactPipeline.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.amadornes.artifactural.base.transform; - -import com.amadornes.artifactural.api.artifact.Artifact; -import com.amadornes.artifactural.api.artifact.ArtifactMetadata; -import com.amadornes.artifactural.api.cache.ArtifactCache; -import com.amadornes.artifactural.api.transform.ArtifactPipeline; -import com.amadornes.artifactural.api.transform.ArtifactTransformer; - -import java.util.function.UnaryOperator; - -public class SimpleArtifactPipeline implements ArtifactPipeline { - - public static ArtifactPipeline create() { - return new SimpleArtifactPipeline(); - } - - private static final ArtifactTransformer IDENTITY = ArtifactTransformer.of(UnaryOperator.identity()); - - private ArtifactTransformer transformer = IDENTITY; - - private SimpleArtifactPipeline() { - } - - @Override - public ArtifactPipeline apply(ArtifactTransformer transformer) { - this.transformer = this.transformer.andThen(transformer); - return this; - } - - @Override - public ArtifactPipeline cache(ArtifactCache cache, String specifier) { - transformer = transformer.andThen(ArtifactTransformer.of(artifact -> cache.store(artifact, specifier))); - return this; - } - - @Override - public Artifact transform(Artifact artifact) { - return transformer.transform(artifact); - } - - @Override - public ArtifactMetadata withInfo(ArtifactMetadata metadata) { - return transformer.withInfo(metadata); - } - -} -- cgit