diff --git a/ansi/build.gradle.kts b/ansi/build.gradle.kts index 1eb02ac..0863746 100644 --- a/ansi/build.gradle.kts +++ b/ansi/build.gradle.kts @@ -17,12 +17,8 @@ * along with this program. If not, see . */ -kotlin { - // Dependencies - sourceSets { - commonMain.dependencies { - // sos!engine - implementation(project(":base")) - } - } +// Dependencies +dependencies { + // sos!engine + implementation(project(":base")) } diff --git a/ansi/src/commonMain/kotlin/de/staropensource/engine/ansi/AnsiFormatter.kt b/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiFormatter.kt similarity index 99% rename from ansi/src/commonMain/kotlin/de/staropensource/engine/ansi/AnsiFormatter.kt rename to ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiFormatter.kt index 87612c9..1c94b55 100644 --- a/ansi/src/commonMain/kotlin/de/staropensource/engine/ansi/AnsiFormatter.kt +++ b/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiFormatter.kt @@ -21,7 +21,6 @@ package de.staropensource.engine.ansi import de.staropensource.engine.ansi.AnsiSubsystem.Companion.logger import de.staropensource.engine.base.implementable.formatter.TwoCycleFormatterImpl -import kotlin.jvm.JvmStatic /** * Formats a string using ANSI diff --git a/ansi/src/commonMain/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt b/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt similarity index 99% rename from ansi/src/commonMain/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt rename to ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt index c7caacb..59a1aed 100644 --- a/ansi/src/commonMain/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt +++ b/ansi/src/main/kotlin/de/staropensource/engine/ansi/AnsiSubsystem.kt @@ -24,7 +24,6 @@ import de.staropensource.engine.base.implementable.Subsystem import de.staropensource.engine.base.logging.Logger import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.utility.dnihbd.BuildInformation -import kotlin.jvm.JvmStatic /** * The ANSI subsystem. diff --git a/ansi/src/commonMain/resources/.gitignore b/ansi/src/main/resources/.gitignore similarity index 100% rename from ansi/src/commonMain/resources/.gitignore rename to ansi/src/main/resources/.gitignore diff --git a/base/build.gradle.kts b/base/build.gradle.kts index bd4bba9..0400252 100644 --- a/base/build.gradle.kts +++ b/base/build.gradle.kts @@ -17,12 +17,8 @@ * along with this program. If not, see . */ -kotlin { - // Dependencies - sourceSets { - jvmMain.dependencies { - // OSHI - implementation("${property("dependencyOshiIdentifier") as String}:${property("dependencyOshiVersion") as String}") - } - } +// Dependencies +dependencies { + // OSHI + implementation("${property("dependencyOshiIdentifier") as String}:${property("dependencyOshiVersion") as String}") } diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/PlatformData.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/PlatformData.kt deleted file mode 100644 index 2131b8f..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/PlatformData.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.implementable - -import org.jetbrains.annotations.ApiStatus - -/** - * Interface for platform-specific data. - * - * @since v1-alpha10 - */ -@ApiStatus.Internal -@ApiStatus.NonExtendable -interface PlatformData { - /** - * Contains platform-specific data. - * - * **DO NOT VIEW OR MODIFY.** - * - * @since v1-alpha10 - */ - val platformData: MutableMap -} diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/EnginePlatform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/EnginePlatform.kt deleted file mode 100644 index e9b3c0e..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/EnginePlatform.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - - -/** - * Bootstraps this platform. - * - * Invoked by [de.staropensource.engine.base.Engine.bootstrap] first. - * - * @throws Throwable on error - * @since v1-alpha10 - */ -@Throws(Throwable::class) -expect fun platformEngineBootstrap() - -/** - * Initializes this platform. - * - * Invoked by [de.staropensource.engine.base.Engine.initialize] first. - * - * @throws Throwable on error - * @since v1-alpha10 - */ -@Throws(Throwable::class) -expect fun platformEngineInitialize() - -/** - * Reloads this platform. - * - * Invoked by [de.staropensource.engine.base.Engine.reload] first. - * - * @throws Throwable on error - * @since v1-alpha10 - */ -@Throws(Throwable::class) -expect fun platformEngineReload() - -/** - * Shuts this platform down. - * - * Invoked by one of the - * engine's shutdown methods - * last. - * - * @param final whether this is the last time the engine shuts down. Doesn't actually shut the application down, just changes some messages and does other things - * @param crashed enables super careful mode to prevent further breakage - * @throws Throwable on error - * @since v1-alpha10 - */ -@Throws(Throwable::class) -expect fun platformEngineShutdown(final: Boolean, crashed: Boolean = false) diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt deleted file mode 100644 index dea18af..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/Platform.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -/** - * Terminates the platform. - * - * @since v1-alpha10 - */ -internal expect fun platformTerminate(exitcode: UByte) - -/** - * Returns the time in milliseconds. - * - * Should only be used for - * comparing time intervals. - * **Should not be stored as - * this method may return a - * timestamp from platform - * to platform.** - * - * @since v1-alpha10 - */ -internal expect fun platformMilliseconds(): ULong diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt deleted file mode 100644 index 4563b2d..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatform.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -import de.staropensource.engine.base.implementable.stream.ReadStream -import de.staropensource.engine.base.implementable.stream.WriteStream -import de.staropensource.engine.base.utility.Process - -/** - * Platform-specific implementation of [Process]. - * - * @constructor Initializes this platform implementation - * @param process [Process] instance - * @since v1-alpha10 - */ -abstract class ProcessPlatform ( - val process: Process -) { - // -----> Lifecycle - /** - * Initializes the process. - * - * @throws Throwable on error - * @since v1-alpha10 - */ - @Throws(Throwable::class) - abstract fun start() - - /** - * Kills the process. - * - * @since v1-alpha10 - */ - abstract fun kill() - - - // -----> Getters - abstract fun isAlive(): Boolean - abstract fun getPid(): Long - abstract fun getExitCode(): UByte? - - - // -----> Stream getters - /** - * Returns the standard input stream. - * - * @return standard input stream - * @since v1-alpha10 - */ - abstract fun getStandardInput(): WriteStream - - /** - * Returns the standard output stream. - * - * @return standard output stream - * @since v1-alpha10 - */ - abstract fun getStandardOutput(): ReadStream - - /** - * Returns the standard error stream. - * - * @return standard error stream - * @since v1-alpha10 - */ - abstract fun getStandardError(): ReadStream -} - -/** - * Returns a [ProcessPlatform] implementation - * for the supplied [Process] instance. - * - * @param process [Process] instance - * @return matching [ProcessPlatform] instance - * @since v1-alpha10 - */ -internal expect fun platformProcessCreate(process: Process): ProcessPlatform diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/StreamPlatform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/StreamPlatform.kt deleted file mode 100644 index 7500f5e..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/StreamPlatform.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -import de.staropensource.engine.base.implementable.stream.ReadStream -import de.staropensource.engine.base.implementable.stream.Stream -import de.staropensource.engine.base.implementable.stream.WriteStream - -/** - * Platform-specific implementation of [Stream]. - * - * @constructor Initializes this platform implementation - * @param stream [Stream] instance - * @since v1-alpha10 - */ -abstract class StreamPlatform( - val stream: Stream -) { - /** - * Starts a watching thread for the specified stream. - * - * @param stream [Stream] instance - * @since v1-alpha10 - */ - abstract fun startWatchingThread() -} - -/** - * Returns a [StreamPlatform] implementation - * for the supplied [Stream] instance. - * - * @param stream [Stream] instance - * @return matching [StreamPlatform] instance - * @since v1-alpha10 - */ -internal expect fun platformStreamCreate(stream: Stream): StreamPlatform - -/** - * Returns a [ReadStream] representing - * the standard input of the current - * process. - * - * @return [ReadStream] instance representing the standard input - * @since v1-alpha10 - */ -internal expect fun platformStreamStandardInput(): ReadStream - -/** - * Returns a [WriteStream] representing - * the standard output of the current - * process. - * - * @return [WriteStream] instance representing the standard output - * @since v1-alpha10 - */ -internal expect fun platformStreamStandardOutput(): WriteStream - -/** - * Returns a [WriteStream] representing - * the standard error of the current - * process. - * - * @return [WriteStream] instance representing the standard error - * @since v1-alpha10 - */ -internal expect fun platformStreamStandardError(): WriteStream diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/package-info.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/package-info.kt deleted file mode 100644 index 374f989..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/platform/package-info.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -/** - * Platform-specific implementations - * and helper classes. - * - * @since v1-alpha10 - */ -package de.staropensource.engine.base.platform diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/GraphicsCard.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/GraphicsCard.kt deleted file mode 100644 index e80d19d..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/GraphicsCard.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.type.environment - -/** - * Represents a graphics card. - * - * @constructor Initializes this class - * @since v1-alpha10 - */ -@Suppress("Unused") -class GraphicsCard internal constructor( - val name: String, - val deviceIdentifier: String, - val manufacturer: String, - val version: String, - val videoMemory: ULong, -) diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/OperatingSystem.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/OperatingSystem.kt deleted file mode 100644 index 960d2fd..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/OperatingSystem.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.type.environment - -import de.staropensource.engine.base.EngineConfiguration - -/** - * Represents all operating systems - * detected and supported by the engine. - * - * @since v1-alpha10 - */ -enum class OperatingSystem { - /** - * Identifies that the application is running - * under the [Linux](https://kernel.org) kernel - * on some kind of Linux distribution. - * - * @since v1-alpha10 - */ - LINUX, - - /** - * Identifies that the application is running - * under the [FreeBSD](https://freebsd.org) kernel - * and likely the FreeBSD operating system. - * - * @since v1-alpha10 - */ - FREEBSD, - - /** - * Identifies that the application is running - * under the [NetBSD](https://netbsd.org) kernel - * and likely the NetBSD operating system. - * - * @since v1-alpha10 - */ - NETBSD, - - /** - * Identifies that the application is running - * under the [OpenBSD](https://openbsd.org) kernel - * and likely the OpenBSD operating system. - * - * @since v1-alpha10 - */ - OPENBSD, - - /** - * Identifies that the application is running - * under [Android](https://android.com), and - * by extension the [Linux kernel](https://kernel.org). - * - * @since v1-alpha10 - */ - ANDROID, - - /** - * Identifies that the application is running - * under [Windows](https://windows.com), and - * by extension the [Windows NT kernel](https://en.wikipedia.org/wiki/Ntoskrnl.exe). - * - * @since v1-alpha10 - */ - WINDOWS, - - /** - * Identifies that the application is running - * under [macOS](https://apple.com/macos), and - * by extension under the [XNU kernel](https://github.com/apple-oss-distributions/xnu). - * - * @since v1-alpha10 - */ - MACOS; - - override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.utility." else ""}Environment\$OperatingSystem.${name}" - - /** - * Returns the human-friendly name - * of this operating system. - * - * @return human-friendly name - * @since v1-alpha10 - */ - fun humanFriendly(): String = when (this) { - LINUX -> "Linux" - FREEBSD -> "FreeBSD" - NETBSD -> "NetBSD" - OPENBSD -> "OpenBSD" - ANDROID -> "Android" - WINDOWS -> "Windows" - MACOS -> "macOS" - } -} diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/package-info.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/package-info.kt deleted file mode 100644 index fb51af3..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/environment/package-info.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -/** - * Data types returned by [Environment]. - * - * @since v1-alpha10 - */ -package de.staropensource.engine.base.type.environment - -import de.staropensource.engine.base.utility.Environment diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt deleted file mode 100644 index f5fe26a..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Environment.kt +++ /dev/null @@ -1,336 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.utility - -import de.staropensource.engine.base.type.environment.GraphicsCard -import de.staropensource.engine.base.type.environment.OperatingSystem -import kotlinx.datetime.Instant -import kotlin.jvm.JvmStatic - -/** - * Provides information about the - * environment the application runs in. - * - * @constructor Initializes this class - * @since v1-alpha10 - */ -@Suppress("Unused", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") -expect class Environment private constructor() { - /** - * Companion class of [Environment]. - * - * @since v1-alpha10 - */ - companion object { - // -----> Update methods - /** - * Unsets the environment. - * - * @since v1-alpha10 - */ - @JvmStatic - internal fun unset() - - /** - * Detects and updates the environment. - * - * @since v1-alpha10 - */ - @JvmStatic - internal fun detect() - - - // -----> Getters - // -------> General - /** - * Returns the amount of - * bits this platform targets. - * - * This may be 32, 64 or an - * even higher value. - * - * @return maximum of supported bits - * @since v1-alpha10 - */ - @JvmStatic - fun getOperatingSystem(): OperatingSystem? - - /** - * Returns the point in time where - * the system the engine is - * running on has started. - * - * @return time of system startup - * @since v1-alpha10 - */ - @JvmStatic - fun getTimeOfStartup(): Instant? - - /** - * Returns whether the current process - * is elevated and is able to execute - * superuser/administrator actions. - * - * @return elevated? - * @since v1-alpha10 - */ - @JvmStatic - fun isElevated(): Boolean? - - /** - * Returns the amount of bits - * this platform targets. - * - * This may be 32, 64 or an - * even higher value. - * - * @return maximum of supported bits - * @since v1-alpha10 - */ - @JvmStatic - fun getBitness(): Int? - - // -------> Computer - /** - * Returns the name of the - * manufacturer of this computer. - * - * @return computer manufacturer name - * @since v1-alpha10 - */ - @JvmStatic - fun getComputerManufacturer(): String? - - /** - * Returns the name of the - * model of this computer. - * - * @return computer model name - * @since v1-alpha10 - */ - @JvmStatic - fun getComputerModel(): String? - - // -------> Firmware (BIOS, UEFI, etc.) - /** - * Returns the name of the firmware (BIOS, - * UEFI, etc.) installed on this computer. - * - * @return firmware name - * @since v1-alpha10 - */ - @JvmStatic - fun getFirmwareName(): String? - - /** - * Returns the description of the firmware (BIOS, - * UEFI, etc.) installed on this computer. - * - * @return firmware description - * @since v1-alpha10 - */ - @JvmStatic - fun getFirmwareDescription(): String? - - /** - * Returns the name of the manufacturer of this - * computer's firmware (BIOS, UEFI, etc.). - * - * @return firmware manufacturer name - * @since v1-alpha10 - */ - @JvmStatic - fun getFirmwareManufacturer(): String? - - /** - * Returns the version of the firmware (BIOS, - * UEFI, etc.) installed on this computer. - * - * @return firmware version - * @since v1-alpha10 - */ - @JvmStatic - fun getFirmwareVersion(): String? - - /** - * Returns the release date of the firmware (BIOS, - * UEFI, etc.) installed on this computer. - * - * @return firmware release date - * @since v1-alpha10 - */ - @JvmStatic - fun getFirmwareReleaseDate(): String? - - // -------> Motherboard - /** - * Returns the name of the model of - * this computer's motherboard. - * - * @return motherboard model name - * @since v1-alpha10 - */ - @JvmStatic - fun getMotherboardModel(): String? - - /** - * Returns the version of this - * computer's motherboard. - * - * @return motherboard version - * @since v1-alpha10 - */ - @JvmStatic - fun getMotherboardVersion(): String? - - /** - * Returns the serial number of - * this computer's motherboard. - * - * @return motherboard serial number - * @since v1-alpha10 - */ - @JvmStatic - fun getMotherboardSerialNumber(): String? - - /** - * Returns the name of the manufacturer - * of this computer's motherboard. - * - * @return motherboard manufacturer name - * @since v1-alpha10 - */ - @JvmStatic - fun getMotherboardManufacturer(): String? - - // -------> Memory - /** - * Returns the total amount of physical - * memory this system has in bytes. - * - * @return amount of physical memory in bytes - * @since v1-alpha10 - */ - @JvmStatic - fun getMemoryTotal(): Long? - - /** - * Returns the amount of available - * physical memory in bytes. - * - * @return amount of physical memory in bytes - * @since v1-alpha10 - */ - @JvmStatic - fun getMemoryAvailable(): Long? - - /** - * Returns the amount of available - * physical memory in bytes. - * - * @return amount of physical memory in bytes - * @since v1-alpha10 - */ - @JvmStatic - fun getMemoryUsed(): Long? - - /** - * Returns the size of a - * memory page in bytes. - * - * @return size of a memory page in bytes - * @since v1-alpha10 - */ - @JvmStatic - fun getMemoryPageSize(): ULong? - - // -------> CPU - /** - * Returns the maximum clock speed of - * the logical processors of the CPU - * installed in this computer in Hz. - * - * @return maximum clock speed of logical processors in Hz or `-1` if it couldn't be determined - * @since v1-alpha10 - */ - @JvmStatic - fun getCPUMaximumFrequency(): Long? - - /** - * Returns the estimated current clock - * speed of the logical processors of the - * CPU installed in this computer in Hz. - * - * Each item in the returned array - * stands for one logical processor. - * - * Depending on the platform the engine - * runs on, this may or may not be - * implemented. The algorithm used for - * calculating this estimate depends on - * the platform targeted. Some special - * restrictions apply to certain platforms. - * In short: Do not rely on the values - * in the array returned by this method. - * - * @return current clock rate of logical processors in Hz or an empty array - * @since v1-alpha10 - */ - @JvmStatic - fun getCPUCurrentFrequency(): LongArray? - - /** - * Returns the current amount of - * logical processors of the CPU - * installed in this computer. - * - * This value may change over time - * on some platforms. Be sure to - * query this number frequently to - * avoid out of date information. - * - * @return amount of logical processors - * @since v1-alpha10 - */ - @JvmStatic - fun getCPULogicalCount(): Int? - - /** - * Returns the amount of physical - * processors installed in this computer. - * - * @return amount of physical processors - * @since v1-alpha10 - */ - @JvmStatic - fun getCPUPhysicalCount(): Int? - - // -------> CPU - /** - * Returns an array of graphics cards - * installed in this computer. - * - * @return array of [GraphicsCard] instances - * @since v1-alpha10 - */ - @JvmStatic - fun getGPUs(): Array? - } -} diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/Platform.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/Platform.kt deleted file mode 100644 index e61ecc8..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/Platform.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.utility.misc - -/** - * Returns if currently - * running on the main thread. - * - * @return `true` if running on the main thread, `false` if not, `null` if not supported - * @since v1-alpha10 - */ -expect fun onMainThread(): Boolean? diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt b/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt deleted file mode 100644 index 45e94b5..0000000 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.utility.misc - -import de.staropensource.engine.base.type.Origin - -/** - * Returns the method caller. - * - * @param depth how deep to go into the stack trace - * @return deepest method caller - * @since v1-alpha10 - */ -expect fun methodCaller(depth: UInt = 1u): Origin - -/** - * Returns the `Caused by: ` header - * usually found in JVM stacktraces. - * - * @param throwable [Throwable] to use - * @return stacktrace header - * @since v1-alpha10 - */ -fun stacktraceHeader(throwable: Throwable): String { - return "Caused by: ${throwable::class.qualifiedName ?: ""}${if (throwable.message == null) "" else ": ${throwable.message}"}" -} - -/** - * Returns the body of the stacktrace - * as it is usually found in JVM - * stacktraces. - * - * @param throwable [Throwable] to use - * @param indent if to add a tab character (`\t`) as indentation - * @return stacktrace body - * @since v1-alpha10 - */ -expect fun stacktraceBody(throwable: Throwable, indent: Boolean = true): String - -/** - * Returns a recursively resolved - * collection of stacktraces, all - * derived from the passed [throwable]. - * - * Use this method if you intend to - * print an exception's stacktrace or - * want to display it nicely elsewhere. - * - * - * @param throwable [Throwable] to use - * @param indent if to add a tab character (`\t`) as indentation - * @param includeHeader if to include the `Caused by` stacktrace header (see [stacktraceHeader]) - * @param depth how deep to recurse into [Throwable]s - * @return recursively resolved stacktrace - * @since v1-alpha10 - */ -fun stacktraceRecursive(throwable: Throwable, indent: Boolean = true, includeHeader: Boolean = true, depth: UInt = 10u): String = buildString { - // Append header - if (includeHeader) { - append(stacktraceHeader(throwable)) - append("\n") - } - - // Append body - append(stacktraceBody(throwable, indent = indent)) - - // Recurse downwards - if (throwable.cause != null) { - append("\n") - if (depth == 0u) - append("...") - else - append(stacktraceRecursive(throwable.cause!!, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) - } - - platformSTUHandleRecursiveThrowables(throwable, indent, includeHeader, depth) -} - -/** - * Handles platform-specific [Throwable]s recursively. - * - * @param throwable [Throwable] to use - * @param indent if to add a tab character (`\t`) as indentation - * @param includeHeader if to include the `Caused by` stacktrace header (see [stacktraceHeader]) - * @param depth how deep to recurse into [Throwable]s - * @return stacktraces - * @since v1-alpha10 - */ -expect fun platformSTUHandleRecursiveThrowables(throwable: Throwable, indent: Boolean = true, includeHeader: Boolean = true, depth: UInt = 10u): String diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/EnginePlatformImpl.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/EnginePlatformImpl.kt deleted file mode 100644 index 648051c..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/EnginePlatformImpl.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -import de.staropensource.engine.base.Engine.Companion.logger -import java.nio.charset.Charset -import java.nio.charset.StandardCharsets - -@Throws(Throwable::class) -actual fun platformEngineBootstrap() { - if (Charset.defaultCharset() != StandardCharsets.UTF_8) - logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8") -} - -@Throws(Throwable::class) -actual fun platformEngineInitialize() = Unit -@Throws(Throwable::class) -actual fun platformEngineReload() = Unit -@Throws(Throwable::class) -actual fun platformEngineShutdown(final: Boolean, crashed: Boolean) = Unit diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt deleted file mode 100644 index 49e4636..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/PlatformImpl.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -actual fun platformTerminate(exitcode: UByte) = Runtime.getRuntime().exit(exitcode.toInt()) -actual fun platformMilliseconds(): ULong = System.currentTimeMillis().toULong() diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatformImpl.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatformImpl.kt deleted file mode 100644 index 9b50d9d..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/ProcessPlatformImpl.kt +++ /dev/null @@ -1,185 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -import de.staropensource.engine.base.implementable.stream.ReadStream -import de.staropensource.engine.base.implementable.stream.Stream -import de.staropensource.engine.base.implementable.stream.WriteStream -import de.staropensource.engine.base.implementation.stream.JavaReadStream -import de.staropensource.engine.base.implementation.stream.JavaWriteStream -import de.staropensource.engine.base.utility.Process -import java.io.InputStream -import java.io.OutputStream - -private typealias JProcess = java.lang.Process - -@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") -/** - * Java implementation of [ProcessPlatform]. - * - * @constructor Initializes this platform implementation - * @param process [Process] instance - * @since v1-alpha10 - */ -private class ProcessPlatformImpl (process: Process) : ProcessPlatform(process) { - /** - * Contains an instance of Java's - * [java.lang.Process] class. - * - * @since v1-alpha10 - */ - private var jProcess: JProcess? = null - - /** - * Contains the standard input - * [Stream] of this [Process]. - * - * @since v1-alpha10 - */ - var standardInput: WriteStream? = null - - /** - * Contains the standard output - * [Stream] of this [Process]. - * - * @since v1-alpha10 - */ - var standardOutput: ReadStream? = null - - /** - * Contains the standard error - * [Stream] of this [Process]. - * - * @since v1-alpha10 - */ - var standardError: ReadStream? = null - - - // -----> Lifecycle - override fun start() { - val builder: ProcessBuilder = ProcessBuilder() - - // Reset environment - if (process.launchedWithFreshEnvironment) - builder.environment().clear() - - // Pass arguments - builder - .command(listOf(process.executable.toStringRaw()).plus(process.arguments)) - .directory(process.workingDirectory.file) - .environment().putAll(process.environmentVariables) - - // Start process - jProcess = builder.start() - - // Set streams - standardError = StandardOutputErrorStream(process, jProcess!!.errorStream) - standardOutput = StandardOutputErrorStream(process, jProcess!!.inputStream) - standardInput = StandardInputStream(process, jProcess!!.outputStream) - - // Attach process exit handling - jProcess!!.onExit().thenAccept { - process.platformDeath() - } - } - - override fun kill() { - jProcess!!.destroyForcibly() - } - - - // -----> Getters - override fun isAlive(): Boolean = jProcess!!.isAlive - - override fun getPid(): Long = jProcess!!.pid() - - override fun getExitCode(): UByte? = try { - jProcess!!.exitValue().toUByte() - } catch (_: IllegalThreadStateException) { - null - } - - - // -----> Stream getters - override fun getStandardInput(): WriteStream = standardInput!! - override fun getStandardOutput(): ReadStream = standardOutput!! - override fun getStandardError(): ReadStream = standardError!! -} - - -// -----> Actual methods -actual fun platformProcessCreate(process: Process): ProcessPlatform = ProcessPlatformImpl(process) - - -// -----> Inner classes -/** - * Used for the standard input - * stream of a [Process]. - * - * @constructor Initializes this stream - * @since v1-alpha10 - */ -private class StandardInputStream( - val process: Process, - stream: OutputStream, -) : JavaWriteStream( - stream, - autoFlushAfter = 100UL -) { - // -----> Closure - override fun close() { - if (!process.isAlive()) - super.close() - } - - // -----> Writing - // Assist in flushing - override fun writeByte(byte: Byte): Stream { - super.writeByte(byte) - if (byte.toInt() == 0x0A) - flush() - return this - } - - override fun writeBytes(bytes: ByteArray): Stream { - super.writeBytes(bytes) - if (bytes.contains((0x0A).toByte())) - flush() - return this - } -} - -/** - * Used for the standard output - * and standard error streams - * of a [Process]. - * - * @constructor Initializes this stream - * @since v1-alpha10 - */ -private class StandardOutputErrorStream( - val process: Process, - stream: InputStream, -) : JavaReadStream(stream) { - override fun close() { - if (!process.isAlive()) - super.close() - } -} diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/StreamPlatformImpl.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/StreamPlatformImpl.kt deleted file mode 100644 index 2219cc9..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/platform/StreamPlatformImpl.kt +++ /dev/null @@ -1,146 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.platform - -import de.staropensource.engine.base.Engine.Companion.logger -import de.staropensource.engine.base.annotation.NonKotlinContact -import de.staropensource.engine.base.exception.io.IOAccessException -import de.staropensource.engine.base.implementable.stream.ReadStream -import de.staropensource.engine.base.implementable.stream.Stream -import de.staropensource.engine.base.implementable.stream.WriteStream -import de.staropensource.engine.base.implementation.stream.JavaReadStream -import de.staropensource.engine.base.implementation.stream.JavaWriteStream -import java.io.IOException -import java.io.InputStream -import java.io.OutputStream - -/** - * Java implementation of [StreamPlatform]. - * - * @constructor Initializes this platform implementation - * @param stream [Stream] instance - * @since v1-alpha10 - */ -private class StreamPlatformImpl(stream: Stream) : StreamPlatform(stream) { - override fun startWatchingThread() { - Thread - .ofVirtual() - .name("Stream watch thread for Stream ${javaClass.name}#${hashCode()}") - .uncaughtExceptionHandler { thread, ueh -> logger.crash("Unable to watch Stream ${javaClass.name}#${hashCode()}", throwable = ueh.cause, fatal = true) } - .start { - while (!stream.closed && stream.watching) - stream.skipNextByte() - } - } -} - - -// -----> Actual methods -actual fun platformStreamCreate(stream: Stream): StreamPlatform = StreamPlatformImpl(stream) -actual fun platformStreamStandardInput(): ReadStream = object : JavaReadStream(System.`in`) { - override fun close() = Unit - override fun closeStream() = Unit -} -actual fun platformStreamStandardOutput(): WriteStream = object : JavaWriteStream(System.out) { - override fun close() = Unit - override fun closeStream() = Unit -} -actual fun platformStreamStandardError(): WriteStream = object : JavaWriteStream(System.err) { - override fun close() = Unit - override fun closeStream() = Unit -} - - -// -----> Extension methods -/** - * Returns this stream as - * a Java [InputStream]. - * - * @since v1-alpha10 - */ -fun Stream.getJavaInputStream(): InputStream = platformData.getOrPut("inputStream") { InputFileStream(this) } as InputStream - -/** - * Returns this stream as - * a Java [OutputStream]. - * - * @since v1-alpha10 - */ -fun Stream.getJavaOutputStream(): OutputStream = platformData.getOrPut("outputStream") { OutputFileStream(this) } as OutputStream - - -// ----> Helper classes -/** - * An implementation of Java - * [InputStream]s for [Stream]s. - * - * @constructor Initializes this stream - * @param stream [Stream] to use - * @throws IOException on IO error - * @since v1-alpha10 - */ -private class InputFileStream -@NonKotlinContact -constructor(val stream: Stream) - : InputStream() { - /** - * Reads the next byte. - * - * @return byte read - * @throws IOException on IO error - * @since v1-alpha10 - */ - @Throws(IOException::class) - override fun read(): Int = try { - stream.readNextByte()?.toInt() ?: -1 - } catch (exception: IOAccessException) { - throw IOException("Failed reading the next byte", exception) - } -} - -/** - * An implementation of Java - * [OutputStream]s for [Stream]s. - * - * @constructor Initializes this stream - * @param stream [Stream] to use - * @since v1-alpha10 - */ -@NonKotlinContact -private class OutputFileStream -@NonKotlinContact -constructor(val stream: Stream) - : OutputStream() { - /** - * Writes (or rather: appends) a byte. - * - * @param byte byte to append - * @throws IOException on IO error - * @since v1-alpha10 - */ - @Throws(IOException::class) - override fun write(byte: Int) { - try { - stream.writeByte(byte.toByte()) - } catch (exception: IOAccessException) { - throw IOException("Failed writing the next byte", exception) - } - } -} diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/Environment.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/Environment.kt deleted file mode 100644 index 3d45eaa..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/Environment.kt +++ /dev/null @@ -1,166 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.utility - -import de.staropensource.engine.base.Engine.Companion.logger -import de.staropensource.engine.base.type.environment.GraphicsCard -import de.staropensource.engine.base.type.environment.OperatingSystem -import kotlinx.datetime.Instant -import oshi.PlatformEnum -import oshi.SystemInfo -import oshi.hardware.HardwareAbstractionLayer - -@Suppress("Unused", "EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") -actual class Environment private actual constructor() { - actual companion object { - // -----> Internal properties - /** - * Contains the [oshi.software.os.OperatingSystem] - * implementation used for accessing - * information about the operating - * system the engine is running on. - * - * @return [oshi.software.os.OperatingSystem] instance - * @since v1-alpha10 - */ - private var os: oshi.software.os.OperatingSystem? = null - - /** - * Contains the [HardwareAbstractionLayer] - * implementation used for accessing - * hardware information of the system the - * engine is running on. - * - * @return [HardwareAbstractionLayer] instance - * @since v1-alpha10 - */ - private var hw: HardwareAbstractionLayer? = null - - @JvmStatic - actual fun unset() { - os = null - hw = null - } - - @JvmStatic - actual fun detect() { - val si: SystemInfo = SystemInfo() - os = si.operatingSystem - hw = si.hardware - } - - @JvmStatic - actual fun getOperatingSystem(): OperatingSystem? { - when (SystemInfo.getCurrentPlatform()) { - PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> return OperatingSystem.LINUX - PlatformEnum.FREEBSD -> return OperatingSystem.FREEBSD - PlatformEnum.NETBSD -> return OperatingSystem.NETBSD - PlatformEnum.OPENBSD -> return OperatingSystem.OPENBSD - //PlatformEnum.ANDROID -> return OperatingSystem.ANDROID // android is not yet supported by the engine, have to figure that one out sometime - PlatformEnum.WINDOWS, PlatformEnum.WINDOWSCE -> return OperatingSystem.WINDOWS - PlatformEnum.MACOS -> return OperatingSystem.MACOS - else -> { - logger.crash("Unsupported operating system '" + SystemInfo.getCurrentPlatform().name + "' reported by OSHI") - return null - } - } - } - - @JvmStatic - actual fun getTimeOfStartup(): Instant? { - if (os == null) - return null - - return Instant.fromEpochSeconds(epochSeconds = os!!.systemBootTime) - } - - @JvmStatic - actual fun isElevated(): Boolean? = os?.isElevated - - @JvmStatic - actual fun getBitness(): Int? = os?.bitness - - @JvmStatic - actual fun getComputerManufacturer(): String? = hw?.computerSystem?.manufacturer - - @JvmStatic - actual fun getComputerModel(): String? = hw?.computerSystem?.model - - @JvmStatic - actual fun getFirmwareName(): String? = hw?.computerSystem?.firmware?.name - - @JvmStatic - actual fun getFirmwareDescription(): String? = hw?.computerSystem?.firmware?.description - - @JvmStatic - actual fun getFirmwareManufacturer(): String? = hw?.computerSystem?.firmware?.manufacturer - - @JvmStatic - actual fun getFirmwareVersion(): String? = hw?.computerSystem?.firmware?.version - - @JvmStatic - actual fun getFirmwareReleaseDate(): String? = hw?.computerSystem?.firmware?.releaseDate - - @JvmStatic - actual fun getMotherboardModel(): String? = hw?.computerSystem?.baseboard?.model - - @JvmStatic - actual fun getMotherboardVersion(): String? = hw?.computerSystem?.baseboard?.version - - @JvmStatic - actual fun getMotherboardSerialNumber(): String? = hw?.computerSystem?.baseboard?.serialNumber - - @JvmStatic - actual fun getMotherboardManufacturer(): String? = hw?.computerSystem?.baseboard?.manufacturer - - @JvmStatic - actual fun getMemoryTotal(): Long? = hw?.memory?.total - - @JvmStatic - actual fun getMemoryAvailable(): Long? = hw?.memory?.available - - @JvmStatic - actual fun getMemoryUsed(): Long? = hw?.memory?.total?.minus(hw!!.memory!!.available) - - @JvmStatic - actual fun getMemoryPageSize(): ULong? = hw?.memory?.pageSize?.toULong() - - @JvmStatic - actual fun getCPUMaximumFrequency(): Long? = hw?.processor?.maxFreq - - @JvmStatic - actual fun getCPUCurrentFrequency(): LongArray? = hw?.processor?.currentFreq - - @JvmStatic - actual fun getCPULogicalCount(): Int? = hw?.processor?.logicalProcessorCount - - @JvmStatic - actual fun getCPUPhysicalCount(): Int? = hw?.processor?.physicalProcessorCount - - @JvmStatic - actual fun getGPUs(): Array? = hw?.graphicsCards?.map { graphicsCard -> GraphicsCard( - graphicsCard.name, - graphicsCard.deviceId, - graphicsCard.vendor, - graphicsCard.versionInfo, - graphicsCard.vRam.toULong(), - ) }?.toTypedArray() - } -} diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/misc/Platform.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/misc/Platform.kt deleted file mode 100644 index 95507f0..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/misc/Platform.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.utility.misc - -actual fun onMainThread(): Boolean? = Thread.currentThread().threadId() == 1L diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt b/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt deleted file mode 100644 index cec3f2d..0000000 --- a/base/src/jvmMain/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt +++ /dev/null @@ -1,85 +0,0 @@ -/* - * STAROPENSOURCE ENGINE SOURCE FILE - * Copyright (c) 2024 The StarOpenSource Engine Authors - * Licensed under the GNU General Public License v3. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.staropensource.engine.base.utility.misc - -import de.staropensource.engine.base.type.Origin -import java.lang.reflect.InvocationTargetException - -actual fun methodCaller(depth: UInt): Origin { - val stacktrace: Array = Throwable().stackTrace - var element: StackTraceElement? = null - - // Get wanted element - element = if (depth.plus(2u).toInt() > stacktrace.size) - stacktrace[stacktrace.size - 1] - else - stacktrace[depth.plus(2u).toInt()] - - // Return origin - return Origin( - packageName = element.className.substringBeforeLast('.'), - className = element.className.substringAfterLast('.'), - methodName = element.methodName, - lineNumber = element.lineNumber.toUInt(), - ) -} - -actual fun stacktraceBody(throwable: Throwable, indent: Boolean): String = buildString { - for (element: StackTraceElement in throwable.stackTrace) { - if (!isEmpty()) - append("\n") - if (indent) - append("\t") - - append("at ") - append(element) - } -} - -actual fun platformSTUHandleRecursiveThrowables(throwable: Throwable, indent: Boolean, includeHeader: Boolean, depth: UInt): String = buildString { - if (throwable is ClassNotFoundException) { - val exception: ClassNotFoundException = throwable - if (exception.exception != null) { - append("\n") - if (depth == 0u) - append("...") - else - append(stacktraceRecursive(exception.exception, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) - } - } else if (throwable is ExceptionInInitializerError) { - val exception: ExceptionInInitializerError = throwable - if (exception.exception != null) { - append("\n") - if (depth == 0u) - append("...") - else - append(stacktraceRecursive(exception.exception, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) - } - } else if (throwable is InvocationTargetException) { - val exception: InvocationTargetException = throwable - if (exception.targetException != null) { - append("\n") - if (depth == 0u) - append("...") - else - append(stacktraceRecursive(exception.targetException, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) - } - } -} diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt similarity index 94% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt rename to base/src/main/kotlin/de/staropensource/engine/base/Engine.kt index ce62f84..ffd861b 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/Engine.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt @@ -22,14 +22,11 @@ package de.staropensource.engine.base import de.staropensource.engine.base.exception.EngineInitializationFailureException import de.staropensource.engine.base.implementable.Subsystem import de.staropensource.engine.base.logging.Logger -import de.staropensource.engine.base.platform.platformEngineBootstrap -import de.staropensource.engine.base.platform.platformEngineInitialize -import de.staropensource.engine.base.platform.platformEngineReload -import de.staropensource.engine.base.platform.platformEngineShutdown import de.staropensource.engine.base.utility.Environment import de.staropensource.engine.base.utility.FileAccess import de.staropensource.engine.base.utility.dnihbd.BuildInformation -import kotlin.jvm.JvmStatic +import java.nio.charset.Charset +import java.nio.charset.StandardCharsets import kotlin.reflect.KClass /** @@ -53,7 +50,6 @@ class Engine private constructor() { * * @since v1-alpha10 */ - @JvmStatic internal val logger: Logger = Logger(channel = "engine-core") /** @@ -61,7 +57,6 @@ class Engine private constructor() { * * @since v1-alpha10 */ - @JvmStatic var state: State = State.UNINITIALIZED internal set @@ -78,7 +73,6 @@ class Engine private constructor() { * @see bootstrap * @since v1-alpha10 */ - @JvmStatic var bootstrapping: Boolean? = null /** @@ -87,7 +81,6 @@ class Engine private constructor() { * @see Subsystem * @since v1-alpha10 */ - @JvmStatic private val subsystems: MutableSet = mutableSetOf() /** @@ -98,7 +91,6 @@ class Engine private constructor() { * @see BuildInformation * @since v1-alpha10 */ - @JvmStatic var info: BuildInformation? = null @@ -110,7 +102,6 @@ class Engine private constructor() { * @return array of registered [Subsystem]s * @since v1-alpha10 */ - @JvmStatic fun getSubsystems(): Array = subsystems.toTypedArray() /** @@ -119,14 +110,11 @@ class Engine private constructor() { * * @since v1-alpha10 */ - @JvmStatic - fun getSubsystem(subsystemClass: KClass): Subsystem? { - return getSubsystems().find { subsystem -> try { - subsystem::class.qualifiedName!! == subsystemClass.qualifiedName!! - } catch (_: NullPointerException) { - false - } } - } + fun getSubsystem(subsystemClass: KClass): Subsystem? = getSubsystems().find { subsystem -> try { + subsystem::class.qualifiedName!! == subsystemClass.qualifiedName!! + } catch (_: NullPointerException) { + false + } } /** * Registers the specified subsystem. @@ -140,7 +128,6 @@ class Engine private constructor() { * @see Subsystem * @since v1-alpha10 */ - @JvmStatic fun registerSubsystem(subsystem: Subsystem) { // Check for state if (bootstrapping == true) @@ -188,7 +175,9 @@ class Engine private constructor() { logger.info("Bootstrapping") // Run bootstrapping code - platformEngineBootstrap() + // -> Run checks + if (Charset.defaultCharset() != StandardCharsets.UTF_8) + logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8") // Bootstrap subsystems logger.verb("Bootstrapping subsystems") @@ -243,7 +232,6 @@ class Engine private constructor() { logger.info("Initializing") // Run initialization code - platformEngineInitialize() Environment.detect() FileAccess.updateDefaultPaths() info = BuildInformation(loadPrefix = "sosengine-base") @@ -304,7 +292,7 @@ class Engine private constructor() { logger.info("Reloading") // Run reload code - platformEngineReload() + // *none yet* // Reload subsystems logger.verb("Reloading subsystems") @@ -400,7 +388,13 @@ class Engine private constructor() { state = State.SHUTTING_DOWN val infoLocal: BuildInformation? = info - // Shut subsystems down + // Run shutdown code + Environment.unset() + FileAccess.deleteScheduled() + FileAccess.unsetDefaultPaths() + info = null + + // Initialize subsystems logger.verb("Shutting subsystems down") for (subsystem: Subsystem in subsystems) { val subsystemVersion: String = subsystem.getVersion() @@ -417,13 +411,6 @@ class Engine private constructor() { } } - // Run shutdown code - Environment.unset() - FileAccess.deleteScheduled() - FileAccess.unsetDefaultPaths() - info = null - platformEngineShutdown(final, crashed) - // Print shutdown message if (final) logger.info(""" diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/EngineConfiguration.kt b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt similarity index 99% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/EngineConfiguration.kt rename to base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt index a691bf5..c5f1d7b 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/EngineConfiguration.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/EngineConfiguration.kt @@ -35,7 +35,6 @@ import de.staropensource.engine.base.type.logging.Feature import de.staropensource.engine.base.type.logging.Level import de.staropensource.engine.base.type.logging.OperationMode import kotlinx.datetime.TimeZone -import kotlin.jvm.JvmStatic import kotlin.reflect.KClass /** diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/annotation/NonKotlinContact.kt b/base/src/main/kotlin/de/staropensource/engine/base/annotation/NonKotlinContact.kt similarity index 91% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/annotation/NonKotlinContact.kt rename to base/src/main/kotlin/de/staropensource/engine/base/annotation/NonKotlinContact.kt index 64b8b18..914abcd 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/annotation/NonKotlinContact.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/annotation/NonKotlinContact.kt @@ -25,9 +25,10 @@ package de.staropensource.engine.base.annotation * the public API. * * Using anything non-Kotlin in conjunction with - * the StarOpenSource Engine is highly - * discouraged, as the engine is optimized for - * multiplatform usage. + * the StarOpenSource Engine is highly discouraged, + * as the engine may be multiplatform in future + * releases and will not support using other + * languages. * * Using anything in contact with non-Kotlin code * is therefore deemed unsafe and should be diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/annotation/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/annotation/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/annotation/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/annotation/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/EngineInitializationFailureException.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/EngineInitializationFailureException.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/EngineInitializationFailureException.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/EngineInitializationFailureException.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/VerificationFailedException.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/VerificationFailedException.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/VerificationFailedException.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/VerificationFailedException.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/FileOrDirectoryNotFoundException.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/io/FileOrDirectoryNotFoundException.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/FileOrDirectoryNotFoundException.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/io/FileOrDirectoryNotFoundException.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/FileTooLargeException.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/io/FileTooLargeException.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/FileTooLargeException.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/io/FileTooLargeException.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/IOAccessException.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/io/IOAccessException.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/IOAccessException.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/io/IOAccessException.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/StreamClosedException.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/io/StreamClosedException.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/StreamClosedException.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/io/StreamClosedException.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/io/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/io/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/io/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/exception/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/exception/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/exception/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/exception/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/ShutdownHandler.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/Subsystem.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/Subsystem.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/Subsystem.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/Subsystem.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/Formatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/Formatter.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/Formatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/Formatter.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/OneCycleFormatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/OneCycleFormatter.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/OneCycleFormatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/OneCycleFormatter.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatter.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatter.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatterImpl.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatterImpl.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatterImpl.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatterImpl.kt index 5021ff1..53af026 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatterImpl.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/TwoCycleFormatterImpl.kt @@ -44,7 +44,7 @@ import kotlin.text.iterator * @since v1-alpha10 */ abstract class TwoCycleFormatterImpl: TwoCycleFormatter() { - @Suppress("NestedBlockDepth", "CyclomaticComplexMethod") + @Suppress("NestedBlockDepth") override fun parse(message: String): Array { val components: MutableList = mutableListOf() var currentComponent: StringBuilder = StringBuilder() diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/formatter/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/formatter/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Adapter.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/CrashCategory.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/Filter.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/FormatBuilder.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/LoggerThreadingHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/LoggerThreadingHandler.kt similarity index 97% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/LoggerThreadingHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/LoggerThreadingHandler.kt index 50ca51e..7470ba5 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/LoggerThreadingHandler.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/LoggerThreadingHandler.kt @@ -19,6 +19,7 @@ package de.staropensource.engine.base.implementable.logging +import de.staropensource.engine.base.logging.Processor import de.staropensource.engine.base.type.logging.Call /** diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/logging/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/package-info.kt similarity index 94% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/package-info.kt index e12d754..a0c08dc 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/package-info.kt @@ -22,4 +22,4 @@ * * @since v1-alpha10 */ -package de.staropensource.engine.base.implementable +package de.staropensource.engine.base.implementable; diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/ReadStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/ReadStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/ReadStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/ReadStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/Stream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/Stream.kt similarity index 79% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/Stream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/Stream.kt index 38e012d..137a610 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/Stream.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/Stream.kt @@ -19,13 +19,14 @@ package de.staropensource.engine.base.implementable.stream +import de.staropensource.engine.base.Engine.Companion.logger +import de.staropensource.engine.base.annotation.NonKotlinContact import de.staropensource.engine.base.exception.io.IOAccessException -import de.staropensource.engine.base.implementable.PlatformData -import de.staropensource.engine.base.platform.StreamPlatform -import de.staropensource.engine.base.platform.platformStreamCreate -import de.staropensource.engine.base.platform.platformStreamStandardError -import de.staropensource.engine.base.platform.platformStreamStandardInput -import de.staropensource.engine.base.platform.platformStreamStandardOutput +import de.staropensource.engine.base.implementation.stream.JavaReadStream +import de.staropensource.engine.base.implementation.stream.JavaWriteStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream /** * Makes streaming data easy. @@ -39,7 +40,7 @@ import de.staropensource.engine.base.platform.platformStreamStandardOutput abstract class Stream( val streamMode: StreamMode, val autoFlushAfter: ULong = 100UL, -) : AutoCloseable, PlatformData { +) : AutoCloseable { /** * Companion object of [Stream]. * @@ -53,7 +54,10 @@ abstract class Stream( * @see stdin(3) * @since v1-alpha10 */ - val standardInput: ReadStream = platformStreamStandardInput() + val standardInput: ReadStream = object : JavaReadStream(System.`in`) { + override fun close() = Unit + override fun closeStream() = Unit + } /** * Contains the standard output as a [Stream]. @@ -62,7 +66,10 @@ abstract class Stream( * @see stdout(3) * @since v1-alpha10 */ - val standardOutput: WriteStream = platformStreamStandardOutput() + val standardOutput: WriteStream = object : JavaWriteStream(System.out) { + override fun close() = Unit + override fun closeStream() = Unit + } /** * Contains the standard error as a [Stream]. @@ -70,22 +77,13 @@ abstract class Stream( * @see stderr(3) * @since v1-alpha10 */ - val standardError: WriteStream = platformStreamStandardError() + val standardError: WriteStream = object : JavaWriteStream(System.err) { + override fun close() = Unit + override fun closeStream() = Unit + } } - // -----> Platform-specific - override val platformData: MutableMap = mutableMapOf() - - /** - * Platform-specific [StreamPlatform] - * instance for this [Stream]. - * - * @since v1-alpha10 - */ - private val platform: StreamPlatform = platformStreamCreate(this) - - // -----> Properties /** * Indicates whether this stream is closed. @@ -135,6 +133,22 @@ abstract class Stream( */ val pipes: MutableList = mutableListOf() + /** + * Contains the Java [InputStream] + * for this [Stream] instance. + * + * @since v1-alpha10 + */ + private var inputStream: InputFileStream? = null + + /** + * Contains the Java [OutputStream] + * for this [Stream] instance. + * + * @since v1-alpha10 + */ + private var outputStream: OutputFileStream? = null + // -----> Closure /** @@ -219,7 +233,7 @@ abstract class Stream( * @since v1-alpha10 */ @Throws(IOAccessException::class) - fun writeString(string: String): Stream = writeBytes(string.encodeToByteArray()) + fun writeString(string: String): Stream = writeBytes(string.toByteArray()) /** * Writes (or rather: appends) @@ -231,7 +245,7 @@ abstract class Stream( * @since v1-alpha10 */ @Throws(IOAccessException::class) - fun write(value: Any): Stream = writeBytes(value.toString().encodeToByteArray()) + fun write(value: Any): Stream = writeBytes(value.toString().toByteArray()) /** * Flushes all currently @@ -380,6 +394,7 @@ abstract class Stream( * if wanting to only pipe the bytes * of this [Stream] to other streams. * + * @param threshold amount of bytes to be read before terminating or `0` to watch indefinitely * @return this instance * @throws IOAccessException on IO error * @since v1-alpha10 @@ -391,7 +406,14 @@ abstract class Stream( watching = true - platform.startWatchingThread() + Thread + .ofVirtual() + .name("Stream watch thread for Stream ${javaClass.name}#${hashCode()}") + .uncaughtExceptionHandler { thread, ueh -> logger.crash("Unable to watch Stream ${javaClass.name}#${hashCode()}", throwable = ueh.cause, fatal = true) } + .start { + while (!closed && watching) + skipNextByte() + } return this } @@ -452,7 +474,7 @@ abstract class Stream( * * Make sure to call this method * before returning from - * [readNextByte], [readNBytes] + * [readBytes], [readNBytes] * and [readRemainingBytes]. * * @param byte [Byte] to pipe @@ -472,7 +494,7 @@ abstract class Stream( * * Make sure to call this method * before returning from - * [readNextByte], [readNBytes] + * [readBytes], [readNBytes] * and [readRemainingBytes]. * * @param bytes [ByteArray] to pipe @@ -618,6 +640,36 @@ abstract class Stream( } + // -----> Java interoperability + /** + * Returns this stream as + * a Java [InputStream]. + * + * @since v1-alpha10 + */ + @NonKotlinContact + fun toInputStream(): InputStream { + if (inputStream == null) + inputStream = InputFileStream(this) + + return inputStream!! + } + + /** + * Returns this stream as + * a Java [OutputStream]. + * + * @since v1-alpha10 + */ + @NonKotlinContact + fun toOutputStream(): OutputStream { + if (outputStream == null) + outputStream = OutputFileStream(this) + + return outputStream!! + } + + // -----> Inner classes /** * Represents the mode in which @@ -650,4 +702,62 @@ abstract class Stream( */ READ_WRITE, } + + /** + * An implementation of Java + * [InputStream]s for [Stream]s. + * + * @constructor Initializes this stream + * @param stream [Stream] to use + * @throws IOException on IO error + * @since v1-alpha10 + */ + class InputFileStream + @NonKotlinContact + internal constructor(val stream: Stream) + : InputStream() { + /** + * Reads the next byte. + * + * @return byte read + * @throws IOException on IO error + * @since v1-alpha10 + */ + @Throws(IOException::class) + override fun read(): Int = try { + stream.readNextByte()?.toInt() ?: -1 + } catch (exception: IOAccessException) { + throw IOException("Failed reading the next byte", exception) + } + } + + /** + * An implementation of Java + * [OutputStream]s for [Stream]s. + * + * @constructor Initializes this stream + * @param stream [Stream] to use + * @since v1-alpha10 + */ + @NonKotlinContact + class OutputFileStream + @NonKotlinContact + internal constructor(val stream: Stream) + : OutputStream() { + /** + * Writes (or rather: appends) a byte. + * + * @param byte byte to append + * @throws IOException on IO error + * @since v1-alpha10 + */ + @Throws(IOException::class) + override fun write(byte: Int) { + try { + stream.writeByte(byte.toByte()) + } catch (exception: IOAccessException) { + throw IOException("Failed writing the next byte", exception) + } + } + } } diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/WriteStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/WriteStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/WriteStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/WriteStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/package-info.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/package-info.kt index cfc56d2..47851c2 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementable/stream/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/stream/package-info.kt @@ -18,7 +18,7 @@ */ /** - * [Stream]s. + * [Streams]. * * @since v1-alpha10 */ diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt similarity index 84% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt index 6c7b79f..c898ef2 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/KotlinShutdownHandler.kt @@ -20,17 +20,15 @@ package de.staropensource.engine.base.implementation.logging import de.staropensource.engine.base.implementable.ShutdownHandler -import de.staropensource.engine.base.platform.platformTerminate -import kotlin.jvm.JvmStatic +import kotlin.system.exitProcess /** - * [ShutdownHandler] implementation which - * simply terminates the application. + * [ShutdownHandler] implementation using + * Kotlin's [exitProcess] method. * * @constructor Initializes this shutdown handler * @since v1-alpha10 */ -@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING") class KotlinShutdownHandler private constructor() : ShutdownHandler { /** * Companion object of [KotlinShutdownHandler]. @@ -48,6 +46,6 @@ class KotlinShutdownHandler private constructor() : ShutdownHandler { } override fun exit(exitcode: UByte) { - platformTerminate(exitcode) + exitProcess(exitcode.toInt()) } } diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt similarity index 99% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt index 2913d35..852c201 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/NoOperationFormatter.kt @@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementation.logging import de.staropensource.engine.base.implementable.formatter.Formatter import de.staropensource.engine.base.implementable.formatter.OneCycleFormatter -import kotlin.jvm.JvmStatic import kotlin.text.iterator /** diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/FileWriteAdapter.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt index 0b7123b..c515714 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/PrintlnAdapter.kt @@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementation.logging.adapter import de.staropensource.engine.base.implementable.logging.Adapter import de.staropensource.engine.base.type.logging.Call -import kotlin.jvm.JvmStatic /** * [Adapter] for printing messages diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/adapter/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt index 0954644..fa3af05 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EngineCrashCategory.kt @@ -21,7 +21,6 @@ package de.staropensource.engine.base.implementation.logging.crashcategory import de.staropensource.engine.base.implementable.logging.CrashCategory import de.staropensource.engine.base.utility.dnihbd.BuildInformation -import kotlin.jvm.JvmStatic /** * [CrashCategory] implementation diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt similarity index 97% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt index b4006cf..abb3803 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/EnvironmentCrashCategory.kt @@ -23,7 +23,9 @@ import de.staropensource.engine.base.implementable.logging.CrashCategory import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.utility.Environment -import kotlin.jvm.JvmStatic +import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toLocalDateTime /** * [CrashCategory] implementation diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt index 8ee3e86..a8de561 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/InfoCrashCategory.kt @@ -23,7 +23,6 @@ import de.staropensource.engine.base.implementable.logging.CrashCategory import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.utility.misc.StackTraceUtils -import kotlin.jvm.JvmStatic /** * [CrashCategory] implementation diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/crashcategory/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt similarity index 94% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt index 417171d..0ee5768 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/SOSLSv2FormatBuilder.kt @@ -143,22 +143,22 @@ open class SOSLSv2FormatBuilder(call: Call, channelSettings: ChannelSettings?) : if (enabledFeatures.contains(Feature.DATE)) format - .append(datetime.dayOfMonth.toString().padStart(2, padChar = '0')) + .append("%02d".format(datetime.dayOfMonth)) .append(".") - .append(datetime.monthNumber.toString().padStart(2, padChar = '0')) + .append("%02d".format(datetime.monthNumber)) .append(".") - .append(datetime.year.toString().padStart(4, padChar = '0')) + .append("%04d".format(datetime.year)) if (enabledFeatures.contains(Feature.DATE) && enabledFeatures.contains(Feature.TIME)) format.append(" ") if (enabledFeatures.contains(Feature.TIME)) format - .append(datetime.hour.toString().padStart(2, padChar = '0')) + .append("%02d".format(datetime.hour)) .append(":") - .append(datetime.minute.toString().padStart(2, padChar = '0')) + .append("%02d".format(datetime.minute)) .append(":") - .append(datetime.second.toString().padStart(2, padChar = '0')) + .append("%02d".format(datetime.second)) if (enabledFeatures.contains(Feature.DATE) || enabledFeatures.contains(Feature.TIME)) { if (enabledFeatures.contains(Feature.FORMATTING)) diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/formatbuilder/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/logging/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/ByteReadStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/ByteReadStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/ByteReadStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/ByteReadStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/ByteStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/ByteStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/ByteStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/ByteStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/ByteWriteStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/ByteWriteStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/ByteWriteStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/ByteWriteStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/FileAccessStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/FileAccessStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/FileAccessStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/FileAccessStream.kt diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/implementation/stream/JavaReadStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/JavaReadStream.kt similarity index 100% rename from base/src/jvmMain/kotlin/de/staropensource/engine/base/implementation/stream/JavaReadStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/JavaReadStream.kt diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/implementation/stream/JavaStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/JavaStream.kt similarity index 100% rename from base/src/jvmMain/kotlin/de/staropensource/engine/base/implementation/stream/JavaStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/JavaStream.kt diff --git a/base/src/jvmMain/kotlin/de/staropensource/engine/base/implementation/stream/JavaWriteStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/JavaWriteStream.kt similarity index 100% rename from base/src/jvmMain/kotlin/de/staropensource/engine/base/implementation/stream/JavaWriteStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/JavaWriteStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/LoggerStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/LoggerStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/LoggerStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/LoggerStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/NullStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/NullStream.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/NullStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/NullStream.kt index 0eb3cf5..d64fa3a 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/NullStream.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/NullStream.kt @@ -20,7 +20,6 @@ package de.staropensource.engine.base.implementation.stream import de.staropensource.engine.base.implementable.stream.Stream -import kotlin.jvm.JvmStatic /** * A [Stream] which does nothing diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringReadStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringReadStream.kt similarity index 96% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringReadStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringReadStream.kt index 96c07aa..98840bb 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringReadStream.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringReadStream.kt @@ -29,4 +29,4 @@ import de.staropensource.engine.base.implementable.stream.Stream * @param stringRead string to provide for reading * @since v1-alpha10 */ -open class StringReadStream(val stringRead: String) : ByteReadStream(bytesRead = stringRead.encodeToByteArray()) +open class StringReadStream(val stringRead: String) : ByteReadStream(bytesRead = stringRead.toByteArray()) diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringStream.kt similarity index 96% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringStream.kt index b9aa463..146f094 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringStream.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringStream.kt @@ -29,7 +29,7 @@ import de.staropensource.engine.base.implementable.stream.Stream * @param stringRead string to provide for reading * @since v1-alpha10 */ -open class StringStream(val stringRead: String) : ByteStream(bytesRead = stringRead.encodeToByteArray()) { +open class StringStream(val stringRead: String) : ByteStream(bytesRead = stringRead.toByteArray()) { /** * Returns the written string. * diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringWriteStream.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringWriteStream.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/StringWriteStream.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/StringWriteStream.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/implementation/stream/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/implementation/stream/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/CrashHandler.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Filterer.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Filterer.kt similarity index 98% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Filterer.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/Filterer.kt index 4ad837b..710d904 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Filterer.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Filterer.kt @@ -21,7 +21,6 @@ package de.staropensource.engine.base.logging import de.staropensource.engine.base.implementable.logging.Filter import de.staropensource.engine.base.type.logging.Call -import kotlin.jvm.JvmStatic /** * Handles call filtering. diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Logger.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt similarity index 93% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Logger.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt index 815406d..29e5369 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Logger.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Logger.kt @@ -27,11 +27,9 @@ import de.staropensource.engine.base.implementation.stream.FileAccessStream import de.staropensource.engine.base.implementation.stream.LoggerStream import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.Level -import de.staropensource.engine.base.utility.misc.methodCaller +import de.staropensource.engine.base.utility.misc.StackTraceUtils import kotlinx.datetime.Clock import kotlinx.datetime.Instant -import kotlin.jvm.JvmName -import kotlin.jvm.JvmStatic /** * Frontend for sos!engine's logging system. @@ -121,10 +119,10 @@ class Logger { * @param callerDepth determines the depth at which to discover the method caller * @since v1-alpha10 */ - fun log(level: Level, message: String, levelData: Map = emptyMap(), callerDepth: UInt = 0u) { + fun log(level: Level, message: String, levelData: Map = emptyMap(), callerDepth: UInt = 0u) { // Create 'Call' instance var call: Call = Call( - methodCaller(depth = callerDepth.plus(1u)), + StackTraceUtils.methodCaller(depth = callerDepth.plus(1u)), level, message, channel @@ -132,7 +130,7 @@ class Logger { // Run processing if (level == Level.CRASH) - CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrElse("fatal") { true } as Boolean) + CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrDefault("fatal", true) as Boolean) else { if (Processor.check(call)) return @@ -212,8 +210,8 @@ class Logger { */ fun crash(error: String, throwable: Throwable? = null, fatal: Boolean = true) { log(Level.CRASH, error, levelData = mapOf( - Pair("throwable", throwable as Any?), - Pair("fatal", fatal as Any?) + Pair("throwable", throwable as Object?), + Pair("fatal", fatal as Object?) ), callerDepth = 1u) } @@ -244,5 +242,5 @@ class Logger { * @return [FileAccessStream] instance * @since v1-alpha10 */ - fun toStream(level: Level): LoggerStream = stream[level] ?: LoggerStream(this, level) + fun toStream(level: Level): LoggerStream = stream.computeIfAbsent(level) { level -> LoggerStream(this, level) } } diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Processor.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt similarity index 96% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Processor.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt index 3ce83f1..75045c8 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/Processor.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/logging/Processor.kt @@ -28,8 +28,7 @@ import de.staropensource.engine.base.type.logging.Call import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.Feature import de.staropensource.engine.base.type.logging.OperationMode -import de.staropensource.engine.base.utility.misc.stacktraceRecursive -import kotlin.jvm.JvmStatic +import de.staropensource.engine.base.utility.misc.StackTraceUtils import kotlin.reflect.full.primaryConstructor /** @@ -88,7 +87,7 @@ class Processor private constructor() { * @param call [Call] metadata * @see EngineConfiguration.logThreadingHandler * @see ChannelSettings.formatter - * @see ChannelSettings.adapters + * @see ChannelSettings.adapter * @since v1-alpha10 */ @JvmStatic @@ -103,7 +102,7 @@ class Processor private constructor() { try { format = (EngineConfiguration.logFormatBuilder).primaryConstructor!!.call(call, channelSettings) } catch (throwable: Throwable) { - println("Logger system failure: Configured FormatBuilder implementation '" + ((EngineConfiguration.logFormatBuilder).qualifiedName ?: "") + "' does not have a primary 'constructor(Call, ChannelSettings?)'. Log messages cannot be processed.\n${stacktraceRecursive(throwable)}") + println("Logger system failure: Configured FormatBuilder implementation '" + ((EngineConfiguration.logFormatBuilder).qualifiedName ?: "") + "' does not have a primary 'constructor(Call, ChannelSettings?)'. Log messages cannot be processed.\n${StackTraceUtils.stacktraceRecursive(throwable)}") return } diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/logging/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/logging/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/logging/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/logging/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/Origin.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/Origin.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/Origin.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/Origin.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/Tristate.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt similarity index 99% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/Tristate.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt index 4dac3cb..e04d67d 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/Tristate.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/Tristate.kt @@ -20,7 +20,6 @@ package de.staropensource.engine.base.type import de.staropensource.engine.base.EngineConfiguration -import kotlin.jvm.JvmStatic /** * Defines a data type which can have diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/Call.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/Call.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/Call.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt similarity index 99% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt index f62dfb5..e0519f7 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/ChannelSettings.kt @@ -24,7 +24,6 @@ import de.staropensource.engine.base.implementable.logging.Adapter import de.staropensource.engine.base.implementable.formatter.Formatter import de.staropensource.engine.base.implementation.logging.NoOperationFormatter import de.staropensource.engine.base.implementation.logging.adapter.PrintlnAdapter -import kotlin.jvm.JvmStatic /** * Holds the configuration of one diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/Feature.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/Feature.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/Feature.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/Level.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/Level.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/Level.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/OperationMode.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/logging/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/logging/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/logging/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/package-info.kt similarity index 95% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/package-info.kt index fa63afe..c532b5a 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/package-info.kt @@ -22,4 +22,4 @@ * * @since v1-alpha10 */ -package de.staropensource.engine.base.type +package de.staropensource.engine.base.type; diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/versioning/VersionType.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt similarity index 94% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt index a515c67..5e36d81 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/type/versioning/package-info.kt @@ -23,4 +23,4 @@ * * @since v1-alpha10 */ -package de.staropensource.engine.base.type.versioning +package de.staropensource.engine.base.type.versioning; diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/DataSize.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/DataSize.kt similarity index 94% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/DataSize.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/DataSize.kt index 114915d..1dd92e9 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/DataSize.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/DataSize.kt @@ -19,9 +19,10 @@ package de.staropensource.engine.base.utility -import kotlin.jvm.JvmStatic -import kotlin.math.round -import kotlin.math.roundToLong +import java.math.RoundingMode +import java.text.DecimalFormat +import java.text.DecimalFormatSymbols +import java.util.Locale /** * Converts between various data size units. @@ -150,7 +151,11 @@ data class DataSize( * @return modified [Double] * @since v1-alpha10 */ - fun formatTo(number: Double): Double = round(number.times(1000)).div(1000) + fun formatTo(number: Double): Double { + val decimalFormat = DecimalFormat("#.####", DecimalFormatSymbols(Locale.ROOT)) + decimalFormat.roundingMode = RoundingMode.HALF_UP + return decimalFormat.format(number).toDouble() + } /** * Performs miscellaneous operations @@ -161,7 +166,11 @@ data class DataSize( * @return modified [Double] * @since v1-alpha10 */ - fun formatOf(number: Double): ULong = number.roundToLong().toULong() + fun formatOf(number: Double): ULong { + val decimalFormat = DecimalFormat("#", DecimalFormatSymbols(Locale.ROOT)) + decimalFormat.roundingMode = RoundingMode.HALF_UP + return decimalFormat.format(number).toULong() + } } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt new file mode 100644 index 0000000..d7c3770 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/Environment.kt @@ -0,0 +1,508 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU General Public License v3. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.engine.base.utility + +import de.staropensource.engine.base.Engine.Companion.logger +import de.staropensource.engine.base.EngineConfiguration +import de.staropensource.engine.base.utility.Environment.OperatingSystem.* +import kotlinx.datetime.Instant +import oshi.PlatformEnum +import oshi.SystemInfo +import oshi.hardware.HardwareAbstractionLayer + +/** + * Provides information about the + * environment the application runs in. + * + * @constructor Initializes this class + * @since v1-alpha10 + */ +@Suppress("Unused") +class Environment private constructor() { + /** + * Companion class of [Environment]. + * + * @since v1-alpha10 + */ + companion object { + // -----> Internal properties + /** + * Contains the [oshi.software.os.OperatingSystem] + * implementation used for accessing + * information about the operating + * system the engine is running on. + * + * @return [oshi.software.os.OperatingSystem] instance + * @since v1-alpha10 + */ + private var os: oshi.software.os.OperatingSystem? = null + + /** + * Contains the [HardwareAbstractionLayer] + * implementation used for accessing + * hardware information of the system the + * engine is running on. + * + * @return [HardwareAbstractionLayer] instance + * @since v1-alpha10 + */ + private var hw: HardwareAbstractionLayer? = null + + + // -----> Update methods + /** + * Unsets the environment. + * + * @since v1-alpha10 + */ + @JvmStatic + internal fun unset() { + os = null + hw = null + } + + /** + * Detects and updates the environment. + * + * @since v1-alpha10 + */ + @JvmStatic + internal fun detect() { + val si: SystemInfo = SystemInfo() + os = si.operatingSystem + hw = si.hardware + } + + + // -----> Getters + // -------> General + /** + * Returns the amount of + * bits this platform targets. + * + * This may be 32, 64 or an + * even higher value. + * + * @return maximum of supported bits + * @since v1-alpha10 + */ + fun getOperatingSystem(): OperatingSystem? { + when (SystemInfo.getCurrentPlatform()) { + PlatformEnum.LINUX, PlatformEnum.GNU, PlatformEnum.KFREEBSD -> return LINUX + PlatformEnum.FREEBSD -> return FREEBSD + PlatformEnum.NETBSD -> return NETBSD + PlatformEnum.OPENBSD -> return OPENBSD + //PlatformEnum.ANDROID -> Environment.getOperatingSystem() = Environment.OperatingSystem.ANDROID // android is not yet supported by the engine, have to figure that one out sometime + PlatformEnum.WINDOWS, PlatformEnum.WINDOWSCE -> return WINDOWS + PlatformEnum.MACOS -> return MACOS + else -> { + logger.crash("Unsupported operating system '" + SystemInfo.getCurrentPlatform().name + "' reported by OSHI") + return null + } + } + } + + /** + * Returns the point in time where + * the system the engine is + * running on has started. + * + * @return time of system startup + * @since v1-alpha10 + */ + fun getTimeOfStartup(): Instant? { + if (os == null) + return null + + return Instant.fromEpochSeconds(epochSeconds = os!!.systemBootTime) + } + + /** + * Returns whether the current process + * is elevated and is able to execute + * superuser/administrator actions. + * + * @return elevated? + * @since v1-alpha10 + */ + fun isElevated(): Boolean? = os?.isElevated + + /** + * Returns the amount of bits + * this platform targets. + * + * This may be 32, 64 or an + * even higher value. + * + * @return maximum of supported bits + * @since v1-alpha10 + */ + fun getBitness(): Int? = os?.bitness + + // -------> Computer + /** + * Returns the name of the + * manufacturer of this computer. + * + * @return computer manufacturer name + * @since v1-alpha10 + */ + fun getComputerManufacturer(): String? = hw?.computerSystem?.manufacturer + + /** + * Returns the name of the + * model of this computer. + * + * @return computer model name + * @since v1-alpha10 + */ + fun getComputerModel(): String? = hw?.computerSystem?.model + + // -------> Firmware (BIOS, UEFI, etc.) + /** + * Returns the name of the firmware (BIOS, + * UEFI, etc.) installed on this computer. + * + * @return firmware name + * @since v1-alpha10 + */ + fun getFirmwareName(): String? = hw?.computerSystem?.firmware?.name + + /** + * Returns the description of the firmware (BIOS, + * UEFI, etc.) installed on this computer. + * + * @return firmware description + * @since v1-alpha10 + */ + fun getFirmwareDescription(): String? = hw?.computerSystem?.firmware?.description + + /** + * Returns the name of the manufacturer of this + * computer's firmware (BIOS, UEFI, etc.). + * + * @return firmware manufacturer name + * @since v1-alpha10 + */ + fun getFirmwareManufacturer(): String? = hw?.computerSystem?.firmware?.manufacturer + + /** + * Returns the version of the firmware (BIOS, + * UEFI, etc.) installed on this computer. + * + * @return firmware version + * @since v1-alpha10 + */ + fun getFirmwareVersion(): String? = hw?.computerSystem?.firmware?.version + + /** + * Returns the release date of the firmware (BIOS, + * UEFI, etc.) installed on this computer. + * + * @return firmware release date + * @since v1-alpha10 + */ + fun getFirmwareReleaseDate(): String? = hw?.computerSystem?.firmware?.releaseDate + + // -------> Motherboard + /** + * Returns the name of the model of + * this computer's motherboard. + * + * @return motherboard model name + * @since v1-alpha10 + */ + fun getMotherboardModel(): String? = hw?.computerSystem?.baseboard?.model + + /** + * Returns the version of this + * computer's motherboard. + * + * @return motherboard version + * @since v1-alpha10 + */ + fun getMotherboardVersion(): String? = hw?.computerSystem?.baseboard?.version + + /** + * Returns the serial number of + * this computer's motherboard. + * + * @return motherboard serial number + * @since v1-alpha10 + */ + fun getMotherboardSerialNumber(): String? = hw?.computerSystem?.baseboard?.serialNumber + + /** + * Returns the name of the manufacturer + * of this computer's motherboard. + * + * @return motherboard manufacturer name + * @since v1-alpha10 + */ + fun getMotherboardManufacturer(): String? = hw?.computerSystem?.baseboard?.manufacturer + + // -------> Memory + /** + * Returns the total amount of physical + * memory this system has in bytes. + * + * @return amount of physical memory in bytes + * @since v1-alpha10 + */ + fun getMemoryTotal(): Long? = hw?.memory?.total + + /** + * Returns the amount of available + * physical memory in bytes. + * + * @return amount of physical memory in bytes + * @since v1-alpha10 + */ + fun getMemoryAvailable(): Long? = hw?.memory?.available + + /** + * Returns the amount of available + * physical memory in bytes. + * + * @return amount of physical memory in bytes + * @since v1-alpha10 + */ + fun getMemoryUsed(): Long? = hw?.memory?.total?.minus(hw!!.memory!!.available) + + /** + * Returns the size of a + * memory page in bytes. + * + * @return size of a memory page in bytes + * @since v1-alpha10 + */ + fun getMemoryPageSize(): Long? = hw?.memory?.pageSize + + // -------> CPU + /** + * Returns the maximum clock speed of + * the logical processors of the CPU + * installed in this computer in Hz. + * + * @return maximum clock speed of logical processors in Hz or `-1` if it couldn't be determined + * @since v1-alpha10 + */ + fun getCPUMaximumFrequency(): Long? = hw?.processor?.maxFreq + + /** + * Returns the estimated current clock + * speed of the logical processors of the + * CPU installed in this computer in Hz. + * + * Each item in the returned array + * stands for one logical processor. + * + * Depending on the platform the engine + * runs on, this may or may not be + * implemented. The algorithm used for + * calculating this estimate depends on + * the platform targeted. Some special + * restrictions apply to certain platforms. + * In short: Do not rely on the values + * in the array returned by this method. + * + * @return current clock rate of logical processors in Hz or an empty array + * @since v1-alpha10 + */ + fun getCPUCurrentFrequency(): LongArray? = hw?.processor?.currentFreq + + /** + * Returns the current amount of + * logical processors of the CPU + * installed in this computer. + * + * This value may change over time + * on some platforms. Be sure to + * query this number frequently to + * avoid out of date information. + * + * @return amount of logical processors + * @since v1-alpha10 + */ + fun getCPULogicalCount(): Int? = hw?.processor?.logicalProcessorCount + + /** + * Returns the amount of physical + * processors installed in this computer. + * + * @return amount of physical processors + * @since v1-alpha10 + */ + fun getCPUPhysicalCount(): Int? = hw?.processor?.physicalProcessorCount + + // -------> CPU + /** + * Returns an array of graphics cards + * installed in this computer. + * + * @return array of [GraphicsCard] instances + * @since v1-alpha10 + */ + fun getGPUs(): Array? = hw?.graphicsCards?.map { graphicsCard -> GraphicsCard(graphicsCard) }?.toTypedArray() + } + + // -----> Data types + /** + * Represents all operating systems + * detected and supported by the engine. + * + * @since v1-alpha10 + */ + enum class OperatingSystem { + /** + * Identifies that the application is running + * under the [Linux](https://kernel.org) kernel + * on some kind of Linux distribution. + * + * @since v1-alpha10 + */ + LINUX, + + /** + * Identifies that the application is running + * under the [FreeBSD](https://freebsd.org) kernel + * and likely the FreeBSD operating system. + * + * @since v1-alpha10 + */ + FREEBSD, + + /** + * Identifies that the application is running + * under the [NetBSD](https://netbsd.org) kernel + * and likely the NetBSD operating system. + * + * @since v1-alpha10 + */ + NETBSD, + + /** + * Identifies that the application is running + * under the [OpenBSD](https://openbsd.org) kernel + * and likely the OpenBSD operating system. + * + * @since v1-alpha10 + */ + OPENBSD, + + /** + * Identifies that the application is running + * under [Android](https://android.com), and + * by extension the [Linux kernel](https://kernel.org). + * + * @since v1-alpha10 + */ + ANDROID, + + /** + * Identifies that the application is running + * under [Windows](https://windows.com), and + * by extension the [Windows NT kernel](https://en.wikipedia.org/wiki/Ntoskrnl.exe). + * + * @since v1-alpha10 + */ + WINDOWS, + + /** + * Identifies that the application is running + * under [macOS](https://apple.com/macos), and + * by extension under the [XNU kernel](https://github.com/apple-oss-distributions/xnu). + * + * @since v1-alpha10 + */ + MACOS; + + override fun toString(): String = "${if (EngineConfiguration.fullTypePath) "de.staropensource.engine.base.utility." else ""}Environment\$OperatingSystem.${name}" + + /** + * Returns the human-friendly name + * of this operating system. + * + * @return human-friendly name + * @since v1-alpha10 + */ + fun humanFriendly(): String = when (this) { + LINUX -> "Linux" + FREEBSD -> "FreeBSD" + NETBSD -> "NetBSD" + OPENBSD -> "OpenBSD" + ANDROID -> "Android" + WINDOWS -> "Windows" + MACOS -> "macOS" + } + } + + /** + * Represents a graphics card. + * + * @constructor Initializes this class + * @since v1-alpha10 + */ + class GraphicsCard internal constructor(val graphicsCard: oshi.hardware.GraphicsCard) { + /** + * Returns the name of this graphics card. + * + * @return name + * @since v1-alpha10 + */ + fun getName(): String = graphicsCard.name + + /** + * Returns the device identifier + * of this graphics card. + * + * @return device identifier + * @since v1-alpha10 + */ + fun getDeviceIdentifier(): String = graphicsCard.deviceId + + /** + * Returns the name of the manufacturer + * of this graphics card. + * + * @return manufacturer name + * @since v1-alpha10 + */ + fun getManufacturer(): String = graphicsCard.vendor + + /** + * Returns the version of + * this graphics card. + * + * @return version + * @since v1-alpha10 + */ + fun getVersion(): String = graphicsCard.versionInfo + + /** + * Returns the amount of VRAM provided + * by this graphics card in bytes. + * + * @return amount of total VRAM + * @since v1-alpha10 + */ + fun getVideoMemory(): Long = graphicsCard.vRam + } +} diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/FileAccess.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt similarity index 99% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/FileAccess.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt index 735e474..5126518 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/FileAccess.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/FileAccess.kt @@ -36,7 +36,6 @@ import java.io.IOException import java.nio.file.* import java.nio.file.attribute.BasicFileAttributes import java.nio.file.attribute.PosixFilePermissions -import kotlin.jvm.JvmStatic /** * Provides a simplified way of diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt similarity index 72% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt index c0b0124..b6520f2 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/Process.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/Process.kt @@ -22,14 +22,14 @@ package de.staropensource.engine.base.utility import de.staropensource.engine.base.Engine.Companion.logger import de.staropensource.engine.base.exception.VerificationFailedException import de.staropensource.engine.base.exception.io.IOAccessException -import de.staropensource.engine.base.implementable.PlatformData import de.staropensource.engine.base.implementable.stream.ReadStream import de.staropensource.engine.base.implementable.stream.Stream import de.staropensource.engine.base.implementable.stream.WriteStream -import de.staropensource.engine.base.platform.ProcessPlatform -import de.staropensource.engine.base.platform.platformMilliseconds -import de.staropensource.engine.base.platform.platformProcessCreate -import kotlin.Throws +import de.staropensource.engine.base.implementation.stream.JavaReadStream +import de.staropensource.engine.base.implementation.stream.JavaWriteStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream /** * Provides a simplified way of @@ -38,20 +38,16 @@ import kotlin.Throws * @since v1-alpha10 */ @Suppress("Unused") -class Process : PlatformData { - // -----> Platform-specific - override val platformData: MutableMap = mutableMapOf() - +class Process { + // -----> Metadata /** - * Platform-specific [ProcessPlatform] - * instance for this [Stream]. + * Contains an instance of Java's + * [java.lang.Process] class. * * @since v1-alpha10 */ - private val platform: ProcessPlatform = platformProcessCreate(this) + private val process: java.lang.Process - - // -----> Metadata /** * Contains the executable this * [Process] is running. @@ -74,7 +70,7 @@ class Process : PlatformData { * * @since v1-alpha10 */ - val workingDirectory: FileAccess + val initialWorkingDirectory: FileAccess /** * Contains if this [Process] was launched @@ -85,13 +81,6 @@ class Process : PlatformData { */ val launchedWithFreshEnvironment: Boolean - /** - * Contains all initial environment variables. - * - * @since v1-alpha10 - */ - val environmentVariables: Map - /** * Contains all registered exit events. * @@ -158,21 +147,47 @@ class Process : PlatformData { autoWatchStreams: Boolean = true, ) { try { + val builder: ProcessBuilder = ProcessBuilder() + // Set properties this.executable = executable this.arguments = arguments - this.workingDirectory = workingDirectory ?: FileAccess.temporaryCacheDirectory!! + this.initialWorkingDirectory = workingDirectory ?: FileAccess(System.getProperty("user.dir")) this.launchedWithFreshEnvironment = freshEnvironment - this.environmentVariables = environmentVariables.toMap() this.exitEvents = exitEvents.toMutableList() - platform.start() + // Reset environment + if (freshEnvironment) + builder.environment().clear() + + // Pass arguments + builder + .command(listOf(executable.toStringRaw()).plus(arguments)) + .directory(workingDirectory?.file) + .environment().putAll(environmentVariables) + + // Start process + process = builder.start() logger.diag("Started process ${getPid()}") // Set streams - standardInput = platform.getStandardInput() - standardOutput = platform.getStandardOutput() - standardError = platform.getStandardError() + this.standardError = StandardOutputErrorStream(this, process.errorStream) + this.standardOutput = StandardOutputErrorStream(this, process.inputStream) + this.standardInput = StandardInputStream(this, process.outputStream) + + // Attach process exit handling + process.onExit().thenAccept { + logger.diag("Process ${getPid()} died") + + // Invoke all exit events + for (exitEvent: UByte.() -> Unit in exitEvents) + exitEvent.invoke(process.exitValue().toUByte()) + + // Close streams + standardInput.close() + standardOutput.close() + standardError.close() + } // Connect streams inputStreams.forEach { it.pipes.add(standardInput) } @@ -184,8 +199,8 @@ class Process : PlatformData { standardOutput.watch() standardError.watch() } - } catch (throwable: Throwable) { - throw IOAccessException("Unable to spawn new process", throwable) + } catch (exception: IOException) { + throw IOAccessException("Unable to spawn new process", exception) } } @@ -201,32 +216,10 @@ class Process : PlatformData { */ fun kill(): Process { logger.diag("Killing process ${getPid()}") - platform.kill() + process.destroyForcibly() return this } - /** - * Handles the death of this [Process]. - * - * Must only be called by the - * matching [ProcessPlatform] - * implementation. - * - * @since v1-alpha10 - */ - fun platformDeath() { - logger.diag("Process ${getPid()} died") - - // Invoke all exit events - for (exitEvent: UByte.() -> Unit in exitEvents) - exitEvent.invoke(getExitCode()!!) - - // Close streams - standardInput.close() - standardOutput.close() - standardError.close() - } - // -----> Getters & setters /** @@ -236,7 +229,7 @@ class Process : PlatformData { * @return still running? * @since v1-alpha10 */ - fun isAlive(): Boolean = platform.isAlive() + fun isAlive(): Boolean = process.isAlive /** * Returns the PID of this [Process] @@ -248,7 +241,7 @@ class Process : PlatformData { * @return process identifier * @since v1-alpha10 */ - fun getPid(): Long = platform.getPid() + fun getPid(): Long = process.pid() /** * Returns the code with which @@ -257,7 +250,13 @@ class Process : PlatformData { * @return exit code or `null` if alive * @since v1-alpha10 */ - fun getExitCode(): UByte? = platform.getExitCode() + fun getExitCode(): UByte? { + return try { + process.exitValue().toUByte() + } catch (exception: IllegalThreadStateException) { + null + } + } // -----> Miscellaneous @@ -269,9 +268,9 @@ class Process : PlatformData { * @since v1-alpha10 */ fun waitForExit(maxTime: ULong = 0UL): Process { - val maxTimeReal: ULong = platformMilliseconds() + val maxTimeReal: Long = System.currentTimeMillis().plus(maxTime.toLong()) - while (maxTime == 0UL || platformMilliseconds() < maxTimeReal) + while (maxTime == 0UL || System.currentTimeMillis() < maxTimeReal) if (!isAlive()) break @@ -352,4 +351,61 @@ class Process : PlatformData { throw VerificationFailedException("Expected that process ${getPid()} was not launched with a fresh environment") return this } + + + // -----> Inner classes + /** + * Used for the [standardInput] + * stream of a [Process]. + * + * @constructor Initializes this stream + * @since v1-alpha10 + */ + private class StandardInputStream( + val process: Process, + stream: OutputStream, + ) : JavaWriteStream( + stream, + autoFlushAfter = 100UL + ) { + // -----> Closure + override fun close() { + if (!process.isAlive()) + super.close() + } + + // -----> Writing + // Assist in flushing + override fun writeByte(byte: Byte): Stream { + super.writeByte(byte) + if (byte.toInt() == 0x0A) + flush() + return this + } + + override fun writeBytes(bytes: ByteArray): Stream { + super.writeBytes(bytes) + if (bytes.contains((0x0A).toByte())) + flush() + return this + } + } + + /** + * Used for the [standardOutput] + * and [standardError] streams + * of a [Process]. + * + * @constructor Initializes this stream + * @since v1-alpha10 + */ + private class StandardOutputErrorStream( + val process: Process, + stream: InputStream, + ) : JavaReadStream(stream) { + override fun close() { + if (!process.isAlive()) + super.close() + } + } } diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/BuildInformation.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/dnihbd/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/dnihbd/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/dnihbd/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/Miscellaneous.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/misc/Miscellaneous.kt similarity index 73% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/Miscellaneous.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/misc/Miscellaneous.kt index de05947..3047502 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/Miscellaneous.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/misc/Miscellaneous.kt @@ -31,5 +31,16 @@ class Miscellaneous private constructor() { * * @since v1-alpha10 */ - companion object + companion object { + /** + * Returns if currently + * running on the main thread. + * + * @return `true` if running on the main thread, `false` if not, `null` if not supported (e.g. not running on the JVM) + * @since v1-alpha10 + */ + fun onMainThread(): Boolean? { + return Thread.currentThread().threadId() == 1L + } + } } diff --git a/base/src/main/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt new file mode 100644 index 0000000..7a778e8 --- /dev/null +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtils.kt @@ -0,0 +1,165 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Authors + * Licensed under the GNU General Public License v3. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.engine.base.utility.misc + +import de.staropensource.engine.base.type.Origin +import java.lang.reflect.InvocationTargetException + +/** + * Utility methods for stack trace + * and exception analysis. + * + * @constructor Initializes this class + * @since v1-alpha10 + */ +class StackTraceUtils private constructor() { + /** + * Companion object of [StackTraceUtils]. + * + * @since v1-alpha10 + */ + companion object { + /** + * Returns the method caller. + * + * @param depth how deep to go into the stack trace + * @return deepest method caller + * @since v1-alpha10 + */ + fun methodCaller(depth: UInt = 1u): Origin { + val stacktrace: Array = Throwable().stackTrace + var element: StackTraceElement? = null + + // Get wanted element + element = if (depth.plus(2u).toInt() > stacktrace.size) + stacktrace[stacktrace.size - 1] + else + stacktrace[depth.plus(2u).toInt()] + + // Return origin + return Origin( + packageName = element.className.substringBeforeLast('.'), + className = element.className.substringAfterLast('.'), + methodName = element.methodName, + lineNumber = element.lineNumber.toUInt(), + ) + } + + + /** + * Returns the `Caused by: ` header + * usually found in JVM stacktraces. + * + * @param throwable [Throwable] to use + * @return stacktrace header + * @since v1-alpha10 + */ + fun stacktraceHeader(throwable: Throwable): String { + return "Caused by: ${throwable.javaClass.name}${if (throwable.message == null) "" else ": ${throwable.message}"}" + } + + /** + * Returns the body of the stacktrace + * as it is usually found in JVM + * stacktraces. + * + * @param throwable [Throwable] to use + * @param indent if to add a tab character (`\t`) as indentation + * @return stacktrace body + * @since v1-alpha10 + */ + fun stacktraceBody(throwable: Throwable, indent: Boolean = true): String = buildString { + for (element: StackTraceElement in throwable.stackTrace) { + if (!isEmpty()) + append("\n") + if (indent) + append("\t") + + append("at ") + append(element) + } + } + + /** + * Returns a recursively resolved + * collection of stacktraces, all + * derived from the passed [throwable]. + * + * Use this method if you intend to + * print an exception's stacktrace or + * want to display it nicely elsewhere. + * + * + * @param throwable [Throwable] to use + * @param indent if to add a tab character (`\t`) as indentation + * @param includeHeader if to include the `Caused by` stacktrace header (see [stacktraceHeader]) + * @return recursively resolved stacktrace + * @since v1-alpha10 + */ + fun stacktraceRecursive(throwable: Throwable, indent: Boolean = true, includeHeader: Boolean = true, depth: UInt = 10u): String = buildString { + // Append header + if (includeHeader) { + append(stacktraceHeader(throwable)) + append("\n") + } + + // Append body + append(stacktraceBody(throwable, indent = indent)) + + // Recurse downwards + if (throwable.cause != null) { + append("\n") + if (depth == 0u) + append("...") + else + append(stacktraceRecursive(throwable.cause!!, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) + } + + if (throwable is ClassNotFoundException) { + val exception: ClassNotFoundException = throwable + if (exception.exception != null) { + append("\n") + if (depth == 0u) + append("...") + else + append(stacktraceRecursive(exception.exception, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) + } + } else if (throwable is ExceptionInInitializerError) { + val exception: ExceptionInInitializerError = throwable + if (exception.exception != null) { + append("\n") + if (depth == 0u) + append("...") + else + append(stacktraceRecursive(exception.exception, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) + } + } else if (throwable is InvocationTargetException) { + val exception: InvocationTargetException = throwable + if (exception.targetException != null) { + append("\n") + if (depth == 0u) + append("...") + else + append(stacktraceRecursive(exception.targetException, indent = indent, includeHeader = includeHeader, depth = depth.minus(1u))) + } + } + } + } +} diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/misc/package-info.kt similarity index 100% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/misc/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/misc/package-info.kt diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/base/utility/package-info.kt similarity index 94% rename from base/src/commonMain/kotlin/de/staropensource/engine/base/utility/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/base/utility/package-info.kt index 358ec07..b0b303b 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/base/utility/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/base/utility/package-info.kt @@ -22,4 +22,4 @@ * * @since v1-alpha10 */ -package de.staropensource.engine.base.utility +package de.staropensource.engine.base.utility; diff --git a/base/src/commonMain/kotlin/de/staropensource/engine/package-info.kt b/base/src/main/kotlin/de/staropensource/engine/package-info.kt similarity index 96% rename from base/src/commonMain/kotlin/de/staropensource/engine/package-info.kt rename to base/src/main/kotlin/de/staropensource/engine/package-info.kt index 33fd576..ae9e4c4 100644 --- a/base/src/commonMain/kotlin/de/staropensource/engine/package-info.kt +++ b/base/src/main/kotlin/de/staropensource/engine/package-info.kt @@ -25,4 +25,4 @@ * * @since v1-alpha10 */ -package de.staropensource.engine +package de.staropensource.engine; diff --git a/base/src/commonMain/resources/.gitignore b/base/src/main/resources/.gitignore similarity index 100% rename from base/src/commonMain/resources/.gitignore rename to base/src/main/resources/.gitignore diff --git a/base/src/commonTest/kotlin/de/staropensource/engine/base/EngineTest.kt b/base/src/test/kotlin/de/staropensource/engine/base/EngineTest.kt similarity index 100% rename from base/src/commonTest/kotlin/de/staropensource/engine/base/EngineTest.kt rename to base/src/test/kotlin/de/staropensource/engine/base/EngineTest.kt diff --git a/base/src/commonTest/kotlin/de/staropensource/engine/base/TestBase.kt b/base/src/test/kotlin/de/staropensource/engine/base/TestBase.kt similarity index 100% rename from base/src/commonTest/kotlin/de/staropensource/engine/base/TestBase.kt rename to base/src/test/kotlin/de/staropensource/engine/base/TestBase.kt diff --git a/base/src/commonTest/kotlin/de/staropensource/engine/base/utility/DataSizeTest.kt b/base/src/test/kotlin/de/staropensource/engine/base/utility/DataSizeTest.kt similarity index 100% rename from base/src/commonTest/kotlin/de/staropensource/engine/base/utility/DataSizeTest.kt rename to base/src/test/kotlin/de/staropensource/engine/base/utility/DataSizeTest.kt diff --git a/base/src/commonTest/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt b/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt similarity index 100% rename from base/src/commonTest/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt rename to base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt diff --git a/base/src/commonTest/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtilsTest.kt b/base/src/test/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtilsTest.kt similarity index 100% rename from base/src/commonTest/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtilsTest.kt rename to base/src/test/kotlin/de/staropensource/engine/base/utility/misc/StackTraceUtilsTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index a4e8ab8..331df3e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,7 +48,7 @@ plugins { id("maven-publish") // Kotlin support - id("org.jetbrains.kotlin.multiplatform") version("2.0.0") + id("org.jetbrains.kotlin.jvm") version("2.0.0") // Dokka id("org.jetbrains.dokka") version("1.9.20") @@ -67,7 +67,7 @@ allprojects { // Plugins apply(plugin = "java-library") apply(plugin = "maven-publish") - apply(plugin = "org.jetbrains.kotlin.multiplatform") + apply(plugin = "org.jetbrains.kotlin.jvm") apply(plugin = "org.jetbrains.dokka") apply(plugin = "com.gorylenko.gradle-git-properties") apply(plugin = "ca.solo-studios.nyx") @@ -125,7 +125,12 @@ allprojects { withDistributeLicense() encoding = "UTF-8" withZip64() + withBuildDependsOnJar() withSuppressWarnings() + jvmToolchain = (property("languageJava") as String).toInt() + jvmTarget = (property("languageJava") as String).toInt() + withSourcesJar() + withJavadocJar() withReproducibleBuilds() // Kotlin-specific settings @@ -136,14 +141,6 @@ allprojects { "-progressive" ) } - - // JVM-specific settings - java { - jvmToolchain = (property("languageJava") as String).toInt() - jvmTarget = (property("languageJava") as String).toInt() - //withSourcesJar() - withJavadocJar() - } } } @@ -153,31 +150,22 @@ allprojects { mavenCentral() } - // Kotlin - kotlin { - // Targets - // -> JVM - jvm() - // -> Native - //linuxX64() - //linuxArm64() - //mingwX64() + // Dependencies + dependencies { + // Kotlin support + implementation("${property("dependencyKotlin_ReflectIdentifier") as String}:${property("dependencyKotlinVersion") as String}") + implementation("${property("dependencyKotlin_CoroutinesIdentifier") as String}:${property("dependencyKotlin_CoroutinesVersion") as String}") + implementation("${property("dependencyKotlin_DateTimeIdentifier") as String}:${property("dependencyKotlin_DateTimeVersion") as String}") - // Dependencies - sourceSets { - commonMain.dependencies { - // Kotlin support - implementation("${property("dependencyKotlin_ReflectIdentifier") as String}:${property("dependencyKotlinVersion") as String}") - implementation("${property("dependencyKotlin_CoroutinesIdentifier") as String}:${property("dependencyKotlin_CoroutinesVersion") as String}") - implementation("${property("dependencyKotlin_DateTimeIdentifier") as String}:${property("dependencyKotlin_DateTimeVersion") as String}") - } - commonTest.dependencies { - // -> Kotlin - implementation(kotlin("test")) - // -> sos!engine - implementation(project(":testing")) - } - } + // Unit testing + // -> Kotlin + testImplementation(kotlin("test")) + // -> JUnit + testImplementation(platform("${property("testDependencyJUnit_BOMIdentifier")}:${property("testDependencyJUnitVersion")}")) + testImplementation("${property("testDependencyJUnit_JupiterIdentifier")}") + testRuntimeOnly("${property("testDependencyJUnit_PlatformIdentifier")}") + // -> sos!engine + testImplementation(project(":testing")) } // Unit testing @@ -251,7 +239,7 @@ allprojects { // -> Copy task tasks.register("copyGitProperties") { dependsOn(tasks.generateGitProperties) - inputs.file("${this@allprojects.projectDir}/build/resources/commonMain/git.properties") + inputs.file("${this@allprojects.projectDir}/build/resources/main/git.properties") doLast { if (rootProject == this@allprojects) @@ -259,7 +247,7 @@ allprojects { file(inputs.files.first()) .copyTo( - file("${this@allprojects.projectDir}/src/commonMain/resources/sosengine-${this@allprojects.name.replace(":", "-")}-git.properties"), + file("${this@allprojects.projectDir}/src/main/resources/sosengine-${this@allprojects.name.replace(":", "-")}-git.properties"), overwrite = true ) } @@ -279,7 +267,7 @@ allprojects { file(inputs.files.first()) .copyTo( - file("${this@allprojects.projectDir}/src/commonMain/resources/sosengine-${this@allprojects.name.replace(":", "-")}-gradle.properties"), + file("${this@allprojects.projectDir}/src/main/resources/sosengine-${this@allprojects.name.replace(":", "-")}-gradle.properties"), overwrite = true ) } diff --git a/dist/detekt.yml b/dist/detekt.yml index cfcee3b..584c1fc 100644 --- a/dist/detekt.yml +++ b/dist/detekt.yml @@ -28,8 +28,6 @@ complexity: naming: MemberNameEqualsClassName: active: false - MatchingDeclarationName: - active: false exceptions: SwallowedException: diff --git a/settings.gradle.kts b/settings.gradle.kts index a69aae7..87fb51d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,5 @@ +import java.net.URI + /* * STAROPENSOURCE ENGINE SOURCE FILE * Copyright (c) 2024 The StarOpenSource Engine Authors diff --git a/testapp/build.gradle.kts b/testapp/build.gradle.kts index d5a8667..90be08c 100644 --- a/testapp/build.gradle.kts +++ b/testapp/build.gradle.kts @@ -24,15 +24,11 @@ plugins { id("com.gradleup.shadow") version ("8.3.5") } -kotlin { - // Dependencies - sourceSets { - commonMain.dependencies { - // sos!engine - implementation(project(":base")) - implementation(project(":ansi")) - } - } +// Dependencies +dependencies { + // sos!engine + implementation(project(":base")) + implementation(project(":ansi")) } // Configure JAR diff --git a/testapp/src/commonMain/kotlin/de/staropensource/engine/testapp/Main.kt b/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt similarity index 98% rename from testapp/src/commonMain/kotlin/de/staropensource/engine/testapp/Main.kt rename to testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt index 4ecb69f..61183e6 100644 --- a/testapp/src/commonMain/kotlin/de/staropensource/engine/testapp/Main.kt +++ b/testapp/src/main/kotlin/de/staropensource/engine/testapp/Main.kt @@ -24,7 +24,6 @@ import de.staropensource.engine.base.Engine import de.staropensource.engine.base.EngineConfiguration import de.staropensource.engine.base.logging.Logger import de.staropensource.engine.base.type.logging.Level -import kotlin.jvm.JvmStatic /** * Testing program for the StarOpenSource Engine. diff --git a/testapp/src/commonMain/kotlin/de/staropensource/engine/testapp/package-info.kt b/testapp/src/main/kotlin/de/staropensource/engine/testapp/package-info.kt similarity index 100% rename from testapp/src/commonMain/kotlin/de/staropensource/engine/testapp/package-info.kt rename to testapp/src/main/kotlin/de/staropensource/engine/testapp/package-info.kt diff --git a/testapp/src/commonMain/resources/.gitignore b/testapp/src/main/resources/.gitignore similarity index 100% rename from testapp/src/commonMain/resources/.gitignore rename to testapp/src/main/resources/.gitignore diff --git a/testing/build.gradle.kts b/testing/build.gradle.kts index 11b1424..dd71b68 100644 --- a/testing/build.gradle.kts +++ b/testing/build.gradle.kts @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -kotlin { - // Dependencies - sourceSets { - commonMain.dependencies { - // sos!engine - implementation(project(":base")) +// Dependencies +dependencies { + // sos!engine + implementation(project(":base")) - // -> Kotlin - implementation(kotlin("test")) - } - } + // Unit testing + // -> Kotlin + implementation(kotlin("test")) + // -> JUnit + implementation(platform("${property("testDependencyJUnit_BOMIdentifier")}:${property("testDependencyJUnitVersion")}")) + implementation("${property("testDependencyJUnit_JupiterIdentifier")}") } diff --git a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/TestBase.kt b/testing/src/main/kotlin/de/staropensource/engine/testing/TestBase.kt similarity index 93% rename from testing/src/commonMain/kotlin/de/staropensource/engine/testing/TestBase.kt rename to testing/src/main/kotlin/de/staropensource/engine/testing/TestBase.kt index 7fd2e18..6145874 100644 --- a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/TestBase.kt +++ b/testing/src/main/kotlin/de/staropensource/engine/testing/TestBase.kt @@ -26,9 +26,13 @@ import de.staropensource.engine.base.type.logging.ChannelSettings import de.staropensource.engine.base.type.logging.Level import de.staropensource.engine.testing.implementation.FailureShutdownHandler import de.staropensource.engine.testing.implementation.NoOperationShutdownHandler -import kotlin.test.AfterTest -import kotlin.test.BeforeTest -import kotlin.test.fail +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.TestInfo +import org.junit.jupiter.api.fail +import kotlin.concurrent.fixedRateTimer +import kotlin.jvm.optionals.getOrDefault +import kotlin.jvm.optionals.getOrNull /** * Base class for implementing tests. @@ -57,8 +61,8 @@ abstract class TestBase( * * @since v1-alpha10 */ - @BeforeTest - fun beforeTest() { + @BeforeEach + fun beforeTask(testInfo: TestInfo) { when (Engine.state) { State.INITIALIZING, State.SHUTTING_DOWN -> fail("Engine is in invalid state 'Engine.State.${Engine.state.name}'") State.CRASHED -> fail("The StarOpenSource Engine has crashed") @@ -69,10 +73,8 @@ abstract class TestBase( initializeEngine() // Print test starting - /* if (printTestExecution) println("-> STARTING test '${testInfo.displayName}' [${testInfo.testClass.getOrNull()?.name ?: ""}#${testInfo.testMethod.getOrNull()?.name ?: ""}]") - */ } /** @@ -80,8 +82,8 @@ abstract class TestBase( * * @since v1-alpha10 */ - @AfterTest - fun afterTest() { + @AfterEach + fun afterTask(testInfo: TestInfo) { when (Engine.state) { State.UNINITIALIZED -> fail("Internal inconsistency detected: Engine configuration was not performed") State.INITIALIZING, State.SHUTTING_DOWN -> fail("Engine is in invalid state 'Engine.State.${Engine.state.name}'") @@ -93,10 +95,8 @@ abstract class TestBase( shutdownEngine() // Print test ending - /* if (printTestExecution) println("-> FINISHED test '${testInfo.displayName}' [${testInfo.testClass.getOrNull()?.name ?: ""}#${testInfo.testMethod.getOrNull()?.name ?: ""}]") - */ } diff --git a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/FailureShutdownHandler.kt b/testing/src/main/kotlin/de/staropensource/engine/testing/implementation/FailureShutdownHandler.kt similarity index 98% rename from testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/FailureShutdownHandler.kt rename to testing/src/main/kotlin/de/staropensource/engine/testing/implementation/FailureShutdownHandler.kt index dff8002..b10ce01 100644 --- a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/FailureShutdownHandler.kt +++ b/testing/src/main/kotlin/de/staropensource/engine/testing/implementation/FailureShutdownHandler.kt @@ -20,7 +20,6 @@ package de.staropensource.engine.testing.implementation import de.staropensource.engine.base.implementable.ShutdownHandler -import kotlin.jvm.JvmStatic import kotlin.test.fail /** diff --git a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/NoOperationShutdownHandler.kt b/testing/src/main/kotlin/de/staropensource/engine/testing/implementation/NoOperationShutdownHandler.kt similarity index 98% rename from testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/NoOperationShutdownHandler.kt rename to testing/src/main/kotlin/de/staropensource/engine/testing/implementation/NoOperationShutdownHandler.kt index bc43ea7..f39e8e0 100644 --- a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/NoOperationShutdownHandler.kt +++ b/testing/src/main/kotlin/de/staropensource/engine/testing/implementation/NoOperationShutdownHandler.kt @@ -20,7 +20,7 @@ package de.staropensource.engine.testing.implementation import de.staropensource.engine.base.implementable.ShutdownHandler -import kotlin.jvm.JvmStatic +import kotlin.test.fail /** * [ShutdownHandler] implementation which diff --git a/testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/package-info.kt b/testing/src/main/kotlin/de/staropensource/engine/testing/implementation/package-info.kt similarity index 100% rename from testing/src/commonMain/kotlin/de/staropensource/engine/testing/implementation/package-info.kt rename to testing/src/main/kotlin/de/staropensource/engine/testing/implementation/package-info.kt diff --git a/testing/src/commonMain/resources/.gitignore b/testing/src/main/resources/.gitignore similarity index 100% rename from testing/src/commonMain/resources/.gitignore rename to testing/src/main/resources/.gitignore