diff options
author | Linnea Gräf <nea@nea.moe> | 2025-07-06 12:03:13 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-07-06 12:03:28 +0200 |
commit | 6c3f8333620e61bc8f00aca4d64b117ac7d0149b (patch) | |
tree | 1c0993adda21a76385c47f514e7a1d972e841c4f /buildSrc | |
parent | 08c81862afd8689c6eb6f4d8deec8b1ab6ad6d3a (diff) | |
download | Firmament-6c3f8333620e61bc8f00aca4d64b117ac7d0149b.tar.gz Firmament-6c3f8333620e61bc8f00aca4d64b117ac7d0149b.tar.bz2 Firmament-6c3f8333620e61bc8f00aca4d64b117ac7d0149b.zip |
build: use composite builds instead of buildSrc
Diffstat (limited to 'buildSrc')
-rw-r--r-- | buildSrc/build.gradle.kts | 29 | ||||
-rw-r--r-- | buildSrc/src/EnvFile.kt | 13 | ||||
-rw-r--r-- | buildSrc/src/FabricModTransform.kt | 80 | ||||
-rw-r--r-- | buildSrc/src/InnerJarsUnpacker.kt | 70 | ||||
-rw-r--r-- | buildSrc/src/RepoDownload.kt | 41 | ||||
-rw-r--r-- | buildSrc/src/licenseinfo.kt | 144 | ||||
-rw-r--r-- | buildSrc/src/lookupversion.kt | 25 |
7 files changed, 0 insertions, 402 deletions
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 1b2542b..0000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> -// -// SPDX-License-Identifier: CC0-1.0 - -plugins { - kotlin("jvm") version "2.1.0" - `kotlin-dsl` -} -repositories { - mavenCentral() - maven { - name = "jitpack" - url = uri("https://jitpack.io") - } -} -dependencies { - implementation("com.github.romangraef:neaslicenseextractificator:1.1.0") - api("com.gradleup.shadow:shadow-gradle-plugin:9.0.0-rc1") - implementation("net.fabricmc:access-widener:2.1.0") - implementation("com.google.code.gson:gson:2.10.1") -} - -sourceSets { - main { - kotlin { - srcDir(file("src")) - } - } -} diff --git a/buildSrc/src/EnvFile.kt b/buildSrc/src/EnvFile.kt deleted file mode 100644 index ceec763..0000000 --- a/buildSrc/src/EnvFile.kt +++ /dev/null @@ -1,13 +0,0 @@ - -import java.io.File - -fun parseEnvFile(file: File): Map<String, String> { - if (!file.exists()) return mapOf() - val map = mutableMapOf<String, String>() - for (line in file.readText().lines()) { - if (line.isEmpty() || line.startsWith("#")) continue - val parts = line.split("=", limit = 2) - map[parts[0]] = parts.getOrNull(1) ?: "" - } - return map -} diff --git a/buildSrc/src/FabricModTransform.kt b/buildSrc/src/FabricModTransform.kt deleted file mode 100644 index 53affbe..0000000 --- a/buildSrc/src/FabricModTransform.kt +++ /dev/null @@ -1,80 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.transformers.ResourceTransformer -import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext -import com.google.gson.Gson -import com.google.gson.JsonObject -import com.google.gson.JsonPrimitive -import java.io.Serializable -import net.fabricmc.accesswidener.AccessWidenerReader -import net.fabricmc.accesswidener.AccessWidenerWriter -import org.apache.tools.zip.ZipEntry -import org.apache.tools.zip.ZipOutputStream -import org.gradle.api.file.FileTreeElement -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Internal - -open class FabricModTransform : ResourceTransformer { - - enum class AccessWidenerInclusion : Serializable { - ALL, - NONE, - } - - @get:Input - var mergeAccessWideners: AccessWidenerInclusion = AccessWidenerInclusion.ALL - - @get:Internal - internal var mergedFmj: JsonObject? = null - - @get:Internal - internal val foundAccessWideners = AccessWidenerWriter() - - @get:Internal - internal var foundAnyAccessWidener = false - - override fun canTransformResource(element: FileTreeElement): Boolean { - if (mergeAccessWideners == AccessWidenerInclusion.ALL && element.name.endsWith(".accesswidener")) - return true - return element.path == "fabric.mod.json" - } - - override fun transform(context: TransformerContext) { - if (context.path.endsWith(".accesswidener")) { - foundAnyAccessWidener = true - // TODO: allow filtering for only those mentioned in a fabric.mod.json, potentially - context.inputStream.use { stream -> - AccessWidenerReader(foundAccessWideners).read(stream.bufferedReader()) - } - return - } - // TODO: mixins.json relocations - val fmj = context.inputStream.use { stream -> - Gson().fromJson(stream.bufferedReader(), JsonObject::class.java) - } - val mergedFmj = this.mergedFmj - println("${fmj["id"]} is first? ${mergedFmj == null}") - if (mergedFmj == null) { - this.mergedFmj = fmj - } else { - // TODO: merge stuff - } - } - - override fun hasTransformedResource(): Boolean { - return mergedFmj != null - } - - override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) { - val mergedFmj = mergedFmj!! - if (foundAnyAccessWidener) { - val awFile = mergedFmj["accessWidener"] - require(awFile is JsonPrimitive && awFile.isString) - os.putNextEntry(ZipEntry(awFile.asString)) - os.write(foundAccessWideners.write()) - os.closeEntry() - } - os.putNextEntry(ZipEntry("fabric.mod.json")) - os.write(mergedFmj.toString().toByteArray()) - os.closeEntry() - } -} diff --git a/buildSrc/src/InnerJarsUnpacker.kt b/buildSrc/src/InnerJarsUnpacker.kt deleted file mode 100644 index de06467..0000000 --- a/buildSrc/src/InnerJarsUnpacker.kt +++ /dev/null @@ -1,70 +0,0 @@ -import com.google.gson.Gson -import com.google.gson.JsonArray -import com.google.gson.JsonObject -import com.google.gson.JsonPrimitive -import java.io.File -import java.util.zip.ZipInputStream -import org.gradle.api.DefaultTask -import org.gradle.api.file.ConfigurableFileCollection -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.InputFiles -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.OutputFiles -import org.gradle.api.tasks.TaskAction -import kotlin.io.path.createDirectories -import kotlin.io.path.outputStream - -abstract class InnerJarsUnpacker : DefaultTask() { - @get:InputFiles - abstract val inputJars: ConfigurableFileCollection - - @get:OutputDirectory - abstract val outputDir: DirectoryProperty - - private fun getFabricModJson(inputFile: File): JsonObject { - inputFile.inputStream().use { - val zis = ZipInputStream(it) - while (true) { - val entry = zis.nextEntry ?: error("Failed to find fabric.mod.json") - if (entry.name == "fabric.mod.json") { - return Gson().fromJson(zis.reader(), JsonObject::class.java) - } - } - } - } - - @TaskAction - fun unpack() { - inputJars.forEach { inputFile -> - val fabricModObject = getFabricModJson(inputFile) - val jars = fabricModObject["jars"] as? JsonArray ?: error("No jars to unpack in $inputFile") - val jarPaths = jars.map { - ((it as? JsonObject)?.get("file") as? JsonPrimitive)?.asString - ?: error("Invalid Jar $it in $inputFile") - } - extractJars(inputFile, jarPaths) - } - } - - private fun extractJars(inputFile: File, jarPaths: List<String>) { - val outputFile = outputDir.get().asFile.toPath() - val jarPathSet = jarPaths.toMutableSet() - inputFile.inputStream().use { - val zis = ZipInputStream(it) - while (true) { - val entry = zis.nextEntry ?: break - if (jarPathSet.remove(entry.name)) { - val resolvedPath = outputFile.resolve(entry.name) - resolvedPath.parent.createDirectories() - resolvedPath.outputStream().use { os -> - zis.copyTo(os) - } - } - } - } - if (jarPathSet.isNotEmpty()) { - error("Could not extract all jars: $jarPathSet") - } - } -} diff --git a/buildSrc/src/RepoDownload.kt b/buildSrc/src/RepoDownload.kt deleted file mode 100644 index 42a09b3..0000000 --- a/buildSrc/src/RepoDownload.kt +++ /dev/null @@ -1,41 +0,0 @@ -import java.net.URI -import java.util.zip.ZipInputStream -import org.gradle.api.DefaultTask -import org.gradle.api.file.DirectoryProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.TaskAction - -abstract class RepoDownload : DefaultTask() { - @get:Input - abstract val hash: Property<String> - - @get:OutputDirectory - abstract val outputDirectory: DirectoryProperty - - init { - outputDirectory.convention(project.layout.buildDirectory.dir("extracted-test-repo")) - } - - @TaskAction - fun performDownload() { - val outputDir = outputDirectory.asFile.get().absoluteFile - outputDir.mkdirs() - URI("https://github.com/notEnoughUpdates/notEnoughUpdates-rEPO/archive/${hash.get()}.zip").toURL().openStream() - .let(::ZipInputStream) - .use { zipInput -> - while (true) { - val entry = zipInput.nextEntry ?: break - val destination = outputDir.resolve( - entry.name.substringAfter('/')).absoluteFile - require(outputDir in generateSequence(destination) { it.parentFile }) - if (entry.isDirectory) continue - destination.parentFile.mkdirs() - destination.outputStream().use { output -> - zipInput.copyTo(output) - } - } - } - } -} diff --git a/buildSrc/src/licenseinfo.kt b/buildSrc/src/licenseinfo.kt deleted file mode 100644 index 50e4593..0000000 --- a/buildSrc/src/licenseinfo.kt +++ /dev/null @@ -1,144 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> -// -// SPDX-License-Identifier: CC0-1.0 - -import moe.nea.licenseextractificator.LicenseExtension - -fun LicenseExtension.addExtraLicenseMatchers() { - solo { - name = "Firmament" - description = "A Hypixel SkyBlock mod" - developer("Linnea Gräf") { - webPresence = "https://nea.moe/" - } - spdxLicense.`GPL-3-0-or-later`() - webPresence = "https://git.nea.moe/nea/Firmament/" - } - match { - if (group == "net.minecraft") useLicense { - name = "Minecraft" - description = "Minecraft - The critically acclaimed video game" - license("All Rights Reserved", "https://www.minecraft.net/en-us/eula") - developer("Mojang") { - webPresence = "https://mojang.com" - } - webPresence = "https://www.minecraft.net/en-us" - } - if (module == "architectury") useLicense { - name = "Architectury API" - description = "An intermediary api aimed at easing development of multiplatform mods." - spdxLicense.`LGPL-3-0-or-later`() - developer("Architectury") { - webPresence = "https://docs.architectury.dev/" - } - webPresence = "https://github.com/architectury/architectury-api" - } - if (module.startsWith("RoughlyEnoughItems")) useLicense { - name = module - description = "Your recipe viewer mod for 1.13+." - spdxLicense.MIT() - developer("Shedaniel") { - webPresence = "https://shedaniel.me/" - } - webPresence = "https://github.com/shedaniel/RoughlyEnoughItems" - } - if (module == "cloth-config") useLicense { - name = "Cloth Config" - description = "Client sided configuration API" - spdxLicense.`LGPL-3-0-or-later`() - developer("Shedaniel") { - webPresence = "https://shedaniel.me/" - } - webPresence = "https://github.com/shedaniel/cloth-config" - } - if (module == "basic-math") useLicense { - name = "Cloth BasicMath" - description = "Basic Math Operations" - spdxLicense.Unlicense() - developer("Shedaniel") { - webPresence = "https://shedaniel.me/" - } - webPresence = "https://github.com/shedaniel/cloth-basic-math" - } - if (module == "fabric-language-kotlin") useLicense { - name = "Fabric Language Kotlin" - description = "Kotlin Language Support for Fabric mods" - webPresence = "https://github.com/FabricMC/fabric-language-kotlin" - spdxLicense.`Apache-2-0`() - developer("FabricMC") { - webPresence = "https://fabricmc.net/" - } - } - if (group == "com.mojang") useLicense { - name = module - description = "Mojang library packaged by Minecraft" - } - } - module("net.fabricmc", "yarn") { - name = "Yarn" - description = "Libre Minecraft mappings, free to use for everyone. No exceptions." - spdxLicense.`CC0-1-0`() - developer("FabricMC") { - webPresence = "https://fabricmc.net/" - } - webPresence = "https://github.com/FabricMC/yarn/" - } - module("com.mojang", "datafixerupper") { - name = "DataFixerUpper" - description = - "A set of utilities designed for incremental building, merging and optimization of data transformations." - spdxLicense.MIT() - developer("Mojang") { - webPresence = "https://mojang.com" - } - webPresence = "https://github.com/Mojang/DataFixerUpper" - } - module("com.mojang", "brigadier") { - name = "Brigadier" - description = "Brigadier is a command parser & dispatcher, designed and developed for Minecraft: Java Edition." - spdxLicense.MIT() - developer("Mojang") { - webPresence = "https://mojang.com" - } - webPresence = "https://github.com/Mojang/brigadier" - } - module("net.fabricmc", "tiny-remapper") { - name = "Tiny Remapper" - description = "Tiny JAR remapping tool" - spdxLicense.`LGPL-3-0-or-later`() - webPresence = "https://github.com/FabricMC/tiny-remapper" - developer("FabricMC") { - webPresence = "https://fabricmc.net/" - } - } - module("net.fabricmc", "sponge-mixin") { - name = "Mixin" - description = "Mixin is a trait/mixin framework for Java using ASM" - spdxLicense.MIT() - webPresence = "https://github.com/FabricMC/mixin" - developer("FabricMC") { - webPresence = "https://fabricmc.net/" - } - developer("SpongePowered") { - webPresence = "https://spongepowered.org/" - } - } - module("net.fabricmc", "tiny-mappings-parser") { - name = "Tiny Mappings Parser" - webPresence = "https://github.com/fabricMC/tiny-mappings-parser" - description = "Library for parsing .tiny mapping files" - developer("FabricMC") { - webPresence = "https://fabricmc.net/" - } - spdxLicense.`Apache-2-0`() - } - module("net.fabricmc", "fabric-loader") { - name = "Fabric Loader" - description = " Fabric's mostly-version-independent mod loader." - spdxLicense.`Apache-2-0`() - developer("FabricMC") { - webPresence = "https://fabricmc.net/" - } - webPresence = "https://github.com/FabricMC/fabric-loader/" - } -} diff --git a/buildSrc/src/lookupversion.kt b/buildSrc/src/lookupversion.kt deleted file mode 100644 index 8a7c2de..0000000 --- a/buildSrc/src/lookupversion.kt +++ /dev/null @@ -1,25 +0,0 @@ -fun execString(vararg args: String): String { - val pb = ProcessBuilder(*args) - .redirectOutput(ProcessBuilder.Redirect.PIPE) - .start() - pb.waitFor() - return pb.inputStream.readAllBytes().decodeToString().trim() -} - -private val tag = "([0-9.]+)(?:\\+[^-]*)?".toRegex() -private val tagOffset = "([0-9.]+)(?:\\+.*)?-([0-9]+)-(.+)".toRegex() - -inline fun <T> Regex.useMatcher(string: String, block: (MatchResult) -> T): T? { - return matchEntire(string)?.let(block) -} - -fun getGitTagInfo(mcVersion: String): String { - val str = execString("git", "describe", "--tags", "HEAD") - tag.useMatcher(str) { - return it.groupValues[1] + "+mc$mcVersion" - } - tagOffset.useMatcher(str) { - return it.groupValues[1] + "-dev+mc$mcVersion+" + it.groupValues[3] - } - return "nogitversion+mc$mcVersion" -} |