diff --git a/build.gradle b/build.gradle index 512d850..70c7e75 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,7 @@ tasks.withType(JavaCompile).configureEach { tasks.register('transformJar', JarTransformationTask) { addTransformer('net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter') { it.methods.find { - it.name == '' && it.desc == '(Lnet/minecraftforge/artifactural/api/repository/Repository;Lorg/gradle/api/internal/artifacts/repositories/DefaultMavenLocalArtifactRepository;)V' + it.name == '' && it.desc == '(Lorg/gradle/api/artifacts/ConfigurationContainer;Lnet/minecraftforge/artifactural/api/repository/Repository;Lorg/gradle/api/internal/artifacts/repositories/DefaultMavenLocalArtifactRepository;)V' }?.tap { it.instructions.find { it instanceof InsnNode && it.opcode == Opcodes.ACONST_NULL @@ -258,6 +258,6 @@ publishing { } } -changelog { - from '3.0' -} +//changelog { +// from '3.0' +//} diff --git a/header.txt b/header.txt index 74e543c..891bc8b 100644 --- a/header.txt +++ b/header.txt @@ -1,5 +1,5 @@ Artifactural -Copyright (c) 2018-2021. +Copyright (c) 2018-2024. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java index 3d444fa..64762b6 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/Artifact.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,13 +19,13 @@ package net.minecraftforge.artifactural.api.artifact; +import net.minecraftforge.artifactural.api.cache.ArtifactCache; +import net.minecraftforge.artifactural.api.transform.ArtifactTransformer; + 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() { @@ -48,6 +48,10 @@ default Artifact.Cached optionallyCache(ArtifactCache cache) { return this instanceof Artifact.Cached ? (Artifact.Cached) this : cache(cache); } + default ArtifactAttributeCollection getAttributes() { + return getIdentifier().getAttributes(); + } + boolean isPresent(); InputStream openStream() throws IOException, MissingArtifactException; diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactAttribute.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactAttribute.java new file mode 100644 index 0000000..39af755 --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactAttribute.java @@ -0,0 +1,30 @@ +/* + * Artifactural + * Copyright (c) 2018-2024. + * + * 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 ArtifactAttribute { + static ArtifactAttribute create(String name, Class type) { + return new SimpleArtifactAttribute<>(name, type); + } + + String getName(); + + Class getType(); +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactAttributeCollection.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactAttributeCollection.java new file mode 100644 index 0000000..632f67f --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactAttributeCollection.java @@ -0,0 +1,35 @@ +/* + * Artifactural + * Copyright (c) 2018-2024. + * + * 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.Map.Entry; +import java.util.Set; + +public interface ArtifactAttributeCollection extends Iterable, Object>> { + static ArtifactAttributeCollection empty() { + return Internal.NO_ATTRIBUTES; + } + + T with(ArtifactAttribute attribute, T value); + + T get(ArtifactAttribute key); + + Set> keys(); +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java index 6485a59..81834ca 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactIdentifier.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -37,6 +37,8 @@ static ArtifactIdentifier none() { String getExtension(); + ArtifactAttributeCollection getAttributes(); + static Predicate groupMatches(String group) { return identifier -> identifier.getGroup().matches(group); } diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java index 6bdf854..9598828 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactMetadata.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java index e2d717c..80502a3 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/ArtifactType.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java index 4e9a03c..ed6c0e5 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/Internal.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,12 +21,39 @@ import java.io.File; import java.io.InputStream; +import java.util.Collections; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import net.minecraftforge.artifactural.api.cache.ArtifactCache; import net.minecraftforge.artifactural.api.transform.ArtifactTransformer; final class Internal { + static final ArtifactAttributeCollection NO_ATTRIBUTES = new ArtifactAttributeCollection() { + @Override + public T with(ArtifactAttribute attribute, T value) { + throw new UnsupportedOperationException(); + } + + @Override + public T get(ArtifactAttribute key) { + return null; + } + + @Override + public Set> keys() { + return Collections.emptySet(); + } + + @Override + public Iterator, Object>> iterator() { + return Collections., Object>>emptyList().iterator(); + } + }; + static final ArtifactIdentifier NO_IDENTIFIER = new ArtifactIdentifier() { @Override @@ -59,6 +86,10 @@ public String toString() { return "NO_IDENTIFIER"; } + @Override + public ArtifactAttributeCollection getAttributes() { + return NO_ATTRIBUTES; + } }; static final Artifact NO_ARTIFACT = new Artifact.Cached() { diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java index 18686a6..87370b8 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/MissingArtifactException.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/SimpleArtifactAttribute.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/SimpleArtifactAttribute.java new file mode 100644 index 0000000..2b799fc --- /dev/null +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/SimpleArtifactAttribute.java @@ -0,0 +1,40 @@ +/* + * Artifactural + * Copyright (c) 2018-2024. + * + * 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; + +final class SimpleArtifactAttribute implements ArtifactAttribute { + private final String name; + private final Class type; + + public SimpleArtifactAttribute(final String name, final Class type) { + this.name = name; + this.type = type; + } + + @Override + public String getName() { + return name; + } + + @Override + public Class getType() { + return type; + } +} diff --git a/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java b/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java index fa073e5..b0bd8d0 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java +++ b/src/api/java/net/minecraftforge/artifactural/api/artifact/Streamable.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java b/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java index 9681b0d..3a4f4d2 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java +++ b/src/api/java/net/minecraftforge/artifactural/api/cache/ArtifactCache.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java b/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java index cdcfc1a..c40c1db 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java +++ b/src/api/java/net/minecraftforge/artifactural/api/repository/ArtifactProvider.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java b/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java index e9694d8..908340d 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java +++ b/src/api/java/net/minecraftforge/artifactural/api/repository/Repository.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java b/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java index 86a43ca..80a87e0 100644 --- a/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java +++ b/src/api/java/net/minecraftforge/artifactural/api/transform/ArtifactTransformer.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/DependencyResolver.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/DependencyResolver.java index a0d8a00..50ac876 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/DependencyResolver.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/DependencyResolver.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleArtifact.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleArtifact.java index e099c73..fd738b2 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleArtifact.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleArtifact.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleAttributeCollection.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleAttributeCollection.java new file mode 100644 index 0000000..fa01ac8 --- /dev/null +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleAttributeCollection.java @@ -0,0 +1,33 @@ +/* + * Artifactural + * Copyright (c) 2018-2024. + * + * 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.gradle; + +import net.minecraftforge.artifactural.api.artifact.ArtifactAttribute; +import net.minecraftforge.artifactural.base.artifact.SimpleAttributeCollection; +import org.gradle.api.attributes.Attribute; +import org.gradle.api.attributes.AttributeContainer; + +public class GradleAttributeCollection extends SimpleAttributeCollection { + public GradleAttributeCollection(final AttributeContainer container) { + for (Attribute attribute : container.keySet()) { + values.put(ArtifactAttribute.create(attribute.getName(), attribute.getType()), container.getAttribute(attribute)); + } + } +} diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java index a0a74e5..fdae35b 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/GradleRepositoryAdapter.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,9 +24,11 @@ import net.minecraftforge.artifactural.api.artifact.MissingArtifactException; import net.minecraftforge.artifactural.api.repository.Repository; import net.minecraftforge.artifactural.base.artifact.SimpleArtifactIdentifier; +import net.minecraftforge.artifactural.base.artifact.SimpleAttributeCollection; import net.minecraftforge.artifactural.base.cache.LocatedArtifactCache; -import org.gradle.api.artifacts.ComponentMetadataSupplierDetails; +import org.gradle.api.Project; +import org.gradle.api.artifacts.*; import org.gradle.api.artifacts.component.ComponentArtifactIdentifier; import org.gradle.api.artifacts.component.ModuleComponentIdentifier; import org.gradle.api.artifacts.dsl.RepositoryHandler; @@ -80,8 +82,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; public class GradleRepositoryAdapter extends AbstractArtifactRepository implements ResolutionAwareRepository { @@ -89,8 +93,9 @@ public class GradleRepositoryAdapter extends AbstractArtifactRepository implemen "^(?\\S+(?:/\\S+)*)/(?\\S+)/(?\\S+)/" + "\\2-\\3(?:-(?[^.\\s]+))?\\.(?\\S+)$"); - public static GradleRepositoryAdapter add(RepositoryHandler handler, String name, File local, Repository repository) { - BaseRepositoryFactory factory = ReflectionUtils.get(handler, "repositoryFactory"); // We reflect here and create it manually so it DOESN'T get attached. + public static GradleRepositoryAdapter add(Project project, String name, File local, Repository repository) { + RepositoryHandler repositoryHandler = project.getRepositories(); + BaseRepositoryFactory factory = ReflectionUtils.get(repositoryHandler, "repositoryFactory"); // We reflect here and create it manually so it DOESN'T get attached. DefaultMavenLocalArtifactRepository maven = (DefaultMavenLocalArtifactRepository)factory.createMavenLocalRepository(); // We use maven local because it bypasses the caching and coping to .m2 maven.setUrl(local); maven.setName(name); @@ -103,17 +108,18 @@ public static GradleRepositoryAdapter add(RepositoryHandler handler, String name if (GradleVersion.current().compareTo(GradleVersion.version("7.6")) >= 0) { // If we are on gradle 7.6+ we want to use the super constructor with 2 arguments (with the VersionParser) - repo = new GradleRepositoryAdapter(repository, maven, getVersionParser(maven)); + repo = new GradleRepositoryAdapter(project.getConfigurations(), repository, maven, getVersionParser(maven)); } else { // If we are on gradle 4.10 - 7.5 we use the super constructor with only the ObjectFactory parameter - repo = new GradleRepositoryAdapter(repository, maven); + repo = new GradleRepositoryAdapter(project.getConfigurations(), repository, maven); } repo.setName(name); - handler.add(repo); + repositoryHandler.add(repo); return repo; } + private final ConfigurationContainer configurations; private final Repository repository; private final DefaultMavenLocalArtifactRepository local; private final String root; @@ -124,9 +130,10 @@ public static GradleRepositoryAdapter add(RepositoryHandler handler, String name // DO NOT change this without modifying 'build.gradle' // This constructor is used on Gradle 7.5.* and below @Deprecated // TODO - remove this constructor when we can break ABI compatibility - private GradleRepositoryAdapter(Repository repository, DefaultMavenLocalArtifactRepository local) { + private GradleRepositoryAdapter(ConfigurationContainer configurations, Repository repository, DefaultMavenLocalArtifactRepository local) { // This is replaced with a call to 'super(getObjectFactory(local))' super(getObjectFactory(local), null); + this.configurations = configurations; this.repository = repository; this.local = local; this.root = cleanRoot(local.getUrl()); @@ -134,8 +141,9 @@ private GradleRepositoryAdapter(Repository repository, DefaultMavenLocalArtifact } // This constructor is used on Gradle 7.6 and above - private GradleRepositoryAdapter(Repository repository, DefaultMavenLocalArtifactRepository local, VersionParser versionParser) { + private GradleRepositoryAdapter(ConfigurationContainer configurations, Repository repository, DefaultMavenLocalArtifactRepository local, VersionParser versionParser) { super(getObjectFactory(local), versionParser); + this.configurations = configurations; this.repository = repository; this.local = local; this.root = cleanRoot(local.getUrl()); @@ -163,7 +171,7 @@ public String getDisplayName() { @Override @SuppressWarnings({"rawtypes", "unchecked"}) public ConfiguredModuleComponentRepository createResolver() { - MavenResolver resolver = (MavenResolver)local.createResolver(); + MavenResolver resolver = local.createResolver(); GeneratingFileResourceRepository repo = new GeneratingFileResourceRepository(); ReflectionUtils.alter(resolver, "repository", prev -> repo); // ExternalResourceResolver.repository @@ -364,14 +372,44 @@ private LocallyAvailableExternalResource findArtifact(String path) { debug(" Relative: " + relative); Matcher matcher = URL_PATTERN.matcher(relative); if (matcher.matches()) { - ArtifactIdentifier identifier = new SimpleArtifactIdentifier( - matcher.group("group").replace('/', '.'), - matcher.group("name"), - matcher.group("version"), - matcher.group("classifier"), - matcher.group("extension")); - Artifact artifact = repository.getArtifact(identifier); - return wrap(artifact, identifier); + String group = matcher.group("group").replace('/', '.'); + String name = matcher.group("name"); + String version = matcher.group("version"); + String classifier = matcher.group("classifier"); + String extension = matcher.group("extension"); + + // Find possible matching dependency candidates + Set candidates = configurations.stream() + .flatMap(config -> config.getIncoming().getDependencies().stream()) + .filter(dependency -> { + if(!(dependency instanceof ExternalModuleDependency)) { + return false; + } + String currentGroup = dependency.getGroup(); + if(currentGroup == null || !currentGroup.equals(group) || !dependency.getName().equals(name)) { + return false; + } + String currentVersion = dependency.getVersion(); + return currentVersion != null && currentVersion.equals(version); + }) + .map(ExternalModuleDependency.class::cast) + .collect(Collectors.toSet()); + + for(ExternalModuleDependency candidate : candidates) { + SimpleArtifactIdentifier identifier = new SimpleArtifactIdentifier( + group, + name, + version, + classifier, + extension, + new GradleAttributeCollection(candidate.getAttributes())); + Artifact artifact = repository.getArtifact(identifier); + if(artifact == Artifact.none()) { + continue; + } + return wrap(artifact, identifier); + } + return new LocalFileStandInExternalResource(new File(path), fileSystem); } else if (relative.endsWith("maven-metadata.xml")) { String tmp = relative.substring(0, relative.length() - "maven-metadata.xml".length() - 1); int idx = tmp.lastIndexOf('/'); diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java index 1c8cdac..5999fb5 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/RepositoryContentUtils.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/RepositoryContentUtils.java index 5adc1c3..1717b92 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/RepositoryContentUtils.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/RepositoryContentUtils.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/artifact/ArtifactBase.java b/src/shared/java/net/minecraftforge/artifactural/base/artifact/ArtifactBase.java index ddcc8a5..f48b2c7 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/artifact/ArtifactBase.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/artifact/ArtifactBase.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,10 +19,7 @@ package net.minecraftforge.artifactural.base.artifact; -import net.minecraftforge.artifactural.api.artifact.Artifact; -import net.minecraftforge.artifactural.api.artifact.ArtifactIdentifier; -import net.minecraftforge.artifactural.api.artifact.ArtifactMetadata; -import net.minecraftforge.artifactural.api.artifact.ArtifactType; +import net.minecraftforge.artifactural.api.artifact.*; import net.minecraftforge.artifactural.api.cache.ArtifactCache; import net.minecraftforge.artifactural.api.transform.ArtifactTransformer; @@ -68,5 +65,4 @@ public Artifact.Cached cache(ArtifactCache cache) { public String toString() { return getClass().getSimpleName() + "(" + identifier + ", " + type +", " + metadata; } - } diff --git a/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactIdentifier.java b/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactIdentifier.java index 5ab60f6..54710ec 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactIdentifier.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactIdentifier.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,18 +19,26 @@ package net.minecraftforge.artifactural.base.artifact; +import net.minecraftforge.artifactural.api.artifact.ArtifactAttributeCollection; import net.minecraftforge.artifactural.api.artifact.ArtifactIdentifier; public class SimpleArtifactIdentifier implements ArtifactIdentifier { private final String group, name, version, classifier, extension; + private final ArtifactAttributeCollection attributes; - public SimpleArtifactIdentifier(String group, String name, String version, String classifier, String extension) { + public SimpleArtifactIdentifier(String group, + String name, + String version, + String classifier, + String extension, + ArtifactAttributeCollection attributes) { this.group = group; this.name = name; this.version = version; this.classifier = classifier; this.extension = extension; + this.attributes = attributes; } @Override @@ -58,6 +66,11 @@ public String getExtension() { return extension; } + @Override + public ArtifactAttributeCollection getAttributes() { + return attributes; + } + @Override public String toString() { String ret = getGroup() + ':' + getName() + ':' + getVersion(); diff --git a/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactMetadata.java b/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactMetadata.java index 21a1f20..74cfac0 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactMetadata.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleArtifactMetadata.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleAttributeCollection.java b/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleAttributeCollection.java new file mode 100644 index 0000000..c824047 --- /dev/null +++ b/src/shared/java/net/minecraftforge/artifactural/base/artifact/SimpleAttributeCollection.java @@ -0,0 +1,54 @@ +/* + * Artifactural + * Copyright (c) 2018-2024. + * + * 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.base.artifact; + +import net.minecraftforge.artifactural.api.artifact.ArtifactAttribute; +import net.minecraftforge.artifactural.api.artifact.ArtifactAttributeCollection; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; +import java.util.Set; + +public class SimpleAttributeCollection implements ArtifactAttributeCollection { + protected final HashMap, Object> values = new HashMap<>(); + + @SuppressWarnings("unchecked") + @Override + public T get(ArtifactAttribute key) { + return (T) values.get(key); + } + + @SuppressWarnings("unchecked") + @Override + public T with(ArtifactAttribute attribute, T value) { + return (T) values.put(attribute, value); + } + + @Override + public Set> keys() { + return values.keySet(); + } + + @Override + public Iterator, Object>> iterator() { + return values.entrySet().iterator(); + } +} diff --git a/src/shared/java/net/minecraftforge/artifactural/base/artifact/StreamableArtifact.java b/src/shared/java/net/minecraftforge/artifactural/base/artifact/StreamableArtifact.java index 0428572..040482d 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/artifact/StreamableArtifact.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/artifact/StreamableArtifact.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/cache/ArtifactCacheBase.java b/src/shared/java/net/minecraftforge/artifactural/base/cache/ArtifactCacheBase.java index 3268871..4694076 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/cache/ArtifactCacheBase.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/cache/ArtifactCacheBase.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/cache/LocatedArtifactCache.java b/src/shared/java/net/minecraftforge/artifactural/base/cache/LocatedArtifactCache.java index 5627b50..bd87a56 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/cache/LocatedArtifactCache.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/cache/LocatedArtifactCache.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/repository/ArtifactProviderBuilder.java b/src/shared/java/net/minecraftforge/artifactural/base/repository/ArtifactProviderBuilder.java index 282f9b4..ab8aed1 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/repository/ArtifactProviderBuilder.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/repository/ArtifactProviderBuilder.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/repository/SimpleRepository.java b/src/shared/java/net/minecraftforge/artifactural/base/repository/SimpleRepository.java index 3076b08..7946dd8 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/repository/SimpleRepository.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/repository/SimpleRepository.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/util/HashFunction.java b/src/shared/java/net/minecraftforge/artifactural/base/util/HashFunction.java index bcf00f9..cdbbf30 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/util/HashFunction.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/util/HashFunction.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/shared/java/net/minecraftforge/artifactural/base/util/PatternReplace.java b/src/shared/java/net/minecraftforge/artifactural/base/util/PatternReplace.java index 6d3cf86..179388f 100644 --- a/src/shared/java/net/minecraftforge/artifactural/base/util/PatternReplace.java +++ b/src/shared/java/net/minecraftforge/artifactural/base/util/PatternReplace.java @@ -1,6 +1,6 @@ /* * Artifactural - * Copyright (c) 2018-2021. + * Copyright (c) 2018-2024. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public