Fix BuildInformationCrashCategory
All checks were successful
PRs & Pushes / test (push) Successful in 4m1s
PRs & Pushes / build-jars (push) Successful in 4m0s
PRs & Pushes / build-apidoc (push) Successful in 4m15s

This commit is contained in:
JeremyStar™ 2025-01-01 16:13:19 +01:00
parent 9685729de9
commit 90158850ef
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 32 additions and 26 deletions

View file

@ -33,7 +33,7 @@ import de.staropensource.engine.base.utility.dnihbd.BuildInformation
* @constructor Initializes this crash category * @constructor Initializes this crash category
* @since v1-alpha10 * @since v1-alpha10
*/ */
class EngineCrashCategory private constructor() : BuildInformation.BuildInformationCrashCategory() { class EngineCrashCategory private constructor() : BuildInformation.BuildInformationCrashCategory({ Engine.info }) {
/** /**
* Companion object of [EngineCrashCategory]. * Companion object of [EngineCrashCategory].
* *

View file

@ -19,7 +19,6 @@
package de.staropensource.engine.base.utility.dnihbd 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.implementable.logging.CrashCategory
import de.staropensource.engine.base.type.Origin import de.staropensource.engine.base.type.Origin
import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.Call
@ -35,7 +34,6 @@ import java.io.InputStreamReader
import java.io.Reader import java.io.Reader
import java.io.StringReader import java.io.StringReader
import java.util.* import java.util.*
import kotlin.Throws
/** /**
* Loads the specified `-git.properties` and * Loads the specified `-git.properties` and
@ -62,7 +60,10 @@ import kotlin.Throws
@Suppress("Unused") @Suppress("Unused")
open class BuildInformation open class BuildInformation
@Throws(RuntimeException::class) @Throws(RuntimeException::class)
constructor(val loadPrefix: String, val loadLocation: FileAccess? = null) { constructor(
val loadPrefix: String,
val loadLocation: FileAccess? = null
) {
// -----> Versioning // -----> Versioning
/** /**
* Returns the current version string. * Returns the current version string.
@ -433,15 +434,20 @@ open class BuildInformation
* details about your running build. * details about your running build.
* *
* @constructor Initializes this crash category * @constructor Initializes this crash category
* @param lambda lambda which returns a [BuildInformation] instance to use
* @since v1-alpha10 * @since v1-alpha10
*/ */
abstract class BuildInformationCrashCategory : CrashCategory { abstract class BuildInformationCrashCategory(
val lambda: () -> BuildInformation?
) : CrashCategory {
override fun execute( override fun execute(
call: Call, call: Call,
channelSettings: ChannelSettings?, channelSettings: ChannelSettings?,
throwable: Throwable?, throwable: Throwable?,
fatal: Boolean, fatal: Boolean,
): LinkedHashMap<String, Any?> { ): LinkedHashMap<String, Any?> {
val info: BuildInformation? = lambda.invoke()
// Check if Engine.info is 'null' // Check if Engine.info is 'null'
if (info == null) if (info == null)
return linkedMapOf( return linkedMapOf(
@ -452,71 +458,71 @@ open class BuildInformation
// Add metadata // Add metadata
// -> Versioning // -> Versioning
map.put("Version", "${info!!.versionString(semver = false)} \"${info!!.versionCodename}\"") map.put("Version", "${info.versionString(semver = false)} \"${info.versionCodename}\"")
// -> Languages // -> Languages
if (!info!!.languages.isEmpty()) { if (!info.languages.isEmpty()) {
val languagesMap: LinkedHashMap<String, String> = linkedMapOf() val languagesMap: LinkedHashMap<String, String> = linkedMapOf()
// Add all languages // Add all languages
for (language: String in info!!.languages.keys) for (language: String in info.languages.keys)
languagesMap.put(language, info!!.languages[language]!!) languagesMap.put(language, info.languages[language]!!)
// Add to output map // Add to output map
map.put("Languages", languagesMap) map.put("Languages", languagesMap)
} }
// -> Dependencies // -> Dependencies
if (!info!!.dependencies.isEmpty()) { if (!info.dependencies.isEmpty()) {
val dependenciesMap: LinkedHashMap<String, String> = linkedMapOf() val dependenciesMap: LinkedHashMap<String, String> = linkedMapOf()
// Add all dependencies // Add all dependencies
for (dependency: String in info!!.dependencies.keys) for (dependency: String in info.dependencies.keys)
dependenciesMap.put(dependency, info!!.dependencies[dependency]!!) dependenciesMap.put(dependency, info.dependencies[dependency]!!)
// Add to output map // Add to output map
map.put("Dependencies", dependenciesMap) map.put("Dependencies", dependenciesMap)
} }
if (!info!!.testDependencies.isEmpty()) { if (!info.testDependencies.isEmpty()) {
val testDependenciesMap: LinkedHashMap<String, String> = linkedMapOf() val testDependenciesMap: LinkedHashMap<String, String> = linkedMapOf()
// Add all test dependencies // Add all test dependencies
for (testDependency: String in info!!.testDependencies.keys) for (testDependency: String in info.testDependencies.keys)
testDependenciesMap.put(testDependency, info!!.testDependencies[testDependency]!!) testDependenciesMap.put(testDependency, info.testDependencies[testDependency]!!)
// Add to output map // Add to output map
map.put("Test dependencies", testDependenciesMap) map.put("Test dependencies", testDependenciesMap)
} }
// -> Git // -> Git
if (info!!.gitFaked) if (info.gitFaked)
map.put("Git", "Unavailable") map.put("Git", "Unavailable")
else { else {
val gitMap: LinkedHashMap<String, Any> = linkedMapOf() val gitMap: LinkedHashMap<String, Any> = linkedMapOf()
val gitCommitMap: LinkedHashMap<String, Any> = linkedMapOf() val gitCommitMap: LinkedHashMap<String, Any> = linkedMapOf()
val gitCommitAuthorMap: LinkedHashMap<String, String> = linkedMapOf() val gitCommitAuthorMap: LinkedHashMap<String, String> = linkedMapOf()
val gitBuilderMap: LinkedHashMap<String, String> = linkedMapOf() val gitBuilderMap: LinkedHashMap<String, String> = linkedMapOf()
val gitCommitTime: LocalDateTime = info!!.gitCommitTime.toLocalDateTime(TimeZone.UTC) val gitCommitTime: LocalDateTime = info.gitCommitTime.toLocalDateTime(TimeZone.UTC)
// Add to 'gitCommitAuthorMap' // Add to 'gitCommitAuthorMap'
gitCommitAuthorMap.put("Username", info!!.gitCommitAuthorUsername) gitCommitAuthorMap.put("Username", info.gitCommitAuthorUsername)
gitCommitAuthorMap.put("Email address", info!!.gitCommitAuthorEmail) gitCommitAuthorMap.put("Email address", info.gitCommitAuthorEmail)
// Add to 'gitCommitMap' // Add to 'gitCommitMap'
gitCommitMap.put("Identifier", info!!.gitCommitIdentifierLong) gitCommitMap.put("Identifier", info.gitCommitIdentifierLong)
gitCommitMap.put("Message (short)", info!!.gitCommitMessageShort) gitCommitMap.put("Message (short)", info.gitCommitMessageShort)
gitCommitMap.put("Time", "${gitCommitTime.dayOfMonth}.${gitCommitTime.monthNumber}.${gitCommitTime.year} ${gitCommitTime.hour}:${gitCommitTime.minute}:${gitCommitTime.second} UTC") gitCommitMap.put("Time", "${gitCommitTime.dayOfMonth}.${gitCommitTime.monthNumber}.${gitCommitTime.year} ${gitCommitTime.hour}:${gitCommitTime.minute}:${gitCommitTime.second} UTC")
gitCommitMap.put("Author", gitCommitAuthorMap) gitCommitMap.put("Author", gitCommitAuthorMap)
// Add to 'gitCommitMap' // Add to 'gitCommitMap'
gitBuilderMap.put("Hostname", info!!.gitBuildHostname) gitBuilderMap.put("Hostname", info.gitBuildHostname)
gitBuilderMap.put("Username", info!!.gitBuildUsername) gitBuilderMap.put("Username", info.gitBuildUsername)
gitBuilderMap.put("Email address", info!!.gitBuildEmail) gitBuilderMap.put("Email address", info.gitBuildEmail)
// Add to 'gitMap' // Add to 'gitMap'
gitMap.put("Dirty", if (info!!.gitDirty) "yes" else "no") gitMap.put("Dirty", if (info.gitDirty) "yes" else "no")
gitMap.put("Branch", info!!.gitBranch) gitMap.put("Branch", info.gitBranch)
gitMap.put("Commit", gitCommitMap) gitMap.put("Commit", gitCommitMap)
gitMap.put("Builder", gitBuilderMap) gitMap.put("Builder", gitBuilderMap)