From 0e4710a9566235b8066f9fddb519229509b32da0 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 29 Jun 2024 12:55:45 +0100 Subject: [PATCH] Update NF and NG - Rename ToolActions to ItemAbilities. Closes #1881. - Remove our source set helper, as NG has built-in support for this now. - Remove our code to generate new JavaExec tasks from runs, as NG now generates JavaExec tasks normally. --- .../kotlin/cc/tweaked/gradle/Extensions.kt | 16 +++++ .../cc/tweaked/gradle/ForgeExtensions.kt | 62 ------------------- gradle/libs.versions.toml | 4 +- projects/forge/build.gradle.kts | 6 +- .../shared/platform/PlatformHelperImpl.java | 4 +- 5 files changed, 23 insertions(+), 69 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/cc/tweaked/gradle/ForgeExtensions.kt diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt index 93870248b..3cd01264a 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt @@ -9,6 +9,7 @@ import org.gradle.api.file.FileSystemLocation import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.tasks.JavaExec +import org.gradle.kotlin.dsl.getByName import org.gradle.process.BaseExecSpec import org.gradle.process.JavaExecSpec import org.gradle.process.ProcessForkOptions @@ -46,6 +47,21 @@ fun JavaExec.copyToFull(spec: JavaExec) { copyToExec(spec) } +/** + * Base this [JavaExec] task on an existing task. + */ +fun JavaExec.copyFromTask(task: JavaExec) { + for (dep in task.dependsOn) dependsOn(dep) + task.copyToFull(this) +} + +/** + * Base this [JavaExec] task on an existing task. + */ +fun JavaExec.copyFromTask(task: String) { + copyFromTask(project.tasks.getByName(task)) +} + /** * Copy additional [BaseExecSpec] options which aren't handled by [ProcessForkOptions.copyTo]. */ diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/ForgeExtensions.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/ForgeExtensions.kt deleted file mode 100644 index 232b86d84..000000000 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/ForgeExtensions.kt +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package cc.tweaked.gradle - -import net.neoforged.gradle.common.runs.run.RunImpl -import net.neoforged.gradle.common.runs.tasks.RunExec -import net.neoforged.gradle.dsl.common.extensions.RunnableSourceSet -import net.neoforged.gradle.dsl.common.runs.run.Run -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.tasks.JavaExec -import org.gradle.api.tasks.SourceSet -import org.gradle.jvm.toolchain.JavaToolchainService -import org.gradle.kotlin.dsl.assign -import org.gradle.kotlin.dsl.create -import org.gradle.kotlin.dsl.findByType -import java.nio.file.Files - -/** - * Set [JavaExec] task to run a given [RunConfig]. - * - * See also [RunExec]. - */ -fun JavaExec.setRunConfig(config: Run) { - mainClass.set(config.mainClass) - workingDir = config.workingDirectory.get().asFile - argumentProviders.add { config.programArguments.get() } - jvmArgumentProviders.add { config.jvmArguments.get() } - - environment(config.environmentVariables.get()) - systemProperties(config.systemProperties.get()) - - config.modSources.all().get().values().forEach { classpath(it.runtimeClasspath) } - classpath(config.classpath) - classpath(config.dependencies.get().runtimeConfiguration) - - (config as RunImpl).taskDependencies.forEach { dependsOn(it) } - - javaLauncher.set( - project.extensions.getByType(JavaToolchainService::class.java) - .launcherFor(project.extensions.getByType(JavaPluginExtension::class.java).toolchain), - ) - - doFirst("Create working directory") { Files.createDirectories(workingDir.toPath()) } -} - -/** - * Add a new [Run.modSource] with a specific mod id. - */ -fun Run.modSourceAs(sourceSet: SourceSet, mod: String) { - // NeoGradle requires a RunnableSourceSet to be present, so we inject it into other project's source sets. - val runnable = sourceSet.extensions.findByType() ?: run { - val extension = sourceSet.extensions.create(RunnableSourceSet.NAME, project) - extension.modIdentifier = mod - extension.modIdentifier.finalizeValueOnRead() - extension - } - if (runnable.modIdentifier.get() != mod) throw IllegalArgumentException("Multiple mod identifiers") - - modSource(sourceSet) -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8dae41ee7..8e970ea2b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ # Remember to update corresponding versions in fabric.mod.json/neoforge.mods.toml fabric-api = "0.100.3+1.21" fabric-loader = "0.15.11" -neoForge = "21.0.21-beta" +neoForge = "21.0.42-beta" neoForgeSpi = "8.0.1" mixin = "0.8.5" parchment = "2024.06.16" @@ -67,7 +67,7 @@ ideaExt = "1.1.7" illuaminate = "0.1.0-73-g43ee16c" lwjgl = "3.3.3" minotaur = "2.8.7" -neoGradle = "7.0.145" +neoGradle = "7.0.152" nullAway = "0.10.25" spotless = "6.23.3" taskTree = "2.1.1" diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 5ce56c5f5..0de1d13a8 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -40,7 +40,7 @@ runs { systemProperty("forge.logging.console.level", "debug") cct.sourceDirectories.get().forEach { - if (it.classes) modSourceAs(it.sourceSet, "computercraft") + if (it.classes) modSources.add("computercraft", it.sourceSet) } dependencies { @@ -74,7 +74,7 @@ runs { modSource(sourceSets.testMod.get()) modSource(sourceSets.testFixtures.get()) - modSourceAs(project(":core").sourceSets.testFixtures.get(), "cctest") + modSources.add("cctest", project(":core").sourceSets.testFixtures.get()) jvmArgument("-ea") @@ -199,7 +199,7 @@ val runGametest by tasks.registering(JavaExec::class) { dependsOn("cleanRunGametest") usesService(MinecraftRunnerService.get(gradle)) - setRunConfig(runs["gameTestServer"]) + copyFromTask("runGameTestServer") systemProperty("forge.logging.console.level", "info") systemProperty("cctest.gametest-report", layout.buildDirectory.dir("test-results/$name.xml").getAbsolutePath()) diff --git a/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java b/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java index 68b47c5ee..3511c830b 100644 --- a/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java +++ b/projects/forge/src/main/java/dan200/computercraft/shared/platform/PlatformHelperImpl.java @@ -54,8 +54,8 @@ import net.neoforged.neoforge.capabilities.BlockCapability; import net.neoforged.neoforge.capabilities.BlockCapabilityCache; import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.common.CommonHooks; +import net.neoforged.neoforge.common.ItemAbilities; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.common.ToolActions; import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.items.wrapper.InvWrapper; @@ -211,7 +211,7 @@ public class PlatformHelperImpl implements PlatformHelper { @Override public boolean hasToolUsage(ItemStack stack) { - return stack.canPerformAction(ToolActions.SHOVEL_FLATTEN) || stack.canPerformAction(ToolActions.HOE_TILL); + return stack.canPerformAction(ItemAbilities.SHOVEL_FLATTEN) || stack.canPerformAction(ItemAbilities.HOE_TILL); } @Override