From 90158850ef4ca77f73c62664f5b39f3bffafaf12 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Wed, 1 Jan 2025 16:13:19 +0100 Subject: [PATCH] Fix BuildInformationCrashCategory --- .../crashcategory/EngineCrashCategory.kt | 2 +- .../base/utility/dnihbd/BuildInformation.kt | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt index 2f56f91..ca1755d 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt @@ -33,7 +33,7 @@ import de.staropensource.engine.base.utility.dnihbd.BuildInformation * @constructor Initializes this crash category * @since v1-alpha10 */ -class EngineCrashCategory private constructor() : BuildInformation.BuildInformationCrashCategory() { +class EngineCrashCategory private constructor() : BuildInformation.BuildInformationCrashCategory({ Engine.info }) { /** * Companion object of [EngineCrashCategory]. * diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt index 144960c..3653057 100644 --- a/base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt @@ -19,7 +19,6 @@ package de.staropensource.engine.base.utility.dnihbd -import de.staropensource.engine.base.Engine.Companion.info import de.staropensource.engine.base.implementable.logging.CrashCategory import de.staropensource.engine.base.type.Origin import de.staropensource.engine.base.type.logging.Call @@ -35,7 +34,6 @@ import java.io.InputStreamReader import java.io.Reader import java.io.StringReader import java.util.* -import kotlin.Throws /** * Loads the specified `-git.properties` and @@ -62,7 +60,10 @@ import kotlin.Throws @Suppress("Unused") open class BuildInformation @Throws(RuntimeException::class) - constructor(val loadPrefix: String, val loadLocation: FileAccess? = null) { + constructor( + val loadPrefix: String, + val loadLocation: FileAccess? = null + ) { // -----> Versioning /** * Returns the current version string. @@ -433,15 +434,20 @@ open class BuildInformation * details about your running build. * * @constructor Initializes this crash category + * @param lambda lambda which returns a [BuildInformation] instance to use * @since v1-alpha10 */ - abstract class BuildInformationCrashCategory : CrashCategory { + abstract class BuildInformationCrashCategory( + val lambda: () -> BuildInformation? + ) : CrashCategory { override fun execute( call: Call, channelSettings: ChannelSettings?, throwable: Throwable?, fatal: Boolean, ): LinkedHashMap { + val info: BuildInformation? = lambda.invoke() + // Check if Engine.info is 'null' if (info == null) return linkedMapOf( @@ -452,71 +458,71 @@ open class BuildInformation // Add metadata // -> Versioning - map.put("Version", "${info!!.versionString(semver = false)} \"${info!!.versionCodename}\"") + map.put("Version", "${info.versionString(semver = false)} \"${info.versionCodename}\"") // -> Languages - if (!info!!.languages.isEmpty()) { + if (!info.languages.isEmpty()) { val languagesMap: LinkedHashMap = linkedMapOf() // Add all languages - for (language: String in info!!.languages.keys) - languagesMap.put(language, info!!.languages[language]!!) + for (language: String in info.languages.keys) + languagesMap.put(language, info.languages[language]!!) // Add to output map map.put("Languages", languagesMap) } // -> Dependencies - if (!info!!.dependencies.isEmpty()) { + if (!info.dependencies.isEmpty()) { val dependenciesMap: LinkedHashMap = linkedMapOf() // Add all dependencies - for (dependency: String in info!!.dependencies.keys) - dependenciesMap.put(dependency, info!!.dependencies[dependency]!!) + for (dependency: String in info.dependencies.keys) + dependenciesMap.put(dependency, info.dependencies[dependency]!!) // Add to output map map.put("Dependencies", dependenciesMap) } - if (!info!!.testDependencies.isEmpty()) { + if (!info.testDependencies.isEmpty()) { val testDependenciesMap: LinkedHashMap = linkedMapOf() // Add all test dependencies - for (testDependency: String in info!!.testDependencies.keys) - testDependenciesMap.put(testDependency, info!!.testDependencies[testDependency]!!) + for (testDependency: String in info.testDependencies.keys) + testDependenciesMap.put(testDependency, info.testDependencies[testDependency]!!) // Add to output map map.put("Test dependencies", testDependenciesMap) } // -> Git - if (info!!.gitFaked) + if (info.gitFaked) map.put("Git", "Unavailable") else { val gitMap: LinkedHashMap = linkedMapOf() val gitCommitMap: LinkedHashMap = linkedMapOf() val gitCommitAuthorMap: LinkedHashMap = linkedMapOf() val gitBuilderMap: LinkedHashMap = linkedMapOf() - val gitCommitTime: LocalDateTime = info!!.gitCommitTime.toLocalDateTime(TimeZone.UTC) + val gitCommitTime: LocalDateTime = info.gitCommitTime.toLocalDateTime(TimeZone.UTC) // Add to 'gitCommitAuthorMap' - gitCommitAuthorMap.put("Username", info!!.gitCommitAuthorUsername) - gitCommitAuthorMap.put("Email address", info!!.gitCommitAuthorEmail) + gitCommitAuthorMap.put("Username", info.gitCommitAuthorUsername) + gitCommitAuthorMap.put("Email address", info.gitCommitAuthorEmail) // Add to 'gitCommitMap' - gitCommitMap.put("Identifier", info!!.gitCommitIdentifierLong) - gitCommitMap.put("Message (short)", info!!.gitCommitMessageShort) + gitCommitMap.put("Identifier", info.gitCommitIdentifierLong) + gitCommitMap.put("Message (short)", info.gitCommitMessageShort) gitCommitMap.put("Time", "${gitCommitTime.dayOfMonth}.${gitCommitTime.monthNumber}.${gitCommitTime.year} ${gitCommitTime.hour}:${gitCommitTime.minute}:${gitCommitTime.second} UTC") gitCommitMap.put("Author", gitCommitAuthorMap) // Add to 'gitCommitMap' - gitBuilderMap.put("Hostname", info!!.gitBuildHostname) - gitBuilderMap.put("Username", info!!.gitBuildUsername) - gitBuilderMap.put("Email address", info!!.gitBuildEmail) + gitBuilderMap.put("Hostname", info.gitBuildHostname) + gitBuilderMap.put("Username", info.gitBuildUsername) + gitBuilderMap.put("Email address", info.gitBuildEmail) // Add to 'gitMap' - gitMap.put("Dirty", if (info!!.gitDirty) "yes" else "no") - gitMap.put("Branch", info!!.gitBranch) + gitMap.put("Dirty", if (info.gitDirty) "yes" else "no") + gitMap.put("Branch", info.gitBranch) gitMap.put("Commit", gitCommitMap) gitMap.put("Builder", gitBuilderMap)