aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build-src/README.md2
-rw-r--r--build-src/build.gradle.kts11
-rw-r--r--build-src/settings.gradle.kts0
-rw-r--r--build-src/src/main/kotlin/GenerateItemIds.kt72
-rw-r--r--build-src/src/main/kotlin/RepoDownload.kt41
-rw-r--r--build-src/src/main/kotlin/ledger-marker.gradle.kts0
-rw-r--r--build-src/src/main/kotlin/ledger-repo.gradle.kts1
-rw-r--r--build.gradle.kts156
-rw-r--r--dependency-injection/build.gradle.kts8
-rw-r--r--dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt (renamed from src/main/kotlin/moe/nea/ledger/utils/di/DI.kt)5
-rw-r--r--dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt (renamed from src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt)6
-rw-r--r--dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt (renamed from src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt)0
-rw-r--r--settings.gradle.kts2
13 files changed, 188 insertions, 116 deletions
diff --git a/build-src/README.md b/build-src/README.md
new file mode 100644
index 0000000..66d45bc
--- /dev/null
+++ b/build-src/README.md
@@ -0,0 +1,2 @@
+
+Intentionally not using `buildSrc` over an `includeBuild("build-src")` due to better performance of composite builds.
diff --git a/build-src/build.gradle.kts b/build-src/build.gradle.kts
new file mode 100644
index 0000000..f203fd6
--- /dev/null
+++ b/build-src/build.gradle.kts
@@ -0,0 +1,11 @@
+plugins {
+ kotlin("jvm") version "2.0.20"
+ `kotlin-dsl`
+}
+repositories {
+ mavenCentral()
+}
+dependencies {
+ implementation("com.google.code.gson:gson:2.11.0")
+ implementation(gradleApi())
+}
diff --git a/build-src/settings.gradle.kts b/build-src/settings.gradle.kts
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build-src/settings.gradle.kts
diff --git a/build-src/src/main/kotlin/GenerateItemIds.kt b/build-src/src/main/kotlin/GenerateItemIds.kt
new file mode 100644
index 0000000..24f2f62
--- /dev/null
+++ b/build-src/src/main/kotlin/GenerateItemIds.kt
@@ -0,0 +1,72 @@
+import com.google.gson.Gson
+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.InputDirectory
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.TaskAction
+import java.io.File
+
+abstract class GenerateItemIds : DefaultTask() {
+ @get: OutputDirectory
+ abstract val outputDirectory: DirectoryProperty
+
+ @get: InputDirectory
+ abstract val repoFiles: DirectoryProperty
+
+ @get: Input
+ abstract val repoHash: Property<String>
+
+ @get: Input
+ abstract val packageName: Property<String>
+
+ @get:Internal
+ val outputFile get() = outputDirectory.asFile.get().resolve(packageName.get().replace(".", "/") + "/ItemIds.java")
+
+ init {
+ repoHash.convention("unknown-repo-git-hash")
+ }
+
+ @TaskAction
+ fun generateItemIds() {
+ val nonIdName = "[^A-Z0-9_]".toRegex()
+
+ data class Item(val id: String, val file: File) {
+ val javaName get() = id.replace(nonIdName, { "__" + it.value.single().code })
+ }
+
+ val items = mutableListOf<Item>()
+ for (listFile in repoFiles.asFile.get().resolve("items").listFiles() ?: emptyArray()) {
+ listFile ?: continue
+ if (listFile.extension != "json") {
+ error("Unknown file $listFile")
+ }
+ items.add(Item(listFile.nameWithoutExtension, listFile))
+ }
+ items.sortedBy { it.id }
+ outputFile.parentFile.mkdirs()
+ val writer = outputFile.writer().buffered()
+ writer.appendLine("// @generated from " + repoHash.get())
+ writer.appendLine("package " + packageName.get() + ";")
+ writer.appendLine()
+ writer.appendLine("import moe.nea.ledger.ItemId;")
+ writer.appendLine()
+ writer.appendLine("/**")
+ writer.appendLine(" * Automatically generated {@link ItemId} list.")
+ writer.appendLine(" */")
+ writer.appendLine("@org.jspecify.annotations.NullMarked")
+ writer.appendLine("public interface ItemIds {")
+ val gson = Gson()
+ for (item in items) {
+ writer.appendLine("\t/**")
+ writer.appendLine("\t * @see <a href=${gson.toJson("https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO/blob/${repoHash.get()}/items/${item.id}.json")}>JSON definition</a>")
+ writer.appendLine("\t */")
+ writer.appendLine("\tItemId ${item.javaName} =" +
+ " ItemId.forName(${gson.toJson(item.id)});")
+ }
+ writer.appendLine("}")
+ writer.close()
+ }
+}
diff --git a/build-src/src/main/kotlin/RepoDownload.kt b/build-src/src/main/kotlin/RepoDownload.kt
new file mode 100644
index 0000000..182c66f
--- /dev/null
+++ b/build-src/src/main/kotlin/RepoDownload.kt
@@ -0,0 +1,41 @@
+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
+import java.net.URI
+import java.util.zip.ZipInputStream
+
+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)
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/build-src/src/main/kotlin/ledger-marker.gradle.kts b/build-src/src/main/kotlin/ledger-marker.gradle.kts
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build-src/src/main/kotlin/ledger-marker.gradle.kts
diff --git a/build-src/src/main/kotlin/ledger-repo.gradle.kts b/build-src/src/main/kotlin/ledger-repo.gradle.kts
new file mode 100644
index 0000000..1a9be63
--- /dev/null
+++ b/build-src/src/main/kotlin/ledger-repo.gradle.kts
@@ -0,0 +1 @@
+tasks.register("downloadRepo", RepoDownload::class)
diff --git a/build.gradle.kts b/build.gradle.kts
index a5173a1..cb69ab4 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,12 +1,8 @@
import com.github.gmazzo.buildconfig.BuildConfigExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
-import com.google.gson.Gson
-import com.google.gson.JsonObject
import org.apache.commons.lang3.SystemUtils
import proguard.gradle.ProGuardTask
import java.io.ByteArrayOutputStream
-import java.net.URI
-import java.util.zip.ZipInputStream
buildscript {
repositories {
@@ -25,6 +21,8 @@ plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.github.gmazzo.buildconfig") version "5.5.0"
kotlin("jvm") version "2.0.20"
+ id("ledger-marker")
+ id("ledger-repo")
}
fun cmd(vararg args: String): String {
@@ -41,9 +39,11 @@ val baseGroup: String by project
val mcVersion: String by project
val gitVersion = cmd("git", "rev-parse", "--short", "HEAD")
val fullVersion = project.property("mod_version").toString()
-val version: String = "$fullVersion-$gitVersion"
+val versionName: String = "$fullVersion-$gitVersion"
val mixinGroup = "$baseGroup.mixin"
-project.version = version
+allprojects {
+ version = versionName
+}
val modid: String by project
// Toolchains:
@@ -89,14 +89,21 @@ sourceSets.main {
kotlin.destinationDirectory.set(java.destinationDirectory)
}
-repositories {
- mavenCentral()
- maven("https://repo.nea.moe/releases/")
- maven("https://repo.spongepowered.org/maven/")
- maven("https://maven.notenoughupdates.org/releases")
- maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1")
+allprojects {
+ repositories {
+ mavenCentral()
+ maven("https://repo.nea.moe/releases/")
+ maven("https://repo.spongepowered.org/maven/")
+ maven("https://maven.notenoughupdates.org/releases")
+ maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1")
+ }
}
+// TODO: Add an extra shadow configuration for optimizable jars
+//val optShadowImpl: Configuration by configurations.creating {
+//
+//}
+
val shadowImpl: Configuration by configurations.creating {
configurations.implementation.get().extendsFrom(this)
}
@@ -117,6 +124,7 @@ dependencies {
shadowImpl("org.xerial:sqlite-jdbc:3.45.3.0")
shadowImpl("org.notenoughupdates.moulconfig:legacy:3.0.0-beta.9")
shadowImpl("io.azam.ulidj:ulidj:1.0.4")
+ shadowImpl(project(":dependency-injection"))
shadowImpl("moe.nea:libautoupdate:1.3.1")
runtimeOnly("me.djtheredstoner:DevAuth-forge-legacy:1.1.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
@@ -129,114 +137,25 @@ tasks.shadowJar {
doFirst { error("Incorrect shadow JAR built!") }
}
-tasks.test {
- useJUnitPlatform()
-}
-
-tasks.withType(JavaCompile::class) {
- options.encoding = "UTF-8"
-}
-
-abstract class GenerateItemIds : DefaultTask() {
- @get: OutputDirectory
- abstract val outputDirectory: DirectoryProperty
-
- @get: InputDirectory
- abstract val repoFiles: DirectoryProperty
-
- @get: Input
- abstract val repoHash: Property<String>
-
- @get: Input
- abstract val packageName: Property<String>
-
- @get:Internal
- val outputFile get() = outputDirectory.asFile.get().resolve(packageName.get().replace(".", "/") + "/ItemIds.java")
-
- @TaskAction
- fun generateItemIds() {
- val nonIdName = "[^A-Z0-9_]".toRegex()
-
- data class Item(val id: String, val file: File) {
- val javaName get() = id.replace(nonIdName, { "__" + it.value.single().code })
- }
-
- val items = mutableListOf<Item>()
- for (listFile in repoFiles.asFile.get().resolve("items").listFiles() ?: emptyArray()) {
- listFile ?: continue
- if (listFile.extension != "json") {
- error("Unknown file $listFile")
- }
- items.add(Item(listFile.nameWithoutExtension, listFile))
- }
- items.sortedBy { it.id }
- outputFile.parentFile.mkdirs()
- val writer = outputFile.writer().buffered()
- writer.appendLine("// @generated from " + repoHash.get())
- writer.appendLine("package " + packageName.get() + ";")
- writer.appendLine()
- writer.appendLine("import moe.nea.ledger.ItemId;")
- writer.appendLine()
- writer.appendLine("/**")
- writer.appendLine(" * Automatically generated {@link ItemId} list.")
- writer.appendLine(" */")
- writer.appendLine("@org.jspecify.annotations.NullMarked")
- writer.appendLine("public interface ItemIds {")
- val gson = Gson()
- for (item in items) {
- writer.appendLine("\t/**")
- writer.appendLine("\t * @see <a href=${gson.toJson("https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO/blob/${repoHash.get()}/items/${item.id}.json")}>JSON definition</a>")
- writer.appendLine("\t */")
- writer.appendLine("\tItemId ${item.javaName} =" +
- " ItemId.forName(${gson.toJson(item.id)});")
- }
- writer.appendLine("}")
- writer.close()
- }
-}
-
-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"))
+allprojects {
+ tasks.withType<Test> {
+ useJUnitPlatform()
}
- @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)
- }
- }
- }
+ tasks.withType(JavaCompile::class) {
+ options.encoding = "UTF-8"
}
}
-val downloadRepo by tasks.register("downloadRepo", RepoDownload::class) {
+tasks.downloadRepo {
hash.set("dcf1dbc")
}
val generateItemIds by tasks.register("generateItemIds", GenerateItemIds::class) {
- repoHash.set(downloadRepo.hash)
+ repoHash.set(tasks.downloadRepo.get().hash)
packageName.set("moe.nea.ledger.gen")
outputDirectory.set(layout.buildDirectory.dir("generated/sources/itemIds"))
- repoFiles.set(downloadRepo.outputDirectory)
+ repoFiles.set(tasks.downloadRepo.get().outputDirectory)
}
sourceSets.main {
java.srcDir(generateItemIds)
@@ -278,7 +197,6 @@ val proguard = tasks.register("proguard", ProGuardTask::class) {
val libJava = javaToolchains.launcherFor(java.toolchain)
.get()
.metadata.installationPath.file("jre/lib/rt.jar")
- println(libJava)
libraryjars(libJava)
libraryjars(configurations.compileClasspath)
}
@@ -313,10 +231,18 @@ tasks.jar {
tasks.assemble.get().dependsOn(tasks.remapJar)
-configure<BuildConfigExtension> {
- packageName("moe.nea.ledger.gen")
- buildConfigField<String>("VERSION", version)
- buildConfigField<String>("FULL_VERSION", fullVersion)
- buildConfigField<String>("GIT_COMMIT", gitVersion)
+inline fun <reified T : Any> ExtensionAware.configureIf(crossinline block: T.() -> Unit) {
+ if (extensions.findByType<T>() != null) {
+ extensions.configure<T> { block() }
+ }
+}
+
+allprojects {
+ configureIf<BuildConfigExtension> {
+ packageName("moe.nea.ledger.gen")
+ buildConfigField<String>("VERSION", versionName)
+ buildConfigField<String>("FULL_VERSION", fullVersion)
+ buildConfigField<String>("GIT_COMMIT", gitVersion)
+ }
}
diff --git a/dependency-injection/build.gradle.kts b/dependency-injection/build.gradle.kts
new file mode 100644
index 0000000..5a51941
--- /dev/null
+++ b/dependency-injection/build.gradle.kts
@@ -0,0 +1,8 @@
+plugins {
+ `java-library`
+ kotlin("jvm")
+}
+
+java {
+ toolchain.languageVersion.set(JavaLanguageVersion.of(8))
+}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt b/dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt
index a9061d7..0683063 100644
--- a/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt
+++ b/dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/DI.kt
@@ -47,6 +47,11 @@ class DI {
providers[type] = provider
}
+ fun <I : Any, T : I> registerInjectableInterface(parent: Class<I>, type: Class<T>) {
+ internalRegisterInjectableClass(type)
+ register(parent, DIProvider.fromInheritance(type))
+ }
+
fun registerInjectableClasses(vararg type: Class<*>) {
type.forEach { internalRegisterInjectableClass(it) }
}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt b/dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt
index bd5b9ef..8a54d5f 100644
--- a/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt
+++ b/dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/DIProvider.kt
@@ -18,7 +18,7 @@ fun interface DIProvider<T : Any> : BaseDIProvider<T, Unit> {
companion object {
- fun <T : Any> fromInjectableClass(clazz: Class<T>): DIProvider<T> {
+ fun <T : Any> fromInjectableClass(clazz: Class<out T>): DIProvider<T> {
@Suppress("UNCHECKED_CAST")
val cons = (clazz.constructors.find { it.getAnnotation(Inject::class.java) != null }
?: clazz.constructors.find { it.parameterCount == 0 }
@@ -41,6 +41,10 @@ fun interface DIProvider<T : Any> : BaseDIProvider<T, Unit> {
fun <T : Any> singeleton(value: T): DIProvider<T> {
return DIProvider { _ -> value }
}
+
+ fun <I : Any> fromInheritance(type: Class<out I>): DIProvider<I> {
+ return DIProvider { it.provide(type) }
+ }
}
}
diff --git a/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt b/dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt
index a8fdd87..a8fdd87 100644
--- a/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt
+++ b/dependency-injection/src/main/kotlin/moe/nea/ledger/utils/di/Inject.kt
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 82d99b6..28eae3b 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -24,3 +24,5 @@ plugins {
rootProject.name = "ledger"
+include("dependency-injection")
+includeBuild("build-src")