From 05b9644eba5263809b6655dabb92669523a95805 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 18 Aug 2024 10:49:46 +0200 Subject: [PATCH] Set java source and target versions This commit also introduces a warning when running the engine on a Java version higher than the engine source is on --- .../staropensource/sosengine/base/Engine.java | 19 +++++++++++- .../data/information/EngineInformation.java | 30 +++++++++++++++++++ build.gradle | 5 ++++ gradle.properties | 4 +++ 4 files changed, 57 insertions(+), 1 deletion(-) 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 4eb265c..4b3eaa5 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 d17bfc3..ed2f1f4 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 be5a56f..b0cc542 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 d45e89a..0a195fd 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