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
This commit is contained in:
JeremyStar™ 2024-08-18 10:49:46 +02:00
parent 081ac106f4
commit 05b9644eba
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 57 additions and 1 deletions

View file

@ -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.
*

View file

@ -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");

View file

@ -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()
}

View file

@ -24,6 +24,10 @@ versioningType=alpha
versioningTyperelease=4
versioningFork=
# Java
javaSource=22
javaTarget=21
# Shared Dependencies
dependencyLombok=1.18.32
dependencyJetbrainsAnnotations=24.1.0