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 +++++ .../artifactural/gradle/DependencyResolver.java | 124 -------- .../artifactural/gradle/GradleArtifact.java | 45 --- .../gradle/GradleRepositoryAdapter.java | 333 --------------------- .../artifactural/gradle/ModifierAccess.java | 55 ---- .../artifactural/gradle/ReflectionUtils.java | 112 ------- .../artifactural/gradle/DependencyResolver.java | 124 ++++++++ .../artifactural/gradle/GradleArtifact.java | 45 +++ .../gradle/GradleRepositoryAdapter.java | 333 +++++++++++++++++++++ .../artifactural/gradle/ModifierAccess.java | 55 ++++ .../artifactural/gradle/ReflectionUtils.java | 112 +++++++ .../artifactural/gradle/ModifierAccess.java | 57 ---- .../artifactural/gradle/ModifierAccess.java | 57 ++++ .../artifactural/base/artifact/ArtifactBase.java | 72 ----- .../base/artifact/SimpleArtifactIdentifier.java | 70 ----- .../base/artifact/SimpleArtifactMetadata.java | 86 ------ .../base/artifact/StreamableArtifact.java | 111 ------- .../artifactural/base/cache/ArtifactCacheBase.java | 129 -------- .../base/cache/LocatedArtifactCache.java | 69 ----- .../base/repository/ArtifactProviderBuilder.java | 100 ------- .../base/repository/SimpleRepository.java | 44 --- .../artifactural/base/util/HashFunction.java | 135 --------- .../artifactural/base/util/PatternReplace.java | 159 ---------- .../artifactural/base/artifact/ArtifactBase.java | 72 +++++ .../base/artifact/SimpleArtifactIdentifier.java | 70 +++++ .../base/artifact/SimpleArtifactMetadata.java | 86 ++++++ .../base/artifact/StreamableArtifact.java | 111 +++++++ .../artifactural/base/cache/ArtifactCacheBase.java | 129 ++++++++ .../base/cache/LocatedArtifactCache.java | 69 +++++ .../base/repository/ArtifactProviderBuilder.java | 100 +++++++ .../base/repository/SimpleRepository.java | 44 +++ .../artifactural/base/util/HashFunction.java | 135 +++++++++ .../artifactural/base/util/PatternReplace.java | 159 ++++++++++ 54 files changed, 2281 insertions(+), 2281 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 delete mode 100644 src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java delete mode 100644 src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java delete mode 100644 src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java delete mode 100644 src/gradlecomp/java/com/amadornes/artifactural/gradle/ModifierAccess.java delete mode 100644 src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java create mode 100644 src/gradlecomp/java/net/minecraftforge/artifactural/gradle/DependencyResolver.java create mode 100644 src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleArtifact.java create mode 100644 src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java create mode 100644 src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ModifierAccess.java create mode 100644 src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java delete mode 100644 src/java9/com/amadornes/artifactural/gradle/ModifierAccess.java create mode 100644 src/java9/net/minecraftforge/artifactural/gradle/ModifierAccess.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/artifact/ArtifactBase.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactIdentifier.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/artifact/SimpleArtifactMetadata.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/cache/ArtifactCacheBase.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/cache/LocatedArtifactCache.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/repository/ArtifactProviderBuilder.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/repository/SimpleRepository.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/util/HashFunction.java delete mode 100644 src/shared/java/com/amadornes/artifactural/base/util/PatternReplace.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/artifact/ArtifactBase.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactIdentifier.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactMetadata.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/artifact/StreamableArtifact.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/cache/ArtifactCacheBase.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/cache/LocatedArtifactCache.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/repository/ArtifactProviderBuilder.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/repository/SimpleRepository.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/util/HashFunction.java create mode 100644 src/shared/java/net/minecraftforge/artifactural/base/util/PatternReplace.java (limited to 'src') 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)); + } + + }; + } + +} diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java deleted file mode 100644 index 9040b63..0000000 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/DependencyResolver.java +++ /dev/null @@ -1,124 +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.gradle; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.gradle.api.Project; -import org.gradle.api.artifacts.ClientModule; -import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.Dependency; -import org.gradle.api.artifacts.DependencyArtifact; -import org.gradle.api.artifacts.FileCollectionDependency; -import org.gradle.api.artifacts.ModuleDependency; - -import java.io.File; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -public class DependencyResolver { - - private final Project project; - private final AtomicInteger counter = new AtomicInteger(0); - private final Cache>> resolved = CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES).build(); - - public DependencyResolver(Project project) { - this.project = project; - } - - /** - * Resolves a dependency, downloading the file and its transitives - * if not cached and returns the set of files. - */ - public Set resolveDependency(Dependency dependency) { - if (dependency instanceof FileCollectionDependency) { - return ((FileCollectionDependency) dependency).getFiles().getFiles(); - } - String name = dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion(); - if (dependency instanceof ModuleDependency) { - Set artifacts = ((ModuleDependency) dependency).getArtifacts(); - if (!artifacts.isEmpty()) { - DependencyArtifact artifact = artifacts.iterator().next(); - name += ":" + artifact.getClassifier() + "@" + artifact.getExtension(); - } - } - - // If this dep is being resolved on another thread, let it do it - CompletableFuture> future; - boolean found = true; - synchronized (resolved) { - future = resolved.getIfPresent(name); - if (future == null) { - resolved.put(name, future = new CompletableFuture<>()); - found = false; - } - } - - if (found) { - try { - return future.get(); - } catch (InterruptedException | ExecutionException ex) { - throw new RuntimeException(ex); - } - } - - // No other thread is resolving this dep and we've claimed it, so let's go! - int currentID = counter.getAndIncrement(); - Configuration cfg = project.getConfigurations().maybeCreate("resolve_dep_" + currentID); - cfg.getDependencies().add(dependency); - Set files = cfg.resolve(); - project.getConfigurations().remove(cfg); - future.complete(files); - return files; - } - - /** - * Resolves a dependency, downloading the file and its transitives - * if not cached and returns the set of files. - */ - public Set resolveDependency(Object dependency) { - Dependency dep = project.getDependencies().create(dependency); - return resolveDependency(dep); - } - - /** - * Resolves a dependency, downloading the file and its transitives - * if not cached and returns the set of files. - */ - public Set resolveDependency(Object dependency, boolean transitive) { - Dependency dep = project.getDependencies().create(dependency); - if (dep instanceof ClientModule) { - dep = ((ClientModule) dep).copy().setTransitive(transitive); - } - return resolveDependency(dep); - } - - /** - * Resolves a single dependency without any of its transitives - * if not cached and returns the file. - */ - public File resolveSingleDependency(Object dependency) { - return resolveDependency(dependency, false).iterator().next(); - } - -} diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java deleted file mode 100644 index b1fc537..0000000 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java +++ /dev/null @@ -1,45 +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.gradle; - -import com.amadornes.artifactural.api.artifact.Artifact; -import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; -import com.amadornes.artifactural.api.artifact.ArtifactType; -import com.amadornes.artifactural.base.artifact.StreamableArtifact; - -import java.io.File; -import java.util.Set; - -public class GradleArtifact { - - public static Artifact maven(DependencyResolver resolver, ArtifactIdentifier identifier, ArtifactType type) { - Set files = resolver.resolveDependency( - identifier.getGroup() - + ":" + identifier.getName() - + ":" + identifier.getVersion() - + (identifier.getClassifier().isEmpty() ? "" : ":" + identifier.getClassifier()) - + (identifier.getExtension().isEmpty() ? "" : "@" + identifier.getExtension()), - false - ); - if (files.isEmpty()) return Artifact.none(); - return StreamableArtifact.ofFile(identifier, type, files.iterator().next()); - } - -} diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java deleted file mode 100644 index 51def33..0000000 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleRepositoryAdapter.java +++ /dev/null @@ -1,333 +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.gradle; - -import com.amadornes.artifactural.api.artifact.Artifact; -import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; -import com.amadornes.artifactural.api.artifact.MissingArtifactException; -import com.amadornes.artifactural.api.repository.Repository; -import com.amadornes.artifactural.base.artifact.SimpleArtifactIdentifier; -import com.amadornes.artifactural.base.cache.LocatedArtifactCache; - -import org.gradle.api.artifacts.ComponentMetadataSupplierDetails; -import org.gradle.api.artifacts.component.ComponentArtifactIdentifier; -import org.gradle.api.artifacts.component.ModuleComponentIdentifier; -import org.gradle.api.artifacts.dsl.RepositoryHandler; -import org.gradle.api.internal.artifacts.BaseRepositoryFactory; -import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentResolvers; -import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ConfiguredModuleComponentRepository; -import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ModuleComponentRepositoryAccess; -import org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvableArtifact; -import org.gradle.api.internal.artifacts.repositories.AbstractArtifactRepository; -import org.gradle.api.internal.artifacts.repositories.DefaultMavenLocalArtifactRepository; -import org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository; -import org.gradle.api.internal.artifacts.repositories.descriptor.FlatDirRepositoryDescriptor; -import org.gradle.api.internal.artifacts.repositories.descriptor.RepositoryDescriptor; -import org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceArtifactResolver; -import org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver; -import org.gradle.api.internal.artifacts.repositories.resolver.MavenResolver; -import org.gradle.api.internal.artifacts.repositories.resolver.MetadataFetchingCost; -import org.gradle.api.internal.component.ArtifactType; -import org.gradle.api.model.ObjectFactory; -import org.gradle.internal.action.InstantiatingAction; -import org.gradle.internal.component.external.model.ModuleComponentResolveMetadata; -import org.gradle.internal.component.external.model.ModuleDependencyMetadata; -import org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata; -import org.gradle.internal.component.model.ComponentArtifactMetadata; -import org.gradle.internal.component.model.ComponentOverrideMetadata; -import org.gradle.internal.component.model.ComponentResolveMetadata; -import org.gradle.internal.component.model.ConfigurationMetadata; -import org.gradle.internal.component.model.ModuleSources; -import org.gradle.internal.nativeintegration.filesystem.FileSystem; -import org.gradle.internal.nativeintegration.services.FileSystems; -import org.gradle.internal.reflect.Instantiator; -import org.gradle.internal.resolve.result.BuildableArtifactResolveResult; -import org.gradle.internal.resolve.result.BuildableArtifactSetResolveResult; -import org.gradle.internal.resolve.result.BuildableComponentArtifactsResolveResult; -import org.gradle.internal.resolve.result.BuildableModuleComponen