From 88419a59af50f82cc80ed4fd98d437168e886b19 Mon Sep 17 00:00:00 2001 From: Sergey Shatunov Date: Sun, 14 Jan 2024 00:03:08 +0800 Subject: [PATCH] fix: add java version infer for fabric --- .../internal/infer/FabricModInfer.kt | 6 ++++++ .../internal/infer/FabricModInferSpec.kt | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInfer.kt b/src/main/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInfer.kt index 38a1c9d..dbbfb39 100644 --- a/src/main/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInfer.kt +++ b/src/main/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInfer.kt @@ -77,6 +77,12 @@ internal object FabricModInfer : Infer, Named { }.keys } + modInfo.depends["java"]?.let { javaRange -> + this += javaVersions.filterValues { + it != null && it.isStable && javaRange.constraint.isSatisfiedBy(it) + }.keys + } + if (Environment.Client in modInfo.environment) { this += environment.single { it.slug == "client" } } diff --git a/src/test/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInferSpec.kt b/src/test/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInferSpec.kt index fab7384..f0b86da 100644 --- a/src/test/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInferSpec.kt +++ b/src/test/kotlin/rocks/aur/cursedpublish/internal/infer/FabricModInferSpec.kt @@ -92,17 +92,32 @@ object FabricModInferSpec : FunSpec({ .map { it.slug } shouldContainExactlyInAnyOrder result } } + + context("should infer java version") { + withData(nameFn = { "Java $it" }, TestInferScope.javaVersions.values.mapNotNull { it?.major }) { javaVersion -> + genDummyFabricMod( + modFile, + javaVersion = "$javaVersion", + javaVersionConstraint = "=$javaVersion" + ) + + infer().filter { it in TestInferScope.javaVersions } + .map { it.name } shouldContainExactlyInAnyOrder setOf("Java $javaVersion") + } + } }) private fun genDummyFabricMod( file: Path, modId: String = "dummy", - modVersion: Version = Version.parse("1.2.3"), + modVersion: String = "1.2.3", minecraftVersion: String = "1.20.4", minecraftVersionConstraint: String = "~$minecraftVersion", fabricLoaderVersion: String = "0.15.0", fabricLoaderVersionConstraint: String = ">=$fabricLoaderVersion", environment: Set = FabricModInfer.Environment.ALL, + javaVersion: String = "17", + javaVersionConstraint: String = ">=$javaVersion", ) { val manifest = Manifest() manifest.mainAttributes[Attributes.Name.MANIFEST_VERSION] = "1.0" @@ -112,10 +127,11 @@ private fun genDummyFabricMod( val modInfo = FabricModInfer.FabricModInfo( schemaVersion = 1, id = modId, - version = modVersion, + version = Version.parse(modVersion, strict = false), depends = mapOf( "minecraft" to FabricModInfer.VersionRange(minecraftVersionConstraint), "fabricloader" to FabricModInfer.VersionRange(fabricLoaderVersionConstraint), + "java" to FabricModInfer.VersionRange(javaVersionConstraint), ), environment = environment )