diff --git a/base/src/main/java/de/staropensource/sosengine/base/Engine.java b/base/src/main/java/de/staropensource/sosengine/base/Engine.java index 4eb265cb..4b3eaa5e 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/Engine.java +++ b/base/src/main/java/de/staropensource/sosengine/base/Engine.java @@ -153,9 +153,10 @@ public final class Engine extends SubsystemClass { /** * Initializes the StarOpenSource Engine. * + * @throws IllegalStateException when running in an incompatible environment * @since v1-alpha0 */ - public Engine() { + public Engine() throws IllegalStateException { if (instance == null) instance = this; else @@ -169,6 +170,8 @@ public final class Engine extends SubsystemClass { logger.info("Initializing engine"); initializeClasses(); // Initialize classes + if (checkEnvironment()) + throw new IllegalStateException("Running in an incompatible environment"); populateCrashContent(); // Populate crash content cacheEvents(); // Cache event listeners startThreads(); // Start threads @@ -192,6 +195,20 @@ public final class Engine extends SubsystemClass { logger.info("Initialized sos!engine %engine_version% (commit %engine_git_commit_id_long%-%engine_git_branch%, dirty %engine_git_dirty%) in " + initTime + "ms"); } + /** + * Checks if the environment is compatible with the engine build. + * + * @since v1-alpha4 + */ + private boolean checkEnvironment() { + logger.diag("Checking environment"); + + if (JvmInformation.getJavaVersion() > EngineInformation.getJavaSource()) + logger.warn("The StarOpenSource Engine is running on an untested Java version.\nThings may not work as expected or features which can improve performance, stability, compatibility or ease of use may be missing.\nIf you encounter issues, try running a JVM implementing Java " + EngineInformation.getJavaSource()); + + return false; + } + /** * Initializes all classes. * diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/information/EngineInformation.java b/base/src/main/java/de/staropensource/sosengine/base/data/information/EngineInformation.java index d17bfc37..ed2f1f48 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/data/information/EngineInformation.java +++ b/base/src/main/java/de/staropensource/sosengine/base/data/information/EngineInformation.java @@ -135,6 +135,33 @@ public final class EngineInformation { private static String versioningString; + /** + * Contains the Java version of the engine source. + * + * @since v1-alpha4 + * -- GETTER -- + * Returns the Java version of the engine source. + * + * @return java version of engine source + * @since v1-alpha4 + */ + @Getter + private static short javaSource; + + /** + * Contains the Java version the engine was compiled against. + * + * @since v1-alpha4 + * -- GETTER -- + * Returns the Java version the engine was compiled against. + * + * @return java version compiled against + * @since v1-alpha4 + */ + @Getter + private static short javaTarget; + + /** * Contains the {@code dirty} value (i.e. if the source tree has been modified). * @@ -382,6 +409,9 @@ public final class EngineInformation { versioningFork = gradleParser.getString("versioningFork"); versioningString = "v" + versioningVersion + "-" + (versioningType == VersionType.RELEASE_CANDIDATE ? "releasecandidate" : versioningType.name().toLowerCase(Locale.ROOT)) + versioningTyperelease + versioningFork; + javaSource = gradleParser.getShort("javaSource"); + javaTarget = gradleParser.getShort("javaTarget"); + dependencyJansi = gradleParser.getString("dependencyJansi"); dependencyReflections = gradleParser.getString("dependencyReflections"); dependencySlf4j = gradleParser.getString("dependencySlf4j"); diff --git a/build.gradle b/build.gradle index be5a56fc..b0cc542f 100644 --- a/build.gradle +++ b/build.gradle @@ -96,6 +96,11 @@ allprojects { group = project.group version = project.versioningVersion + "-" + project.versioningType + project.versioningTyperelease + project.versioningFork + java { + setSourceCompatibility(JavaVersion.valueOf("VERSION_" + project.javaSource)) + setTargetCompatibility(JavaVersion.valueOf("VERSION_" + project.javaTarget)) + } + repositories { mavenCentral() } diff --git a/gradle.properties b/gradle.properties index d45e89a3..0a195fde 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,6 +24,10 @@ versioningType=alpha versioningTyperelease=4 versioningFork= +# Java +javaSource=22 +javaTarget=21 + # Shared Dependencies dependencyLombok=1.18.32 dependencyJetbrainsAnnotations=24.1.0