Skip to content

Commit

Permalink
feat(userdev): Default setup toolchain to JDK 17 for <1.19.3 dev bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Dec 30, 2024
1 parent a73c0c6 commit f2cc105
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ abstract class PaperweightUser : Plugin<Project> {
configureRepositories(userdevSetup)

setupTask.configure { setupService.set(userdevSetupProvider) }
userdevSetup.afterEvaluate(this)
userdevSetup.afterEvaluate(createContext(this, setupTask))

userdev.addServerDependencyTo.get().forEach {
it.extendsFrom(configurations.getByName(MOJANG_MAPPED_SERVER_CONFIG))
Expand Down Expand Up @@ -339,7 +339,7 @@ abstract class PaperweightUser : Plugin<Project> {
}

private fun createContext(project: Project, setupTask: TaskProvider<UserdevSetupTask>): SetupHandler.ConfigurationContext =
SetupHandler.ConfigurationContext(project, dependencyFactory, setupTask)
SetupHandler.ConfigurationContext(project, dependencyFactory, javaToolchainService, setupTask)

private fun createSetup(target: Project): Provider<UserdevSetup> {
val bundleConfig = target.configurations.named(DEV_BUNDLE_CONFIG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.gradle.api.tasks.TaskProvider
import org.gradle.internal.logging.progress.ProgressLogger
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.workers.WorkerExecutor

interface SetupHandler {
Expand All @@ -57,7 +58,7 @@ interface SetupHandler {

fun extractReobfMappings(output: Path)

fun afterEvaluate(project: Project) {
fun afterEvaluate(context: ConfigurationContext) {
}

val minecraftVersion: String
Expand All @@ -77,17 +78,20 @@ interface SetupHandler {
data class ConfigurationContext(
val project: Project,
val dependencyFactory: DependencyFactory,
val javaToolchainService: JavaToolchainService,
val devBundleCoordinates: String,
val setupTask: TaskProvider<UserdevSetupTask>,
val layout: ProjectLayout = project.layout,
) {
constructor(
project: Project,
dependencyFactory: DependencyFactory,
javaToolchainService: JavaToolchainService,
setupTask: TaskProvider<UserdevSetupTask>
) : this(
project,
dependencyFactory,
javaToolchainService,
determineArtifactCoordinates(project.configurations.getByName(DEV_BUNDLE_CONFIG)).single(),
setupTask,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.mache.*
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.Project
import org.gradle.api.artifacts.DependencySet
import org.gradle.api.file.FileCollection
import org.gradle.kotlin.dsl.*
Expand Down Expand Up @@ -204,11 +203,11 @@ class SetupHandlerImpl(
}
}

override fun afterEvaluate(project: Project) {
super.afterEvaluate(project)
setupMacheMeta(project.configurations.getByName(MACHE_CONFIG))
override fun afterEvaluate(context: SetupHandler.ConfigurationContext) {
super.afterEvaluate(context)
setupMacheMeta(context.project.configurations.getByName(MACHE_CONFIG))

val configurations = project.configurations
val configurations = context.project.configurations

val macheCodebook = configurations.register(MACHE_CODEBOOK_CONFIG) {
isTransitive = false
Expand All @@ -226,16 +225,16 @@ class SetupHandlerImpl(
isTransitive = false
}

project.tasks.withType(UserdevSetupTask::class).configureEach {
context.project.tasks.withType(UserdevSetupTask::class).configureEach {
macheCodebookConfig.from(macheCodebook)
macheRemapperConfig.from(macheRemapper)
macheDecompilerConfig.from(macheDecompiler)
macheParamMappingsConfig.from(macheParamMappings)
macheConstantsConfig.from(macheConstants)
}

macheMeta().addDependencies(project)
macheMeta().addRepositories(project)
macheMeta().addDependencies(context.project)
macheMeta().addRepositories(context.project)
}

override val minecraftVersion: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import io.papermc.paperweight.DownloadService
import io.papermc.paperweight.userdev.internal.action.CacheManager
import io.papermc.paperweight.util.*
import java.nio.file.Path
import org.gradle.api.Project
import org.gradle.api.artifacts.DependencySet
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
Expand Down Expand Up @@ -83,8 +82,8 @@ abstract class UserdevSetup : BuildService<UserdevSetup.Parameters>, SetupHandle
setup.extractReobfMappings(output)
}

override fun afterEvaluate(project: Project) {
setup.afterEvaluate(project)
override fun afterEvaluate(context: SetupHandler.ConfigurationContext) {
setup.afterEvaluate(context)
}

override val minecraftVersion: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package io.papermc.paperweight.userdev.internal.setup.v2

import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.userdev.PaperweightUserExtension
import io.papermc.paperweight.userdev.internal.action.*
import io.papermc.paperweight.userdev.internal.action.Input
import io.papermc.paperweight.userdev.internal.action.Output
Expand All @@ -35,8 +36,8 @@ import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.Project
import org.gradle.api.artifacts.DependencySet
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*

class SetupHandlerImplV2(
Expand Down Expand Up @@ -258,11 +259,18 @@ class SetupHandlerImplV2(
}
}

override fun afterEvaluate(project: Project) {
super.afterEvaluate(project)
project.tasks.withType(UserdevSetupTask::class).configureEach {
override fun afterEvaluate(context: SetupHandler.ConfigurationContext) {
super.afterEvaluate(context)
context.project.tasks.withType(UserdevSetupTask::class).configureEach {
legacyPaperclipResult.set(layout.cache.resolve(paperTaskOutput("legacyPaperclipResult", "jar")))
}
context.project.extensions.configure<PaperweightUserExtension> {
javaLauncher.convention(
context.javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
)
}
}

override val minecraftVersion: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package io.papermc.paperweight.userdev.internal.setup.v5

import io.papermc.paperweight.userdev.PaperweightUserExtension
import io.papermc.paperweight.userdev.internal.action.FileCollectionValue
import io.papermc.paperweight.userdev.internal.action.StringValue
import io.papermc.paperweight.userdev.internal.action.WorkDispatcher
Expand All @@ -36,6 +37,8 @@ import io.papermc.paperweight.util.*
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.artifacts.DependencySet
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.*

class SetupHandlerImplV5(
private val parameters: UserdevSetup.Parameters,
Expand Down Expand Up @@ -242,6 +245,29 @@ class SetupHandlerImplV5(
}
}

override fun afterEvaluate(context: SetupHandler.ConfigurationContext) {
super.afterEvaluate(context)
legacyDefaultJavaLauncher(context)
}

// Apply JDK 17 launcher as default for < 1.19.3
private fun legacyDefaultJavaLauncher(context: SetupHandler.ConfigurationContext) {
val versionParts = bundle.config.minecraftVersion.split('.', '-').mapNotNull { it.toIntOrNull() }
if (versionParts[1] > 19) {
return
}
if (versionParts[1] == 19 && versionParts[2] >= 3) {
return
}
context.project.extensions.configure<PaperweightUserExtension> {
javaLauncher.convention(
context.javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
)
}
}

override val minecraftVersion: String
get() = bundle.config.minecraftVersion

Expand Down

0 comments on commit f2cc105

Please sign in to comment.