mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
Merge remote-tracking branch 'FabricMC/exp/1.5' into exp/1.5
# Conflicts: # .github/workflows/publish.yml # gradle/libs.versions.toml # src/main/java/net/fabricmc/loom/LoomGradleExtension.java # src/main/java/net/fabricmc/loom/api/LoomGradleExtensionAPI.java # src/main/java/net/fabricmc/loom/build/nesting/IncludedJarFactory.java # src/main/java/net/fabricmc/loom/configuration/decompile/SingleJarDecompileConfiguration.java # src/main/java/net/fabricmc/loom/configuration/providers/mappings/tiny/TinyJarInfo.java # src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/AbstractMappedMinecraftProvider.java # src/main/java/net/fabricmc/loom/configuration/providers/minecraft/mapped/ProcessedNamedMinecraftProvider.java # src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java # src/main/java/net/fabricmc/loom/task/RemapTaskConfiguration.java # src/test/groovy/net/fabricmc/loom/test/unit/kotlin/KotlinRemapperClassloaderTest.groovy
This commit is contained in:
40
.gitattributes
vendored
40
.gitattributes
vendored
@@ -1,38 +1,2 @@
|
||||
# Handle line endings automatically for files detected as text
|
||||
# and leave all files detected as binary untouched.
|
||||
* text=auto
|
||||
|
||||
*.patch text eol=lf
|
||||
|
||||
#
|
||||
# The above will handle all files NOT found below
|
||||
#
|
||||
# These files are text and should be normalized (Convert crlf => lf)
|
||||
*.css text
|
||||
*.df text
|
||||
*.htm text
|
||||
*.html text
|
||||
*.java text
|
||||
*.js text
|
||||
*.json text
|
||||
*.jsp text
|
||||
*.jspf text
|
||||
*.properties text
|
||||
*.sh text
|
||||
*.tld text
|
||||
*.txt text
|
||||
*.xml text
|
||||
|
||||
# These files are binary and should be left untouched
|
||||
# (binary is a macro for -text -diff)
|
||||
*.class binary
|
||||
*.dll binary
|
||||
*.ear binary
|
||||
*.gif binary
|
||||
*.ico binary
|
||||
*.jar binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.png binary
|
||||
*.so binary
|
||||
*.war binary
|
||||
* text=auto eol=lf
|
||||
*.bat text eol=crlf
|
||||
11
.github/workflows/publish.yml
vendored
11
.github/workflows/publish.yml
vendored
@@ -22,7 +22,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v4
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
|
||||
# Generate the build number based on tags to allow per branch build numbers, not something github provides by default.
|
||||
- name: Generate build number
|
||||
id: buildnumber
|
||||
uses: onyxmueller/build-tag-number@v1
|
||||
with:
|
||||
token: ${{ secrets.github_token }}
|
||||
prefix: "build/${{ github.ref }}"
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
|
||||
26
.github/workflows/test-push.yml
vendored
26
.github/workflows/test-push.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
||||
image: gradle:${{ matrix.version }}
|
||||
options: --user root
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
- run: gradle build check -x test --stacktrace --warning-mode fail
|
||||
- uses: Juuxel/publish-checkstyle-report@v1
|
||||
@@ -25,6 +25,18 @@ jobs:
|
||||
reports: |
|
||||
build/reports/checkstyle/*.xml
|
||||
|
||||
build_windows:
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: setup jdk
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
- run: ./gradlew build check -x test --stacktrace --warning-mode fail
|
||||
|
||||
# This job is used to feed the test matrix of next job to allow the tests to run in parallel
|
||||
prepare_test_matrix:
|
||||
# Lets wait to ensure it builds before going running tests
|
||||
@@ -36,7 +48,7 @@ jobs:
|
||||
options: --user root
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- run: gradle writeActionsTestMatrix --stacktrace --warning-mode fail
|
||||
-
|
||||
id: set-matrix
|
||||
@@ -60,7 +72,7 @@ jobs:
|
||||
options: --user root
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- run: gradle printActionsTestName --name="${{ matrix.test }}" test --tests ${{ matrix.test }} --stacktrace --warning-mode fail
|
||||
env:
|
||||
TEST_WARNING_MODE: fail
|
||||
@@ -89,9 +101,9 @@ jobs:
|
||||
runs-on: windows-2022
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: setup jdk ${{ matrix.java }}
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'temurin'
|
||||
@@ -123,8 +135,8 @@ jobs:
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'temurin'
|
||||
|
||||
@@ -239,6 +239,8 @@ java {
|
||||
}
|
||||
|
||||
spotless {
|
||||
lineEndings = com.diffplug.spotless.LineEnding.UNIX
|
||||
|
||||
java {
|
||||
licenseHeaderFile(rootProject.file("HEADER")).yearSeparator("-")
|
||||
targetExclude("**/loom/util/DownloadUtil.java", "**/loom/util/FileSystemUtil.java")
|
||||
|
||||
@@ -4,15 +4,15 @@ asm = "9.6"
|
||||
commons-io = "2.15.0"
|
||||
gson = "2.10.1"
|
||||
jackson = "2.16.0"
|
||||
guava = "32.1.3-jre"
|
||||
guava = "33.0.0-jre"
|
||||
|
||||
stitch = "0.6.2"
|
||||
tiny-remapper = "1.10.23"
|
||||
access-widener = "2.1.0"
|
||||
mapping-io = "0.5.0"
|
||||
mapping-io = "0.5.1"
|
||||
lorenz-tiny = "4.0.2"
|
||||
mercury = "0.1.4.17"
|
||||
kotlinx-metadata = "0.7.0"
|
||||
kotlinx-metadata = "0.8.0"
|
||||
|
||||
# Plugins
|
||||
spotless = "6.20.0"
|
||||
|
||||
@@ -6,7 +6,7 @@ mockito = "5.7.0"
|
||||
java-debug = "0.49.0"
|
||||
mixin = "0.11.4+mixin.0.8.5"
|
||||
|
||||
gradle-nightly = "8.6-20231118001259+0000"
|
||||
gradle-nightly = "8.6-20231219002119+0000"
|
||||
fabric-loader = "0.14.24"
|
||||
fabric-installer = "0.11.1"
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraft
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.SrgMinecraftProvider;
|
||||
import net.fabricmc.loom.extension.LoomFiles;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
import net.fabricmc.loom.extension.RemapperExtensionHolder;
|
||||
import net.fabricmc.loom.util.ModPlatform;
|
||||
import net.fabricmc.loom.util.download.DownloadBuilder;
|
||||
|
||||
@@ -143,6 +144,8 @@ public interface LoomGradleExtension extends LoomGradleExtensionAPI {
|
||||
|
||||
ListProperty<LibraryProcessorManager.LibraryProcessorFactory> getLibraryProcessors();
|
||||
|
||||
ListProperty<RemapperExtensionHolder> getRemapperExtensions();
|
||||
|
||||
// ===================
|
||||
// Architectury Loom
|
||||
// ===================
|
||||
|
||||
@@ -46,6 +46,8 @@ import net.fabricmc.loom.api.decompilers.DecompilerOptions;
|
||||
import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
|
||||
import net.fabricmc.loom.api.processor.MinecraftJarProcessor;
|
||||
import net.fabricmc.loom.api.remapping.RemapperExtension;
|
||||
import net.fabricmc.loom.api.remapping.RemapperParameters;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.processors.JarProcessor;
|
||||
@@ -226,6 +228,13 @@ public interface LoomGradleExtensionAPI {
|
||||
|
||||
Property<Boolean> getSplitModDependencies();
|
||||
|
||||
<T extends RemapperParameters> void addRemapperExtension(Class<RemapperExtension<T>> remapperExtensionClass, Class<T> parametersClass, Action<T> parameterAction);
|
||||
|
||||
/**
|
||||
* @return The minecraft version, as a {@link Provider}.
|
||||
*/
|
||||
Provider<String> getMinecraftVersion();
|
||||
|
||||
// ===================
|
||||
// Architectury Loom
|
||||
// ===================
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.api.remapping;
|
||||
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
/**
|
||||
* Context for a {@link RemapperExtension}.
|
||||
*/
|
||||
public interface RemapperContext {
|
||||
/**
|
||||
* @return The {@link Remapper} instance
|
||||
*/
|
||||
Remapper remapper();
|
||||
|
||||
/**
|
||||
* @return the source namespace
|
||||
*/
|
||||
String sourceNamespace();
|
||||
|
||||
/**
|
||||
* @return the target namespace
|
||||
*/
|
||||
String targetNamespace();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.api.remapping;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
|
||||
/**
|
||||
* A remapper extension can be used to add extra processing to the remapping process.
|
||||
*
|
||||
* <p>Implementations of RemapperExtension's must have the following:
|
||||
* A single constructor annotated with {@link Inject}, and taking a single argument of the parameters.
|
||||
* Or a single constructor annotated with {@link Inject} taking no arguments, when the extension does not have any parameters.
|
||||
*
|
||||
* <p>Use {@link net.fabricmc.loom.api.LoomGradleExtensionAPI#addRemapperExtension(Class, Class, Action)} to register a remapper extension.
|
||||
*
|
||||
* @param <T> Parameter type for the extension. Should be {@link RemapperParameters.None} if the action does not have parameters.
|
||||
*/
|
||||
public interface RemapperExtension<T extends RemapperParameters> {
|
||||
/**
|
||||
* Return a {@link ClassVisitor} that will be used when remapping the given class.
|
||||
*
|
||||
* @param className The name of the class being remapped
|
||||
* @param remapperContext The remapper context
|
||||
* @param classVisitor The parent class visitor
|
||||
* @return A {@link ClassVisitor} that will be used when remapping the given class, or the given {@code classVisitor} if no extra processing is required for this class.
|
||||
*/
|
||||
ClassVisitor insertVisitor(String className, RemapperContext remapperContext, ClassVisitor classVisitor);
|
||||
}
|
||||
@@ -22,16 +22,21 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.kotlin.remapping;
|
||||
package net.fabricmc.loom.api.remapping;
|
||||
|
||||
import kotlin.Metadata;
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Similar story to JvmExtensionWrapper, lets abuse the fact that Java can call "internal" Kotlin APIs without reflection :).
|
||||
* Marker interface for parameter objects to {@link RemapperExtension}s.
|
||||
*
|
||||
* <p>Design based off of Gradle's {@link org.gradle.workers.WorkParameters}.
|
||||
*/
|
||||
public record KotlinClassMetadataWrapper(KotlinClassMetadata metadata) {
|
||||
public Metadata getAnnotationData() {
|
||||
return metadata.getAnnotationData$kotlinx_metadata_jvm();
|
||||
public interface RemapperParameters {
|
||||
final class None implements RemapperParameters {
|
||||
@ApiStatus.Internal
|
||||
public static None INSTANCE = new None();
|
||||
|
||||
private None() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.api.remapping;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
|
||||
/**
|
||||
* A remapper extension, that has direct access to the TinyRemapper APIs.
|
||||
*
|
||||
* <p>This API is not stable and may change without notice.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public interface TinyRemapperExtension {
|
||||
/**
|
||||
* See: {@link TinyRemapper.Builder#extraAnalyzeVisitor(TinyRemapper.AnalyzeVisitorProvider)}.
|
||||
*
|
||||
* @return A {@link TinyRemapper.AnalyzeVisitorProvider} or {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
default TinyRemapper.AnalyzeVisitorProvider getAnalyzeVisitorProvider() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* See: {@link TinyRemapper.Builder#extraPreApplyVisitor(TinyRemapper.ApplyVisitorProvider)}.
|
||||
*
|
||||
* @return A {@link TinyRemapper.ApplyVisitorProvider} or {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
default TinyRemapper.ApplyVisitorProvider getPreApplyVisitor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* See: {@link TinyRemapper.Builder#extraPostApplyVisitor(TinyRemapper.ApplyVisitorProvider)}.
|
||||
*
|
||||
* @return A {@link TinyRemapper.ApplyVisitorProvider} or {@code null}.
|
||||
*/
|
||||
@Nullable
|
||||
default TinyRemapper.ApplyVisitorProvider getPostApplyVisitor() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,8 @@ public final class IncludedJarFactory {
|
||||
}
|
||||
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
File tempDir = new File(extension.getFiles().getProjectBuildCache(), "temp/modprocessing");
|
||||
String childName = "temp/modprocessing/%s/%s/%s/%s".formatted(metadata.group().replace(".", "/"), metadata.name(), metadata.version(), input.getName());
|
||||
File tempDir = new File(extension.getFiles().getProjectBuildCache(), childName);
|
||||
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
@@ -182,15 +183,15 @@ public final class IncludedJarFactory {
|
||||
|
||||
File tempFile = new File(tempDir, input.getName());
|
||||
|
||||
if (tempFile.exists()) {
|
||||
tempFile.delete();
|
||||
if (tempFile.exists() && FabricModJsonFactory.isModJar(tempFile)) {
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
try {
|
||||
FileUtils.copyFile(input, tempFile);
|
||||
|
||||
// TODO generate Quilt qmjs natively
|
||||
ZipReprocessorUtil.appendZipEntry(tempFile, "fabric.mod.json", generateModForDependency(metadata).getBytes(StandardCharsets.UTF_8));
|
||||
ZipReprocessorUtil.appendZipEntry(tempFile.toPath(), "fabric.mod.json", generateModForDependency(metadata).getBytes(StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to add dummy mod while including %s".formatted(input), e);
|
||||
}
|
||||
|
||||
@@ -312,8 +312,10 @@ public abstract class CompileConfiguration implements Runnable {
|
||||
private void configureDecompileTasks(ConfigContext configContext) {
|
||||
final LoomGradleExtension extension = configContext.extension();
|
||||
|
||||
extension.getMinecraftJarConfiguration().get().getDecompileConfigurationBiFunction()
|
||||
.apply(configContext, extension.getNamedMinecraftProvider()).afterEvaluation();
|
||||
extension.getMinecraftJarConfiguration().get()
|
||||
.getDecompileConfigurationBiFunction()
|
||||
.apply(configContext.project(), extension.getNamedMinecraftProvider())
|
||||
.afterEvaluation();
|
||||
}
|
||||
|
||||
private Path getLockFile() {
|
||||
|
||||
@@ -25,10 +25,13 @@
|
||||
package net.fabricmc.loom.configuration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@@ -53,6 +56,8 @@ import org.w3c.dom.NodeList;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.download.DownloadException;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJson;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
|
||||
public abstract class FabricApiExtension {
|
||||
@@ -104,7 +109,6 @@ public abstract class FabricApiExtension {
|
||||
DataGenerationSettings settings = getProject().getObjects().newInstance(DataGenerationSettings.class);
|
||||
settings.getOutputDirectory().set(getProject().file("src/main/generated"));
|
||||
settings.getCreateRunConfiguration().convention(true);
|
||||
settings.getCreateSourceSet().convention(true);
|
||||
settings.getCreateSourceSet().convention(false);
|
||||
settings.getStrictValidation().convention(false);
|
||||
settings.getAddToResources().convention(true);
|
||||
@@ -117,7 +121,9 @@ public abstract class FabricApiExtension {
|
||||
if (settings.getAddToResources().get()) {
|
||||
mainSourceSet.resources(files -> {
|
||||
// Add the src/main/generated to the main sourceset's resources.
|
||||
files.getSrcDirs().add(outputDirectory);
|
||||
Set<File> srcDirs = new HashSet<>(files.getSrcDirs());
|
||||
srcDirs.add(outputDirectory);
|
||||
files.setSrcDirs(srcDirs);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -133,14 +139,10 @@ public abstract class FabricApiExtension {
|
||||
});
|
||||
|
||||
if (settings.getCreateSourceSet().get()) {
|
||||
if (!settings.getModId().isPresent()) {
|
||||
throw new IllegalStateException("DataGenerationSettings.getModId() must be set when using split sources.");
|
||||
}
|
||||
|
||||
SourceSetContainer sourceSets = SourceSetHelper.getSourceSets(getProject());
|
||||
|
||||
// Create the new datagen sourceset, depend on the main sourceset.
|
||||
sourceSets.create(DATAGEN_SOURCESET_NAME, sourceSet -> {
|
||||
SourceSet dataGenSourceSet = sourceSets.create(DATAGEN_SOURCESET_NAME, sourceSet -> {
|
||||
sourceSet.setCompileClasspath(
|
||||
sourceSet.getCompileClasspath()
|
||||
.plus(mainSourceSet.getOutput())
|
||||
@@ -155,6 +157,20 @@ public abstract class FabricApiExtension {
|
||||
extendsFrom(getProject(), sourceSet.getRuntimeClasspathConfigurationName(), mainSourceSet.getRuntimeClasspathConfigurationName());
|
||||
});
|
||||
|
||||
settings.getModId().convention(getProject().provider(() -> {
|
||||
try {
|
||||
final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(dataGenSourceSet);
|
||||
|
||||
if (fabricModJson == null) {
|
||||
throw new RuntimeException("Could not find a fabric.mod.json file in the data source set or a value for DataGenerationSettings.getModId()");
|
||||
}
|
||||
|
||||
return fabricModJson.getId();
|
||||
} catch (IOException e) {
|
||||
throw new org.gradle.api.UncheckedIOException("Failed to read mod id from the datagen source set.", e);
|
||||
}
|
||||
}));
|
||||
|
||||
extension.getMods().create(settings.getModId().get(), mod -> {
|
||||
// Create a classpath group for this mod. Assume that the main sourceset is already in a group.
|
||||
mod.sourceSet(DATAGEN_SOURCESET_NAME);
|
||||
@@ -165,7 +181,7 @@ public abstract class FabricApiExtension {
|
||||
|
||||
if (settings.getCreateRunConfiguration().get()) {
|
||||
extension.getRunConfigs().create("datagen", run -> {
|
||||
run.name("Data Generation");
|
||||
run.setConfigName("Data Generation");
|
||||
run.inherit(extension.getRunConfigs().getByName("server"));
|
||||
|
||||
run.property("fabric-api.datagen");
|
||||
|
||||
@@ -83,7 +83,8 @@ public abstract class LoomConfigurations implements Runnable {
|
||||
registerNonTransitive(Constants.Configurations.LOADER_DEPENDENCIES, Role.RESOLVABLE);
|
||||
|
||||
registerNonTransitive(Constants.Configurations.MINECRAFT, Role.NONE);
|
||||
registerNonTransitive(Constants.Configurations.INCLUDE, Role.RESOLVABLE);
|
||||
// We don't need to make this non-transitive due to the way we resolve it. Also, doing so would break platform dependencies.
|
||||
register(Constants.Configurations.INCLUDE, Role.RESOLVABLE);
|
||||
registerNonTransitive(Constants.Configurations.MAPPING_CONSTANTS, Role.RESOLVABLE);
|
||||
|
||||
register(Constants.Configurations.NAMED_ELEMENTS, Role.CONSUMABLE).configure(configuration -> {
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.MappedMinecraftProvider;
|
||||
import net.fabricmc.loom.task.GenerateSourcesTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
@@ -42,13 +42,15 @@ public abstract class DecompileConfiguration<T extends MappedMinecraftProvider>
|
||||
protected final LoomGradleExtension extension;
|
||||
protected final MappingConfiguration mappingConfiguration;
|
||||
|
||||
public DecompileConfiguration(ConfigContext configContext, T minecraftProvider) {
|
||||
this.project = configContext.project();
|
||||
public DecompileConfiguration(Project project, T minecraftProvider) {
|
||||
this.project = project;
|
||||
this.minecraftProvider = minecraftProvider;
|
||||
this.extension = configContext.extension();
|
||||
this.extension = LoomGradleExtension.get(project);
|
||||
this.mappingConfiguration = extension.getMappingConfiguration();
|
||||
}
|
||||
|
||||
public abstract String getTaskName(MinecraftJar.Type type);
|
||||
|
||||
public abstract void afterEvaluation();
|
||||
|
||||
protected final void configureUnpick(GenerateSourcesTask task, File unpickOutputJar) {
|
||||
|
||||
@@ -27,8 +27,9 @@ package net.fabricmc.loom.configuration.decompile;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.forge.MinecraftPatchedProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
@@ -38,8 +39,13 @@ import net.fabricmc.loom.task.GenerateSourcesTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public class SingleJarDecompileConfiguration extends DecompileConfiguration<MappedMinecraftProvider> {
|
||||
public SingleJarDecompileConfiguration(ConfigContext configContext, MappedMinecraftProvider minecraftProvider) {
|
||||
super(configContext, minecraftProvider);
|
||||
public SingleJarDecompileConfiguration(Project project, MappedMinecraftProvider minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskName(MinecraftJar.Type type) {
|
||||
return "genSources";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,10 +53,11 @@ public class SingleJarDecompileConfiguration extends DecompileConfiguration<Mapp
|
||||
final List<MinecraftJar> minecraftJars = minecraftProvider.getMinecraftJars();
|
||||
assert minecraftJars.size() == 1;
|
||||
final MinecraftJar minecraftJar = minecraftJars.get(0);
|
||||
final String taskBaseName = getTaskName(minecraftJar.getType());
|
||||
|
||||
LoomGradleExtension.get(project).getDecompilerOptions().forEach(options -> {
|
||||
final String decompilerName = options.getFormattedName();
|
||||
String taskName = "genSourcesWith" + decompilerName;
|
||||
String taskName = "%sWith%s".formatted(taskBaseName, decompilerName);
|
||||
// Decompiler will be passed to the constructor of GenerateSourcesTask
|
||||
project.getTasks().register(taskName, GenerateSourcesTask.class, options).configure(task -> {
|
||||
task.getInputJarName().set(minecraftJar.getName());
|
||||
@@ -67,7 +74,7 @@ public class SingleJarDecompileConfiguration extends DecompileConfiguration<Mapp
|
||||
});
|
||||
});
|
||||
|
||||
project.getTasks().register("genSources", task -> {
|
||||
project.getTasks().register(taskBaseName, task -> {
|
||||
task.setDescription("Decompile minecraft using the default decompiler.");
|
||||
task.setGroup(Constants.TaskGroup.FABRIC);
|
||||
|
||||
|
||||
@@ -27,19 +27,28 @@ package net.fabricmc.loom.configuration.decompile;
|
||||
import java.io.File;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
|
||||
import net.fabricmc.loom.api.decompilers.DecompilerOptions;
|
||||
import net.fabricmc.loom.configuration.ConfigContext;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.MappedMinecraftProvider;
|
||||
import net.fabricmc.loom.task.GenerateSourcesTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
|
||||
public final class SplitDecompileConfiguration extends DecompileConfiguration<MappedMinecraftProvider.Split> {
|
||||
public SplitDecompileConfiguration(ConfigContext configContext, MappedMinecraftProvider.Split minecraftProvider) {
|
||||
super(configContext, minecraftProvider);
|
||||
public SplitDecompileConfiguration(Project project, MappedMinecraftProvider.Split minecraftProvider) {
|
||||
super(project, minecraftProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskName(MinecraftJar.Type type) {
|
||||
return switch (type) {
|
||||
case COMMON -> "genCommonSources";
|
||||
case CLIENT_ONLY -> "genClientSources";
|
||||
default -> throw new AssertionError();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -113,8 +113,11 @@ public class RunConfig {
|
||||
return e;
|
||||
}
|
||||
|
||||
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String environment) {
|
||||
runConfig.configName += extension.isRootProject() ? "" : " (" + project.getPath() + ")";
|
||||
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String environment, boolean appendProjectPath) {
|
||||
if (appendProjectPath && !extension.isRootProject()) {
|
||||
runConfig.configName += " (" + project.getPath() + ")";
|
||||
}
|
||||
|
||||
runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName();
|
||||
|
||||
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
||||
@@ -170,9 +173,10 @@ public class RunConfig {
|
||||
runDir = "run";
|
||||
}
|
||||
|
||||
boolean appendProjectPath = settings.getAppendProjectPathToConfigName().get();
|
||||
RunConfig runConfig = new RunConfig();
|
||||
runConfig.configName = configName;
|
||||
populate(project, extension, runConfig, environment);
|
||||
populate(project, extension, runConfig, environment, appendProjectPath);
|
||||
runConfig.ideaModuleName = IdeaUtils.getIdeaModuleName(new SourceSetReference(sourceSet, project));
|
||||
runConfig.runDirIdeaUrl = "file://$PROJECT_DIR$/" + runDir;
|
||||
runConfig.runDir = runDir;
|
||||
|
||||
@@ -74,9 +74,20 @@ public class RunConfigSettings implements Named {
|
||||
* The full name of the run configuration, i.e. 'Minecraft Client'.
|
||||
*
|
||||
* <p>By default this is determined from the base name.
|
||||
*
|
||||
* <p>Note: unless the project is the root project (or {@link #appendProjectPathToConfigName} is disabled),
|
||||
* the project path will be appended automatically, e.g. 'Minecraft Client (:some:project)'.
|
||||
*/
|
||||
private String configName;
|
||||
|
||||
/**
|
||||
* Whether to append the project path to the {@link #configName} when {@code project} isn't the root project.
|
||||
*
|
||||
* <p>Warning: could produce ambiguous run config names if disabled, unless used carefully in conjunction with
|
||||
* {@link #configName}.
|
||||
*/
|
||||
private final Property<Boolean> appendProjectPathToConfigName;
|
||||
|
||||
/**
|
||||
* The default main class of the run configuration.
|
||||
*
|
||||
@@ -129,6 +140,7 @@ public class RunConfigSettings implements Named {
|
||||
public RunConfigSettings(Project project, String name) {
|
||||
this.name = name;
|
||||
this.project = project;
|
||||
this.appendProjectPathToConfigName = project.getObjects().property(Boolean.class).convention(true);
|
||||
this.extension = LoomGradleExtension.get(project);
|
||||
this.ideConfigGenerated = extension.isRootProject();
|
||||
this.mainClass = project.getObjects().property(String.class).convention(project.provider(() -> {
|
||||
@@ -210,6 +222,10 @@ public class RunConfigSettings implements Named {
|
||||
this.configName = name;
|
||||
}
|
||||
|
||||
public Property<Boolean> getAppendProjectPathToConfigName() {
|
||||
return appendProjectPathToConfigName;
|
||||
}
|
||||
|
||||
public String getDefaultMainClass() {
|
||||
return defaultMainClass;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.ide.idea;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.mods.dependency.LocalMavenHelper;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.mapped.NamedMinecraftProvider;
|
||||
|
||||
// See: https://github.com/JetBrains/intellij-community/blob/a09b1b84ab64a699794c860bc96774766dd38958/plugins/gradle/java/src/util/GradleAttachSourcesProvider.java
|
||||
record DownloadSourcesHook(Project project, Task task) {
|
||||
public static final String INIT_SCRIPT_NAME = "ijDownloadSources";
|
||||
private static final Pattern NOTATION_PATTERN = Pattern.compile("dependencyNotation = '(?<notation>.*)'");
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DownloadSourcesHook.class);
|
||||
|
||||
public static boolean hasInitScript(Project project) {
|
||||
List<File> initScripts = project.getGradle().getStartParameter().getInitScripts();
|
||||
|
||||
for (File initScript : initScripts) {
|
||||
if (initScript.getName().contains(INIT_SCRIPT_NAME)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void tryHook() {
|
||||
List<File> initScripts = project.getGradle().getStartParameter().getInitScripts();
|
||||
|
||||
for (File initScript : initScripts) {
|
||||
if (!initScript.getName().contains(INIT_SCRIPT_NAME)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
final String script = Files.readString(initScript.toPath(), StandardCharsets.UTF_8);
|
||||
final String notation = parseInitScript(script);
|
||||
|
||||
if (notation == null) {
|
||||
LOGGER.debug("failed to parse init script dependency");
|
||||
continue;
|
||||
}
|
||||
|
||||
final MinecraftJar.Type jarType = getJarType(notation);
|
||||
|
||||
if (jarType == null) {
|
||||
LOGGER.debug("init script is trying to download sources for another Minecraft jar ({}) not used by this project ({})", notation, project.getPath());
|
||||
continue;
|
||||
}
|
||||
|
||||
String sourcesTaskName = getGenSourcesTaskName(jarType);
|
||||
task.dependsOn(project.getTasks().named(sourcesTaskName));
|
||||
|
||||
LOGGER.info("Running genSources task: {} in project: {} for {}", sourcesTaskName, project.getPath(), notation);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String parseInitScript(String script) {
|
||||
if (!script.contains("IjDownloadTask")) {
|
||||
// Failed some basic sanity checks.
|
||||
return null;
|
||||
}
|
||||
|
||||
// A little gross but should do the job nicely.
|
||||
final Matcher matcher = NOTATION_PATTERN.matcher(script);
|
||||
|
||||
if (matcher.find()) {
|
||||
return matcher.group("notation");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getGenSourcesTaskName(MinecraftJar.Type jarType) {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
return extension.getMinecraftJarConfiguration().get()
|
||||
.getDecompileConfigurationBiFunction()
|
||||
.apply(project, extension.getNamedMinecraftProvider())
|
||||
.getTaskName(jarType);
|
||||
}
|
||||
|
||||
// Return the jar type, or null when this jar isnt used by the project
|
||||
@Nullable
|
||||
private MinecraftJar.Type getJarType(String name) {
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
final NamedMinecraftProvider<?> minecraftProvider = extension.getNamedMinecraftProvider();
|
||||
final List<MinecraftJar.Type> dependencyTypes = minecraftProvider.getDependencyTypes();
|
||||
|
||||
if (dependencyTypes.isEmpty()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
for (MinecraftJar.Type type : dependencyTypes) {
|
||||
final LocalMavenHelper mavenHelper = minecraftProvider.getMavenHelper(type).withClassifier("sources");
|
||||
|
||||
if (mavenHelper.getNotation().equals(name)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -24,40 +24,27 @@
|
||||
|
||||
package net.fabricmc.loom.configuration.ide.idea;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.StartParameter;
|
||||
import org.gradle.TaskExecutionRequest;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
import org.gradle.internal.DefaultTaskExecutionRequest;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJarConfiguration;
|
||||
import net.fabricmc.loom.task.LoomTasks;
|
||||
import net.fabricmc.loom.util.gradle.GradleUtils;
|
||||
|
||||
public abstract class IdeaConfiguration implements Runnable {
|
||||
private static final String INIT_SCRIPT_NAME = "ijmiscinit";
|
||||
private static final Pattern NOTATION_PATTERN = Pattern.compile("'net\\.minecraft:(?<name>.*):(.*):sources'");
|
||||
|
||||
@Inject
|
||||
protected abstract Project getProject();
|
||||
|
||||
public void run() {
|
||||
TaskProvider<IdeaSyncTask> ideaSyncTask = getProject().getTasks().register("ideaSyncTask", IdeaSyncTask.class, task -> {
|
||||
getProject().getTasks().register("ideaSyncTask", IdeaSyncTask.class, task -> {
|
||||
if (LoomGradleExtension.get(getProject()).getRunConfigs().stream().anyMatch(RunConfigSettings::isIdeConfigGenerated)) {
|
||||
task.dependsOn(LoomTasks.getIDELaunchConfigureTaskName(getProject()));
|
||||
} else {
|
||||
@@ -65,11 +52,7 @@ public abstract class IdeaConfiguration implements Runnable {
|
||||
}
|
||||
});
|
||||
|
||||
getProject().getTasks().configureEach(task -> {
|
||||
if (task.getName().equals("DownloadSources")) {
|
||||
hookDownloadSources(getProject(), task);
|
||||
}
|
||||
});
|
||||
hookDownloadSources();
|
||||
|
||||
if (!IdeaUtils.isIdeaSync()) {
|
||||
return;
|
||||
@@ -82,62 +65,27 @@ public abstract class IdeaConfiguration implements Runnable {
|
||||
startParameter.setTaskRequests(taskRequests);
|
||||
}
|
||||
|
||||
/*
|
||||
"Parse" the init script enough to figure out what jar we are talking about.
|
||||
private void hookDownloadSources() {
|
||||
LoomGradleExtension extension = LoomGradleExtension.get(getProject());
|
||||
|
||||
Intelij code: https://github.com/JetBrains/intellij-community/blob/a09b1b84ab64a699794c860bc96774766dd38958/plugins/gradle/java/src/util/GradleAttachSourcesProvider.java
|
||||
*/
|
||||
private static void hookDownloadSources(Project project, Task task) {
|
||||
List<File> initScripts = project.getGradle().getStartParameter().getInitScripts();
|
||||
if (!extension.isRootProject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (File initScript : initScripts) {
|
||||
if (!initScript.getName().contains(INIT_SCRIPT_NAME)) {
|
||||
continue;
|
||||
if (!DownloadSourcesHook.hasInitScript(getProject())) {
|
||||
return;
|
||||
}
|
||||
|
||||
getProject().getTasks().configureEach(task -> {
|
||||
if (task.getName().startsWith(DownloadSourcesHook.INIT_SCRIPT_NAME)) {
|
||||
getProject().allprojects(subProject -> {
|
||||
if (!GradleUtils.isLoomProject(subProject)) {
|
||||
return;
|
||||
}
|
||||
|
||||
new DownloadSourcesHook(subProject, task).tryHook();
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
final String script = Files.readString(initScript.toPath(), StandardCharsets.UTF_8);
|
||||
final String notation = parseInitScript(project, script);
|
||||
|
||||
if (notation != null) {
|
||||
task.dependsOn(getGenSourcesTaskName(LoomGradleExtension.get(project), notation));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String parseInitScript(Project project, String script) {
|
||||
if (!script.contains("Attempt to download sources from")
|
||||
|| !script.contains("downloadSources_")
|
||||
|| !script.contains("'%s'".formatted(project.getPath()))) {
|
||||
// Failed some basic sanity checks.
|
||||
return null;
|
||||
}
|
||||
|
||||
// A little gross but should do the job nicely.
|
||||
final Matcher matcher = NOTATION_PATTERN.matcher(script);
|
||||
|
||||
if (matcher.find()) {
|
||||
return matcher.group("name");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getGenSourcesTaskName(LoomGradleExtension extension, String notation) {
|
||||
final MinecraftJarConfiguration configuration = extension.getMinecraftJarConfiguration().get();
|
||||
|
||||
if (configuration == MinecraftJarConfiguration.SPLIT) {
|
||||
if (notation.toLowerCase(Locale.ROOT).contains("minecraft-clientonly")) {
|
||||
return "genClientOnlySources";
|
||||
}
|
||||
|
||||
return "genCommonSources";
|
||||
}
|
||||
|
||||
return "genSources";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +259,10 @@ public class ModConfigurationRemapper {
|
||||
|
||||
@Nullable
|
||||
public static Path findSources(Project project, ResolvedArtifact artifact) {
|
||||
if (isCIBuild()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final DependencyHandler dependencies = project.getDependencies();
|
||||
|
||||
@SuppressWarnings("unchecked") ArtifactResolutionQuery query = dependencies.createArtifactResolutionQuery()
|
||||
|
||||
@@ -59,6 +59,7 @@ import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.configuration.mods.dependency.ModDependency;
|
||||
import net.fabricmc.loom.configuration.providers.mappings.MappingConfiguration;
|
||||
import net.fabricmc.loom.extension.RemapperExtensionHolder;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.LoggerFilter;
|
||||
import net.fabricmc.loom.util.ModPlatform;
|
||||
@@ -197,6 +198,10 @@ public class ModProcessor {
|
||||
builder.extension(new MixinExtension(tag -> extension.isNeoForge() || remapMixins.contains(tag)));
|
||||
}
|
||||
|
||||
for (RemapperExtensionHolder holder : extension.getRemapperExtensions().get()) {
|
||||
holder.apply(builder, fromM, toM, project.getObjects());
|
||||
}
|
||||
|
||||
final TinyRemapper remapper = builder.build();
|
||||
|
||||
for (Path minecraftJar : extension.getMinecraftJars(IntermediaryNamespaces.intermediaryNamespace(project))) {
|
||||
|
||||
@@ -34,22 +34,7 @@ import java.nio.file.StandardCopyOption;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class LocalMavenHelper {
|
||||
private final String group;
|
||||
private final String name;
|
||||
private final String version;
|
||||
@Nullable
|
||||
private final String baseClassifier;
|
||||
private final Path root;
|
||||
|
||||
public LocalMavenHelper(String group, String name, String version, @Nullable String classifier, Path root) {
|
||||
this.group = group;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.baseClassifier = classifier;
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public record LocalMavenHelper(String group, String name, String version, @Nullable String baseClassifier, Path root) {
|
||||
public Path copyToMaven(Path artifact, @Nullable String classifier) throws IOException {
|
||||
if (!artifact.getFileName().toString().endsWith(".jar")) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -108,4 +93,8 @@ public final class LocalMavenHelper {
|
||||
: String.format("%s-%s-%s.jar", name, version, classifier);
|
||||
return getDirectory().resolve(fileName);
|
||||
}
|
||||
|
||||
public LocalMavenHelper withClassifier(String classifier) {
|
||||
return new LocalMavenHelper(group, name, version, classifier, root);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016-2022 FabricMC
|
||||
* Copyright (c) 2016-2023 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
|
||||
@@ -122,7 +122,7 @@ public class MappingConfiguration {
|
||||
final TinyJarInfo jarInfo = TinyJarInfo.get(inputJar);
|
||||
jarInfo.minecraftVersionId().ifPresent(id -> {
|
||||
if (!minecraftProvider.minecraftVersion().equals(id)) {
|
||||
LOGGER.warn("The mappings (%s) were not build for minecraft version (%s) produce with caution.".formatted(dependency.getDepString(), minecraftProvider.minecraftVersion()));
|
||||
LOGGER.warn("The mappings (%s) were not built for Minecraft version %s, proceed with caution.".formatted(dependency.getDepString(), minecraftProvider.minecraftVersion()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2022 FabricMC
|
||||
* Copyright (c) 2022-2023 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
|
||||
@@ -26,32 +26,52 @@ package net.fabricmc.loom.configuration.providers.mappings.tiny;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.mappingio.MappingReader;
|
||||
import net.fabricmc.mappingio.format.MappingFormat;
|
||||
|
||||
public record TinyJarInfo(boolean v2, Optional<String> minecraftVersionId) {
|
||||
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
|
||||
private static final String MANIFEST_VERSION_ID_ATTRIBUTE = "Minecraft-Version-Id";
|
||||
|
||||
public static TinyJarInfo get(Path jar) {
|
||||
try {
|
||||
return new TinyJarInfo(doesJarContainV2Mappings(jar), Optional.empty());
|
||||
try (FileSystemUtil.Delegate delegate = FileSystemUtil.getJarFileSystem(jar)) {
|
||||
return new TinyJarInfo(doesJarContainV2Mappings(delegate), getMinecraftVersionId(delegate));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to read tiny jar info", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean doesJarContainV2Mappings(Path path) throws IOException {
|
||||
try (FileSystemUtil.Delegate delegate = FileSystemUtil.getJarFileSystem(path)) {
|
||||
try (BufferedReader reader = Files.newBufferedReader(delegate.fs().getPath("mappings", "mappings.tiny"))) {
|
||||
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2_FILE;
|
||||
}
|
||||
private static boolean doesJarContainV2Mappings(FileSystemUtil.Delegate fs) throws IOException {
|
||||
try (BufferedReader reader = Files.newBufferedReader(fs.getPath("mappings", "mappings.tiny"))) {
|
||||
return MappingReader.detectFormat(reader) == MappingFormat.TINY_2_FILE;
|
||||
}
|
||||
} catch (NoSuchFileException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Optional<String> getMinecraftVersionId(FileSystemUtil.Delegate fs) throws IOException {
|
||||
final Path manifestPath = fs.getPath(MANIFEST_PATH);
|
||||
|
||||
if (Files.exists(manifestPath)) {
|
||||
final var manifest = new Manifest();
|
||||
|
||||
try (InputStream in = Files.newInputStream(manifestPath)) {
|
||||
manifest.read(in);
|
||||
}
|
||||
|
||||
final String minecraftVersionId = manifest.getMainAttributes().getValue(MANIFEST_VERSION_ID_ATTRIBUTE);
|
||||
return Optional.ofNullable(minecraftVersionId);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ import java.util.Objects;
|
||||
public abstract sealed class MinecraftJar permits MinecraftJar.Client, MinecraftJar.ClientOnly, MinecraftJar.Common, MinecraftJar.Merged, MinecraftJar.Server {
|
||||
private final Path path;
|
||||
private final boolean merged, client, server;
|
||||
private final String name;
|
||||
private final Type type;
|
||||
|
||||
protected MinecraftJar(Path path, boolean merged, boolean client, boolean server, String name) {
|
||||
protected MinecraftJar(Path path, boolean merged, boolean client, boolean server, Type type) {
|
||||
this.path = Objects.requireNonNull(path);
|
||||
this.merged = merged;
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Path getPath() {
|
||||
@@ -62,16 +62,18 @@ public abstract sealed class MinecraftJar permits MinecraftJar.Client, Minecraft
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract MinecraftJar forPath(Path path);
|
||||
|
||||
public static final class Merged extends MinecraftJar {
|
||||
public static final String NAME = "merged";
|
||||
|
||||
public Merged(Path path) {
|
||||
super(path, true, true, true, NAME);
|
||||
super(path, true, true, true, Type.MERGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,10 +83,8 @@ public abstract sealed class MinecraftJar permits MinecraftJar.Client, Minecraft
|
||||
}
|
||||
|
||||
public static final class Common extends MinecraftJar {
|
||||
public static final String NAME = "common";
|
||||
|
||||
public Common(Path path) {
|
||||
super(path, false, false, true, NAME);
|
||||
super(path, false, false, true, Type.COMMON);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,10 +94,8 @@ public abstract sealed class MinecraftJar permits MinecraftJar.Client, Minecraft
|
||||
}
|
||||
|
||||
public static final class Server extends MinecraftJar {
|
||||
public static final String NAME = "server";
|
||||
|
||||
public Server(Path path) {
|
||||
super(path, false, false, true, NAME);
|
||||
super(path, false, false, true, Type.SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,10 +106,8 @@ public abstract sealed class MinecraftJar permits MinecraftJar.Client, Minecraft
|
||||
|
||||
// Un-split client jar
|
||||
public static final class Client extends MinecraftJar {
|
||||
public static final String NAME = "client";
|
||||
|
||||
public Client(Path path) {
|
||||
super(path, false, true, false, NAME);
|
||||
super(path, false, true, false, Type.CLIENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,10 +118,8 @@ public abstract sealed class MinecraftJar permits MinecraftJar.Client, Minecraft
|
||||
|
||||
// Split client jar
|
||||
public static final class ClientOnly extends MinecraftJar {
|
||||
public static final String NAME = "clientOnly";
|
||||
|
||||
public ClientOnly(Path path) {
|
||||
super(path, false, true, false, NAME);
|
||||
super(path, false, true, false, Type.CLIENT_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,4 +127,28 @@ public abstract sealed class MinecraftJar permits MinecraftJar.Client, Minecraft
|
||||
return new ClientOnly(path);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
// Merged jar
|
||||
MERGED("merged"),
|
||||
|
||||
// Regular jars, not merged or split
|
||||
SERVER("server"),
|
||||
CLIENT("client"),
|
||||
|
||||
// Split jars
|
||||
COMMON("common"),
|
||||
CLIENT_ONLY("clientOnly");
|
||||
|
||||
private final String name;
|
||||
|
||||
Type(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public enum MinecraftJarConfiguration {
|
||||
private final BiFunction<Project, MinecraftProvider, SrgMinecraftProvider<?>> srgMinecraftProviderBiFunction;
|
||||
private final BiFunction<Project, MinecraftProvider, MojangMappedMinecraftProvider<?>> mojangMappedMinecraftProviderBiFunction;
|
||||
private final BiFunction<NamedMinecraftProvider<?>, MinecraftJarProcessorManager, ProcessedNamedMinecraftProvider<?, ?>> processedNamedMinecraftProviderBiFunction;
|
||||
private final BiFunction<ConfigContext, MappedMinecraftProvider, DecompileConfiguration<?>> decompileConfigurationBiFunction;
|
||||
private final BiFunction<Project, MappedMinecraftProvider, DecompileConfiguration<?>> decompileConfigurationBiFunction;
|
||||
private final List<String> supportedEnvironments;
|
||||
|
||||
@SuppressWarnings("unchecked") // Just a bit of a generic mess :)
|
||||
@@ -102,7 +102,7 @@ public enum MinecraftJarConfiguration {
|
||||
BiFunction<Project, M, SrgMinecraftProvider<M>> srgMinecraftProviderBiFunction,
|
||||
BiFunction<Project, M, MojangMappedMinecraftProvider<M>> mojangMappedMinecraftProviderBiFunction,
|
||||
BiFunction<P, MinecraftJarProcessorManager, ProcessedNamedMinecraftProvider<M, P>> processedNamedMinecraftProviderBiFunction,
|
||||
BiFunction<ConfigContext, Q, DecompileConfiguration<?>> decompileConfigurationBiFunction,
|
||||
BiFunction<Project, Q, DecompileConfiguration<?>> decompileConfigurationBiFunction,
|
||||
List<String> supportedEnvironments
|
||||
) {
|
||||
this.minecraftProviderFunction = (Function<ConfigContext, MinecraftProvider>) minecraftProviderFunction;
|
||||
@@ -111,7 +111,7 @@ public enum MinecraftJarConfiguration {
|
||||
this.srgMinecraftProviderBiFunction = (BiFunction<Project, MinecraftProvider, SrgMinecraftProvider<?>>) (Object) srgMinecraftProviderBiFunction;
|
||||
this.mojangMappedMinecraftProviderBiFunction = (BiFunction<Project, MinecraftProvider, MojangMappedMinecraftProvider<?>>) (Object) mojangMappedMinecraftProviderBiFunction;
|
||||
this.processedNamedMinecraftProviderBiFunction = (BiFunction<NamedMinecraftProvider<?>, MinecraftJarProcessorManager, ProcessedNamedMinecraftProvider<?, ?>>) (Object) processedNamedMinecraftProviderBiFunction;
|
||||
this.decompileConfigurationBiFunction = (BiFunction<ConfigContext, MappedMinecraftProvider, DecompileConfiguration<?>>) decompileConfigurationBiFunction;
|
||||
this.decompileConfigurationBiFunction = (BiFunction<Project, MappedMinecraftProvider, DecompileConfiguration<?>>) decompileConfigurationBiFunction;
|
||||
this.supportedEnvironments = supportedEnvironments;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public enum MinecraftJarConfiguration {
|
||||
return processedNamedMinecraftProviderBiFunction;
|
||||
}
|
||||
|
||||
public BiFunction<ConfigContext, MappedMinecraftProvider, DecompileConfiguration<?>> getDecompileConfigurationBiFunction() {
|
||||
public BiFunction<Project, MappedMinecraftProvider, DecompileConfiguration<?>> getDecompileConfigurationBiFunction() {
|
||||
return decompileConfigurationBiFunction;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract sealed class MinecraftSourceSets permits MinecraftSourceSets.Sin
|
||||
return LoomGradleExtension.get(project).areEnvironmentSourceSetsSplit() ? Split.INSTANCE : Single.INSTANCE;
|
||||
}
|
||||
|
||||
public abstract void applyDependencies(BiConsumer<String, String> consumer, List<String> targets);
|
||||
public abstract void applyDependencies(BiConsumer<String, MinecraftJar.Type> consumer, List<MinecraftJar.Type> targets);
|
||||
|
||||
public abstract String getSourceSetForEnv(String env);
|
||||
|
||||
@@ -104,8 +104,8 @@ public abstract sealed class MinecraftSourceSets permits MinecraftSourceSets.Sin
|
||||
private static final Single INSTANCE = new Single();
|
||||
|
||||
@Override
|
||||
public void applyDependencies(BiConsumer<String, String> consumer, List<String> targets) {
|
||||
for (String target : targets) {
|
||||
public void applyDependencies(BiConsumer<String, MinecraftJar.Type> consumer, List<MinecraftJar.Type> targets) {
|
||||
for (MinecraftJar.Type target : targets) {
|
||||
consumer.accept(MINECRAFT_NAMED.compile(), target);
|
||||
consumer.accept(MINECRAFT_NAMED.runtime(), target);
|
||||
}
|
||||
@@ -154,15 +154,15 @@ public abstract sealed class MinecraftSourceSets permits MinecraftSourceSets.Sin
|
||||
private static final Split INSTANCE = new Split();
|
||||
|
||||
@Override
|
||||
public void applyDependencies(BiConsumer<String, String> consumer, List<String> targets) {
|
||||
public void applyDependencies(BiConsumer<String, MinecraftJar.Type> consumer, List<MinecraftJar.Type> targets) {
|
||||
Preconditions.checkArgument(targets.size() == 2);
|
||||
Preconditions.checkArgument(targets.contains(MinecraftJar.Common.NAME));
|
||||
Preconditions.checkArgument(targets.contains(MinecraftJar.ClientOnly.NAME));
|
||||
Preconditions.checkArgument(targets.contains(MinecraftJar.Type.COMMON));
|
||||
Preconditions.checkArgument(targets.contains(MinecraftJar.Type.CLIENT_ONLY));
|
||||
|
||||
consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), MinecraftJar.Common.NAME);
|
||||
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), MinecraftJar.ClientOnly.NAME);
|
||||
consumer.accept(MINECRAFT_COMMON_NAMED.compile(), MinecraftJar.Common.NAME);
|
||||
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), MinecraftJar.ClientOnly.NAME);
|
||||
consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), MinecraftJar.Type.COMMON);
|
||||
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), MinecraftJar.Type.CLIENT_ONLY);
|
||||
consumer.accept(MINECRAFT_COMMON_NAMED.compile(), MinecraftJar.Type.COMMON);
|
||||
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), MinecraftJar.Type.CLIENT_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,22 +28,22 @@ import java.nio.file.Path;
|
||||
import java.util.function.Function;
|
||||
|
||||
public enum SingleJarEnvType {
|
||||
CLIENT(MinecraftJar.Client::new, MinecraftJar.Client.NAME),
|
||||
SERVER(MinecraftJar.Server::new, MinecraftJar.Server.NAME);
|
||||
CLIENT(MinecraftJar.Client::new, MinecraftJar.Type.CLIENT),
|
||||
SERVER(MinecraftJar.Server::new, MinecraftJar.Type.SERVER);
|
||||
|
||||
private final Function<Path, MinecraftJar> jarFunction;
|
||||
private final String name;
|
||||
private final MinecraftJar.Type type;
|
||||
|
||||
SingleJarEnvType(Function<Path, MinecraftJar> jarFunction, String name) {
|
||||
SingleJarEnvType(Function<Path, MinecraftJar> jarFunction, MinecraftJar.Type type) {
|
||||
this.jarFunction = jarFunction;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Function<Path, MinecraftJar> getJar() {
|
||||
return jarFunction;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public MinecraftJar.Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
|
||||
public abstract List<RemappedJars> getRemappedJars();
|
||||
|
||||
public List<String> getDependencyTargets() {
|
||||
// Returns a list of MinecraftJar.Type's that this provider exports to be used as a dependency
|
||||
public List<MinecraftJar.Type> getDependencyTypes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -96,11 +97,11 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
if (context.applyDependencies()) {
|
||||
final List<String> dependencyTargets = getDependencyTargets();
|
||||
final List<MinecraftJar.Type> dependencyTargets = getDependencyTypes();
|
||||
|
||||
if (!dependencyTargets.isEmpty()) {
|
||||
MinecraftSourceSets.get(getProject()).applyDependencies(
|
||||
(configuration, name) -> getProject().getDependencies().add(configuration, getDependencyNotation(name)),
|
||||
(configuration, type) -> getProject().getDependencies().add(configuration, getDependencyNotation(type)),
|
||||
dependencyTargets
|
||||
);
|
||||
}
|
||||
@@ -118,8 +119,8 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getJar(String name) {
|
||||
return getMavenHelper(name).getOutputFile(null);
|
||||
public Path getJar(MinecraftJar.Type type) {
|
||||
return getMavenHelper(type).getOutputFile(null);
|
||||
}
|
||||
|
||||
public enum MavenScope {
|
||||
@@ -141,16 +142,16 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
|
||||
public abstract MavenScope getMavenScope();
|
||||
|
||||
public LocalMavenHelper getMavenHelper(String name) {
|
||||
return new LocalMavenHelper("net.minecraft", getName(name), getVersion(), null, getMavenScope().getRoot(extension));
|
||||
public LocalMavenHelper getMavenHelper(MinecraftJar.Type type) {
|
||||
return new LocalMavenHelper("net.minecraft", getName(type), getVersion(), null, getMavenScope().getRoot(extension));
|
||||
}
|
||||
|
||||
protected String getName(String name) {
|
||||
protected String getName(MinecraftJar.Type type) {
|
||||
final String intermediateName = extension.getIntermediateMappingsProvider().getName();
|
||||
|
||||
var sj = new StringJoiner("-");
|
||||
sj.add("minecraft");
|
||||
sj.add(name);
|
||||
sj.add(type.toString());
|
||||
|
||||
// Include the intermediate mapping name if it's not the default intermediary
|
||||
if (!intermediateName.equals(IntermediaryMappingsProvider.NAME)) {
|
||||
@@ -168,13 +169,13 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
return "%s-%s".formatted(extension.getMinecraftProvider().minecraftVersion(), extension.getMappingConfiguration().mappingsIdentifier());
|
||||
}
|
||||
|
||||
protected String getDependencyNotation(String name) {
|
||||
return "net.minecraft:%s:%s".formatted(getName(name), getVersion());
|
||||
protected String getDependencyNotation(MinecraftJar.Type type) {
|
||||
return "net.minecraft:%s:%s".formatted(getName(type), getVersion());
|
||||
}
|
||||
|
||||
private boolean areOutputsValid(List<RemappedJars> remappedJars) {
|
||||
for (RemappedJars remappedJar : remappedJars) {
|
||||
if (!getMavenHelper(remappedJar.name()).exists(null)) {
|
||||
if (!getMavenHelper(remappedJar.type()).exists(null)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -224,7 +225,7 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
remapper.finish();
|
||||
}
|
||||
|
||||
getMavenHelper(remappedJars.name()).savePom();
|
||||
getMavenHelper(remappedJars.type()).savePom();
|
||||
|
||||
if (extension.isForgeLikeAndOfficial()) {
|
||||
try (var serviceManager = new ScopedSharedServiceManager()) {
|
||||
@@ -281,5 +282,9 @@ public abstract class AbstractMappedMinecraftProvider<M extends MinecraftProvide
|
||||
public String name() {
|
||||
return outputJar().getName();
|
||||
}
|
||||
|
||||
public MinecraftJar.Type type() {
|
||||
return outputJar().getType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,14 +38,12 @@ public interface MappedMinecraftProvider {
|
||||
List<MinecraftJar> getMinecraftJars();
|
||||
|
||||
interface ProviderImpl extends MappedMinecraftProvider {
|
||||
Path getJar(String name);
|
||||
Path getJar(MinecraftJar.Type type);
|
||||
}
|
||||
|
||||
interface Merged extends ProviderImpl {
|
||||
String MERGED = MinecraftJar.Merged.NAME;
|
||||
|
||||
default MinecraftJar getMergedJar() {
|
||||
return new MinecraftJar.Merged(getJar(MERGED));
|
||||
return new MinecraftJar.Merged(getJar(MinecraftJar.Type.MERGED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,15 +53,12 @@ public interface MappedMinecraftProvider {
|
||||
}
|
||||
|
||||
interface Split extends ProviderImpl {
|
||||
String COMMON = MinecraftJar.Common.NAME;
|
||||
String CLIENT_ONLY = MinecraftJar.ClientOnly.NAME;
|
||||
|
||||
default MinecraftJar getCommonJar() {
|
||||
return new MinecraftJar.Common(getJar(COMMON));
|
||||
return new MinecraftJar.Common(getJar(MinecraftJar.Type.COMMON));
|
||||
}
|
||||
|
||||
default MinecraftJar getClientOnlyJar() {
|
||||
return new MinecraftJar.ClientOnly(getJar(CLIENT_ONLY));
|
||||
return new MinecraftJar.ClientOnly(getJar(MinecraftJar.Type.CLIENT_ONLY));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,12 +70,12 @@ public interface MappedMinecraftProvider {
|
||||
interface SingleJar extends ProviderImpl {
|
||||
SingleJarEnvType env();
|
||||
|
||||
default String envName() {
|
||||
return env().getName();
|
||||
default MinecraftJar.Type envType() {
|
||||
return env().getType();
|
||||
}
|
||||
|
||||
default MinecraftJar getEnvOnlyJar() {
|
||||
return env().getJar().apply(getJar(envName()));
|
||||
return env().getJar().apply(getJar(env().getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.gradle.api.Project;
|
||||
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MergedMinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftJar;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.SingleJarEnvType;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.SingleJarMinecraftProvider;
|
||||
@@ -64,8 +65,8 @@ public abstract class NamedMinecraftProvider<M extends MinecraftProvider> extend
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDependencyTargets() {
|
||||
return List.of(MERGED);
|
||||
public List<MinecraftJar.Type> getDependencyTypes() {
|
||||
return List.of(MinecraftJar.Type.MERGED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +89,8 @@ public abstract class NamedMinecraftProvider<M extends MinecraftProvider> extend
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDependencyTargets() {
|
||||
return List.of(CLIENT_ONLY, COMMON);
|
||||
public List<MinecraftJar.Type> getDependencyTypes() {
|
||||
return List.of(MinecraftJar.Type.CLIENT_ONLY, MinecraftJar.Type.COMMON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +118,8 @@ public abstract class NamedMinecraftProvider<M extends MinecraftProvider> extend
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDependencyTargets() {
|
||||
return List.of(envName());
|
||||
public List<MinecraftJar.Type> getDependencyTypes() {
|
||||
return List.of(envType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class ProcessedNamedMinecraftProvider<M extends MinecraftProvide
|
||||
final MinecraftJar outputJar = entry.getValue();
|
||||
deleteSimilarJars(outputJar.getPath());
|
||||
|
||||
final LocalMavenHelper mavenHelper = getMavenHelper(minecraftJar.getName());
|
||||
final LocalMavenHelper mavenHelper = getMavenHelper(minecraftJar.getType());
|
||||
final Path outputPath = mavenHelper.copyToMaven(minecraftJar.getPath(), null);
|
||||
|
||||
assert outputJar.getPath().equals(outputPath);
|
||||
@@ -97,8 +97,13 @@ public abstract class ProcessedNamedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MinecraftJar.Type> getDependencyTypes() {
|
||||
return parentMinecraftProvider.getDependencyTypes();
|
||||
}
|
||||
|
||||
private void applyDependencies() {
|
||||
final List<String> dependencyTargets = parentMinecraftProvider.getDependencyTargets();
|
||||
final List<MinecraftJar.Type> dependencyTargets = getDependencyTypes();
|
||||
|
||||
if (dependencyTargets.isEmpty()) {
|
||||
return;
|
||||
@@ -125,14 +130,14 @@ public abstract class ProcessedNamedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(String name) {
|
||||
protected String getName(MinecraftJar.Type type) {
|
||||
final String jarPrefix = parentMinecraftProvider.getMinecraftProvider().getJarPrefix();
|
||||
// Hash the cache value so that we don't have to process the same JAR multiple times for many projects
|
||||
return jarPrefix + "minecraft-%s-%s".formatted(name, jarProcessorManager.getJarHash());
|
||||
return jarPrefix + "minecraft-%s-%s".formatted(type.toString(), jarProcessorManager.getJarHash());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getJar(String name) {
|
||||
public Path getJar(MinecraftJar.Type type) {
|
||||
// Something has gone wrong if this gets called.
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -154,7 +159,7 @@ public abstract class ProcessedNamedMinecraftProvider<M extends MinecraftProvide
|
||||
}
|
||||
|
||||
private Path getProcessedPath(MinecraftJar minecraftJar) {
|
||||
final LocalMavenHelper mavenHelper = getMavenHelper(minecraftJar.getName());
|
||||
final LocalMavenHelper mavenHelper = getMavenHelper(minecraftJar.getType());
|
||||
return mavenHelper.getOutputFile(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,6 @@ public final class LoomFilesProjectImpl extends LoomFilesBaseImpl {
|
||||
|
||||
@Override
|
||||
protected File getBuildDir() {
|
||||
return project.getBuildDir();
|
||||
return project.getLayout().getBuildDirectory().getAsFile().get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package net.fabricmc.loom.extension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -38,9 +39,11 @@ import org.gradle.api.Action;
|
||||
import org.gradle.api.NamedDomainObjectContainer;
|
||||
import org.gradle.api.NamedDomainObjectList;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.UncheckedIOException;
|
||||
import org.gradle.api.artifacts.Dependency;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.model.ObjectFactory;
|
||||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.provider.Provider;
|
||||
@@ -60,6 +63,8 @@ import net.fabricmc.loom.api.decompilers.DecompilerOptions;
|
||||
import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider;
|
||||
import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
|
||||
import net.fabricmc.loom.api.processor.MinecraftJarProcessor;
|
||||
import net.fabricmc.loom.api.remapping.RemapperExtension;
|
||||
import net.fabricmc.loom.api.remapping.RemapperParameters;
|
||||
import net.fabricmc.loom.configuration.RemapConfigurations;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
|
||||
@@ -73,6 +78,8 @@ import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.task.GenerateSourcesTask;
|
||||
import net.fabricmc.loom.util.DeprecationHelper;
|
||||
import net.fabricmc.loom.util.ModPlatform;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJson;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
|
||||
/**
|
||||
@@ -99,13 +106,12 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
private final Property<Boolean> splitEnvironmentalSourceSet;
|
||||
private final InterfaceInjectionExtensionAPI interfaceInjectionExtension;
|
||||
|
||||
private final ModVersionParser versionParser;
|
||||
|
||||
private final NamedDomainObjectContainer<RunConfigSettings> runConfigs;
|
||||
private final NamedDomainObjectContainer<DecompilerOptions> decompilers;
|
||||
private final NamedDomainObjectContainer<ModSettings> mods;
|
||||
private final NamedDomainObjectList<RemapConfigurationSettings> remapConfigurations;
|
||||
private final ListProperty<MinecraftJarProcessor<?>> minecraftJarProcessors;
|
||||
protected final ListProperty<RemapperExtensionHolder> remapperExtensions;
|
||||
|
||||
// A common mistake with layered mappings is to call the wrong `officialMojangMappings` method, use this to keep track of when we are building a layered mapping spec.
|
||||
protected final ThreadLocal<Boolean> layeredSpecBuilderScope = ThreadLocal.withInitial(() -> false);
|
||||
@@ -143,8 +149,6 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
this.intermediateMappingsProvider = project.getObjects().property(IntermediateMappingsProvider.class);
|
||||
this.intermediateMappingsProvider.finalizeValueOnRead();
|
||||
|
||||
this.versionParser = new ModVersionParser(project);
|
||||
|
||||
this.deprecationHelper = new DeprecationHelper.ProjectBased(project);
|
||||
|
||||
this.runConfigs = project.container(RunConfigSettings.class,
|
||||
@@ -174,6 +178,9 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
this.splitEnvironmentalSourceSet = project.getObjects().property(Boolean.class).convention(false);
|
||||
this.splitEnvironmentalSourceSet.finalizeValueOnRead();
|
||||
|
||||
remapperExtensions = project.getObjects().listProperty(RemapperExtensionHolder.class);
|
||||
remapperExtensions.finalizeValueOnRead();
|
||||
|
||||
// Enable dep iface injection by default
|
||||
interfaceInjection(interfaceInjection -> {
|
||||
interfaceInjection.getEnableDependencyInterfaceInjection().convention(true).finalizeValueOnRead();
|
||||
@@ -292,7 +299,17 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
|
||||
@Override
|
||||
public String getModVersion() {
|
||||
return versionParser.getModVersion();
|
||||
try {
|
||||
final FabricModJson fabricModJson = FabricModJsonFactory.createFromSourceSetsNullable(SourceSetHelper.getMainSourceSet(getProject()));
|
||||
|
||||
if (fabricModJson == null) {
|
||||
throw new RuntimeException("Could not find a fabric.mod.json file in the main sourceset");
|
||||
}
|
||||
|
||||
return fabricModJson.getModVersion();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to read mod version from main sourceset.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -430,6 +447,28 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
RemapConfigurations.setupForSourceSet(getProject(), sourceSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends RemapperParameters> void addRemapperExtension(Class<RemapperExtension<T>> remapperExtensionClass, Class<T> parametersClass, Action<T> parameterAction) {
|
||||
final ObjectFactory objectFactory = getProject().getObjects();
|
||||
final RemapperExtensionHolder holder;
|
||||
|
||||
if (parametersClass != RemapperParameters.None.class) {
|
||||
T parameters = objectFactory.newInstance(parametersClass);
|
||||
parameterAction.execute(parameters);
|
||||
holder = objectFactory.newInstance(RemapperExtensionHolder.class, parameters);
|
||||
} else {
|
||||
holder = objectFactory.newInstance(RemapperExtensionHolder.class, RemapperParameters.None.INSTANCE);
|
||||
}
|
||||
|
||||
holder.getRemapperExtensionClassName().set(remapperExtensionClass.getName());
|
||||
remapperExtensions.add(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Provider<String> getMinecraftVersion() {
|
||||
return getProject().provider(() -> LoomGradleExtension.get(getProject()).getMinecraftProvider().minecraftVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void silentMojangMappingsLicense() {
|
||||
this.silentMojangMappingsLicense = true;
|
||||
|
||||
@@ -288,6 +288,11 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
|
||||
return libraryProcessorFactories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListProperty<RemapperExtensionHolder> getRemapperExtensions() {
|
||||
return remapperExtensions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T extends IntermediateMappingsProvider> void configureIntermediateMappingsProviderInternal(T provider) {
|
||||
provider.getMinecraftVersion().set(getProject().provider(() -> getMinecraftProvider().minecraftVersion()));
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2021 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.extension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
|
||||
import net.fabricmc.loom.LoomGradlePlugin;
|
||||
|
||||
public class ModVersionParser {
|
||||
private final Project project;
|
||||
|
||||
private String version = null;
|
||||
|
||||
public ModVersionParser(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getModVersion() {
|
||||
if (version != null) {
|
||||
return version;
|
||||
}
|
||||
|
||||
File json = locateModJsonFile();
|
||||
JsonObject jsonObject;
|
||||
|
||||
try (var reader = new FileReader(json)) {
|
||||
jsonObject = LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read fabric.mod.json file");
|
||||
}
|
||||
|
||||
if (!jsonObject.has("version") || !jsonObject.get("version").isJsonPrimitive()) {
|
||||
throw new UnsupportedOperationException("Could not find valid version in the fabric.mod.json file");
|
||||
}
|
||||
|
||||
version = jsonObject.get("version").getAsString();
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
private File locateModJsonFile() {
|
||||
return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()
|
||||
.getByName("main")
|
||||
.getResources()
|
||||
.matching(patternFilterable -> patternFilterable.include("fabric.mod.json"))
|
||||
.getSingleFile();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.extension;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.model.ObjectFactory;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.Nested;
|
||||
import org.gradle.api.tasks.Optional;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
import net.fabricmc.loom.api.remapping.RemapperContext;
|
||||
import net.fabricmc.loom.api.remapping.RemapperExtension;
|
||||
import net.fabricmc.loom.api.remapping.RemapperParameters;
|
||||
import net.fabricmc.loom.api.remapping.TinyRemapperExtension;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.api.TrClass;
|
||||
|
||||
public abstract class RemapperExtensionHolder {
|
||||
// Null when RemapperParameters.None.class
|
||||
private final RemapperParameters remapperParameters;
|
||||
|
||||
@Inject
|
||||
public RemapperExtensionHolder(RemapperParameters remapperParameters) {
|
||||
this.remapperParameters = remapperParameters;
|
||||
}
|
||||
|
||||
@Input
|
||||
public abstract Property<String> getRemapperExtensionClassName();
|
||||
|
||||
@Nested
|
||||
@Optional
|
||||
public RemapperParameters getRemapperParameters() {
|
||||
return remapperParameters;
|
||||
}
|
||||
|
||||
public void apply(TinyRemapper.Builder tinyRemapperBuilder, String sourceNamespace, String targetNamespace, ObjectFactory objectFactory) {
|
||||
final RemapperExtension<?> remapperExtension = newInstance(objectFactory);
|
||||
|
||||
tinyRemapperBuilder.extraPostApplyVisitor(new RemapperExtensionImpl(remapperExtension, sourceNamespace, targetNamespace));
|
||||
|
||||
if (remapperExtension instanceof TinyRemapperExtension tinyRemapperExtension) {
|
||||
final TinyRemapper.AnalyzeVisitorProvider analyzeVisitorProvider = tinyRemapperExtension.getAnalyzeVisitorProvider();
|
||||
final TinyRemapper.ApplyVisitorProvider preApplyVisitorProvider = tinyRemapperExtension.getPreApplyVisitor();
|
||||
final TinyRemapper.ApplyVisitorProvider postApplyVisitorProvider = tinyRemapperExtension.getPostApplyVisitor();
|
||||
|
||||
if (analyzeVisitorProvider != null) {
|
||||
tinyRemapperBuilder.extraAnalyzeVisitor(analyzeVisitorProvider);
|
||||
}
|
||||
|
||||
if (preApplyVisitorProvider != null) {
|
||||
tinyRemapperBuilder.extraPreApplyVisitor(preApplyVisitorProvider);
|
||||
}
|
||||
|
||||
if (postApplyVisitorProvider != null) {
|
||||
tinyRemapperBuilder.extraPostApplyVisitor(postApplyVisitorProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RemapperExtension<?> newInstance(ObjectFactory objectFactory) {
|
||||
try {
|
||||
Class<? extends RemapperExtension> remapperExtensionClass = Class.forName(getRemapperExtensionClassName().get())
|
||||
.asSubclass(RemapperExtension.class);
|
||||
|
||||
if (remapperParameters == RemapperParameters.None.INSTANCE) {
|
||||
return objectFactory.newInstance(remapperExtensionClass);
|
||||
}
|
||||
|
||||
return objectFactory.newInstance(remapperExtensionClass, remapperParameters);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to create remapper extension", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RemapperExtensionImpl implements TinyRemapper.ApplyVisitorProvider {
|
||||
private final RemapperExtension<?> remapperExtension;
|
||||
private final String sourceNamespace;
|
||||
private final String targetNamespace;
|
||||
|
||||
@Nullable
|
||||
private RemapperContext context;
|
||||
|
||||
private RemapperExtensionImpl(RemapperExtension<?> remapperExtension, String sourceNamespace, String targetNamespace) {
|
||||
this.remapperExtension = remapperExtension;
|
||||
this.sourceNamespace = sourceNamespace;
|
||||
this.targetNamespace = targetNamespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
|
||||
if (context == null) {
|
||||
context = new RemapperContextImpl(cls.getEnvironment().getRemapper(), sourceNamespace, targetNamespace);
|
||||
}
|
||||
|
||||
return remapperExtension.insertVisitor(cls.getName(), context, next);
|
||||
}
|
||||
}
|
||||
|
||||
private record RemapperContextImpl(Remapper remapper, String sourceNamespace, String targetNamespace) implements RemapperContext {
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public abstract class AbstractRemapJarTask extends Jar {
|
||||
final ZipEntryCompression compression = getParameters().getEntryCompression().get();
|
||||
|
||||
if (isReproducibleFileOrder || !isPreserveFileTimestamps || compression != ZipEntryCompression.DEFLATED) {
|
||||
ZipReprocessorUtil.reprocessZip(outputFile.toFile(), isReproducibleFileOrder, isPreserveFileTimestamps, compression);
|
||||
ZipReprocessorUtil.reprocessZip(outputFile, isReproducibleFileOrder, isPreserveFileTimestamps, compression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,13 +478,15 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
}
|
||||
|
||||
for (RemapParams.RefmapData refmapData : getParameters().getMixinData().get()) {
|
||||
int transformed = ZipUtils.transformJson(JsonObject.class, outputFile, refmapData.mixinConfigs().stream().collect(Collectors.toMap(s -> s, s -> json -> {
|
||||
if (!json.has("refmap")) {
|
||||
json.addProperty("refmap", refmapData.refmapName());
|
||||
}
|
||||
if (ZipUtils.contains(outputFile, refmapData.refmapName())) {
|
||||
int transformed = ZipUtils.transformJson(JsonObject.class, outputFile, refmapData.mixinConfigs().stream().collect(Collectors.toMap(s -> s, s -> json -> {
|
||||
if (!json.has("refmap")) {
|
||||
json.addProperty("refmap", refmapData.refmapName());
|
||||
}
|
||||
|
||||
return json;
|
||||
})));
|
||||
return json;
|
||||
})));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -96,7 +95,7 @@ public abstract class RemapTaskConfiguration implements Runnable {
|
||||
// Configure the default jar task
|
||||
getTasks().named(JavaPlugin.JAR_TASK_NAME, AbstractArchiveTask.class).configure(task -> {
|
||||
task.getArchiveClassifier().convention("dev");
|
||||
task.getDestinationDirectory().set(new File(getProject().getBuildDir(), "devlibs"));
|
||||
task.getDestinationDirectory().set(getProject().getLayout().getBuildDirectory().map(directory -> directory.dir("devlibs")));
|
||||
});
|
||||
|
||||
getTasks().named(BasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(remapJarTask));
|
||||
@@ -161,7 +160,7 @@ public abstract class RemapTaskConfiguration implements Runnable {
|
||||
}
|
||||
|
||||
sourcesJarTask.getArchiveClassifier().convention("dev-sources");
|
||||
sourcesJarTask.getDestinationDirectory().set(new File(getProject().getBuildDir(), "devlibs"));
|
||||
sourcesJarTask.getDestinationDirectory().set(getProject().getLayout().getBuildDirectory().map(directory -> directory.dir("devlibs")));
|
||||
task.getArchiveClassifier().convention("sources");
|
||||
|
||||
task.dependsOn(sourcesJarTask);
|
||||
|
||||
@@ -42,12 +42,14 @@ import dev.architectury.tinyremapper.InputTag;
|
||||
import dev.architectury.tinyremapper.TinyRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.invocation.Gradle;
|
||||
import org.gradle.api.model.ObjectFactory;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.build.IntermediaryNamespaces;
|
||||
import net.fabricmc.loom.build.mixin.AnnotationProcessorInvoker;
|
||||
import net.fabricmc.loom.extension.RemapperExtensionHolder;
|
||||
import net.fabricmc.loom.task.AbstractRemapJarTask;
|
||||
import net.fabricmc.loom.util.gradle.GradleUtils;
|
||||
import net.fabricmc.loom.util.gradle.SourceSetHelper;
|
||||
@@ -95,7 +97,7 @@ public class TinyRemapperService implements SharedService {
|
||||
mappings.add(gradleMixinMappingProvider(serviceManager, project.getGradle(), extension.getMappingConfiguration().mappingsIdentifier, from, to));
|
||||
}
|
||||
|
||||
return new TinyRemapperService(mappings, !legacyMixin, kotlinClasspathService, extension.getKnownIndyBsms().get());
|
||||
return new TinyRemapperService(mappings, !legacyMixin, kotlinClasspathService, extension.getKnownIndyBsms().get(), extension.getRemapperExtensions().get(), from, to, project.getObjects());
|
||||
});
|
||||
|
||||
service.readClasspath(remapJarTask.getClasspath().getFiles().stream().map(File::toPath).filter(Files::exists).toList());
|
||||
@@ -135,7 +137,7 @@ public class TinyRemapperService implements SharedService {
|
||||
// Set to true once remapping has started, once set no inputs can be read.
|
||||
private boolean isRemapping = false;
|
||||
|
||||
public TinyRemapperService(List<IMappingProvider> mappings, boolean useMixinExtension, @Nullable KotlinClasspath kotlinClasspath, Set<String> knownIndyBsms) {
|
||||
private TinyRemapperService(List<IMappingProvider> mappings, boolean useMixinExtension, @Nullable KotlinClasspath kotlinClasspath, Set<String> knownIndyBsms, List<RemapperExtensionHolder> remapperExtensions, String sourceNamespace, String targetNamespace, ObjectFactory objectFactory) {
|
||||
TinyRemapper.Builder builder = TinyRemapper.newRemapper().withKnownIndyBsm(knownIndyBsms);
|
||||
|
||||
for (IMappingProvider provider : mappings) {
|
||||
@@ -151,6 +153,10 @@ public class TinyRemapperService implements SharedService {
|
||||
builder.extension(kotlinRemapperClassloader.getTinyRemapperExtension());
|
||||
}
|
||||
|
||||
for (RemapperExtensionHolder holder : remapperExtensions) {
|
||||
holder.apply(builder, sourceNamespace, targetNamespace, objectFactory);
|
||||
}
|
||||
|
||||
tinyRemapper = builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public class SourceRemapper {
|
||||
try {
|
||||
logger.progress("remapping sources - " + source.getName());
|
||||
remapSourcesInner(source, destination);
|
||||
ZipReprocessorUtil.reprocessZip(destination, reproducibleFileOrder, preserveFileTimestamps);
|
||||
ZipReprocessorUtil.reprocessZip(destination.toPath(), reproducibleFileOrder, preserveFileTimestamps);
|
||||
|
||||
// Set the remapped sources creation date to match the sources if we're likely succeeded in making it
|
||||
destination.setLastModified(source.lastModified());
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
|
||||
package net.fabricmc.loom.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Calendar;
|
||||
import java.util.Comparator;
|
||||
import java.util.GregorianCalendar;
|
||||
@@ -87,16 +86,19 @@ public class ZipReprocessorUtil {
|
||||
return name1.compareTo(name2);
|
||||
}
|
||||
|
||||
public static void reprocessZip(File file, boolean reproducibleFileOrder, boolean preserveFileTimestamps) throws IOException {
|
||||
public static void reprocessZip(Path file, boolean reproducibleFileOrder, boolean preserveFileTimestamps) throws IOException {
|
||||
reprocessZip(file, reproducibleFileOrder, preserveFileTimestamps, ZipEntryCompression.DEFLATED);
|
||||
}
|
||||
|
||||
public static void reprocessZip(File file, boolean reproducibleFileOrder, boolean preserveFileTimestamps, ZipEntryCompression zipEntryCompression) throws IOException {
|
||||
public static void reprocessZip(Path file, boolean reproducibleFileOrder, boolean preserveFileTimestamps, ZipEntryCompression zipEntryCompression) throws IOException {
|
||||
if (!reproducibleFileOrder && preserveFileTimestamps) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (var zipFile = new ZipFile(file)) {
|
||||
final Path tempFile = file.resolveSibling(file.getFileName() + ".tmp");
|
||||
|
||||
try (var zipFile = new ZipFile(file.toFile());
|
||||
var fileOutputStream = Files.newOutputStream(tempFile)) {
|
||||
ZipEntry[] entries;
|
||||
|
||||
if (reproducibleFileOrder) {
|
||||
@@ -108,9 +110,7 @@ public class ZipReprocessorUtil {
|
||||
.toArray(ZipEntry[]::new);
|
||||
}
|
||||
|
||||
final var outZip = new ByteArrayOutputStream(entries.length);
|
||||
|
||||
try (var zipOutputStream = new ZipOutputStream(outZip)) {
|
||||
try (var zipOutputStream = new ZipOutputStream(fileOutputStream)) {
|
||||
zipOutputStream.setMethod(zipOutputStreamCompressionMethod(zipEntryCompression));
|
||||
|
||||
for (ZipEntry entry : entries) {
|
||||
@@ -125,11 +125,9 @@ public class ZipReprocessorUtil {
|
||||
copyZipEntry(zipOutputStream, newEntry, zipFile.getInputStream(entry));
|
||||
}
|
||||
}
|
||||
|
||||
try (var fileOutputStream = new FileOutputStream(file)) {
|
||||
outZip.writeTo(fileOutputStream);
|
||||
}
|
||||
}
|
||||
|
||||
Files.move(tempFile, file, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,15 +135,20 @@ public class ZipReprocessorUtil {
|
||||
* The new entry is added with a constant time stamp to ensure reproducibility.
|
||||
* This method should only be used when a reproducible output is required, use {@link ZipUtils#add(Path, String, byte[])} normally.
|
||||
*/
|
||||
public static void appendZipEntry(File file, String path, byte[] data) throws IOException {
|
||||
try (var zipFile = new ZipFile(file)) {
|
||||
public static void appendZipEntry(Path file, String path, byte[] data) throws IOException {
|
||||
final Path tempFile = file.resolveSibling(file.getFileName() + ".tmp");
|
||||
|
||||
try (var zipFile = new ZipFile(file.toFile());
|
||||
var fileOutputStream = Files.newOutputStream(tempFile)) {
|
||||
ZipEntry[] entries = zipFile.stream().toArray(ZipEntry[]::new);
|
||||
|
||||
final var outZip = new ByteArrayOutputStream(entries.length);
|
||||
|
||||
try (var zipOutputStream = new ZipOutputStream(outZip)) {
|
||||
try (var zipOutputStream = new ZipOutputStream(fileOutputStream)) {
|
||||
// Copy existing entries
|
||||
for (ZipEntry entry : entries) {
|
||||
if (entry.getName().equals(path)) {
|
||||
throw new IllegalArgumentException("Zip file (%s) already contains entry (%s)".formatted(file.getFileName().toString(), path));
|
||||
}
|
||||
|
||||
copyZipEntry(zipOutputStream, entry, zipFile.getInputStream(entry));
|
||||
}
|
||||
|
||||
@@ -156,11 +159,9 @@ public class ZipReprocessorUtil {
|
||||
zipOutputStream.write(data, 0, data.length);
|
||||
zipOutputStream.closeEntry();
|
||||
}
|
||||
|
||||
try (var fileOutputStream = new FileOutputStream(file)) {
|
||||
outZip.writeTo(fileOutputStream);
|
||||
}
|
||||
}
|
||||
|
||||
Files.move(tempFile, file, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private static void copyZipEntry(ZipOutputStream zipOutputStream, ZipEntry entry, InputStream inputStream) throws IOException {
|
||||
|
||||
@@ -50,6 +50,10 @@ public abstract sealed class FabricModJson permits FabricModJsonV0, FabricModJso
|
||||
return readString(jsonObject, "id");
|
||||
}
|
||||
|
||||
public String getModVersion() {
|
||||
return readString(jsonObject, "version");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract JsonElement getCustom(String key);
|
||||
|
||||
|
||||
@@ -56,11 +56,11 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
logger.info("Kotlin metadata for class ($className) as it was built using a different major Kotlin version (${header.metadataVersion[0]}.${header.metadataVersion[1]}.x) while the remapper is using (${KotlinVersion.CURRENT}).")
|
||||
}
|
||||
|
||||
when (val metadata = KotlinClassMetadata.read(header)) {
|
||||
when (val metadata = KotlinClassMetadata.readLenient(header)) {
|
||||
is KotlinClassMetadata.Class -> {
|
||||
var klass = metadata.kmClass
|
||||
klass = KotlinClassRemapper(remapper).remap(klass)
|
||||
val remapped = KotlinClassMetadata.writeClass(klass, header.metadataVersion, header.extraInt)
|
||||
val remapped = KotlinClassMetadata.Class(klass, metadata.version, metadata.flags).write()
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
|
||||
if (klambda != null) {
|
||||
klambda = KotlinClassRemapper(remapper).remap(klambda)
|
||||
val remapped = KotlinClassMetadata.writeLambda(klambda, header.metadataVersion, header.extraInt)
|
||||
val remapped = KotlinClassMetadata.SyntheticClass(klambda, metadata.version, metadata.flags).write()
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
} else {
|
||||
@@ -79,15 +79,14 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
|
||||
is KotlinClassMetadata.FileFacade -> {
|
||||
var kpackage = metadata.kmPackage
|
||||
kpackage = KotlinClassRemapper(remapper).remap(kpackage)
|
||||
val remapped = KotlinClassMetadata.writeFileFacade(kpackage, header.metadataVersion, header.extraInt)
|
||||
val remapped = KotlinClassMetadata.FileFacade(kpackage, metadata.version, metadata.flags).write()
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
}
|
||||
is KotlinClassMetadata.MultiFileClassPart -> {
|
||||
var kpackage = metadata.kmPackage
|
||||
kpackage = KotlinClassRemapper(remapper).remap(kpackage)
|
||||
val wrapper = KotlinClassMetadataWrapper(metadata)
|
||||
val remapped = KotlinClassMetadata.writeMultiFileClassPart(kpackage, metadata.facadeClassName, wrapper.annotationData.metadataVersion, wrapper.annotationData.extraInt)
|
||||
val remapped = KotlinClassMetadata.MultiFileClassPart(kpackage, metadata.facadeClassName, metadata.version, metadata.flags).write()
|
||||
writeClassHeader(remapped)
|
||||
validateKotlinClassHeader(remapped, header)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
|
||||
<!-- System out -->
|
||||
<Console name="SysOut" target="SYSTEM_OUT">
|
||||
<!-- Filter out the authentication error when starting in development -->
|
||||
<RegexFilter regex="^Failed to verify authentication$" onMatch="DENY" onMismatch="ACCEPT"/>
|
||||
<!-- Filter out the authentication errors when starting in development -->
|
||||
<Filters>
|
||||
<RegexFilter regex="^Failed to verify authentication$" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
<RegexFilter regex="^Failed to fetch user properties$" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
<RegexFilter regex="^Couldn't connect to realms$" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
</Filters>
|
||||
<PatternLayout>
|
||||
<LoggerNamePatternSelector defaultPattern="%style{[%d{HH:mm:ss}]}{blue} %highlight{[%t/%level]}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=green, TRACE=blue} %style{(%logger{1})}{cyan} %highlight{%msg%n}{FATAL=red, ERROR=red, WARN=normal, INFO=normal, DEBUG=normal, TRACE=normal}" disableAnsi="${sys:fabric.log.disableAnsi:-true}">
|
||||
<!-- Dont show the logger name for minecraft classes-->
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.test.integration
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
import net.fabricmc.loom.test.util.GradleProjectTestTrait
|
||||
|
||||
import static net.fabricmc.loom.test.LoomTestConstants.STANDARD_TEST_VERSIONS
|
||||
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
|
||||
|
||||
class IncludedJarsTest extends Specification implements GradleProjectTestTrait {
|
||||
@Unroll
|
||||
def "included jars (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "includedJars", version: version)
|
||||
|
||||
when:
|
||||
def result = gradle.run(tasks: ["remapJar"])
|
||||
|
||||
then:
|
||||
result.task(":remapJar").outcome == SUCCESS
|
||||
|
||||
// Assert directly declared dependencies are present
|
||||
gradle.hasOutputZipEntry("includedJars.jar", "META-INF/jars/log4j-core-2.22.0.jar")
|
||||
gradle.hasOutputZipEntry("includedJars.jar", "META-INF/jars/adventure-text-serializer-gson-4.14.0.jar")
|
||||
|
||||
// But not transitives.
|
||||
!gradle.hasOutputZipEntry("includedJars.jar", "META-INF/jars/log4j-api-2.22.0.jar")
|
||||
!gradle.hasOutputZipEntry("includedJars.jar", "META-INF/jars/adventure-api-4.14.0.jar")
|
||||
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class MultiProjectTest extends Specification implements GradleProjectTestTrait {
|
||||
|
||||
gradle.hasOutputZipEntry("multiproject-1.0.0.jar", "META-INF/jars/example-1.0.0.jar")
|
||||
gradle.hasOutputZipEntry("multiproject-1.0.0.jar", "META-INF/jars/core-1.0.0.jar")
|
||||
gradle.hasOutputZipEntry("multiproject-1.0.0.jar", "META-INF/jars/fabric-api-base-0.2.1+9354966b7d.jar")
|
||||
gradle.hasOutputZipEntry("multiproject-1.0.0.jar", "META-INF/jars/fabric-api-base-0.3.0+f74f7c7d7d.jar")
|
||||
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
|
||||
@@ -51,18 +51,12 @@ class ReproducibleBuildTest extends Specification implements GradleProjectTestTr
|
||||
then:
|
||||
result.task(":build").outcome == SUCCESS
|
||||
generateMD5(gradle.getOutputFile("fabric-example-mod-1.0.0.jar")) == modHash
|
||||
generateMD5(gradle.getOutputFile("fabric-example-mod-1.0.0-sources.jar")) in sourceHash // Done for different line endings.
|
||||
generateMD5(gradle.getOutputFile("fabric-example-mod-1.0.0-sources.jar")) == sourceHash
|
||||
|
||||
where:
|
||||
version | modHash | sourceHash
|
||||
DEFAULT_GRADLE | "207bd75aa34fc996a97e962dd98b61d5" | [
|
||||
"8e8fac2a5e32fc872e6cf0f9ccc55cfd",
|
||||
"ed331b6fae5677797a0104eba014e255"
|
||||
]
|
||||
PRE_RELEASE_GRADLE | "207bd75aa34fc996a97e962dd98b61d5" | [
|
||||
"8e8fac2a5e32fc872e6cf0f9ccc55cfd",
|
||||
"ed331b6fae5677797a0104eba014e255"
|
||||
]
|
||||
DEFAULT_GRADLE | "207bd75aa34fc996a97e962dd98b61d5" | "8e8fac2a5e32fc872e6cf0f9ccc55cfd"
|
||||
PRE_RELEASE_GRADLE | "207bd75aa34fc996a97e962dd98b61d5" | "8e8fac2a5e32fc872e6cf0f9ccc55cfd"
|
||||
}
|
||||
|
||||
String generateMD5(File file) {
|
||||
|
||||
@@ -42,6 +42,7 @@ class SimpleProjectTest extends Specification implements GradleProjectTestTrait
|
||||
def "build and run (gradle #version)"() {
|
||||
setup:
|
||||
def gradle = gradleProject(project: "simple", version: version)
|
||||
gradle.buildSrc("remapext") // apply the remap extension plugin
|
||||
|
||||
def server = ServerRunner.create(gradle.projectDir, "1.16.5")
|
||||
.withMod(gradle.getOutputFile("fabric-example-mod-1.0.0.jar"))
|
||||
@@ -60,6 +61,7 @@ class SimpleProjectTest extends Specification implements GradleProjectTestTrait
|
||||
|
||||
serverResult.successful()
|
||||
serverResult.output.contains("Hello simple Fabric mod") // A check to ensure our mod init was actually called
|
||||
serverResult.output.contains("Hello Loom!") // Check that the remapper extension worked
|
||||
where:
|
||||
version << STANDARD_TEST_VERSIONS
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.test.integration.buildSrc.remapext
|
||||
|
||||
import org.objectweb.asm.ClassVisitor
|
||||
import org.objectweb.asm.MethodVisitor
|
||||
|
||||
class StringReplacementClassVisitor extends ClassVisitor {
|
||||
final Map<String, String> replacements
|
||||
|
||||
StringReplacementClassVisitor(int api, ClassVisitor classVisitor, Map<String, String> replacements) {
|
||||
super(api, classVisitor)
|
||||
this.replacements = replacements
|
||||
}
|
||||
|
||||
@Override
|
||||
MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
def methodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions)
|
||||
return new StringReplacementMethodVisitor(api, methodVisitor)
|
||||
}
|
||||
|
||||
class StringReplacementMethodVisitor extends MethodVisitor {
|
||||
StringReplacementMethodVisitor(int api, MethodVisitor methodVisitor) {
|
||||
super(api, methodVisitor)
|
||||
}
|
||||
|
||||
@Override
|
||||
void visitLdcInsn(Object value) {
|
||||
if (value instanceof String) {
|
||||
String replacement = replacements.get(value)
|
||||
if (replacement != null) {
|
||||
value = replacement
|
||||
}
|
||||
}
|
||||
|
||||
super.visitLdcInsn(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.test.integration.buildSrc.remapext
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension
|
||||
import net.fabricmc.loom.api.remapping.RemapperParameters
|
||||
|
||||
class TestPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
def extension = LoomGradleExtension.get(project)
|
||||
extension.addRemapperExtension(TestRemapperExtension.class, TestRemapperExtension.Params.class) { TestRemapperExtension.Params p ->
|
||||
p.replacements.put("Hello World!", "Hello Loom!")
|
||||
}
|
||||
extension.addRemapperExtension(TestTinyRemapperExtension.class, RemapperParameters.None.class) { RemapperParameters.None p ->
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.test.integration.buildSrc.remapext
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
import org.gradle.api.provider.MapProperty
|
||||
import org.objectweb.asm.ClassVisitor
|
||||
|
||||
import net.fabricmc.loom.api.remapping.RemapperContext
|
||||
import net.fabricmc.loom.api.remapping.RemapperExtension
|
||||
import net.fabricmc.loom.api.remapping.RemapperParameters
|
||||
import net.fabricmc.loom.util.Constants
|
||||
|
||||
abstract class TestRemapperExtension implements RemapperExtension<Params> {
|
||||
final Params parameters
|
||||
|
||||
@Inject
|
||||
TestRemapperExtension(Params parameters) {
|
||||
this.parameters = parameters
|
||||
}
|
||||
|
||||
@Override
|
||||
ClassVisitor insertVisitor(String className, RemapperContext remapperContext, ClassVisitor classVisitor) {
|
||||
def replacements = parameters.replacements.get()
|
||||
return new StringReplacementClassVisitor(Constants.ASM_VERSION, classVisitor, replacements)
|
||||
}
|
||||
|
||||
interface Params extends RemapperParameters {
|
||||
MapProperty<String, String> getReplacements()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.test.integration.buildSrc.remapext
|
||||
|
||||
import org.objectweb.asm.ClassVisitor
|
||||
|
||||
import net.fabricmc.loom.api.remapping.RemapperContext
|
||||
import net.fabricmc.loom.api.remapping.RemapperExtension
|
||||
import net.fabricmc.loom.api.remapping.RemapperParameters
|
||||
import net.fabricmc.loom.api.remapping.TinyRemapperExtension
|
||||
import net.fabricmc.tinyremapper.TinyRemapper
|
||||
|
||||
class TestTinyRemapperExtension implements RemapperExtension<RemapperParameters.None>, TinyRemapperExtension {
|
||||
@Override
|
||||
ClassVisitor insertVisitor(String className, RemapperContext remapperContext, ClassVisitor classVisitor) {
|
||||
return classVisitor
|
||||
}
|
||||
|
||||
TinyRemapper.AnalyzeVisitorProvider analyzeVisitorProvider = null
|
||||
TinyRemapper.ApplyVisitorProvider preApplyVisitor = null
|
||||
TinyRemapper.ApplyVisitorProvider PostApplyVisitor = null
|
||||
}
|
||||
@@ -165,11 +165,11 @@ class ZipUtilsTest extends Specification {
|
||||
def fileInside = dir.resolve("text.txt")
|
||||
Files.writeString(fileInside, "hello world")
|
||||
ZipUtils.pack(dir, zip)
|
||||
ZipReprocessorUtil.reprocessZip(zip.toFile(), true, false)
|
||||
ZipReprocessorUtil.reprocessZip(zip, true, false)
|
||||
|
||||
when:
|
||||
// Add an entry to it
|
||||
ZipReprocessorUtil.appendZipEntry(zip.toFile(), "fabric.mod.json", "Some text".getBytes(StandardCharsets.UTF_8))
|
||||
ZipReprocessorUtil.appendZipEntry(zip, "fabric.mod.json", "Some text".getBytes(StandardCharsets.UTF_8))
|
||||
|
||||
// Reset the timezone back
|
||||
TimeZone.setDefault(currentTimezone)
|
||||
|
||||
@@ -62,6 +62,7 @@ class FabricModJsonV0Test extends Specification {
|
||||
def fmj = FabricModJsonFactory.create(JSON_OBJECT, mockSource)
|
||||
then:
|
||||
fmj.version == 0
|
||||
fmj.modVersion == "1.0.0"
|
||||
}
|
||||
|
||||
def "id"() {
|
||||
|
||||
@@ -69,6 +69,7 @@ class FabricModJsonV1Test extends Specification {
|
||||
def fmj = FabricModJsonFactory.create(JSON_OBJECT, mockSource)
|
||||
then:
|
||||
fmj.version == 1
|
||||
fmj.modVersion == "1.0.0"
|
||||
}
|
||||
|
||||
def "id"() {
|
||||
|
||||
@@ -83,6 +83,7 @@ class FabricModJsonV2Test extends Specification {
|
||||
def fmj = FabricModJsonFactory.create(JSON_OBJECT, mockSource)
|
||||
then:
|
||||
fmj.version == 2
|
||||
fmj.modVersion == "1.0.0"
|
||||
}
|
||||
|
||||
def "id"() {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
package net.fabricmc.loom.test.unit.kotlin
|
||||
|
||||
import kotlin.KotlinVersion
|
||||
import dev.architectury.tinyremapper.api.TrClass
|
||||
import dev.architectury.tinyremapper.api.TrEnvironment
|
||||
import dev.architectury.tinyremapper.api.TrRemapper
|
||||
@@ -36,7 +37,7 @@ import net.fabricmc.loom.util.kotlin.KotlinPluginUtils
|
||||
import net.fabricmc.loom.util.kotlin.KotlinRemapperClassloader
|
||||
|
||||
class KotlinRemapperClassloaderTest extends Specification {
|
||||
private static String KOTLIN_VERSION = "1.6.10"
|
||||
private static String KOTLIN_VERSION = KotlinVersion.CURRENT.toString()
|
||||
private static String KOTLIN_METADATA_VERSION = KotlinPluginUtils.kotlinMetadataVersion
|
||||
private static String KOTLIN_URL = "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/${KOTLIN_VERSION}/kotlin-stdlib-${KOTLIN_VERSION}.jar"
|
||||
private static String KOTLIN_METADATA_URL = "https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-metadata-jvm/${KOTLIN_METADATA_VERSION}/kotlinx-metadata-jvm-${KOTLIN_METADATA_VERSION}.jar"
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2023 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.test.unit.providers
|
||||
|
||||
import java.nio.file.Path
|
||||
import java.util.jar.Attributes
|
||||
import java.util.jar.Manifest
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.lang.TempDir
|
||||
|
||||
import net.fabricmc.loom.configuration.providers.mappings.tiny.TinyJarInfo
|
||||
import net.fabricmc.loom.util.ZipUtils
|
||||
|
||||
class TinyJarInfoTest extends Specification {
|
||||
@TempDir
|
||||
Path tempDir
|
||||
Path v1MappingsJar
|
||||
Path v2MappingsJar
|
||||
|
||||
def setup() {
|
||||
v1MappingsJar = tempDir.resolve('mappings-v1.jar')
|
||||
v2MappingsJar = tempDir.resolve('mappings-v2.jar')
|
||||
ZipUtils.add(v1MappingsJar, 'mappings/mappings.tiny', 'v1\tintermediary\tnamed\n')
|
||||
ZipUtils.add(v2MappingsJar, 'mappings/mappings.tiny', 'tiny\t2\t0\tintermediary\tnamed\n')
|
||||
}
|
||||
|
||||
def "v1 without minecraft version"() {
|
||||
when:
|
||||
def jarInfo = TinyJarInfo.get(v1MappingsJar)
|
||||
|
||||
then:
|
||||
jarInfo == new TinyJarInfo(false, Optional.empty())
|
||||
}
|
||||
|
||||
def "v2 without minecraft version"() {
|
||||
when:
|
||||
def jarInfo = TinyJarInfo.get(v2MappingsJar)
|
||||
|
||||
then:
|
||||
jarInfo == new TinyJarInfo(true, Optional.empty())
|
||||
}
|
||||
|
||||
def "v1 with minecraft version"() {
|
||||
setup:
|
||||
def manifest = new Manifest()
|
||||
manifest.mainAttributes.put(Attributes.Name.MANIFEST_VERSION, '1.0')
|
||||
manifest.mainAttributes.putValue('Minecraft-Version-Id', '18w50a')
|
||||
def out = new ByteArrayOutputStream()
|
||||
manifest.write(out)
|
||||
ZipUtils.add(v1MappingsJar, 'META-INF/MANIFEST.MF', out.toByteArray())
|
||||
|
||||
when:
|
||||
def jarInfo = TinyJarInfo.get(v1MappingsJar)
|
||||
|
||||
then:
|
||||
jarInfo == new TinyJarInfo(false, Optional.of('18w50a'))
|
||||
}
|
||||
|
||||
def "v2 with minecraft version"() {
|
||||
setup:
|
||||
def manifest = new Manifest()
|
||||
manifest.mainAttributes.put(Attributes.Name.MANIFEST_VERSION, '1.0')
|
||||
manifest.mainAttributes.putValue('Minecraft-Version-Id', '18w50a')
|
||||
def out = new ByteArrayOutputStream()
|
||||
manifest.write(out)
|
||||
ZipUtils.add(v2MappingsJar, 'META-INF/MANIFEST.MF', out.toByteArray())
|
||||
|
||||
when:
|
||||
def jarInfo = TinyJarInfo.get(v2MappingsJar)
|
||||
|
||||
then:
|
||||
jarInfo == new TinyJarInfo(true, Optional.of('18w50a'))
|
||||
}
|
||||
}
|
||||
21
src/test/resources/projects/includedJars/build.gradle
Normal file
21
src/test/resources/projects/includedJars/build.gradle
Normal file
@@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
id 'fabric-loom'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft 'com.mojang:minecraft:1.18.2'
|
||||
mappings 'net.fabricmc:yarn:1.18.2+build.1:v2'
|
||||
modImplementation 'net.fabricmc:fabric-loader:0.13.3'
|
||||
|
||||
include 'org.apache.logging.log4j:log4j-core:2.22.0'
|
||||
|
||||
// Test bom/platform dependencies
|
||||
include platform('net.kyori:adventure-bom:4.14.0')
|
||||
|
||||
// bom provides version
|
||||
include 'net.kyori:adventure-text-serializer-gson'
|
||||
}
|
||||
1
src/test/resources/projects/includedJars/settings.gradle
Normal file
1
src/test/resources/projects/includedJars/settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
rootProject.name = 'includedJars'
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "modid",
|
||||
"version": "0.0.0",
|
||||
|
||||
"name": "Example Mod",
|
||||
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||
"environment": "*"
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.fabricmc.example;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
public class ExampleMod implements ModInitializer {
|
||||
public static final Logger LOGGER = LogManager.getLogger("modid");
|
||||
|
||||
@@ -13,5 +14,6 @@ public class ExampleMod implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
LOGGER.info("Hello simple Fabric mod!");
|
||||
LOGGER.info("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user