diff --git a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorExtension.kt b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorExtension.kt index 3189dcd726c..f845f9310af 100644 --- a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorExtension.kt +++ b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorExtension.kt @@ -98,9 +98,16 @@ abstract class AccessorGeneratorExtension(protected val project: Project, protec abstract val accessorType: Property /** - * Namespaces that should be used in accessors, empty if all namespaces should be used. + * Namespaces that should be used in accessors, defaults to all supported namespaces ("mojang", "spigot", "yarn", "quilt", "searge", "intermediary" and "hashed"). */ - abstract val accessedNamespaces: ListProperty + abstract val namespaces: ListProperty + + /** + * Alias for [namespaces]. + */ + @Deprecated("Use namespaces.", ReplaceWith("namespaces")) + val accessedNamespaces: ListProperty + get() = namespaces /** * Namespaces that should be used for computing history, defaults to "mojang", "spigot", "searge" and "intermediary". @@ -127,6 +134,7 @@ abstract class AccessorGeneratorExtension(protected val project: Project, protec cacheDirectory.convention(project.layout.buildDirectory.dir("takenaka/cache")) codeLanguage.convention(CodeLanguage.JAVA) accessorType.convention(AccessorType.NONE) + namespaces.convention(listOf("mojang", "spigot", "yarn", "quilt", "searge", "intermediary", "hashed")) historyNamespaces.convention(listOf("mojang", "spigot", "searge", "intermediary")) historyIndexNamespace.convention(DEFAULT_INDEX_NS) relaxedCache.convention(true) @@ -261,12 +269,20 @@ abstract class AccessorGeneratorExtension(protected val project: Project, protec } /** - * Adds new namespaces to the [accessedNamespaces] property. + * Adds new namespaces to the [namespaces] property. * - * @param accessedNamespaces the namespaces + * @param namespaces the namespaces + */ + fun namespaces(vararg namespaces: String) { + this.namespaces.addAll(*namespaces) + } + + /** + * Alias for [namespaces]. */ + @Deprecated("Use namespaces(vararg String).", ReplaceWith("namespaces(*accessedNamespaces)")) fun accessedNamespaces(vararg accessedNamespaces: String) { - this.accessedNamespaces.addAll(*accessedNamespaces) + this.namespaces(*accessedNamespaces) } /** diff --git a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorPlugin.kt b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorPlugin.kt index 8068a9a65d5..c032d8e6b45 100644 --- a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorPlugin.kt +++ b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/AccessorGeneratorPlugin.kt @@ -60,6 +60,7 @@ class AccessorGeneratorPlugin : Plugin { this.cacheDir.set(config.cacheDirectory) this.versions.set(config.versions) + this.namespaces.set(project.provider { config.namespaces.get() + config.historyNamespaces.get() }) this.relaxedCache.set(config.relaxedCache) this.manifest.set(manifest) this.mappingBundle.fileProvider(mappingBundle.flatMap { mb -> @@ -84,7 +85,7 @@ class AccessorGeneratorPlugin : Plugin { this.accessors.set(config.accessors) this.codeLanguage.set(config.codeLanguage) this.accessorType.set(config.accessorType) - this.accessedNamespaces.set(config.accessedNamespaces) + this.namespaces.set(config.namespaces) this.historyNamespaces.set(config.historyNamespaces) this.historyIndexNamespace.set(config.historyIndexNamespace) this.namingStrategy.set(config.namingStrategy) @@ -100,7 +101,7 @@ class AccessorGeneratorPlugin : Plugin { this.accessors.set(config.accessors) this.codeLanguage.set(config.codeLanguage) this.accessorType.set(config.accessorType) - this.accessedNamespaces.set(config.accessedNamespaces) + this.namespaces.set(config.namespaces) this.historyNamespaces.set(config.historyNamespaces) this.historyIndexNamespace.set(config.historyIndexNamespace) this.namingStrategy.set(config.namingStrategy) diff --git a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerateAccessorsTask.kt b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerateAccessorsTask.kt index 30acaf91589..ded8998de0f 100644 --- a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerateAccessorsTask.kt +++ b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerateAccessorsTask.kt @@ -41,7 +41,7 @@ abstract class GenerateAccessorsTask : GenerationTask() { codeLanguage = codeLanguage.get(), accessorType = accessorType.get(), namespaceFriendlinessIndex = namespaceFriendlinessIndex.get(), - accessedNamespaces = accessedNamespaces.get(), + accessedNamespaces = namespaces.get(), craftBukkitVersionReplaceCandidates = craftBukkitVersionReplaceCandidates.get(), namingStrategy = namingStrategy.get(), runtimePackage = runtimePackage.get() diff --git a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerationTask.kt b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerationTask.kt index 9e8c6d25367..9cf1e86308d 100644 --- a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerationTask.kt +++ b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/GenerationTask.kt @@ -103,12 +103,20 @@ abstract class GenerationTask : DefaultTask() { abstract val accessorType: Property /** - * Namespaces that should be used in accessors, empty if all namespaces should be used. + * Namespaces that should be used in accessors, defaults to all supported namespaces ("mojang", "spigot", "yarn", "quilt", "searge", "intermediary" and "hashed"). * - * @see me.kcra.takenaka.generator.accessor.plugin.AccessorGeneratorExtension.accessedNamespaces + * @see me.kcra.takenaka.generator.accessor.plugin.AccessorGeneratorExtension.namespaces */ @get:Input - abstract val accessedNamespaces: ListProperty + abstract val namespaces: ListProperty + + /** + * Alias for [namespaces]. + */ + @get:Internal + @Deprecated("Use namespaces.", ReplaceWith("namespaces")) + val accessedNamespaces: ListProperty + get() = namespaces /** * Namespaces that should have [me.kcra.takenaka.core.mapping.adapter.replaceCraftBukkitNMSVersion] applied @@ -163,6 +171,7 @@ abstract class GenerationTask : DefaultTask() { codeLanguage.convention(CodeLanguage.JAVA) accessorType.convention(AccessorType.NONE) craftBukkitVersionReplaceCandidates.convention(listOf("spigot")) + namespaces.convention(listOf("mojang", "spigot", "yarn", "quilt", "searge", "intermediary", "hashed")) historyNamespaces.convention(listOf("mojang", "spigot", "searge", "intermediary")) historyIndexNamespace.convention(DEFAULT_INDEX_NS) @Suppress("DEPRECATION") diff --git a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/ResolveMappingsTask.kt b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/ResolveMappingsTask.kt index bfddbfcb05b..7054d625330 100644 --- a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/ResolveMappingsTask.kt +++ b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/ResolveMappingsTask.kt @@ -22,11 +22,14 @@ import kotlinx.coroutines.runBlocking import me.kcra.takenaka.core.Version import me.kcra.takenaka.core.VersionManifest import me.kcra.takenaka.core.compositeWorkspace +import me.kcra.takenaka.core.mapping.MappingContributor import me.kcra.takenaka.core.mapping.adapter.* import me.kcra.takenaka.core.mapping.analysis.impl.AnalysisOptions import me.kcra.takenaka.core.mapping.analysis.impl.MappingAnalyzerImpl import me.kcra.takenaka.core.mapping.resolve.impl.* +import me.kcra.takenaka.core.util.md5Digest import me.kcra.takenaka.core.util.objectMapper +import me.kcra.takenaka.core.util.updateAndHex import me.kcra.takenaka.generator.accessor.plugin.PlatformTristate import me.kcra.takenaka.generator.common.provider.impl.BundledMappingProvider import me.kcra.takenaka.generator.common.provider.impl.ResolvingMappingProvider @@ -35,6 +38,7 @@ import net.fabricmc.mappingio.tree.MappingTree import org.gradle.api.DefaultTask import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.api.provider.SetProperty @@ -85,6 +89,17 @@ abstract class ResolveMappingsTask : DefaultTask() { @get:Input abstract val versions: SetProperty + /** + * Namespaces to be resolved, defaults to all supported namespaces ("mojang", "spigot", "yarn", "quilt", "searge", "intermediary" and "hashed"). + * + * *This is ignored if a [mappingBundle] is specified.* + * + * @see me.kcra.takenaka.generator.accessor.plugin.AccessorGeneratorExtension.namespaces + * @see me.kcra.takenaka.generator.accessor.plugin.AccessorGeneratorExtension.historyNamespaces + */ + @get:Input + abstract val namespaces: ListProperty + /** * Whether output cache verification constraints should be relaxed, defaults to true. * @@ -144,6 +159,7 @@ abstract class ResolveMappingsTask : DefaultTask() { } init { + namespaces.convention(listOf("mojang", "spigot", "yarn", "quilt", "searge", "intermediary", "hashed")) cacheDir.convention(project.layout.buildDirectory.dir("takenaka/cache")) relaxedCache.convention(true) platform.convention(PlatformTristate.SERVER) @@ -185,6 +201,12 @@ abstract class ResolveMappingsTask : DefaultTask() { val requiredPlatform = platform.get() val requiredVersions = versions.get().toList() + + val requiredNamespaces = namespaces.get().toSet() + fun MutableCollection.addIfSupported(contributor: T) { + if (contributor.targetNamespace in requiredNamespaces) add(contributor) + } + val resolvedMappings = runBlocking { // resolve mappings on this system, if a bundle is not available if (mappingBundle.isPresent) { @@ -217,49 +239,78 @@ abstract class ResolveMappingsTask : DefaultTask() { buildList { if (requiredPlatform.wantsServer) { - add(VanillaServerMappingContributor(versionWorkspace, mojangProvider, relaxedCache.get())) - add(MojangServerMappingResolver(versionWorkspace, mojangProvider)) + add( + VanillaServerMappingContributor( + versionWorkspace, + mojangProvider, + relaxedCache.get() + ) + ) + addIfSupported(MojangServerMappingResolver(versionWorkspace, mojangProvider)) } if (requiredPlatform.wantsClient) { - add(VanillaClientMappingContributor(versionWorkspace, mojangProvider, relaxedCache.get())) - add(MojangClientMappingResolver(versionWorkspace, mojangProvider)) + add( + VanillaClientMappingContributor( + versionWorkspace, + mojangProvider, + relaxedCache.get() + ) + ) + addIfSupported(MojangClientMappingResolver(versionWorkspace, mojangProvider)) } - add(IntermediaryMappingResolver(versionWorkspace, sharedCacheWorkspace)) - add(HashedMappingResolver(versionWorkspace)) - add(YarnMappingResolver(versionWorkspace, yarnProvider, relaxedCache.get())) - add(QuiltMappingResolver(versionWorkspace, quiltProvider, relaxedCache.get())) - add(SeargeMappingResolver(versionWorkspace, sharedCacheWorkspace, relaxedCache = relaxedCache.get())) + addIfSupported(IntermediaryMappingResolver(versionWorkspace, sharedCacheWorkspace)) + addIfSupported(HashedMappingResolver(versionWorkspace)) + addIfSupported(YarnMappingResolver(versionWorkspace, yarnProvider, relaxedCache.get())) + addIfSupported(QuiltMappingResolver(versionWorkspace, quiltProvider, relaxedCache.get())) + addIfSupported( + SeargeMappingResolver( + versionWorkspace, + sharedCacheWorkspace, + relaxedCache = relaxedCache.get() + ) + ) // Spigot resolvers have to be last if (requiredPlatform.wantsServer) { val link = LegacySpigotMappingPrepender.Link() - add( + addIfSupported( // 1.16.5 mappings have been republished with proper packages, even though the reobfuscated JAR does not have those // See: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/builddata/commits/80d35549ec67b87a0cdf0d897abbe826ba34ac27 link.createPrependingContributor( - SpigotClassMappingResolver(versionWorkspace, xmlMapper, spigotProvider, relaxedCache.get()), + SpigotClassMappingResolver( + versionWorkspace, + xmlMapper, + spigotProvider, + relaxedCache.get() + ), prependEverything = versionWorkspace.version.id == "1.16.5" ) ) - add(link.createPrependingContributor(SpigotMemberMappingResolver(versionWorkspace, xmlMapper, spigotProvider, relaxedCache.get()))) + addIfSupported( + link.createPrependingContributor( + SpigotMemberMappingResolver( + versionWorkspace, + xmlMapper, + spigotProvider, + relaxedCache.get() + ) + ) + ) } } } joinedOutputPath { workspace -> - val fileName = when (requiredPlatform) { - PlatformTristate.CLIENT_SERVER -> "client+server.tiny" - PlatformTristate.CLIENT -> "client.tiny" - else -> "server.tiny" - } + val hash = md5Digest.updateAndHex(requiredNamespaces.sorted().joinToString(",")) - workspace[fileName] + workspace["$hash.$requiredPlatform.tiny"] } } val analyzer = MappingAnalyzerImpl( + // if the namespaces are missing, nothing happens anyway - no need to configure based on resolvedNamespaces AnalysisOptions( innerClassNameCompletionCandidates = setOf("spigot"), inheritanceAdditionalNamespaces = setOf("searge") // mojang could be here too for maximal parity, but that's in exchange for a little bit of performance diff --git a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/TraceAccessorsTask.kt b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/TraceAccessorsTask.kt index faf0b854493..cb4cdbe7735 100644 --- a/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/TraceAccessorsTask.kt +++ b/generator/accessor-plugin/src/main/kotlin/me/kcra/takenaka/generator/accessor/plugin/tasks/TraceAccessorsTask.kt @@ -64,7 +64,7 @@ abstract class TraceAccessorsTask : GenerationTask() { codeLanguage = codeLanguage.get(), accessorType = accessorType.get(), namespaceFriendlinessIndex = namespaceFriendlinessIndex.get(), - accessedNamespaces = accessedNamespaces.get(), + accessedNamespaces = namespaces.get(), craftBukkitVersionReplaceCandidates = craftBukkitVersionReplaceCandidates.get(), namingStrategy = namingStrategy.get(), runtimePackage = runtimePackage.get()