From cd81e60808d365e57e09ba243416acdeaa39571f Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 20 Dec 2024 21:59:19 +0100 Subject: [PATCH] Add register method and version checks to the ANSI subsystem --- .../engine/ansi/AnsiSubsystem.kt | 28 +++++++++++++++++++ .../de/staropensource/engine/testapp/Main.kt | 3 ++ 2 files changed, 31 insertions(+) diff --git a/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt b/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt index e326dae..af6b799 100644 --- a/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt +++ b/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt @@ -19,6 +19,7 @@ package de.staropensource.engine.ansi +import de.staropensource.engine.base.Engine import de.staropensource.engine.base.implementable.Subsystem import de.staropensource.engine.base.logging.Logger import de.staropensource.engine.base.utility.dnihbd.BuildInformation @@ -40,6 +41,7 @@ class AnsiSubsystem : Subsystem() { * * @since v1-alpha10 */ + @JvmStatic internal val logger: Logger = Logger(channel = "engine-ansi") /** @@ -50,7 +52,19 @@ class AnsiSubsystem : Subsystem() { * @see BuildInformation * @since v1-alpha10 */ + @JvmStatic var info: BuildInformation? = null + + /** + * Registers this subsystem. + * + * @since v1-alpha10 + */ + @JvmStatic + fun register() { + if (!Engine.getSubsystems().map { item -> item::class }.contains(AnsiSubsystem::class)) + Engine.registerSubsystem(AnsiSubsystem()) + } } @@ -62,6 +76,20 @@ class AnsiSubsystem : Subsystem() { // -----> Lifecycle override fun initialize() { info = BuildInformation("sosengine-ansi") + + if (Engine.info!!.versionString(semver = false) != info!!.versionString(semver = false)) + logger.crash(""" + The version of the core engine and the ANSI subsystem differs. + Engine: ${Engine.info!!.versionString(semver = false)} + ANSI subsystem: ${info!!.versionString(semver = false)} + """.trimIndent().trimEnd()) + + if (Engine.info!!.gitCommitIdentifierLong != info!!.gitCommitIdentifierLong) + logger.crash(""" + The commit id of the core engine and the ANSI subsystem differs. + Engine: ${Engine.info!!.gitCommitIdentifierLong} + ANSI subsystem: ${info!!.gitCommitIdentifierLong} + """.trimIndent().trimEnd()) } override fun shutdown(final: Boolean, fatalCrash: Boolean) { diff --git a/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt b/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt index eeede52..6d23ee4 100644 --- a/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt +++ b/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt @@ -54,6 +54,9 @@ class Main private constructor() { // Update engine configuration EngineConfiguration.logLevels = Level.entries.toMutableSet() + // Register subsystems + AnsiSubsystem.register() + // Initialize engine Engine.initialize()