From fa28bfba882d186fbd548b45436ac49b85fe5516 Mon Sep 17 00:00:00 2001 From: Marc Hermans Date: Sun, 20 Oct 2024 14:48:52 +0200 Subject: [PATCH] Fix vanilla user transformer not detecting missing files and not running. --- .../common/util/CommonRuntimeTaskUtils.java | 4 +-- .../extensions/VanillaRuntimeExtension.java | 34 ++++++++++--------- .../steps/ApplyAccessTransformerStep.java | 5 ++- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/common/src/main/java/net/neoforged/gradle/common/util/CommonRuntimeTaskUtils.java b/common/src/main/java/net/neoforged/gradle/common/util/CommonRuntimeTaskUtils.java index 171408bf7..050f7a2c8 100644 --- a/common/src/main/java/net/neoforged/gradle/common/util/CommonRuntimeTaskUtils.java +++ b/common/src/main/java/net/neoforged/gradle/common/util/CommonRuntimeTaskUtils.java @@ -9,8 +9,6 @@ import org.gradle.api.file.FileTree; import org.gradle.api.tasks.TaskProvider; -import java.io.File; - public final class CommonRuntimeTaskUtils { private CommonRuntimeTaskUtils() { @@ -35,7 +33,7 @@ public static TaskProvider createSourceInter }); } - public static TaskProvider createBinaryAccessTransformer(Definition definition, String namePreFix, File workspaceDirectory, FileTree files) { + public static TaskProvider createBinaryAccessTransformer(Definition definition, String namePreFix, FileTree files) { return definition.getSpecification().getProject().getTasks().register(CommonRuntimeUtils.buildTaskName(definition.getSpecification(), String.format("apply%sAccessTransformer", StringCapitalizationUtils.capitalize(namePreFix))), BinaryAccessTransformer.class, task -> { task.getTransformers().from(files); }); diff --git a/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/extensions/VanillaRuntimeExtension.java b/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/extensions/VanillaRuntimeExtension.java index 2658acd6b..2f643a8b9 100644 --- a/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/extensions/VanillaRuntimeExtension.java +++ b/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/extensions/VanillaRuntimeExtension.java @@ -165,26 +165,28 @@ protected void bakeDefinition(VanillaRuntimeDefinition definition) { ) ); - task.configure((Runtime mcpRuntimeTask) -> configureCommonRuntimeTaskParameters(mcpRuntimeTask, step.getName(), spec, runtimeWorkingDirectory)); - - if (!spec.getPostTypeAdapters().containsKey(step.getName())) { - definition.getTasks().put(task.getName(), task); - } else { - int taskPostAdapterIndex = 0; - for (TaskTreeAdapter taskTreeAdapter : spec.getPostTypeAdapters().get(step.getName())) { - final AtomicInteger additionalPostAdapterTasks = new AtomicInteger(0); - final int currentPostAdapterIndex = taskPostAdapterIndex++; - final TaskProvider taskProvider = taskTreeAdapter.adapt(definition, task, vanillaDirectory, definition.getGameArtifactProvidingTasks(), definition.getMappingVersionData(), dependentTaskProvider -> dependentTaskProvider.configure(additionalTask -> configureCommonRuntimeTaskParameters(additionalTask, step.getName() + "PostAdapter" + currentPostAdapterIndex + "-" + additionalPostAdapterTasks.getAndIncrement(), spec, runtimeWorkingDirectory))); - if (taskProvider != null) { - taskProvider.configure(adaptedTask -> configureCommonRuntimeTaskParameters(adaptedTask, step.getName() + "PostAdapter" + currentPostAdapterIndex + "-" + additionalPostAdapterTasks.getAndIncrement(), spec, runtimeWorkingDirectory)); - task = taskProvider; + if (task != null) { + task.configure((Runtime mcpRuntimeTask) -> configureCommonRuntimeTaskParameters(mcpRuntimeTask, step.getName(), spec, runtimeWorkingDirectory)); + + if (!spec.getPostTypeAdapters().containsKey(step.getName())) { + definition.getTasks().put(task.getName(), task); + } else { + int taskPostAdapterIndex = 0; + for (TaskTreeAdapter taskTreeAdapter : spec.getPostTypeAdapters().get(step.getName())) { + final AtomicInteger additionalPostAdapterTasks = new AtomicInteger(0); + final int currentPostAdapterIndex = taskPostAdapterIndex++; + final TaskProvider taskProvider = taskTreeAdapter.adapt(definition, task, vanillaDirectory, definition.getGameArtifactProvidingTasks(), definition.getMappingVersionData(), dependentTaskProvider -> dependentTaskProvider.configure(additionalTask -> configureCommonRuntimeTaskParameters(additionalTask, step.getName() + "PostAdapter" + currentPostAdapterIndex + "-" + additionalPostAdapterTasks.getAndIncrement(), spec, runtimeWorkingDirectory))); + if (taskProvider != null) { + taskProvider.configure(adaptedTask -> configureCommonRuntimeTaskParameters(adaptedTask, step.getName() + "PostAdapter" + currentPostAdapterIndex + "-" + additionalPostAdapterTasks.getAndIncrement(), spec, runtimeWorkingDirectory)); + task = taskProvider; + } } + + definition.getTasks().put(task.getName(), task); } - definition.getTasks().put(task.getName(), task); + currentInput = task; } - - currentInput = task; } final TaskProvider sourcesTask = Iterators.getLast(definition.getTasks().values().iterator()); diff --git a/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/steps/ApplyAccessTransformerStep.java b/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/steps/ApplyAccessTransformerStep.java index f58514a76..32771d3eb 100644 --- a/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/steps/ApplyAccessTransformerStep.java +++ b/vanilla/src/main/java/net/neoforged/gradle/vanilla/runtime/steps/ApplyAccessTransformerStep.java @@ -24,10 +24,13 @@ public TaskProvider buildTask(VanillaRuntimeDefinition defini final Minecraft minecraftExtension = definition.getSpecification().getProject().getExtensions().getByType(Minecraft.class); final AccessTransformers accessTransformerFiles = minecraftExtension.getAccessTransformers(); + if (accessTransformerFiles.getFiles().isEmpty()) { + return null; + } + final TaskProvider task = CommonRuntimeTaskUtils.createBinaryAccessTransformer( definition, "user", - workingDirectory, accessTransformerFiles.getFiles().getAsFileTree() );