mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Ship each built-in module as its own jar and let a pack's modules.json decide which update on their own
The built-ins no longer travel as one iris-builtins.jar that a pack has to copy by hand. IrisModule builds one jar per module (the eight placement stages share one) with an index of the id and version each module reports, and Iris bundles that folder. A pack lists the modules it uses in modules.json, with the version it was built with and an optional pinned list. Before a pack loads, Iris installs the jars of listed modules and replaces a jar that differs from the one it ships. It keeps a jar when the module is pinned, when the pack holds a newer version than Iris ships, and, in a world's copy of a pack, when the major version changed, because new chunks would not match the old ones. A jar that shares classes with a kept jar stays with it, since the two were compiled against each other. /iris pack update takes the kept terrain changes for a world. What is installed is recorded in modules.lock.json. Module versions are now major.minor.patch per module, starting at 1.0.0, with major meaning "places different blocks or stops loading settings".
This commit is contained in:
1 parent
e7d1ed24cb
commit
6e96c6b71e
85 files changed
+2568
-480
No files matched your search
+144
-78
@@ -1,7 +1,6 @@
|
||||
import org.gradle.api.tasks.bundling.ZipEntryCompression
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
@@ -38,7 +37,7 @@ dependencies {
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||
}
|
||||
|
||||
// The same options as Iris's own compilation, so the classes, and the built-ins jar made from them, are the ones Iris
|
||||
// The same options as Iris's own compilation, so the classes, and the module jars made from them, are the ones Iris
|
||||
// shipped when it compiled these sources itself.
|
||||
tasks.named<JavaCompile>("compileJava") {
|
||||
options.encoding = "UTF-8"
|
||||
@@ -51,52 +50,30 @@ tasks.named<JavaCompile>("compileJava") {
|
||||
}
|
||||
|
||||
// The version every built-in module reports: Iris's own, so a pack's copy of the built-ins jar names the Iris build it came
|
||||
// from. This included build does not inherit Iris's gradle.properties, so it reads irisVersion from there.
|
||||
val irisVersion: String = providers.gradleProperty("irisVersion").orElse(provider {
|
||||
Properties().apply { layout.projectDirectory.file("../gradle.properties").asFile.reader().use(::load) }
|
||||
.getProperty("irisVersion")
|
||||
}).get()
|
||||
|
||||
val generateBuiltInModulesVersion = tasks.register("generateBuiltInModulesVersion") {
|
||||
description = "Writes BuiltInModulesVersion, which holds the version the built-in modules report."
|
||||
val output = layout.buildDirectory.dir("generated/sources/builtin-modules-version")
|
||||
inputs.property("irisVersion", irisVersion)
|
||||
outputs.dir(output)
|
||||
doLast {
|
||||
val source = output.get().file("art/arcane/iris/modules/BuiltInModulesVersion.java").asFile
|
||||
source.parentFile.mkdirs()
|
||||
source.writeText("""
|
||||
|package art.arcane.iris.modules;
|
||||
|
|
||||
|/** The version every built-in module reports: the Iris build the built-ins jar came from. Generated by the build. */
|
||||
|public final class BuiltInModulesVersion {
|
||||
| public static final String VERSION = "$irisVersion";
|
||||
|
|
||||
| private BuiltInModulesVersion() {
|
||||
| }
|
||||
|}
|
||||
|""".trimMargin())
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java.srcDir(generateBuiltInModulesVersion)
|
||||
}
|
||||
|
||||
// The built-ins as a pack module jar, build/libs/iris-builtins.jar. builtin-modules.txt lists what goes in:
|
||||
// "module <class>" (an entry point, with its nested classes) or "include <ant pattern>".
|
||||
val builtinModulesJarName = "iris-builtins.jar"
|
||||
val builtinModuleEntryFile = "com.volmit.IrisModule"
|
||||
// The built-in modules as pack module jars, one per "jar" section of builtin-modules.txt: build/shipped-modules/iris-<name>.jar,
|
||||
// with index.json naming the id and version of every module in them. Iris bundles that folder and installs the jars a
|
||||
// pack's modules.json lists.
|
||||
val moduleEntryFile = "com.volmit.IrisModule"
|
||||
val builtinModulesFile = layout.projectDirectory.file("builtin-modules.txt").asFile
|
||||
val shippedJarPrefix = "iris-"
|
||||
val shippedIndexName = "index.json"
|
||||
// The packages an Iris host exposes to pack modules besides the API (Iris's IrisModuleHost.EXPOSED_PACKAGES).
|
||||
val exposedHostPackages = listOf("art.arcane.iris.builtin", "art.arcane.iris.core.structure.authoring", "art.arcane.volmlib",
|
||||
"com.google.gson")
|
||||
|
||||
data class BuiltinModulesList(val moduleClasses: List<String>, val classPatterns: List<String>)
|
||||
data class ListedJar(val name: String, val moduleClasses: MutableList<String> = mutableListOf(),
|
||||
val classPatterns: MutableList<String> = mutableListOf()) {
|
||||
val fileName get() = "iris-$name.jar"
|
||||
val taskSuffix get() = name.split('-').joinToString("") { it.replaceFirstChar(Char::uppercase) }
|
||||
val packagedPatterns
|
||||
get() = moduleClasses.flatMap { moduleClass ->
|
||||
val path = moduleClass.replace('.', '/')
|
||||
listOf("$path.class", "$path\$*.class")
|
||||
} + classPatterns
|
||||
}
|
||||
|
||||
fun readBuiltinModulesList(): BuiltinModulesList {
|
||||
val moduleClasses = mutableListOf<String>()
|
||||
val classPatterns = mutableListOf<String>()
|
||||
fun readListedJars(): List<ListedJar> {
|
||||
val jars = mutableListOf<ListedJar>()
|
||||
builtinModulesFile.readLines()
|
||||
.map { it.substringBefore('#').trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
@@ -105,51 +82,100 @@ fun readBuiltinModulesList(): BuiltinModulesList {
|
||||
if (parts.size < 2 || parts[1].isBlank()) {
|
||||
throw GradleException("${builtinModulesFile.name}: '$line' needs a value after '${parts[0]}'")
|
||||
}
|
||||
val value = parts[1].trim()
|
||||
if (parts[0] == "jar") {
|
||||
if (jars.any { it.name == value }) {
|
||||
throw GradleException("${builtinModulesFile.name}: jar '$value' is listed twice")
|
||||
}
|
||||
jars.add(ListedJar(value))
|
||||
return@forEach
|
||||
}
|
||||
val jar = jars.lastOrNull()
|
||||
?: throw GradleException("${builtinModulesFile.name}: '$line' comes before the first 'jar' line")
|
||||
when (parts[0]) {
|
||||
"module" -> moduleClasses.add(parts[1].trim())
|
||||
"include" -> classPatterns.add(parts[1].trim())
|
||||
else -> throw GradleException("${builtinModulesFile.name}: unknown line '$line'; start it with 'module' or 'include'")
|
||||
"module" -> jar.moduleClasses.add(value)
|
||||
"include" -> jar.classPatterns.add(value)
|
||||
else -> throw GradleException("${builtinModulesFile.name}: unknown line '$line'; start it with 'jar', 'module' or 'include'")
|
||||
}
|
||||
}
|
||||
return BuiltinModulesList(moduleClasses, classPatterns)
|
||||
jars.filter { it.moduleClasses.isEmpty() }.forEach {
|
||||
throw GradleException("${builtinModulesFile.name}: jar '${it.name}' lists no module; a pack module jar needs one")
|
||||
}
|
||||
return jars
|
||||
}
|
||||
|
||||
val builtinModulesList = readBuiltinModulesList()
|
||||
val builtinPackagedPatterns = builtinModulesList.moduleClasses.flatMap { moduleClass ->
|
||||
val path = moduleClass.replace('.', '/')
|
||||
listOf("$path.class", "$path\$*.class")
|
||||
} + builtinModulesList.classPatterns
|
||||
val listedJars = readListedJars()
|
||||
val builtinModulesBuild = layout.buildDirectory.dir("builtin-modules")
|
||||
|
||||
val writeBuiltinModuleEntries = tasks.register("writeBuiltinModuleEntries") {
|
||||
description = "Writes the built-ins jar's META-INF/services/$builtinModuleEntryFile, one module class per line."
|
||||
val entries = builtinModulesBuild.map { it.file("services/$builtinModuleEntryFile") }
|
||||
fun entryFileOf(jar: ListedJar) = builtinModulesBuild.map { it.file("services/${jar.name}/$moduleEntryFile") }
|
||||
|
||||
val writeModuleEntries = tasks.register("writeModuleEntries") {
|
||||
description = "Writes each jar's META-INF/services/$moduleEntryFile, one module class per line."
|
||||
inputs.file(builtinModulesFile)
|
||||
outputs.dir(builtinModulesBuild.map { it.dir("services") })
|
||||
doLast {
|
||||
listedJars.forEach { jar ->
|
||||
val entriesFile = entryFileOf(jar).get().asFile
|
||||
entriesFile.parentFile.mkdirs()
|
||||
entriesFile.writeText(jar.moduleClasses.joinToString("\n") + "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A jar's bytes decide whether a pack's copy is the one Iris ships, so the same classes must give the same bytes.
|
||||
fun Jar.packagedAsShippedModule() {
|
||||
isPreserveFileTimestamps = false
|
||||
isReproducibleFileOrder = true
|
||||
// Iris's own jar compresses this one as a whole, which squeezes more out of the classes than compressing them twice.
|
||||
entryCompression = ZipEntryCompression.STORED
|
||||
inputs.file(builtinModulesFile)
|
||||
}
|
||||
|
||||
val packageModuleJars = listedJars.map { listed ->
|
||||
tasks.register<Jar>("package${listed.taskSuffix}ModuleJar") {
|
||||
description = "Packages ${listed.fileName} before the built-in modules are checked."
|
||||
archiveFileName.set(listed.fileName)
|
||||
destinationDirectory.set(builtinModulesBuild.map { it.dir("jars") })
|
||||
packagedAsShippedModule()
|
||||
from(sourceSets.main.map { it.java.classesDirectory }) {
|
||||
include(listed.packagedPatterns)
|
||||
}
|
||||
from(entryFileOf(listed)) {
|
||||
into("META-INF/services")
|
||||
}
|
||||
dependsOn(writeModuleEntries)
|
||||
}
|
||||
}
|
||||
|
||||
// The checks judge a pack's jars together, as a pack load does, so they read all the built-ins as one jar. Nothing ships it.
|
||||
val allModulesJarName = "iris-builtins.jar"
|
||||
val writeAllModuleEntries = tasks.register("writeAllModuleEntries") {
|
||||
description = "Writes the entry file that lists every built-in module, for the jar the checks read."
|
||||
val entries = builtinModulesBuild.map { it.file("all-services/$moduleEntryFile") }
|
||||
inputs.file(builtinModulesFile)
|
||||
outputs.file(entries)
|
||||
doLast {
|
||||
val entriesFile = entries.get().asFile
|
||||
entriesFile.parentFile.mkdirs()
|
||||
entriesFile.writeText(builtinModulesList.moduleClasses.joinToString("\n") + "\n")
|
||||
entriesFile.writeText(listedJars.flatMap { it.moduleClasses }.joinToString("\n") + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
val packageBuiltinModules = tasks.register<Jar>("packageBuiltinModules") {
|
||||
description = "Packages the listed built-in modules and classes before they are checked."
|
||||
archiveFileName.set(builtinModulesJarName)
|
||||
val packageAllModules = tasks.register<Jar>("packageAllModules") {
|
||||
description = "Packages every built-in module into one jar for the pack module checks."
|
||||
archiveFileName.set(allModulesJarName)
|
||||
destinationDirectory.set(builtinModulesBuild.map { it.dir("unchecked") })
|
||||
// Iris's own jar compresses this one as a whole, which squeezes more out of the classes than compressing them twice.
|
||||
entryCompression = ZipEntryCompression.STORED
|
||||
inputs.file(builtinModulesFile)
|
||||
packagedAsShippedModule()
|
||||
from(sourceSets.main.map { it.java.classesDirectory }) {
|
||||
include(builtinPackagedPatterns)
|
||||
include(listedJars.flatMap { it.packagedPatterns })
|
||||
}
|
||||
from(writeBuiltinModuleEntries) {
|
||||
from(writeAllModuleEntries) {
|
||||
into("META-INF/services")
|
||||
}
|
||||
}
|
||||
|
||||
// The check runs on the API's host side, which knows the rules of a pack load; the module classes are on its class path as
|
||||
// the host's, so a listed class that uses one left out of the jar fails as it would in Iris.
|
||||
// the host's, so a listed class that uses one left out of every jar fails as it would in Iris.
|
||||
val builtinModulesCheckClasspath = configurations.create("builtinModulesCheckClasspath") {
|
||||
isCanBeConsumed = false
|
||||
isTransitive = false
|
||||
@@ -158,19 +184,23 @@ val builtinModulesCheckClasspath = configurations.create("builtinModulesCheckCla
|
||||
}
|
||||
}
|
||||
|
||||
val tools = sourceSets.create("tools")
|
||||
|
||||
dependencies {
|
||||
builtinModulesCheckClasspath("com.volmit:iris-api")
|
||||
builtinModulesCheckClasspath("com.volmit:iris-host")
|
||||
builtinModulesCheckClasspath(volmLibCoordinate)
|
||||
builtinModulesCheckClasspath("com.google.code.gson:gson:2.14.0")
|
||||
"toolsImplementation"("com.volmit:iris-api")
|
||||
"toolsImplementation"("com.google.code.gson:gson:2.14.0")
|
||||
}
|
||||
|
||||
val builtinModulesJar = tasks.register<JavaExec>("builtinModulesJar") {
|
||||
val checkedModulesJar = tasks.register<JavaExec>("checkedModulesJar") {
|
||||
group = "build"
|
||||
description = "Builds build/libs/$builtinModulesJarName, the built-in modules as a pack module jar, checked with IrisApi's" +
|
||||
" pack class and reference checks as a pack load would."
|
||||
val unchecked = packageBuiltinModules.flatMap { it.archiveFile }
|
||||
val checked = layout.buildDirectory.file("libs/$builtinModulesJarName")
|
||||
description = "Checks the built-in modules with IrisApi's pack class and reference checks, as a pack load would, and" +
|
||||
" writes them as one jar to build/libs/$allModulesJarName for Iris's own check."
|
||||
val unchecked = packageAllModules.flatMap { it.archiveFile }
|
||||
val checked = layout.buildDirectory.file("libs/$allModulesJarName")
|
||||
classpath = builtinModulesCheckClasspath + files(sourceSets.main.map { it.java.classesDirectory })
|
||||
mainClass.set("com.volmit.host.ModuleJarCheck")
|
||||
inputs.file(unchecked)
|
||||
@@ -185,15 +215,38 @@ val builtinModulesJar = tasks.register<JavaExec>("builtinModulesJar") {
|
||||
}
|
||||
doLast {
|
||||
if (executionResult.get().exitValue != 0) {
|
||||
throw GradleException("The built-in modules jar breaks the rules of a pack module jar:\n" + problems.toString().trim() +
|
||||
"\nFix the classes listed in ${builtinModulesFile.name}, or move what they use into the jar or into art.arcane.iris.builtin.")
|
||||
throw GradleException("The built-in modules break the rules of a pack module jar:\n" + problems.toString().trim() +
|
||||
"\nFix the classes listed in ${builtinModulesFile.name}, or move what they use into a jar or into art.arcane.iris.builtin.")
|
||||
}
|
||||
unchecked.get().asFile.copyTo(checked.get().asFile, overwrite = true)
|
||||
}
|
||||
}
|
||||
|
||||
// Iris bundles the checked jar into its plugin. It asks for it by this capability of the module's coordinate.
|
||||
configurations.create("builtinModulesJarElements") {
|
||||
val writeShippedModuleIndex = tasks.register<JavaExec>("writeShippedModuleIndex") {
|
||||
description = "Writes $shippedIndexName: the hash of every shipped module jar and the id and version its modules report."
|
||||
val jars = files(packageModuleJars.map { it.flatMap(Jar::getArchiveFile) })
|
||||
val index = builtinModulesBuild.map { it.file(shippedIndexName) }
|
||||
classpath = tools.runtimeClasspath + builtinModulesCheckClasspath + files(sourceSets.main.map { it.java.classesDirectory })
|
||||
mainClass.set("art.arcane.iris.modulebuild.ShippedModuleIndex")
|
||||
inputs.files(jars)
|
||||
outputs.file(index)
|
||||
argumentProviders.add(CommandLineArgumentProvider {
|
||||
listOf(index.get().asFile.absolutePath) + jars.files.sortedBy { it.name }.map { it.absolutePath }
|
||||
})
|
||||
// The index must not describe modules that failed the checks.
|
||||
dependsOn(checkedModulesJar)
|
||||
}
|
||||
|
||||
val shippedModulesFolder = layout.buildDirectory.dir("shipped-modules")
|
||||
val shippedModules = tasks.register<Sync>("shippedModules") {
|
||||
group = "build"
|
||||
description = "Builds build/shipped-modules: the checked built-in module jars and their $shippedIndexName."
|
||||
from(packageModuleJars)
|
||||
from(writeShippedModuleIndex)
|
||||
into(shippedModulesFolder)
|
||||
}
|
||||
|
||||
fun Configuration.asModuleArtifacts(capability: String) {
|
||||
isCanBeConsumed = true
|
||||
isCanBeResolved = false
|
||||
attributes {
|
||||
@@ -202,16 +255,29 @@ configurations.create("builtinModulesJarElements") {
|
||||
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR))
|
||||
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
|
||||
}
|
||||
outgoing.capability("art.arcane:iris-builtins:${project.version}")
|
||||
outgoing.artifact(builtinModulesJar.map { layout.buildDirectory.file("libs/$builtinModulesJarName").get() }) {
|
||||
builtBy(builtinModulesJar)
|
||||
outgoing.capability("art.arcane:$capability:${project.version}")
|
||||
}
|
||||
|
||||
// Iris checks the one-jar form once more against what its own Bukkit jar leaves out. It asks for it by this capability.
|
||||
configurations.create("builtinModulesJarElements") {
|
||||
asModuleArtifacts("iris-builtins")
|
||||
outgoing.artifact(checkedModulesJar.map { layout.buildDirectory.file("libs/$allModulesJarName").get() }) {
|
||||
builtBy(checkedModulesJar)
|
||||
}
|
||||
}
|
||||
|
||||
// Iris bundles the folder of shipped jars into its plugin. It asks for it by this capability.
|
||||
configurations.create("shippedModulesElements") {
|
||||
asModuleArtifacts("iris-shipped-modules")
|
||||
outgoing.artifact(shippedModulesFolder) {
|
||||
builtBy(shippedModules)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("check") {
|
||||
dependsOn(builtinModulesJar)
|
||||
dependsOn(shippedModules)
|
||||
}
|
||||
|
||||
tasks.named("assemble") {
|
||||
dependsOn(builtinModulesJar)
|
||||
dependsOn(shippedModules)
|
||||
}
|
||||
Reference in new issue
Block a user