mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-12-02 02:44:33 +00:00
feat: build improvements
This commit is contained in:
1 parent
b8f94a67ef
commit
407aaf203e
32 files changed
+378
-356
No files matched your search
@@ -28,10 +28,10 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
//TODO Allow pulling from Versions.kt
|
||||
implementation("com.gradleup.shadow", "shadow-gradle-plugin", "9.3.1")
|
||||
implementation("com.gradleup.shadow:shadow-gradle-plugin:9.6.1")
|
||||
|
||||
implementation("org.ow2.asm", "asm", "9.9")
|
||||
implementation("org.ow2.asm", "asm-tree", "9.9")
|
||||
implementation("com.dfsek.tectonic", "common", "4.4.0")
|
||||
implementation("org.yaml", "snakeyaml", "2.5")
|
||||
implementation("org.ow2.asm:asm:9.11.1")
|
||||
implementation("org.ow2.asm:asm-tree:9.11.1")
|
||||
implementation("com.dfsek.tectonic:common:4.4.0")
|
||||
implementation("org.yaml:snakeyaml:2.7")
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import java.io.File
|
||||
import java.util.function.Predicate
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import kotlin.streams.asStream
|
||||
|
||||
|
||||
@@ -11,8 +11,13 @@ import kotlin.streams.asStream
|
||||
* Configures a directory where addons will be put.
|
||||
*/
|
||||
fun Project.addonDir(dir: File, task: Task) {
|
||||
val addonProjects = project(":common:addons").subprojects
|
||||
val moveAddons = tasks.register("moveAddons" + task.name) {
|
||||
dependsOn("compileAddons")
|
||||
// Resolved here rather than in doLast: task actions can't reach into other projects.
|
||||
val jars = addonProjects.map { addon ->
|
||||
(if (addon.isBootstrapAddon()) "bootstrap/" else "") to addon.tasks.named<ShadowJar>("shadowJar").flatMap { it.archiveFile }
|
||||
}
|
||||
doLast {
|
||||
dir.parentFile.mkdirs()
|
||||
matchingAddons(dir) {
|
||||
@@ -21,20 +26,13 @@ fun Project.addonDir(dir: File, task: Task) {
|
||||
logger.info("Deleting old addon: " + it.absolutePath)
|
||||
it.delete()
|
||||
}
|
||||
forSubProjects(":common:addons") {
|
||||
val jar = tasks.named("shadowJar").get() as ShadowJar
|
||||
|
||||
val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else ""
|
||||
val target = File(dir, boot + jar.archiveFileName.get())
|
||||
|
||||
val base = "${jar.archiveBaseName.get()}-${version}"
|
||||
|
||||
logger.info("Copying addon ${jar.archiveFileName.get()} to ${target.absolutePath}. Base name: $base")
|
||||
|
||||
jar.archiveFile.orNull?.asFile?.copyTo(target)
|
||||
jars.forEach { (subdirectory, jar) ->
|
||||
val file = jar.get().asFile
|
||||
val target = File(dir, subdirectory + file.name)
|
||||
logger.info("Copying addon ${file.name} to ${target.absolutePath}")
|
||||
file.copyTo(target)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task.dependsOn(moveAddons)
|
||||
|
||||
@@ -35,18 +35,16 @@ fun Project.configureCompilation() {
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
doFirst {
|
||||
options.compilerArgs.add("-Xlint:all")
|
||||
}
|
||||
options.compilerArgs.add("-Xlint:all")
|
||||
}
|
||||
|
||||
// Gradle doesn't fingerprint filter arguments; the tokens are declared as inputs.
|
||||
val metadataTokens = mapOf(
|
||||
"DESCRIPTION" to properties["terra.description"],
|
||||
"WIKI" to properties["terra.wiki"],
|
||||
"SOURCE" to properties["terra.source"],
|
||||
"ISSUES" to properties["terra.issues"],
|
||||
"LICENSE" to properties["terra.license"]
|
||||
"DESCRIPTION" to findProperty("terra.description"),
|
||||
"WIKI" to findProperty("terra.wiki"),
|
||||
"SOURCE" to findProperty("terra.source"),
|
||||
"ISSUES" to findProperty("terra.issues"),
|
||||
"LICENSE" to findProperty("terra.license")
|
||||
)
|
||||
tasks.withType<ProcessResources> {
|
||||
include("**/*.*")
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.creating
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.kotlin.dsl.getValue
|
||||
import org.gradle.kotlin.dsl.getting
|
||||
import org.gradle.kotlin.dsl.maven
|
||||
import org.gradle.kotlin.dsl.repositories
|
||||
|
||||
fun Project.configureDependencies() {
|
||||
val testImplementation by configurations.getting
|
||||
val compileOnly by configurations.getting
|
||||
val testImplementation = configurations.getByName("testImplementation")
|
||||
val compileOnly = configurations.getByName("compileOnly")
|
||||
|
||||
val api by configurations.getting
|
||||
val implementation by configurations.getting
|
||||
val api = configurations.getByName("api")
|
||||
val implementation = configurations.getByName("implementation")
|
||||
|
||||
val shaded by configurations.creating
|
||||
val shaded = configurations.create("shaded")
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val shadedApi by configurations.creating {
|
||||
configurations.create("shadedApi") {
|
||||
shaded.extendsFrom(this)
|
||||
api.extendsFrom(this)
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val shadedImplementation by configurations.creating {
|
||||
configurations.create("shadedImplementation") {
|
||||
shaded.extendsFrom(this)
|
||||
implementation.extendsFrom(this)
|
||||
}
|
||||
@@ -72,11 +67,11 @@ fun Project.configureDependencies() {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation("org.junit.jupiter", "junit-jupiter", Versions.Libraries.Internal.junit)
|
||||
"testRuntimeOnly"("org.junit.platform", "junit-platform-launcher")
|
||||
compileOnly("org.jetbrains", "annotations", Versions.Libraries.Internal.jetBrainsAnnotations)
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:${Versions.Libraries.Internal.junit}")
|
||||
"testRuntimeOnly"("org.junit.platform:junit-platform-launcher")
|
||||
compileOnly("org.jetbrains:annotations:${Versions.Libraries.Internal.jetBrainsAnnotations}")
|
||||
|
||||
compileOnly("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
||||
testImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
||||
compileOnly("com.google.guava:guava:${Versions.Libraries.Internal.guava}")
|
||||
testImplementation("com.google.guava:guava:${Versions.Libraries.Internal.guava}")
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,36 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.net.URL
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Path
|
||||
import java.net.URI
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
import java.time.Duration
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.plugins.BasePluginExtension
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.MapProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.SourceSetContainer
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.kotlin.dsl.register
|
||||
import org.yaml.snakeyaml.DumperOptions
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import kotlin.io.path.copyTo
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.createFile
|
||||
import kotlin.io.path.exists
|
||||
|
||||
private fun Project.installAddonsInto(dest: Path) {
|
||||
FileSystems.newFileSystem(dest, mapOf("create" to "false"), null).use { fs ->
|
||||
forSubProjects(":common:addons") {
|
||||
val jar = getJarTask()
|
||||
|
||||
logger.info("Packaging addon ${jar.archiveFileName.get()} to $dest. size: ${jar.archiveFile.get().asFile.length() / 1024}KB")
|
||||
|
||||
val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else ""
|
||||
val addonPath = fs.getPath("/addons/$boot${jar.archiveFileName.get()}")
|
||||
|
||||
if (!addonPath.exists()) {
|
||||
addonPath.parent.createDirectories()
|
||||
addonPath.createFile()
|
||||
jar.archiveFile.get().asFile.toPath().copyTo(addonPath, overwrite = true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.configureDistribution() {
|
||||
apply(plugin = "com.gradleup.shadow")
|
||||
@@ -52,150 +44,171 @@ fun Project.configureDistribution() {
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
|
||||
|
||||
val addonProjects = project(":common:addons").subprojects
|
||||
|
||||
tasks.register("compileAddons") {
|
||||
dependsOn(addonProjects.map { "${it.path}:shadowJar" })
|
||||
}
|
||||
|
||||
val generateResources = tasks.register<GenerateTerraResources>("generateTerraResources") {
|
||||
group = "terra"
|
||||
doFirst {
|
||||
try {
|
||||
file("${buildDir}/resources/main/packs/").deleteRecursively()
|
||||
file("${buildDir}/resources/main/metapacks/").deleteRecursively()
|
||||
val overworldPackUrl =
|
||||
URL("https://github.com/PolyhedralDev/TerraOverworldConfig/releases/download/" + Versions.Terra.overworldConfig + "/Overworld.zip")
|
||||
val reimagENDPackUrl =
|
||||
URL("https://github.com/PolyhedralDev/ReimagEND/releases/download/" + Versions.Terra.reimagENDConfig + "/ReimagEND.zip")
|
||||
val tartarusPackUrl =
|
||||
URL("https://github.com/PolyhedralDev/Tartarus/releases/download/" + Versions.Terra.tartarusConfig + "/Tartarus.zip")
|
||||
val defaultPackUrl =
|
||||
URL("https://github.com/PolyhedralDev/DefaultMetapack/releases/download/" + Versions.Terra.defaultConfig + "/default.zip")
|
||||
downloadPack(overworldPackUrl, project)
|
||||
downloadPack(reimagENDPackUrl, project)
|
||||
downloadPack(tartarusPackUrl, project)
|
||||
downloadPack(defaultPackUrl, project, true)
|
||||
} catch (_: Exception) {
|
||||
defaultPacks.set(defaultPacksTask().flatMap { it.outputDir })
|
||||
outputDir.set(layout.buildDirectory.dir("generated/terra-resources"))
|
||||
}
|
||||
configure<SourceSetContainer> {
|
||||
named("main") {
|
||||
output.dir(mapOf("builtBy" to generateResources), generateResources.flatMap { it.outputDir })
|
||||
}
|
||||
}
|
||||
|
||||
gradle.projectsEvaluated {
|
||||
generateResources.configure {
|
||||
addonProjects.forEach { addon ->
|
||||
val name = addon.tasks.named<ShadowJar>("shadowJar").get().archiveFileName.get()
|
||||
(if (addon.isBootstrapAddon()) bootstrapAddons else addons).add(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val compileAddons = tasks.create("compileAddons") {
|
||||
forSubProjects(":common:addons") {
|
||||
afterEvaluate {
|
||||
dependsOn(getJarTask())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val installAddons = tasks.create("installAddons") {
|
||||
group = "terra"
|
||||
dependsOn(compileAddons)
|
||||
|
||||
doLast {
|
||||
// https://github.com/johnrengelman/shadow/issues/111
|
||||
val dest = tasks.named<ShadowJar>("shadowJar").get().archiveFile.get().asFile.toPath()
|
||||
installAddonsInto(dest)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.create("installAddonsIntoDefaultJar") {
|
||||
group = "terra"
|
||||
dependsOn(compileAddons)
|
||||
|
||||
doLast {
|
||||
val dest = tasks.named<Jar>("jar").get().archiveFile.get().asFile.toPath()
|
||||
installAddonsInto(dest)
|
||||
}
|
||||
}
|
||||
|
||||
val generateResourceManifest = tasks.create("generateResourceManifest") {
|
||||
group = "terra"
|
||||
doLast {
|
||||
val resources = HashMap<String, MutableList<String>>()
|
||||
val packsDir = File("${project.buildDir}/resources/main/packs/")
|
||||
|
||||
packsDir.walkTopDown().forEach {
|
||||
if (it.isDirectory || !it.name.endsWith(".zip")) return@forEach
|
||||
resources.computeIfAbsent("packs") { ArrayList() }.add(it.name)
|
||||
}
|
||||
|
||||
val metaPacksDir = File("${project.buildDir}/resources/main/metapacks/")
|
||||
|
||||
metaPacksDir.walkTopDown().forEach {
|
||||
if (it.isDirectory || !it.name.endsWith(".zip")) return@forEach
|
||||
resources.computeIfAbsent("metapacks") { ArrayList() }.add(it.name)
|
||||
}
|
||||
|
||||
val langDir = File("${project(":common:implementation").buildDir}/resources/main/lang/")
|
||||
|
||||
langDir.walkTopDown().forEach {
|
||||
if (it.isDirectory || !it.name.endsWith(".yml")) return@forEach
|
||||
resources.computeIfAbsent("lang") { ArrayList() }.add(it.name)
|
||||
}
|
||||
|
||||
forSubProjects(":common:addons") {
|
||||
val jar = getJarTask().archiveFileName.get()
|
||||
resources.computeIfAbsent(
|
||||
if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "addons/bootstrap"
|
||||
else "addons"
|
||||
) { ArrayList() }.add(jar)
|
||||
}
|
||||
|
||||
val options = DumperOptions()
|
||||
options.indent = 2
|
||||
options.indentWithIndicator = true
|
||||
options.indicatorIndent = 2
|
||||
options.isPrettyFlow = true
|
||||
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
|
||||
options.defaultScalarStyle = DumperOptions.ScalarStyle.DOUBLE_QUOTED
|
||||
|
||||
val yaml = Yaml(options)
|
||||
|
||||
val manifest = File("${project.buildDir}/resources/main/resources.yml")
|
||||
|
||||
if (manifest.exists()) manifest.delete()
|
||||
manifest.parentFile.mkdirs()
|
||||
manifest.createNewFile()
|
||||
FileWriter(manifest).use {
|
||||
yaml.dump(resources, it)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("processResources") {
|
||||
generateResourceManifest.mustRunAfter(downloadDefaultPacks)
|
||||
finalizedBy(downloadDefaultPacks)
|
||||
finalizedBy(generateResourceManifest)
|
||||
}
|
||||
|
||||
|
||||
|
||||
bundleAddons(tasks.named<ShadowJar>("shadowJar"))
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
// Tell shadow to download the packs
|
||||
dependsOn(downloadDefaultPacks)
|
||||
configurations.set(listOf(project.configurations["shaded"]))
|
||||
configurations.set(listOf(project.configurations.getByName("shaded")))
|
||||
archiveClassifier.set("shaded")
|
||||
version = project.version
|
||||
relocate("org.apache.commons", "com.dfsek.terra.lib.commons")
|
||||
relocate("org.objectweb.asm", "com.dfsek.terra.lib.asm")
|
||||
relocate("org.json", "com.dfsek.terra.lib.json")
|
||||
relocate("org.yaml", "com.dfsek.terra.lib.yaml")
|
||||
|
||||
finalizedBy(installAddons)
|
||||
}
|
||||
|
||||
|
||||
configure<BasePluginExtension> {
|
||||
archivesName.set(project.name)
|
||||
}
|
||||
|
||||
tasks.named<DefaultTask>("build") {
|
||||
dependsOn(tasks["shadowJar"])
|
||||
|
||||
tasks.named("build") {
|
||||
dependsOn("shadowJar")
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadPack(packUrl: URL, project: Project, metapack: Boolean = false) {
|
||||
val fileName = packUrl.file.substring(packUrl.file.lastIndexOf("/"))
|
||||
val resourceType = if (metapack) "metapacks" else "packs"
|
||||
val file = File("${project.buildDir}/resources/main/${resourceType}/${fileName}")
|
||||
file.parentFile.mkdirs()
|
||||
file.outputStream().write(packUrl.readBytes())
|
||||
fun Project.bundleAddons(archive: TaskProvider<out AbstractArchiveTask>) {
|
||||
val addonProjects = project(":common:addons").subprojects
|
||||
gradle.projectsEvaluated {
|
||||
archive.configure {
|
||||
addonProjects.forEach { addon ->
|
||||
from(addon.tasks.named("shadowJar")) {
|
||||
into(if (addon.isBootstrapAddon()) "addons/bootstrap" else "addons")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.getJarTask() = tasks.named("shadowJar").get() as ShadowJar
|
||||
internal fun Project.isBootstrapAddon() = extra.has("bootstrap") && extra.get("bootstrap") as Boolean
|
||||
|
||||
private fun Project.defaultPacksTask(): TaskProvider<DownloadDefaultPacks> {
|
||||
val root = rootProject
|
||||
if ("downloadDefaultPacks" in root.tasks.names) return root.tasks.named<DownloadDefaultPacks>("downloadDefaultPacks")
|
||||
return root.tasks.register<DownloadDefaultPacks>("downloadDefaultPacks") {
|
||||
group = "terra"
|
||||
fun release(repo: String, tag: String, file: String) =
|
||||
"https://github.com/PolyhedralDev/$repo/releases/download/$tag/$file"
|
||||
packs.put("packs/Overworld.zip", release("TerraOverworldConfig", Versions.Terra.overworldConfig, "Overworld.zip"))
|
||||
packs.put("packs/ReimagEND.zip", release("ReimagEND", Versions.Terra.reimagENDConfig, "ReimagEND.zip"))
|
||||
packs.put("packs/Tartarus.zip", release("Tartarus", Versions.Terra.tartarusConfig, "Tartarus.zip"))
|
||||
packs.put("metapacks/default.zip", release("DefaultMetapack", Versions.Terra.defaultConfig, "default.zip"))
|
||||
offline.set(root.gradle.startParameter.isOffline)
|
||||
outputDir.set(root.layout.buildDirectory.dir("default-packs"))
|
||||
}
|
||||
}
|
||||
|
||||
abstract class DownloadDefaultPacks : DefaultTask() {
|
||||
@get:Input
|
||||
abstract val packs: MapProperty<String, String>
|
||||
|
||||
@get:Internal
|
||||
abstract val offline: Property<Boolean>
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val outputDir: DirectoryProperty
|
||||
|
||||
init {
|
||||
outputs.upToDateWhen { packs.get().values.none { "/latest/" in it } }
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun download() {
|
||||
val out = outputDir.get().asFile
|
||||
if (offline.get()) {
|
||||
logger.warn("Offline: using the default packs from the last build in $out")
|
||||
return
|
||||
}
|
||||
val client = HttpClient.newBuilder()
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build()
|
||||
val responses = packs.get().mapValues { (_, url) ->
|
||||
client.sendAsync(HttpRequest.newBuilder(URI(url)).timeout(Duration.ofMinutes(2)).build(),
|
||||
HttpResponse.BodyHandlers.ofByteArray())
|
||||
}
|
||||
responses.forEach { (path, response) ->
|
||||
val file = File(out, path)
|
||||
val body = try {
|
||||
response.join().takeIf { it.statusCode() == 200 }?.body()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
when {
|
||||
body != null -> if (!file.exists() || !file.readBytes().contentEquals(body)) {
|
||||
file.parentFile.mkdirs()
|
||||
file.writeBytes(body)
|
||||
}
|
||||
|
||||
file.exists() -> logger.warn("Could not download ${packs.get()[path]}; using the copy from the last build")
|
||||
else -> logger.warn("Could not download ${packs.get()[path]}; jars will not include $path")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class GenerateTerraResources : DefaultTask() {
|
||||
@get:InputDirectory
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
abstract val defaultPacks: DirectoryProperty
|
||||
|
||||
@get:Input
|
||||
abstract val addons: ListProperty<String>
|
||||
|
||||
@get:Input
|
||||
abstract val bootstrapAddons: ListProperty<String>
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val outputDir: DirectoryProperty
|
||||
|
||||
@TaskAction
|
||||
fun generate() {
|
||||
val out = outputDir.get().asFile
|
||||
out.deleteRecursively()
|
||||
defaultPacks.get().asFile.copyRecursively(out)
|
||||
|
||||
val resources = LinkedHashMap<String, List<String>>()
|
||||
fun put(key: String, entries: List<String>) {
|
||||
if (entries.isNotEmpty()) resources[key] = entries
|
||||
}
|
||||
fun zips(dir: String) = File(out, dir).listFiles { file -> file.name.endsWith(".zip") }?.map { it.name }?.sorted().orEmpty()
|
||||
put("addons/bootstrap", bootstrapAddons.get())
|
||||
put("addons", addons.get())
|
||||
put("packs", zips("packs"))
|
||||
put("metapacks", zips("metapacks"))
|
||||
|
||||
val options = DumperOptions()
|
||||
options.indent = 2
|
||||
options.indentWithIndicator = true
|
||||
options.indicatorIndent = 2
|
||||
options.isPrettyFlow = true
|
||||
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
|
||||
options.defaultScalarStyle = DumperOptions.ScalarStyle.DOUBLE_QUOTED
|
||||
File(out, "resources.yml").writer().use { Yaml(options).dump(resources, it) }
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,13 @@ fun Project.configurePublishing() {
|
||||
//val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
|
||||
|
||||
maven(mavenUrl) {
|
||||
val SoloStudiosReleasesUsername: String? by project
|
||||
val SoloStudiosReleasesPassword: String? by project
|
||||
val releasesUsername = findProperty("SoloStudiosReleasesUsername") as String?
|
||||
val releasesPassword = findProperty("SoloStudiosReleasesPassword") as String?
|
||||
|
||||
if (SoloStudiosReleasesUsername != null && SoloStudiosReleasesPassword != null) {
|
||||
if (releasesUsername != null && releasesPassword != null) {
|
||||
credentials {
|
||||
username = SoloStudiosReleasesUsername
|
||||
password = SoloStudiosReleasesPassword
|
||||
username = releasesUsername
|
||||
password = releasesPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,25 +14,25 @@ object Versions {
|
||||
|
||||
const val cloud = "2.1.0"
|
||||
|
||||
const val caffeine = "3.2.2"
|
||||
const val caffeine = "3.3.1"
|
||||
|
||||
const val slf4j = "2.0.17"
|
||||
const val slf4j = "2.0.20"
|
||||
|
||||
object Internal {
|
||||
const val shadow = "9.3.1"
|
||||
const val apacheText = "1.14.0"
|
||||
const val apacheIO = "2.20.0"
|
||||
const val guava = "33.5.0-jre"
|
||||
const val asm = "9.9"
|
||||
const val snakeYml = "2.5"
|
||||
const val jetBrainsAnnotations = "26.0.2-1"
|
||||
const val junit = "6.0.0"
|
||||
const val shadow = "9.6.1"
|
||||
const val apacheText = "1.15.0"
|
||||
const val apacheIO = "2.22.0"
|
||||
const val guava = "33.8.0-jre"
|
||||
const val asm = "9.11.1"
|
||||
const val snakeYml = "2.7"
|
||||
const val jetBrainsAnnotations = "26.1.0"
|
||||
const val junit = "6.1.3"
|
||||
const val nbt = "6.1"
|
||||
}
|
||||
}
|
||||
|
||||
object Fabric {
|
||||
const val fabricAPI = "0.165.2+${Mod.minecraft}"
|
||||
const val fabricAPI = "0.166.0+${Mod.minecraft}"
|
||||
const val cloud = "2.1.0"
|
||||
}
|
||||
//
|
||||
@@ -60,12 +60,12 @@ object Versions {
|
||||
|
||||
object Bukkit {
|
||||
const val minecraft = "26.3"
|
||||
const val paperBuild = "$minecraft.build.244-stable"
|
||||
const val paperBuild = "$minecraft.build.246-stable"
|
||||
const val paper = paperBuild
|
||||
const val runPaper = "3.0.2"
|
||||
const val runPaper = "3.1.0"
|
||||
const val wyck = "4.0.0-0f573ad7"
|
||||
const val cloud = "2.0.1"
|
||||
const val multiverse = "5.3.0"
|
||||
const val multiverse = "5.8.2"
|
||||
}
|
||||
|
||||
//
|
||||
@@ -76,7 +76,7 @@ object Versions {
|
||||
// }
|
||||
//
|
||||
object CLI {
|
||||
const val logback = "1.5.19"
|
||||
const val logback = "1.6.6"
|
||||
const val picocli = "4.7.7"
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,13 @@ import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.api.file.Directory
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.objectweb.asm.ClassReader
|
||||
import org.objectweb.asm.tree.ClassNode
|
||||
@@ -15,11 +21,18 @@ import org.objectweb.asm.tree.FieldNode
|
||||
|
||||
|
||||
abstract class GenerateDocsTask : DefaultTask() {
|
||||
@get:InputFiles
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
abstract val classDirectories: ListProperty<Directory>
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val docsDirectory: DirectoryProperty
|
||||
|
||||
@TaskAction
|
||||
fun generateDocs() {
|
||||
project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.forEach { sources ->
|
||||
classDirectories.get().forEach { classesDirectory ->
|
||||
val classes = HashMap<String, ClassNode>()
|
||||
sources.java.classesDirectory.get().asFileTree.forEach { file ->
|
||||
classesDirectory.asFileTree.forEach { file ->
|
||||
if (file.name.endsWith(".class")) {
|
||||
val node = createClassNode(FileInputStream(file))
|
||||
if (node.fields.stream().anyMatch { field ->
|
||||
@@ -27,10 +40,7 @@ abstract class GenerateDocsTask : DefaultTask() {
|
||||
it.desc.equals(descriptor(Value::class.java.canonicalName))
|
||||
} == true
|
||||
}) {
|
||||
var name = sources
|
||||
.java
|
||||
.classesDirectory
|
||||
.get()
|
||||
var name = classesDirectory
|
||||
.asFile
|
||||
.toPath()
|
||||
.relativize(file.toPath())
|
||||
@@ -44,7 +54,7 @@ abstract class GenerateDocsTask : DefaultTask() {
|
||||
}
|
||||
}
|
||||
|
||||
val docsDir = File(project.buildDir, "tectonic")
|
||||
val docsDir = docsDirectory.get().asFile
|
||||
docsDir.mkdirs()
|
||||
|
||||
classes.forEach { (name, clazz) ->
|
||||
|
||||
@@ -2,9 +2,15 @@ package com.dfsek.terra.tectonicdoc
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
|
||||
class TectonicDocPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.tasks.create("generateDocs", GenerateDocsTask::class.java)
|
||||
project.tasks.register("generateDocs", GenerateDocsTask::class.java) {
|
||||
project.extensions.getByType(JavaPluginExtension::class.java).sourceSets.configureEach {
|
||||
classDirectories.add(java.classesDirectory)
|
||||
}
|
||||
docsDirectory.set(project.layout.buildDirectory.dir("tectonic"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user