From 5c69a6be885d0d37f17e611f3c5974150ad5751f Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Mon, 20 May 2024 10:55:14 -0500 Subject: [PATCH] Update a lot of stuff --- build.gradle.kts | 73 +++++++++++-------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../JProgressBarProgressHandler.kt | 4 +- .../additiveinstaller/PackInstaller.kt | 10 +-- .../additiveinstaller/darkModeDetector.kt | 4 +- .../gaming32/additiveinstaller/generalUtil.kt | 6 +- .../github/gaming32/additiveinstaller/main.kt | 7 +- .../additiveinstaller/versionHolder.kt | 3 - 8 files changed, 58 insertions(+), 51 deletions(-) delete mode 100644 src/main/kotlin/io/github/gaming32/additiveinstaller/versionHolder.kt diff --git a/build.gradle.kts b/build.gradle.kts index e611351..6982295 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,16 +1,14 @@ import de.undercouch.gradle.tasks.download.Download -import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName plugins { application - kotlin("jvm") version "1.8.21" - id("io.ktor.plugin") version "2.1.1" // It builds fat JARs - id("net.kyori.blossom") version "1.3.1" - id("de.undercouch.download") version "5.4.0" + kotlin("jvm") version "1.9.23" + id("net.raphimc.class-token-replacer") version "1.0.0" + id("de.undercouch.download") version "5.6.0" } group = "io.github.gaming32" -version = "1.0.1" +version = "1.0.2" application { mainClass.set("io.github.gaming32.additiveinstaller.MainKt") @@ -21,22 +19,24 @@ repositories { } dependencies { - implementation("org.slf4j:slf4j-api:2.0.7") - implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0") - implementation("org.apache.logging.log4j:log4j-core:2.20.0") - implementation("io.github.oshai:kotlin-logging-jvm:4.0.0-beta-22") + implementation("org.slf4j:slf4j-api:2.0.13") + implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1") + implementation("org.apache.logging.log4j:log4j-core:2.23.1") + implementation("io.github.oshai:kotlin-logging-jvm:6.0.9") - implementation("com.google.jimfs:jimfs:1.2") + implementation("com.google.jimfs:jimfs:1.3.0") - implementation("com.formdev:flatlaf:3.1.1") + implementation("com.formdev:flatlaf:3.4.1") - implementation("com.google.code.gson:gson:2.10.1") + implementation("com.google.code.gson:gson:2.11.0") - implementation("io.github.z4kn4fein:semver:1.4.2") + implementation("io.github.z4kn4fein:semver-jvm:2.0.0") } -blossom { - replaceToken("<>", project.version, "src/main/kotlin/io/github/gaming32/additiveinstaller/versionHolder.kt") +sourceSets.main { + classTokenReplacer { + property("<>", version) + } } kotlin { @@ -49,12 +49,8 @@ tasks.jar { attributes["Multi-Release"] = true attributes["SplashScreen-Image"] = "splash.png" } -} - -// Based on https://github.com/IrisShaders/Iris-Installer/blob/main/build.gradle -abstract class FileOutput : DefaultTask() { - @get:OutputFile - abstract val output: Property + from(configurations.runtimeClasspath.get().files.map { if (it.isDirectory) it else zipTree(it) }) + duplicatesStrategy = DuplicatesStrategy.WARN } val bootstrapVersion = "0.5.2" @@ -62,25 +58,38 @@ val bootstrapArch = "i686" val downloadBootstrap by tasks.registering(Download::class) { src("https://maven.fabricmc.net/net/fabricmc/fabric-installer-native-bootstrap/windows-$bootstrapArch/$bootstrapVersion/windows-$bootstrapArch-$bootstrapVersion.exe") - dest(project.buildDir) + dest(project.layout.buildDirectory.get().dir("native-bootstrap")) +} + +abstract class NativeExeTask : DefaultTask() { + @get:InputFile + abstract val bootstrapFile: RegularFileProperty + + @get:InputFile + abstract val jarFile: RegularFileProperty + + @get:OutputFile + abstract val output: RegularFileProperty } -val nativeExe by tasks.registering(FileOutput::class) { +val nativeExe by tasks.registering(NativeExeTask::class) { dependsOn(downloadBootstrap) - dependsOn(tasks.shadowJar) + dependsOn(tasks.jar) - output.set(file("$projectDir/build/libs/${project.archivesName.get()}-${project.version}.exe")) - outputs.upToDateWhen { false } + bootstrapFile = downloadBootstrap.get().outputFiles.first() + jarFile = tasks.jar.get().archiveFile + output = file("$projectDir/build/libs/${base.archivesName.get()}-${project.version}.exe") doFirst { - output.get().delete() + output.get().asFile.delete() } doLast { - output.get().createNewFile() - output.get().writeBytes(downloadBootstrap.get().outputFiles.first().readBytes()) - output.get().appendBytes(tasks.shadowJar.get().archiveFile.get().asFile.readBytes()) + val outputFile = output.get().asFile + outputFile.createNewFile() + outputFile.writeBytes(downloadBootstrap.get().outputFiles.first().readBytes()) + outputFile.appendBytes(tasks.jar.get().archiveFile.get().asFile.readBytes()) } } -tasks.build.get().dependsOn(nativeExe) +tasks.assemble.get().dependsOn(nativeExe) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 60c76b3..a8382d7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file diff --git a/src/main/kotlin/io/github/gaming32/additiveinstaller/JProgressBarProgressHandler.kt b/src/main/kotlin/io/github/gaming32/additiveinstaller/JProgressBarProgressHandler.kt index b3b468b..bb2169d 100644 --- a/src/main/kotlin/io/github/gaming32/additiveinstaller/JProgressBarProgressHandler.kt +++ b/src/main/kotlin/io/github/gaming32/additiveinstaller/JProgressBarProgressHandler.kt @@ -1,6 +1,6 @@ package io.github.gaming32.additiveinstaller -import io.github.oshai.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import javax.swing.JProgressBar import javax.swing.SwingUtilities @@ -25,7 +25,7 @@ class JProgressBarProgressHandler(private val bar: JProgressBar) : ProgressHandl } override fun newTask(title: String) { - logger.info("New task: $title") + logger.info { "New task: $title" } SwingUtilities.invokeLater { prepared = false bar.value++ diff --git a/src/main/kotlin/io/github/gaming32/additiveinstaller/PackInstaller.kt b/src/main/kotlin/io/github/gaming32/additiveinstaller/PackInstaller.kt index 6f92bde..72778f1 100644 --- a/src/main/kotlin/io/github/gaming32/additiveinstaller/PackInstaller.kt +++ b/src/main/kotlin/io/github/gaming32/additiveinstaller/PackInstaller.kt @@ -6,7 +6,7 @@ import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonParser -import io.github.oshai.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import io.github.z4kn4fein.semver.toVersion import java.io.IOException import java.net.URI @@ -115,7 +115,7 @@ class PackInstaller( progressHandler.newTaskSet(8) val loaderVersion = packIndex["dependencies"].asJsonObject[packVersion.loader.dependencyName].asString - logger.info("Using ${packVersion.loader.dependencyName} $loaderVersion") + logger.info { "Using ${packVersion.loader.dependencyName} $loaderVersion" } progressHandler.newTask(I18N.getString("downloading.client.json")) val clientJson = requestJson( @@ -160,7 +160,7 @@ class PackInstaller( dest.parent.createDirectories() val downloadUrl = file["downloads"].asJsonArray.first().asString if ("/$YOSBR_ID/" in downloadUrl && "yosbr" in file["path"].asString) { - logger.info("Skipping yosbr") + logger.info { "Skipping yosbr" } return@forEach } download(file, downloadUrl, dest) @@ -179,7 +179,7 @@ class PackInstaller( if (relative.startsWith("config/yosbr/")) { relative = relative.substring(13) overwrite = false - logger.info("Override $relative is in yosbr") + logger.info { "Override $relative is in yosbr" } } progressHandler.newTask(I18N.getString("extracting.override", relative)) val dest = destination / relative @@ -190,7 +190,7 @@ class PackInstaller( try { override.copyTo(dest, overwrite) } catch (_: FileAlreadyExistsException) { - logger.info("Skipping override $relative because it was in yosbr and the file already exists") + logger.info { "Skipping override $relative because it was in yosbr and the file already exists" } } } } diff --git a/src/main/kotlin/io/github/gaming32/additiveinstaller/darkModeDetector.kt b/src/main/kotlin/io/github/gaming32/additiveinstaller/darkModeDetector.kt index 8d110b8..017fc8f 100644 --- a/src/main/kotlin/io/github/gaming32/additiveinstaller/darkModeDetector.kt +++ b/src/main/kotlin/io/github/gaming32/additiveinstaller/darkModeDetector.kt @@ -1,6 +1,6 @@ package io.github.gaming32.additiveinstaller -import io.github.oshai.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import java.io.BufferedReader import java.io.IOException @@ -50,6 +50,6 @@ private fun query(cmd: String) = try { .bufferedReader() .use(BufferedReader::readText) } catch (e: IOException) { - logger.error("Exception caught while querying the OS", e) + logger.error(e) { "Exception caught while querying the OS" } "" } diff --git a/src/main/kotlin/io/github/gaming32/additiveinstaller/generalUtil.kt b/src/main/kotlin/io/github/gaming32/additiveinstaller/generalUtil.kt index d2fd6e0..9e5c3b0 100644 --- a/src/main/kotlin/io/github/gaming32/additiveinstaller/generalUtil.kt +++ b/src/main/kotlin/io/github/gaming32/additiveinstaller/generalUtil.kt @@ -5,7 +5,7 @@ import com.google.gson.JsonObject import com.google.gson.JsonParser import com.google.gson.internal.Streams import com.google.gson.stream.JsonWriter -import io.github.oshai.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import java.awt.Component import java.io.InputStream import java.io.Writer @@ -49,7 +49,7 @@ fun Component.withLabel(label: String? = null) = JPanel().apply { } fun request(url: String): InputStream { - logger.info("Requesting $url") + logger.info { "Requesting $url" } val cnxn = URL(url).openConnection() cnxn.setRequestProperty("User-Agent", "Additive Installer/$VERSION") return cnxn.getInputStream() @@ -60,7 +60,7 @@ fun requestJson(url: String) = request(url).reader().use(JsonParser::parseReader fun requestCriticalJson(url: String) = try { requestJson(url) } catch (e: Exception) { - logger.error("Failed to request $url", e) + logger.error(e) { "Failed to request $url" } JOptionPane.showMessageDialog( null, I18N.getString("modrinth.access.failed"), diff --git a/src/main/kotlin/io/github/gaming32/additiveinstaller/main.kt b/src/main/kotlin/io/github/gaming32/additiveinstaller/main.kt index 4f7d613..05b0444 100644 --- a/src/main/kotlin/io/github/gaming32/additiveinstaller/main.kt +++ b/src/main/kotlin/io/github/gaming32/additiveinstaller/main.kt @@ -4,7 +4,7 @@ import com.formdev.flatlaf.FlatDarkLaf import com.formdev.flatlaf.FlatLightLaf import com.formdev.flatlaf.themes.FlatMacDarkLaf import com.formdev.flatlaf.themes.FlatMacLightLaf -import io.github.oshai.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import java.awt.BorderLayout import java.util.* import javax.swing.* @@ -16,10 +16,11 @@ import kotlin.io.path.isDirectory private val logger = KotlinLogging.logger {} +const val VERSION = "<>" val I18N = ResourceBundle.getBundle("i18n/lang", Locale.getDefault())!! fun main() { - logger.info("Additive Installer $VERSION") + logger.info { "Additive Installer $VERSION" } if (isDarkMode()) { if (operatingSystem == OperatingSystem.MACOS) { @@ -145,7 +146,7 @@ fun main() { ) null } catch (t: Throwable) { - logger.error("Failed to install pack", t) + logger.error(t) { "Failed to install pack" } t } SwingUtilities.invokeLater { diff --git a/src/main/kotlin/io/github/gaming32/additiveinstaller/versionHolder.kt b/src/main/kotlin/io/github/gaming32/additiveinstaller/versionHolder.kt deleted file mode 100644 index 7e13c4e..0000000 --- a/src/main/kotlin/io/github/gaming32/additiveinstaller/versionHolder.kt +++ /dev/null @@ -1,3 +0,0 @@ -package io.github.gaming32.additiveinstaller - -const val VERSION = "<>"