diff options
author | Amadornes <amadornes@gmail.com> | 2018-08-19 00:16:53 +0200 |
---|---|---|
committer | Amadornes <amadornes@gmail.com> | 2018-08-19 00:16:53 +0200 |
commit | dcf33551be719282d7569e6c0c48011a8275b543 (patch) | |
tree | 503f96626657cfefbcc42601fbdb634f7d7b7dca | |
parent | c266c1320597fb1385547a4ad8384b74231b96ca (diff) | |
download | Artifactural-dcf33551be719282d7569e6c0c48011a8275b543.tar.gz Artifactural-dcf33551be719282d7569e6c0c48011a8275b543.tar.bz2 Artifactural-dcf33551be719282d7569e6c0c48011a8275b543.zip |
Remove artifact pipelines and exclusive transformers
4 files changed, 0 insertions, 139 deletions
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<String> 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<Pattern> 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); - } - -} |