Make engine multiplatform (incomplete)
Some checks failed
PRs & Pushes / test (push) Successful in 2m6s
PRs & Pushes / build-jars (push) Successful in 2m6s
PRs & Pushes / build-apidoc (push) Failing after 2m31s

I've only performed basic steps to allow the engine to be multiplatform.
Major classes such as FileAccess, various Stream implementations and so on need to be updated accordingly.
This commit is contained in:
JeremyStar™ 2024-12-28 18:13:33 +01:00
parent df3ef9829e
commit 06b279e8b6
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
108 changed files with 138 additions and 87 deletions

View file

@ -17,8 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Dependencies
dependencies {
// sos!engine
implementation(project(":base"))
kotlin {
// Dependencies
sourceSets {
commonMain.dependencies {
// sos!engine
implementation(project(":base"))
}
}
}

View file

@ -21,6 +21,7 @@ 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

View file

@ -24,6 +24,7 @@ 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.

View file

@ -17,8 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// Dependencies
dependencies {
// OSHI
implementation("${property("dependencyOshiIdentifier") as String}:${property("dependencyOshiVersion") as String}")
kotlin {
// Dependencies
sourceSets {
jvmMain.dependencies {
// OSHI
implementation("${property("dependencyOshiIdentifier") as String}:${property("dependencyOshiVersion") as String}")
}
}
}

View file

@ -27,6 +27,7 @@ import de.staropensource.engine.base.utility.FileAccess
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import kotlin.jvm.JvmStatic
import kotlin.reflect.KClass
/**
@ -50,6 +51,7 @@ class Engine private constructor() {
*
* @since v1-alpha10
*/
@JvmStatic
internal val logger: Logger = Logger(channel = "engine-core")
/**
@ -57,6 +59,7 @@ class Engine private constructor() {
*
* @since v1-alpha10
*/
@JvmStatic
var state: State = State.UNINITIALIZED
internal set
@ -73,6 +76,7 @@ class Engine private constructor() {
* @see bootstrap
* @since v1-alpha10
*/
@JvmStatic
var bootstrapping: Boolean? = null
/**
@ -81,6 +85,7 @@ class Engine private constructor() {
* @see Subsystem
* @since v1-alpha10
*/
@JvmStatic
private val subsystems: MutableSet<Subsystem> = mutableSetOf()
/**
@ -91,6 +96,7 @@ class Engine private constructor() {
* @see BuildInformation
* @since v1-alpha10
*/
@JvmStatic
var info: BuildInformation? = null
@ -102,6 +108,7 @@ class Engine private constructor() {
* @return array of registered [Subsystem]s
* @since v1-alpha10
*/
@JvmStatic
fun getSubsystems(): Array<Subsystem> = subsystems.toTypedArray()
/**
@ -110,11 +117,14 @@ class Engine private constructor() {
*
* @since v1-alpha10
*/
fun getSubsystem(subsystemClass: KClass<out Subsystem>): Subsystem? = getSubsystems().find { subsystem -> try {
subsystem::class.qualifiedName!! == subsystemClass.qualifiedName!!
} catch (_: NullPointerException) {
false
} }
@JvmStatic
fun getSubsystem(subsystemClass: KClass<out Subsystem>): Subsystem? {
return getSubsystems().find { subsystem -> try {
subsystem::class.qualifiedName!! == subsystemClass.qualifiedName!!
} catch (_: NullPointerException) {
false
} }
}
/**
* Registers the specified subsystem.
@ -128,6 +138,7 @@ class Engine private constructor() {
* @see Subsystem
* @since v1-alpha10
*/
@JvmStatic
fun registerSubsystem(subsystem: Subsystem) {
// Check for state
if (bootstrapping == true)

View file

@ -35,6 +35,7 @@ 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
/**

View file

@ -25,10 +25,9 @@ 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 may be multiplatform in future
* releases and will not support using other
* languages.
* the StarOpenSource Engine is highly
* discouraged, as the engine is optimized for
* multiplatform usage.
*
* Using anything in contact with non-Kotlin code
* is therefore deemed unsafe and should be

View file

@ -44,7 +44,7 @@ import kotlin.text.iterator
* @since v1-alpha10
*/
abstract class TwoCycleFormatterImpl: TwoCycleFormatter() {
@Suppress("NestedBlockDepth")
@Suppress("NestedBlockDepth", "CyclomaticComplexMethod")
override fun parse(message: String): Array<String> {
val components: MutableList<String> = mutableListOf()
var currentComponent: StringBuilder = StringBuilder()

View file

@ -19,7 +19,6 @@
package de.staropensource.engine.base.implementable.logging
import de.staropensource.engine.base.logging.Processor
import de.staropensource.engine.base.type.logging.Call
/**

View file

@ -22,4 +22,4 @@
*
* @since v1-alpha10
*/
package de.staropensource.engine.base.implementable;
package de.staropensource.engine.base.implementable

View file

@ -20,6 +20,7 @@
package de.staropensource.engine.base.implementation.logging
import de.staropensource.engine.base.implementable.ShutdownHandler
import kotlin.jvm.JvmStatic
import kotlin.system.exitProcess
/**

View file

@ -21,6 +21,7 @@ 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
/**

View file

@ -21,6 +21,7 @@ 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

View file

@ -21,6 +21,7 @@ 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

View file

@ -23,9 +23,7 @@ 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 kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlin.jvm.JvmStatic
/**
* [CrashCategory] implementation

View file

@ -23,6 +23,7 @@ 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

View file

@ -20,6 +20,7 @@
package de.staropensource.engine.base.implementation.stream
import de.staropensource.engine.base.implementable.stream.Stream
import kotlin.jvm.JvmStatic
/**
* A [Stream] which does nothing

View file

@ -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.toByteArray())
open class StringReadStream(val stringRead: String) : ByteReadStream(bytesRead = stringRead.encodeToByteArray())

View file

@ -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.toByteArray()) {
open class StringStream(val stringRead: String) : ByteStream(bytesRead = stringRead.encodeToByteArray()) {
/**
* Returns the written string.
*

View file

@ -21,6 +21,7 @@ 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.

View file

@ -30,6 +30,8 @@ import de.staropensource.engine.base.type.logging.Level
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.
@ -119,7 +121,7 @@ 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<String, Object?> = emptyMap(), callerDepth: UInt = 0u) {
fun log(level: Level, message: String, levelData: Map<String, Any?> = emptyMap(), callerDepth: UInt = 0u) {
// Create 'Call' instance
var call: Call = Call(
StackTraceUtils.methodCaller(depth = callerDepth.plus(1u)),
@ -130,7 +132,7 @@ class Logger {
// Run processing
if (level == Level.CRASH)
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrDefault("fatal", true) as Boolean)
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrElse("fatal") { true } as Boolean)
else {
if (Processor.check(call))
return
@ -210,8 +212,8 @@ class Logger {
*/
fun crash(error: String, throwable: Throwable? = null, fatal: Boolean = true) {
log(Level.CRASH, error, levelData = mapOf(
Pair("throwable", throwable as Object?),
Pair("fatal", fatal as Object?)
Pair("throwable", throwable as Any?),
Pair("fatal", fatal as Any?)
), callerDepth = 1u)
}
@ -242,5 +244,5 @@ class Logger {
* @return [FileAccessStream] instance
* @since v1-alpha10
*/
fun toStream(level: Level): LoggerStream = stream.computeIfAbsent(level) { level -> LoggerStream(this, level) }
fun toStream(level: Level): LoggerStream = stream[level] ?: LoggerStream(this, level)
}

View file

@ -29,6 +29,7 @@ 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.StackTraceUtils
import kotlin.jvm.JvmStatic
import kotlin.reflect.full.primaryConstructor
/**
@ -87,7 +88,7 @@ class Processor private constructor() {
* @param call [Call] metadata
* @see EngineConfiguration.logThreadingHandler
* @see ChannelSettings.formatter
* @see ChannelSettings.adapter
* @see ChannelSettings.adapters
* @since v1-alpha10
*/
@JvmStatic

View file

@ -20,6 +20,7 @@
package de.staropensource.engine.base.type
import de.staropensource.engine.base.EngineConfiguration
import kotlin.jvm.JvmStatic
/**
* Defines a data type which can have

View file

@ -24,6 +24,7 @@ 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

View file

@ -22,4 +22,4 @@
*
* @since v1-alpha10
*/
package de.staropensource.engine.base.type;
package de.staropensource.engine.base.type

View file

@ -23,4 +23,4 @@
*
* @since v1-alpha10
*/
package de.staropensource.engine.base.type.versioning;
package de.staropensource.engine.base.type.versioning

View file

@ -23,6 +23,7 @@ import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.Locale
import kotlin.jvm.JvmStatic
/**
* Converts between various data size units.

View file

@ -26,6 +26,7 @@ import kotlinx.datetime.Instant
import oshi.PlatformEnum
import oshi.SystemInfo
import oshi.hardware.HardwareAbstractionLayer
import kotlin.jvm.JvmStatic
/**
* Provides information about the

View file

@ -36,6 +36,7 @@ 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

View file

@ -22,4 +22,4 @@
*
* @since v1-alpha10
*/
package de.staropensource.engine.base.utility;
package de.staropensource.engine.base.utility

View file

@ -25,4 +25,4 @@
*
* @since v1-alpha10
*/
package de.staropensource.engine;
package de.staropensource.engine

View file

@ -48,7 +48,7 @@ plugins {
id("maven-publish")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version("2.0.0")
id("org.jetbrains.kotlin.multiplatform") 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.jvm")
apply(plugin = "org.jetbrains.kotlin.multiplatform")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.gorylenko.gradle-git-properties")
apply(plugin = "ca.solo-studios.nyx")
@ -125,12 +125,7 @@ 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
@ -141,6 +136,14 @@ allprojects {
"-progressive"
)
}
// JVM-specific settings
java {
jvmToolchain = (property("languageJava") as String).toInt()
jvmTarget = (property("languageJava") as String).toInt()
//withSourcesJar()
withJavadocJar()
}
}
}
@ -150,22 +153,31 @@ allprojects {
mavenCentral()
}
// 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}")
// Kotlin
kotlin {
// Targets
// -> JVM
jvm()
// -> Native
linuxX64()
linuxArm64()
mingwX64()
// 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"))
// 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

2
dist/detekt.yml vendored
View file

@ -28,6 +28,8 @@ complexity:
naming:
MemberNameEqualsClassName:
active: false
MatchingDeclarationName:
active: false
exceptions:
SwallowedException:

View file

@ -1,5 +1,3 @@
import java.net.URI
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Authors

View file

@ -24,11 +24,15 @@ plugins {
id("com.gradleup.shadow") version ("8.3.5")
}
// Dependencies
dependencies {
// sos!engine
implementation(project(":base"))
implementation(project(":ansi"))
kotlin {
// Dependencies
sourceSets {
commonMain.dependencies {
// sos!engine
implementation(project(":base"))
implementation(project(":ansi"))
}
}
}
// Configure JAR

View file

@ -24,6 +24,7 @@ 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.

Some files were not shown because too many files have changed in this diff Show more