Skip to content

Commit

Permalink
Update a lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 20, 2024
1 parent e628851 commit 5c69a6b
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 51 deletions.
73 changes: 41 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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("<<VERSION>>", project.version, "src/main/kotlin/io/github/gaming32/additiveinstaller/versionHolder.kt")
sourceSets.main {
classTokenReplacer {
property("<<VERSION>>", version)
}
}

kotlin {
Expand All @@ -49,38 +49,47 @@ 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<File>
from(configurations.runtimeClasspath.get().files.map { if (it.isDirectory) it else zipTree(it) })
duplicatesStrategy = DuplicatesStrategy.WARN
}

val bootstrapVersion = "0.5.2"
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)
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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" }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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" }
""
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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"),
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/io/github/gaming32/additiveinstaller/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -16,10 +16,11 @@ import kotlin.io.path.isDirectory

private val logger = KotlinLogging.logger {}

const val VERSION = "<<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) {
Expand Down Expand Up @@ -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 {
Expand Down

This file was deleted.

0 comments on commit 5c69a6b

Please sign in to comment.