mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
Support MinimalExternalModuleDependency's as a FileSpec input (#785)
This commit is contained in:
@@ -28,6 +28,7 @@ import java.nio.file.Path;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
|
||||
import org.gradle.api.logging.Logger;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -39,6 +40,8 @@ import net.fabricmc.mappingio.tree.MemoryMappingTree;
|
||||
public interface MappingContext {
|
||||
Path resolveDependency(Dependency dependency);
|
||||
|
||||
Path resolveDependency(MinimalExternalModuleDependency dependency);
|
||||
|
||||
Path resolveMavenDependency(String mavenNotation);
|
||||
|
||||
Supplier<MemoryMappingTree> intermediaryTree();
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
|
||||
import org.gradle.api.file.FileSystemLocation;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.provider.Provider;
|
||||
@@ -38,9 +39,10 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.DependencyFileSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.URLFileSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.LocalFileSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.MavenFileSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.MinimalExternalModuleDependencyFileSpec;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.utils.URLFileSpec;
|
||||
|
||||
/**
|
||||
* FileSpec should be used in MappingsSpec's that take an input file. The input file can either be a local file or a gradle dep.
|
||||
@@ -56,6 +58,7 @@ public interface FileSpec {
|
||||
* <li>{@link Provider} (including {@link org.gradle.api.provider.Property}) will recursively be resolved as its current value</li>
|
||||
* <li>{@link CharSequence} (including {@link String} and {@link groovy.lang.GString}) will be resolved as Maven dependencies</li>
|
||||
* <li>{@link Dependency} will be resolved as any dependency</li>
|
||||
* <li>{@link MinimalExternalModuleDependency} will be resolved as any dependency</li>
|
||||
* <li>{@code FileSpec} will just return the spec itself</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -75,6 +78,8 @@ public interface FileSpec {
|
||||
}
|
||||
|
||||
return createFromMavenDependency(s.toString());
|
||||
} else if (o instanceof MinimalExternalModuleDependency d) {
|
||||
return createFromMinimalExternalModuleDependency(d);
|
||||
} else if (o instanceof Dependency d) {
|
||||
return createFromDependency(d);
|
||||
} else if (o instanceof Provider<?> p) {
|
||||
@@ -123,5 +128,9 @@ public interface FileSpec {
|
||||
return createFromFile(regularFileProperty.get());
|
||||
}
|
||||
|
||||
static FileSpec createFromMinimalExternalModuleDependency(MinimalExternalModuleDependency externalModuleDependency) {
|
||||
return new MinimalExternalModuleDependencyFileSpec(externalModuleDependency);
|
||||
}
|
||||
|
||||
Path get(MappingContext context);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.function.Supplier;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
|
||||
import org.gradle.api.artifacts.ResolutionStrategy;
|
||||
import org.gradle.api.logging.Logger;
|
||||
|
||||
@@ -65,6 +66,11 @@ public class GradleMappingContext implements MappingContext {
|
||||
return resolveDependency(project.getDependencies().create(mavenNotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolveDependency(MinimalExternalModuleDependency dependency) {
|
||||
return resolveDependency(project.getDependencies().create(dependency));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<MemoryMappingTree> intermediaryTree() {
|
||||
return () -> {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.configuration.providers.mappings.utils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.gradle.api.artifacts.MinimalExternalModuleDependency;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingContext;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.FileSpec;
|
||||
|
||||
public record MinimalExternalModuleDependencyFileSpec(MinimalExternalModuleDependency dependency) implements FileSpec {
|
||||
@Override
|
||||
public Path get(MappingContext context) {
|
||||
return context.resolveDependency(dependency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(dependency.getModule().getGroup(), dependency.getModule().getName(), dependency.getVersionConstraint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof MinimalExternalModuleDependencyFileSpec other) {
|
||||
return other.dependency().equals(this.dependency());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user