From 4089917696fffbd4b818fb90958d20f0714f93fb Mon Sep 17 00:00:00 2001 From: LexManos Date: Sun, 17 Jan 2021 17:35:01 -0800 Subject: Move to net.minecraftforge package, and update license headers. --- .../artifactural/api/artifact/Artifact.java | 65 ---------- .../api/artifact/ArtifactIdentifier.java | 80 ------------ .../api/artifact/ArtifactMetadata.java | 28 ----- .../artifactural/api/artifact/ArtifactType.java | 24 ---- .../artifactural/api/artifact/Internal.java | 137 --------------------- .../api/artifact/MissingArtifactException.java | 29 ----- .../artifactural/api/artifact/Streamable.java | 30 ----- .../artifactural/api/cache/ArtifactCache.java | 28 ----- .../api/repository/ArtifactProvider.java | 47 ------- .../artifactural/api/repository/Repository.java | 44 ------- .../api/transform/ArtifactTransformer.java | 68 ---------- .../artifactural/api/artifact/Artifact.java | 65 ++++++++++ .../api/artifact/ArtifactIdentifier.java | 80 ++++++++++++ .../api/artifact/ArtifactMetadata.java | 28 +++++ .../artifactural/api/artifact/ArtifactType.java | 24 ++++ .../artifactural/api/artifact/Internal.java | 137 +++++++++++++++++++++ .../api/artifact/MissingArtifactException.java | 29 +++++ .../artifactural/api/artifact/Streamable.java | 30 +++++ .../artifactural/api/cache/ArtifactCache.java | 28 +++++ .../api/repository/ArtifactProvider.java | 47 +++++++ .../artifactural/api/repository/Repository.java | 44 +++++++ .../api/transform/ArtifactTransformer.java | 68 ++++++++++ 22 files changed, 580 insertions(+), 580 deletions(-) delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/ArtifactIdentifier.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/ArtifactMetadata.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/ArtifactType.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/Internal.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/MissingArtifactException.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/artifact/Streamable.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/repository/ArtifactProvider.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/repository/Repository.java delete mode 100644 src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java create mode 100644 src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java (limited to 'src/api/java') diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java b/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java deleted file mode 100644 index 1da3c90..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/Artifact.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -import com.amadornes.artifactural.api.cache.ArtifactCache; -import com.amadornes.artifactural.api.transform.ArtifactTransformer; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -public interface Artifact { - - static Artifact none() { - return Internal.NO_ARTIFACT; - } - - ArtifactIdentifier getIdentifier(); - - ArtifactMetadata getMetadata(); - - ArtifactType getType(); - - Artifact withMetadata(ArtifactMetadata metadata); - - Artifact apply(ArtifactTransformer transformer); - - Artifact.Cached cache(ArtifactCache cache); - - default Artifact.Cached optionallyCache(ArtifactCache cache) { - return this instanceof Artifact.Cached ? (Artifact.Cached) this : cache(cache); - } - - boolean isPresent(); - - InputStream openStream() throws IOException, MissingArtifactException; - - interface Cached extends Artifact { - - // Gets the file location, AND writes the file to disc if it hasn't already. - File asFile() throws IOException, MissingArtifactException; - - // Gets the file location, but doesn't guarantee that it exists. As the wrapped Artifact may not of been written. What's the point of this? - File getFileLocation() throws IOException, MissingArtifactException; - - } - -} diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactIdentifier.java b/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactIdentifier.java deleted file mode 100644 index e663c11..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactIdentifier.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -import java.util.function.Predicate; - -public interface ArtifactIdentifier { - - static ArtifactIdentifier none() { - return Internal.NO_IDENTIFIER; - } - - String getGroup(); - - String getName(); - - String getVersion(); - - String getClassifier(); - - String getExtension(); - - static Predicate groupMatches(String group) { - return identifier -> identifier.getGroup().matches(group); - } - - static Predicate nameMatches(String name) { - return identifier -> identifier.getName().matches(name); - } - - static Predicate versionMatches(String version) { - return identifier -> identifier.getVersion().matches(version); - } - - static Predicate classifierMatches(String classifier) { - return identifier -> identifier.getClassifier().matches(classifier); - } - - static Predicate extensionMatches(String extension) { - return identifier -> identifier.getExtension().matches(extension); - } - - static Predicate groupEquals(String group) { - return identifier -> identifier.getGroup().equals(group); - } - - static Predicate nameEquals(String name) { - return identifier -> identifier.getName().equals(name); - } - - static Predicate versionEquals(String version) { - return identifier -> identifier.getVersion().equals(version); - } - - static Predicate classifierEquals(String classifier) { - return identifier -> identifier.getClassifier().equals(classifier); - } - - static Predicate extensionEquals(String extension) { - return identifier -> identifier.getExtension().equals(extension); - } - -} diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactMetadata.java b/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactMetadata.java deleted file mode 100644 index af5e08a..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactMetadata.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -public interface ArtifactMetadata { - - ArtifactMetadata with(String key, String value); - - String getHash(); - -} diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactType.java b/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactType.java deleted file mode 100644 index 40e5aa6..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/ArtifactType.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -public enum ArtifactType { - BINARY, SOURCE, OTHER -} diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java b/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java deleted file mode 100644 index 39bc983..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/Internal.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -import com.amadornes.artifactural.api.cache.ArtifactCache; -import com.amadornes.artifactural.api.transform.ArtifactTransformer; - -import java.io.File; -import java.io.InputStream; - -final class Internal { - - static final ArtifactIdentifier NO_IDENTIFIER = new ArtifactIdentifier() { - - @Override - public String getGroup() { - return "missing"; - } - - @Override - public String getName() { - return "missing"; - } - - @Override - public String getVersion() { - return "0.0.0"; - } - - @Override - public String getClassifier() { - return ""; - } - - @Override - public String getExtension() { - return "missing"; - } - - @Override - public String toString() { - return "NO_IDENTIFIER"; - } - - }; - - static final Artifact NO_ARTIFACT = new Artifact.Cached() { - @Override - public String toString() { - return "NO_ARTIFACT"; - } - - @Override - public ArtifactIdentifier getIdentifier() { - return ArtifactIdentifier.none(); - } - - @Override - public ArtifactMetadata getMetadata() { - return new ArtifactMetadata() { - @Override - public ArtifactMetadata with(String key, String value) { - throw new UnsupportedOperationException(); - } - - @Override - public String getHash() { - return "ERROR"; - } - - @Override - public String toString() { - return "NO_METADATA"; - } - }; - } - - @Override - public ArtifactType getType() { - return ArtifactType.OTHER; - } - - @Override - public Artifact withMetadata(ArtifactMetadata metadata) { - return this; - } - - @Override - public Artifact apply(ArtifactTransformer transformer) { - return this; - } - - @Override - public Artifact.Cached cache(ArtifactCache cache) { - return this; - } - - @Override - public boolean isPresent() { - return false; - } - - @Override - public InputStream openStream() throws MissingArtifactException { - 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/artifact/MissingArtifactException.java b/src/api/java/com/amadornes/artifactural/api/artifact/MissingArtifactException.java deleted file mode 100644 index 3caa7ec..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/MissingArtifactException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -public class MissingArtifactException extends RuntimeException { - private static final long serialVersionUID = 4902516963452435653L; - - public MissingArtifactException(ArtifactIdentifier identifier) { - super("Could not find artifact: " + identifier); - } - -} diff --git a/src/api/java/com/amadornes/artifactural/api/artifact/Streamable.java b/src/api/java/com/amadornes/artifactural/api/artifact/Streamable.java deleted file mode 100644 index b8fcdf6..0000000 --- a/src/api/java/com/amadornes/artifactural/api/artifact/Streamable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.artifact; - -import java.io.IOException; -import java.io.InputStream; - -@FunctionalInterface -public interface Streamable { - - InputStream openStream() throws IOException; - -} diff --git a/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java b/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java deleted file mode 100644 index 00e2197..0000000 --- a/src/api/java/com/amadornes/artifactural/api/cache/ArtifactCache.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.cache; - -import com.amadornes.artifactural.api.artifact.Artifact; - -public interface ArtifactCache { - - Artifact.Cached store(Artifact artifact); - -} diff --git a/src/api/java/com/amadornes/artifactural/api/repository/ArtifactProvider.java b/src/api/java/com/amadornes/artifactural/api/repository/ArtifactProvider.java deleted file mode 100644 index d48856f..0000000 --- a/src/api/java/com/amadornes/artifactural/api/repository/ArtifactProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.repository; - -import com.amadornes.artifactural.api.artifact.Artifact; - -import java.util.function.Function; -import java.util.function.Predicate; - -public interface ArtifactProvider { - - Artifact getArtifact(I info); - - interface Builder { - - Builder filter(Predicate filter); - - Builder mapInfo(Function mapper); - - Complete provide(ArtifactProvider provider); - - interface Complete extends ArtifactProvider { - - Complete provide(ArtifactProvider provider); - - } - - } - -} diff --git a/src/api/java/com/amadornes/artifactural/api/repository/Repository.java b/src/api/java/com/amadornes/artifactural/api/repository/Repository.java deleted file mode 100644 index 2e1de79..0000000 --- a/src/api/java/com/amadornes/artifactural/api/repository/Repository.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.repository; - -import java.io.File; - -import com.amadornes.artifactural.api.artifact.Artifact; -import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; - -public interface Repository { - - Artifact getArtifact(ArtifactIdentifier identifier); - - /** - * Returns a file in maven-metadata.xml format for the specified artifact, - * this is used by gradle to list all known versions, so that it can resolve wildcard - * dependencies such as foo:bar:1.+ - * - * @param group Group - * @param name Artifact name - * @return maven-metadata.xml file listing all versions of the artifact this repo can provide. Or null if you don't want to list any. - */ - default File getMavenMetadata(String group, String name) { - return null; - } - -} diff --git a/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java b/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java deleted file mode 100644 index b129d5b..0000000 --- a/src/api/java/com/amadornes/artifactural/api/transform/ArtifactTransformer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Artifactural - * Copyright (c) 2018. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation version 2.1 - * of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -package com.amadornes.artifactural.api.transform; - -import com.amadornes.artifactural.api.artifact.Artifact; -import com.amadornes.artifactural.api.artifact.ArtifactMetadata; - -import java.util.function.UnaryOperator; - -public interface ArtifactTransformer { - - static ArtifactTransformer of(UnaryOperator operator) { - return new ArtifactTransformer() { - @Override - public Artifact transform(Artifact artifact) { - return operator.apply(artifact); - } - - @Override - public ArtifactMetadata withInfo(ArtifactMetadata metadata) { - return metadata; - } - }; - } - - default boolean appliesTo(Artifact artifact) { - return true; - } - - Artifact transform(Artifact artifact); - - ArtifactMetadata withInfo(ArtifactMetadata metadata); - - default ArtifactTransformer andThen(ArtifactTransformer other) { - ArtifactTransformer current = this; - return new ArtifactTransformer() { - - @Override - public Artifact transform(Artifact artifact) { - return other.transform(current.transform(artifact)); - } - - @Override - public ArtifactMetadata withInfo(ArtifactMetadata metadata) { - return other.withInfo(current.withInfo(metadata)); - } - - }; - } - -} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java new file mode 100644 index 0000000..3d444fa --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java @@ -0,0 +1,65 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import net.minecraftforge.artifactural.api.cache.ArtifactCache; +import net.minecraftforge.artifactural.api.transform.ArtifactTransformer; + +public interface Artifact { + + static Artifact none() { + return Internal.NO_ARTIFACT; + } + + ArtifactIdentifier getIdentifier(); + + ArtifactMetadata getMetadata(); + + ArtifactType getType(); + + Artifact withMetadata(ArtifactMetadata metadata); + + Artifact apply(ArtifactTransformer transformer); + + Artifact.Cached cache(ArtifactCache cache); + + default Artifact.Cached optionallyCache(ArtifactCache cache) { + return this instanceof Artifact.Cached ? (Artifact.Cached) this : cache(cache); + } + + boolean isPresent(); + + InputStream openStream() throws IOException, MissingArtifactException; + + interface Cached extends Artifact { + + // Gets the file location, AND writes the file to disc if it hasn't already. + File asFile() throws IOException, MissingArtifactException; + + // Gets the file location, but doesn't guarantee that it exists. As the wrapped Artifact may not of been written. What's the point of this? + File getFileLocation() throws IOException, MissingArtifactException; + + } + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java new file mode 100644 index 0000000..6485a59 --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java @@ -0,0 +1,80 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +import java.util.function.Predicate; + +public interface ArtifactIdentifier { + + static ArtifactIdentifier none() { + return Internal.NO_IDENTIFIER; + } + + String getGroup(); + + String getName(); + + String getVersion(); + + String getClassifier(); + + String getExtension(); + + static Predicate groupMatches(String group) { + return identifier -> identifier.getGroup().matches(group); + } + + static Predicate nameMatches(String name) { + return identifier -> identifier.getName().matches(name); + } + + static Predicate versionMatches(String version) { + return identifier -> identifier.getVersion().matches(version); + } + + static Predicate classifierMatches(String classifier) { + return identifier -> identifier.getClassifier().matches(classifier); + } + + static Predicate extensionMatches(String extension) { + return identifier -> identifier.getExtension().matches(extension); + } + + static Predicate groupEquals(String group) { + return identifier -> identifier.getGroup().equals(group); + } + + static Predicate nameEquals(String name) { + return identifier -> identifier.getName().equals(name); + } + + static Predicate versionEquals(String version) { + return identifier -> identifier.getVersion().equals(version); + } + + static Predicate classifierEquals(String classifier) { + return identifier -> identifier.getClassifier().equals(classifier); + } + + static Predicate extensionEquals(String extension) { + return identifier -> identifier.getExtension().equals(extension); + } + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java new file mode 100644 index 0000000..6bdf854 --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java @@ -0,0 +1,28 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +public interface ArtifactMetadata { + + ArtifactMetadata with(String key, String value); + + String getHash(); + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java new file mode 100644 index 0000000..e2d717c --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java @@ -0,0 +1,24 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +public enum ArtifactType { + BINARY, SOURCE, OTHER +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java new file mode 100644 index 0000000..4e9a03c --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java @@ -0,0 +1,137 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +import java.io.File; +import java.io.InputStream; + +import net.minecraftforge.artifactural.api.cache.ArtifactCache; +import net.minecraftforge.artifactural.api.transform.ArtifactTransformer; + +final class Internal { + + static final ArtifactIdentifier NO_IDENTIFIER = new ArtifactIdentifier() { + + @Override + public String getGroup() { + return "missing"; + } + + @Override + public String getName() { + return "missing"; + } + + @Override + public String getVersion() { + return "0.0.0"; + } + + @Override + public String getClassifier() { + return ""; + } + + @Override + public String getExtension() { + return "missing"; + } + + @Override + public String toString() { + return "NO_IDENTIFIER"; + } + + }; + + static final Artifact NO_ARTIFACT = new Artifact.Cached() { + @Override + public String toString() { + return "NO_ARTIFACT"; + } + + @Override + public ArtifactIdentifier getIdentifier() { + return ArtifactIdentifier.none(); + } + + @Override + public ArtifactMetadata getMetadata() { + return new ArtifactMetadata() { + @Override + public ArtifactMetadata with(String key, String value) { + throw new UnsupportedOperationException(); + } + + @Override + public String getHash() { + return "ERROR"; + } + + @Override + public String toString() { + return "NO_METADATA"; + } + }; + } + + @Override + public ArtifactType getType() { + return ArtifactType.OTHER; + } + + @Override + public Artifact withMetadata(ArtifactMetadata metadata) { + return this; + } + + @Override + public Artifact apply(ArtifactTransformer transformer) { + return this; + } + + @Override + public Artifact.Cached cache(ArtifactCache cache) { + return this; + } + + @Override + public boolean isPresent() { + return false; + } + + @Override + public InputStream openStream() throws MissingArtifactException { + 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/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java new file mode 100644 index 0000000..18686a6 --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java @@ -0,0 +1,29 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +public class MissingArtifactException extends RuntimeException { + private static final long serialVersionUID = 4902516963452435653L; + + public MissingArtifactException(ArtifactIdentifier identifier) { + super("Could not find artifact: " + identifier); + } + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java new file mode 100644 index 0000000..fa073e5 --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java @@ -0,0 +1,30 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.artifact; + +import java.io.IOException; +import java.io.InputStream; + +@FunctionalInterface +public interface Streamable { + + InputStream openStream() throws IOException; + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java b/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java new file mode 100644 index 0000000..9681b0d --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java @@ -0,0 +1,28 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.cache; + +import net.minecraftforge.artifactural.api.artifact.Artifact; + +public interface ArtifactCache { + + Artifact.Cached store(Artifact artifact); + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java b/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java new file mode 100644 index 0000000..cdcfc1a --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java @@ -0,0 +1,47 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.repository; + +import java.util.function.Function; +import java.util.function.Predicate; + +import net.minecraftforge.artifactural.api.artifact.Artifact; + +public interface ArtifactProvider { + + Artifact getArtifact(I info); + + interface Builder { + + Builder filter(Predicate filter); + + Builder mapInfo(Function mapper); + + Complete provide(ArtifactProvider provider); + + interface Complete extends ArtifactProvider { + + Complete provide(ArtifactProvider provider); + + } + + } + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java b/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java new file mode 100644 index 0000000..e9694d8 --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java @@ -0,0 +1,44 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.repository; + +import java.io.File; + +import net.minecraftforge.artifactural.api.artifact.Artifact; +import net.minecraftforge.artifactural.api.artifact.ArtifactIdentifier; + +public interface Repository { + + Artifact getArtifact(ArtifactIdentifier identifier); + + /** + * Returns a file in maven-metadata.xml format for the specified artifact, + * this is used by gradle to list all known versions, so that it can resolve wildcard + * dependencies such as foo:bar:1.+ + * + * @param group Group + * @param name Artifact name + * @return maven-metadata.xml file listing all versions of the artifact this repo can provide. Or null if you don't want to list any. + */ + default File getMavenMetadata(String group, String name) { + return null; + } + +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java b/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java new file mode 100644 index 0000000..86a43ca --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java @@ -0,0 +1,68 @@ +/* + * Artifactural + * Copyright (c) 2018-2021. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.artifactural.api.transform; + +import java.util.function.UnaryOperator; + +import net.minecraftforge.artifactural.api.artifact.Artifact; +import net.minecraftforge.artifactural.api.artifact.ArtifactMetadata; + +public interface ArtifactTransformer { + + static ArtifactTransformer of(UnaryOperator operator) { + return new ArtifactTransformer() { + @Override + public Artifact transform(Artifact artifact) { + return operator.apply(artifact); + } + + @Override + public ArtifactMetadata withInfo(ArtifactMetadata metadata) { + return metadata; + } + }; + } + + default boolean appliesTo(Artifact artifact) { + return true; + } + + Artifact transform(Artifact artifact); + + ArtifactMetadata withInfo(ArtifactMetadata metadata); + + default ArtifactTransformer andThen(ArtifactTransformer other) { + ArtifactTransformer current = this; + return new ArtifactTransformer() { + + @Override + public Artifact transform(Artifact artifact) { + return other.transform(current.transform(artifact)); + } + + @Override + public ArtifactMetadata withInfo(ArtifactMetadata metadata) { + return other.withInfo(current.withInfo(metadata)); + } + + }; + } + +} -- cgit