Compare commits
No commits in common. "develop" and "v1-alpha4" have entirely different histories.
315 changed files with 5142 additions and 7553 deletions
|
@ -1,7 +1,7 @@
|
|||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="allowReplaceRegexp" value="Copyright .* The StarOpenSource Engine Authors" />
|
||||
<option name="allowReplaceRegexp" value="Copyright .* The StarOpenSource Engine Contributors" />
|
||||
<option name="notice" value="STAROPENSOURCE ENGINE SOURCE FILE Copyright (c) &#36;today.year The StarOpenSource Engine Authors Licensed under the GNU Affero General Public License v3 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>." />
|
||||
<option name="myName" value="sos!engine" />
|
||||
</copyright>
|
||||
</component>
|
||||
</component>
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -16,7 +16,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Plugins
|
||||
plugins {
|
||||
id("java")
|
||||
|
@ -24,8 +23,9 @@ plugins {
|
|||
id("maven-publish")
|
||||
}
|
||||
|
||||
// Dependencies
|
||||
// Project dependencies
|
||||
dependencies {
|
||||
// -> Runtime <-
|
||||
// Lombok
|
||||
compileOnly("org.projectlombok:lombok:${dependencyLombok}")
|
||||
annotationProcessor("org.projectlombok:lombok:${dependencyLombok}")
|
||||
|
@ -33,11 +33,36 @@ dependencies {
|
|||
// JetBrains Annotations
|
||||
compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
|
||||
|
||||
// Jansi
|
||||
// ANSI support
|
||||
implementation("org.fusesource.jansi:jansi:${dependencyJansi}")
|
||||
|
||||
// Project
|
||||
implementation(project(":base"))
|
||||
|
||||
// -> Testing <-
|
||||
// Jetbrains Annotations
|
||||
testCompileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
|
||||
|
||||
// JUnit
|
||||
testImplementation(platform("org.junit:junit-bom:${dependencyJunit}"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
// Fix delombok task
|
||||
delombok.doFirst {
|
||||
File target = file("${project.projectDir}/src/main/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
delombok.doLast {
|
||||
File target = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
|
||||
// Javadoc configuration
|
||||
|
@ -63,6 +88,26 @@ javadoc {
|
|||
}
|
||||
}
|
||||
|
||||
// Unit testing configuration
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
|
||||
// Pass test configuration to test VMs
|
||||
Map<String, String> testConfiguration = new HashMap<>();
|
||||
for (String property : project.properties.keySet())
|
||||
if (property.startsWith("test."))
|
||||
testConfiguration.put(property, project.properties.get(property).toString())
|
||||
systemProperties(testConfiguration)
|
||||
|
||||
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
|
||||
setForkEvery(1)
|
||||
setFailFast(true)
|
||||
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
// Include javadoc and source jar during publishing
|
||||
java {
|
||||
withJavadocJar()
|
||||
|
@ -75,7 +120,7 @@ publishing {
|
|||
repositories {
|
||||
maven {
|
||||
name = "staropensource"
|
||||
url = uri("https://mvn.staropensource.de/engine")
|
||||
url = uri("https://mvn.staropensource.de/sosengine")
|
||||
credentials(org.gradle.api.credentials.PasswordCredentials)
|
||||
authentication {
|
||||
//noinspection GroovyAssignabilityCheck
|
||||
|
@ -94,19 +139,3 @@ publishing {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fix delombok task
|
||||
delombok.doFirst {
|
||||
File target = file("${project.projectDir}/src/main/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
delombok.doLast {
|
||||
File target = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
|
|
|
@ -17,15 +17,16 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.ansi;
|
||||
package de.staropensource.sosengine.ansi;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Prints colored log output using the Jansi library.
|
||||
|
@ -36,22 +37,34 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class AnsiLoggingAdapter implements LoggingAdapter {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public AnsiLoggingAdapter() {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return format; // No modifications necessary
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String postPlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return format; // No modifications necessary
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@SuppressWarnings({ "resource" }) // Using try-with-resources will cause issues here
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
||||
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
// Convert to Ansi
|
||||
Ansi output = new AnsiShortcodeParser(format, true).getAnsi();
|
||||
Ansi output = new AnsiShortcodeConverter(format, true).getAnsi();
|
||||
|
||||
// Print message
|
||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||
if (EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
||||
AnsiConsole.out().println(output);
|
||||
else
|
||||
AnsiConsole.err().println(output);
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.ansi;
|
||||
package de.staropensource.sosengine.ansi;
|
||||
|
||||
import de.staropensource.engine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.engine.base.exception.ParserException;
|
||||
import de.staropensource.sosengine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.sosengine.base.exception.ParserException;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -28,22 +28,21 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link ShortcodeParser} class
|
||||
* with ANSI support using the Jansi library.
|
||||
* Converts shortcodes such as {@code <bold>} or {@code <blink>} into a usable {@link Ansi} escape sequence.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @since v1-alpha8
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public final class AnsiShortcodeParser extends ShortcodeParser {
|
||||
public final class AnsiShortcodeConverter extends ShortcodeParser {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @param string string to convert
|
||||
* @param ignoreInvalidEscapes will ignore invalid escapes and print treat them like regular text
|
||||
* @throws ParserException when parsing failed
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public AnsiShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
public AnsiShortcodeConverter(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
super(string, ignoreInvalidEscapes);
|
||||
}
|
||||
|
|
@ -17,19 +17,19 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.ansi;
|
||||
package de.staropensource.sosengine.ansi;
|
||||
|
||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import de.staropensource.sosengine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.sosengine.base.implementable.SubsystemClass;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.type.DependencyVector;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Main class of the ANSI Compatibility subsystem.
|
||||
* Main object for the ANSI Compatibility subsystem.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
|
@ -50,7 +50,7 @@ public final class AnsiSubsystem extends SubsystemClass {
|
|||
private static AnsiSubsystem instance = null;
|
||||
|
||||
/**
|
||||
* Initializes this subsystem.
|
||||
* Constructs this subsystem.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
|
@ -59,7 +59,7 @@ public final class AnsiSubsystem extends SubsystemClass {
|
|||
if (instance == null)
|
||||
instance = this;
|
||||
else
|
||||
Logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
|
||||
logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
|
@ -20,4 +20,4 @@
|
|||
/**
|
||||
* Contains the ANSI subsystem code.
|
||||
*/
|
||||
package de.staropensource.engine.ansi;
|
||||
package de.staropensource.sosengine.ansi;
|
|
@ -6,18 +6,22 @@
|
|||
*/
|
||||
module sosengine.ansi {
|
||||
// Dependencies
|
||||
// -> Java
|
||||
// -> Java <-
|
||||
requires transitive java.management;
|
||||
// -> Engine
|
||||
|
||||
// -> Engine <-
|
||||
requires transitive sosengine.base;
|
||||
// -> Libraries
|
||||
|
||||
// -> Common stuff <-
|
||||
requires transitive static lombok;
|
||||
requires transitive org.jetbrains.annotations;
|
||||
|
||||
// -> Subystem-specific dependencies <-
|
||||
requires org.fusesource.jansi;
|
||||
|
||||
// API access
|
||||
exports de.staropensource.engine.ansi;
|
||||
exports de.staropensource.sosengine.ansi;
|
||||
|
||||
// Reflection access
|
||||
opens de.staropensource.engine.ansi;
|
||||
opens de.staropensource.sosengine.ansi;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<!--
|
||||
~ STAROPENSOURCE ENGINE SOURCE FILE
|
||||
~ Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
~ Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||
~ Licensed under the GNU Affero General Public License v3
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Contributors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -26,9 +26,9 @@ plugins {
|
|||
id("maven-publish")
|
||||
}
|
||||
|
||||
// Dependencies
|
||||
// Project dependencies
|
||||
dependencies {
|
||||
// -> Runtime
|
||||
// -> Runtime <-
|
||||
// Lombok
|
||||
compileOnly("org.projectlombok:lombok:${dependencyLombok}")
|
||||
annotationProcessor("org.projectlombok:lombok:${dependencyLombok}")
|
||||
|
@ -39,7 +39,7 @@ dependencies {
|
|||
// Reflections
|
||||
implementation("org.reflections:reflections:${dependencyReflections}")
|
||||
|
||||
// -> Testing
|
||||
// -> Testing <-
|
||||
// Jetbrains Annotations
|
||||
testCompileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
|
||||
|
||||
|
@ -48,10 +48,65 @@ dependencies {
|
|||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
// Project
|
||||
// -> Project <-
|
||||
testImplementation(project(":testing"))
|
||||
}
|
||||
|
||||
// Fix delombok task
|
||||
delombok.doFirst {
|
||||
File target = file("${project.projectDir}/src/main/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
delombok.doLast {
|
||||
File target = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
|
||||
// Copy gradle.properties file
|
||||
// for inclusion in final build
|
||||
tasks.register("copyGradleProperties") {
|
||||
doFirst {
|
||||
File target = file("${project.projectDir}/src/main/resources/sosengine-gradle.properties")
|
||||
File source = file(project(":").projectDir.getPath() + "/gradle.properties")
|
||||
target.delete()
|
||||
Files.copy(source.toPath(), target.toPath())
|
||||
}
|
||||
|
||||
outputs.upToDateWhen({ false }) // Force task execution
|
||||
}
|
||||
processResources.dependsOn(copyGradleProperties)
|
||||
|
||||
// Git properties configuration
|
||||
// Allows us to embed git commit information in the engine build
|
||||
gitProperties {
|
||||
dotGitDirectory = file("${rootProject.rootDir}/.git")
|
||||
failOnNoGitDirectory = false // Allow continuing if .git directory is missing for the few who use tarballs
|
||||
extProperty = "gitProps"
|
||||
|
||||
dateFormat = "yyyy-MM-dd'T'HH:mmZ"
|
||||
dateFormatTimeZone = "UTC"
|
||||
}
|
||||
|
||||
tasks.register("writeGitProperties") { // This task's only purpose is to copy the git.properties from our git properties plugin to the resources directory so it's included in the final build
|
||||
doLast {
|
||||
File target = file("${project.projectDir}/src/main/resources/sosengine-git.properties")
|
||||
File source = file("${project.projectDir}/build/resources/main/git.properties")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
|
||||
outputs.upToDateWhen({ false }) // Force task execution
|
||||
}
|
||||
generateGitProperties.outputs.upToDateWhen({ false }) // Force task execution
|
||||
processResources.dependsOn(writeGitProperties) // Ensure git.properties file is present
|
||||
|
||||
// Javadoc configuration
|
||||
javadoc {
|
||||
outputs.upToDateWhen { false } // Force task execution
|
||||
|
@ -107,7 +162,7 @@ publishing {
|
|||
repositories {
|
||||
maven {
|
||||
name = "staropensource"
|
||||
url = uri("https://mvn.staropensource.de/engine")
|
||||
url = uri("https://mvn.staropensource.de/sosengine")
|
||||
credentials(org.gradle.api.credentials.PasswordCredentials)
|
||||
authentication {
|
||||
//noinspection GroovyAssignabilityCheck
|
||||
|
@ -126,58 +181,3 @@ publishing {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy gradle.properties file
|
||||
// for inclusion in final build
|
||||
tasks.register("copyGradleProperties") {
|
||||
doFirst {
|
||||
File target = file("${project.projectDir}/src/main/resources/sosengine-gradle.properties")
|
||||
File source = file(project(":").projectDir.getPath() + "/gradle.properties")
|
||||
target.delete()
|
||||
Files.copy(source.toPath(), target.toPath())
|
||||
}
|
||||
|
||||
outputs.upToDateWhen({ false }) // Force task execution
|
||||
}
|
||||
processResources.dependsOn(copyGradleProperties)
|
||||
|
||||
// Git properties configuration
|
||||
// Allows us to embed git commit information in the engine build
|
||||
gitProperties {
|
||||
dotGitDirectory = file("${rootProject.rootDir}/.git")
|
||||
failOnNoGitDirectory = false // Allow continuing if .git directory is missing for the few who use tarballs
|
||||
extProperty = "gitProps"
|
||||
|
||||
dateFormat = "yyyy-MM-dd'T'HH:mmZ"
|
||||
dateFormatTimeZone = "UTC"
|
||||
}
|
||||
|
||||
tasks.register("writeGitProperties") { // This task's only purpose is to copy the git.properties from our git properties plugin to the resources directory so it's included in the final build
|
||||
doLast {
|
||||
File target = file("${project.projectDir}/src/main/resources/sosengine-git.properties")
|
||||
File source = file("${project.projectDir}/build/resources/main/git.properties")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
|
||||
outputs.upToDateWhen({ false }) // Force task execution
|
||||
}
|
||||
generateGitProperties.outputs.upToDateWhen({ false }) // Force task execution
|
||||
processResources.dependsOn(writeGitProperties) // Ensure git.properties file is present
|
||||
|
||||
// Fix delombok task
|
||||
delombok.doFirst {
|
||||
File target = file("${project.projectDir}/src/main/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
delombok.doLast {
|
||||
File target = file("${project.projectDir}/src/main/java/module-info.java")
|
||||
File source = file("${project.projectDir}/src/main/module-info.java")
|
||||
|
||||
target.delete()
|
||||
source.renameTo(target)
|
||||
}
|
||||
|
|
|
@ -1,414 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Configuration;
|
||||
import de.staropensource.engine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.logging.backend.async.LoggingThread;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.engine.base.type.vector.Vec2f;
|
||||
import de.staropensource.engine.base.type.vector.Vec2i;
|
||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Provides the base engine configuration.
|
||||
* <p>
|
||||
* This class does not only provide engine settings but is also
|
||||
* responsible for loading them into memory from {@link Properties} objects.
|
||||
* <p>
|
||||
* Now you might ask why we didn't go with the string-based approach.
|
||||
* The answer is simple: It's a maintenance burden.
|
||||
* Having various settings strings scattered across many classes will cause
|
||||
* trouble at some point, which will cause some strings to be undocumented
|
||||
* or have an inconsistent naming scheme. Containing settings as variables in
|
||||
* one centralized place mitigates this.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class EngineConfiguration extends Configuration {
|
||||
/**
|
||||
* Contains the class instance.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the class instance.
|
||||
*
|
||||
* @return class instance unless {@link Engine} is uninitialized
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static EngineConfiguration instance;
|
||||
|
||||
/**
|
||||
* Contains prefix properties must begin with.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns prefix properties must begin with.
|
||||
*
|
||||
* @return property group
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @NotNull String group = "sosengine.base.";
|
||||
|
||||
|
||||
/**
|
||||
* If enabled, allows for unintentional behaviour
|
||||
* and excess logging. Unless you want to debug or work
|
||||
* on a sensitive part of the engine, don't enable this!
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debug}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debug
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
/**
|
||||
* If enabled, all called events will be logged.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debugEvents}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debugEvents
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debugEvents;
|
||||
|
||||
|
||||
/**
|
||||
* If enabled, will try to automatically initialize every
|
||||
* subsystem found though reflection.
|
||||
* <p>
|
||||
* This however may fail in certain situation, where manual
|
||||
* subsystem initialization may be required. For this reason,
|
||||
* this can be turned off before the engine initializes. Please
|
||||
* note though that dependency resolution between subsystems
|
||||
* won't be performed, be careful when initializing subsystems manually.
|
||||
*
|
||||
* @see Engine
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #initialPerformSubsystemInitialization}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #initialPerformSubsystemInitialization
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private boolean initialPerformSubsystemInitialization;
|
||||
|
||||
/**
|
||||
* Will try to load the specified classes as subsystems,
|
||||
* if reflective classpath scanning is disabled.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #initialIncludeSubsystemClasses}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #initialIncludeSubsystemClasses
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private Set<@NotNull String> initialIncludeSubsystemClasses;
|
||||
|
||||
|
||||
/**
|
||||
* If enabled, will cause {@link ShortcodeParser} to print
|
||||
* invalid shortcodes as {@link LogLevel#SILENT_WARNING}s.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @see #logLevel
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #errorShortcodeParser}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #errorShortcodeParser
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean errorShortcodeParser;
|
||||
|
||||
|
||||
/**
|
||||
* If enabled, will makes the {@link Logger} work asynchronous,
|
||||
* in a separate platform thread. Don't disable unless you want
|
||||
* your application to run <b>extremely</b> slowly.
|
||||
*
|
||||
* @see #logPollingSpeed
|
||||
* @see Thread
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeLogging}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeLogging
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean optimizeLogging;
|
||||
|
||||
/**
|
||||
* If enabled, will make all events asynchronous,
|
||||
* in separate virtual threads. Don't disable unless you
|
||||
* want your application to run slower.
|
||||
*
|
||||
* @see VirtualThread
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeEvents}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeEvents
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean optimizeEvents;
|
||||
|
||||
|
||||
/**
|
||||
* Contains which logger levels are allowed
|
||||
* by setting the minimum logger level.
|
||||
*
|
||||
* @see Logger
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #logLevel}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #logLevel
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private LogLevel logLevel;
|
||||
|
||||
/**
|
||||
* Contains a comma-separated list of optional
|
||||
* features to add to the final log output.
|
||||
* <p>
|
||||
* Available features (in order of appearance):
|
||||
* <ul>
|
||||
* <li><code>formatting</code></li>
|
||||
* <li><code>runtime</code></li>
|
||||
* <li><code>date</code></li>
|
||||
* <li><code>time</code></li>
|
||||
* <li><code>shortIssuerClass</code></li>
|
||||
* <li><code>moduleName</code></li>
|
||||
* <li><code>moduleVersion</code> (requires <code>moduleName</code>)</li>
|
||||
* <li><code>methodName</code></li>
|
||||
* <li><code>lineNumber</code></li>
|
||||
* </ul>
|
||||
*
|
||||
* @see Logger
|
||||
* @since v1-alpha8
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #logFeatures}
|
||||
*
|
||||
* @return variable value
|
||||
* @see #logFeatures
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private Set<@NotNull String> logFeatures;
|
||||
|
||||
/**
|
||||
* Contains how fast the logging thread will
|
||||
* poll for queued messages. This also causes
|
||||
* messages to be buffered.
|
||||
* <p>
|
||||
* Only applies if {@code optimizeLogging} is turned on.
|
||||
* Values below {@code 1} will poll for queued
|
||||
* messages as fast as it can. This however has pretty much
|
||||
* no benefit. Leave it at {@code 5}, it works quite well.
|
||||
*
|
||||
* @see #optimizeLogging
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #logPollingSpeed}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #logPollingSpeed
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private int logPollingSpeed;
|
||||
|
||||
/**
|
||||
* If enabled, will force sos!engine's logging infrastructure to use
|
||||
* <a href="https://www.man7.org/linux/man-pages/man3/stderr.3.html">the standard output</a>
|
||||
* instead of <a href="https://www.man7.org/linux/man-pages/man3/stderr.3.html">the standard error</a>
|
||||
* for logging the {@code ERROR} and {@code CRASH} log levels.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #logForceStandardOutput}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #logForceStandardOutput
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean logForceStandardOutput;
|
||||
|
||||
|
||||
/**
|
||||
* Will truncate the path of types when using
|
||||
* their {@code toString} method.
|
||||
* <p>
|
||||
* Here's an example: Lets say that you
|
||||
* have a {@link Vec2f} and to convert it
|
||||
* to a String, which you can do with
|
||||
* {@link Vec2f#toString()}. With this flag
|
||||
* disabled it would return
|
||||
* {@code de.staropensource.engine.base.types.vectors.}{@link Vec2i}{@code (x=64 y=64)},
|
||||
* with it however it would just return
|
||||
* {@link Vec2i}{@code (x=64 y=64)},
|
||||
* which is much smaller.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #hideFullTypePath}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #hideFullTypePath
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private boolean hideFullTypePath;
|
||||
|
||||
/**
|
||||
* Constructs this class.
|
||||
*
|
||||
* @see Engine
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
EngineConfiguration() {
|
||||
super();
|
||||
|
||||
instance = this;
|
||||
|
||||
// Load default configuration
|
||||
loadDefaultConfiguration();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
||||
try {
|
||||
switch (property) {
|
||||
case "debug" -> debug = parser.getBoolean(group + property);
|
||||
case "debugEvents" -> debugEvents = parser.getBoolean(group + property);
|
||||
|
||||
case "initialPerformSubsystemInitialization" -> initialPerformSubsystemInitialization = parser.getBoolean(group + property);
|
||||
case "initialIncludeSubsystemClasses" -> {
|
||||
initialIncludeSubsystemClasses = new HashSet<>();
|
||||
initialIncludeSubsystemClasses.addAll(Arrays.stream(parser.getString(group + property).split(",")).toList());
|
||||
}
|
||||
|
||||
case "errorShortcodeParser" -> errorShortcodeParser = parser.getBoolean(group + property);
|
||||
|
||||
case "optimizeLogging" -> {
|
||||
optimizeLogging = parser.getBoolean(group + property);
|
||||
|
||||
// Start logging thread automatically
|
||||
if (optimizeLogging && Engine.getInstance().getState() == EngineState.RUNNING) {
|
||||
LoggingThread.startThread(false);
|
||||
}
|
||||
}
|
||||
case "optimizeEvents" -> optimizeEvents = parser.getBoolean(group + property);
|
||||
|
||||
case "logLevel" -> {
|
||||
try {
|
||||
logLevel = LogLevel.valueOf(parser.getString(group + property).toUpperCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
Logger.error("The log level '" + parser.getString(group + property) + "' is not valid");
|
||||
}
|
||||
}
|
||||
case "logFeatures" -> logFeatures = Set.copyOf(Arrays.stream(parser.getString(group + property).split(",")).toList());
|
||||
case "logPollingSpeed" -> logPollingSpeed = parser.getInteger(group + property, true);
|
||||
case "logForceStandardOutput" -> logForceStandardOutput = parser.getBoolean(group + property);
|
||||
|
||||
case "hideFullTypePath" -> hideFullTypePath = parser.getBoolean(group + property);
|
||||
}
|
||||
} catch (NullPointerException ignored) {}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void processSettings(@NotNull PropertiesReader parser) {
|
||||
// Disable all debugging switches if 'debug' is disabled
|
||||
if (!debug) {
|
||||
debugEvents = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void loadDefaultConfiguration() {
|
||||
debug = false;
|
||||
debugEvents = false;
|
||||
|
||||
initialPerformSubsystemInitialization = true;
|
||||
initialIncludeSubsystemClasses = new HashSet<>();
|
||||
|
||||
errorShortcodeParser = true;
|
||||
|
||||
optimizeLogging = true;
|
||||
optimizeEvents = true;
|
||||
|
||||
logLevel = LogLevel.INFORMATIONAL;
|
||||
logFeatures = Set.of("formatting", "time", "methodName", "lineNumber");
|
||||
logPollingSpeed = 5;
|
||||
logForceStandardOutput = false;
|
||||
|
||||
hideFullTypePath = false;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @Nullable Object getSetting(@NotNull String setting) {
|
||||
return switch (setting) {
|
||||
case "debug" -> debug;
|
||||
case "debugEvents" -> debugEvents;
|
||||
|
||||
case "initialPerformSubsystemInitialization" -> initialPerformSubsystemInitialization;
|
||||
case "initialIncludeSubsystemClasses" -> initialIncludeSubsystemClasses;
|
||||
|
||||
case "errorShortcodeParser" -> errorShortcodeParser;
|
||||
|
||||
case "optimizeLogging" -> optimizeLogging;
|
||||
case "optimizeEvents" -> optimizeEvents;
|
||||
|
||||
case "logLevel" -> logLevel;
|
||||
case "logFeatures" -> logFeatures;
|
||||
case "logPollingSpeed" -> logPollingSpeed;
|
||||
case "logForceStandardOutput" -> logForceStandardOutput;
|
||||
|
||||
case "hideFullTypePath" -> hideFullTypePath;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.type.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Used by {@link EventHelper} to execute event listeners.
|
||||
*
|
||||
* @see Runnable
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public abstract class EventListenerCode {
|
||||
/**
|
||||
* Contains the priority of this
|
||||
* event listener.
|
||||
* <p>
|
||||
* Set automatically by {@link EventHelper},
|
||||
* do not change this manually.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public @NotNull EventPriority priority = EventPriority.DEFAULT;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
protected EventListenerCode() {}
|
||||
|
||||
/**
|
||||
* Invokes the event listener.
|
||||
*
|
||||
* @param arguments arguments passed along by the event
|
||||
* @throws Exception exceptions thrown
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public abstract void run(Object... arguments) throws Exception;
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable.helper;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.EngineInternals;
|
||||
import de.staropensource.engine.base.annotation.EventListener;
|
||||
import de.staropensource.engine.base.event.LogEvent;
|
||||
import de.staropensource.engine.base.exception.reflection.InstanceMethodFromStaticContextException;
|
||||
import de.staropensource.engine.base.exception.reflection.InvalidMethodSignatureException;
|
||||
import de.staropensource.engine.base.exception.reflection.NoAccessException;
|
||||
import de.staropensource.engine.base.exception.reflection.StaticInitializerException;
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.EventListenerCode;
|
||||
import de.staropensource.engine.base.internal.implementation.EventListenerMethod;
|
||||
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.EventPriority;
|
||||
import de.staropensource.engine.base.utility.ListFormatter;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Simplifies event logging and calling.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
public final class EventHelper {
|
||||
/**
|
||||
* Holds all cached events.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private static final @NotNull Map<@NotNull Class<? extends Event>, LinkedList<@NotNull EventListenerCode>> cachedEventListeners = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private EventHelper() {}
|
||||
|
||||
/**
|
||||
* Registers a new {@link Event}.
|
||||
* <p>
|
||||
* This method does nothing if classpath searching is disabled.
|
||||
*
|
||||
* @param event {@link Event} to register for
|
||||
* @param eventListener {@link EventListenerCode} to register
|
||||
* @param priority priority of the listener
|
||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static synchronized void registerEvent(@NotNull Class<? extends Event> event, @NotNull EventListenerCode eventListener, @NotNull EventPriority priority) {
|
||||
if (EngineInternals.getInstance().getReflectiveClasspathScanning())
|
||||
return;
|
||||
|
||||
// Update 'eventListener' priority
|
||||
eventListener.priority = priority;
|
||||
|
||||
// Check if event already exists in map
|
||||
// If not, create entry with a LinkedList
|
||||
if (cachedEventListeners.containsKey(event))
|
||||
if (cachedEventListeners.get(event).contains(eventListener))
|
||||
return;
|
||||
else
|
||||
cachedEventListeners.get(event).add(eventListener);
|
||||
else {
|
||||
LinkedList<@NotNull EventListenerCode> list = new LinkedList<>();
|
||||
list.add(eventListener);
|
||||
cachedEventListeners.put(event, list);
|
||||
}
|
||||
|
||||
Logger.diag("Registered event listener " + eventListener + " for event " + event + " with priority " + priority.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new {@link Event}.
|
||||
* <p>
|
||||
* This method does nothing if classpath searching is disabled.
|
||||
*
|
||||
* @param event {@link Event} to register for
|
||||
* @param eventListener {@link EventListenerCode} to register
|
||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static void registerEvent(@NotNull Class<? extends Event> event, @NotNull EventListenerCode eventListener) {
|
||||
registerEvent(event, eventListener, EventPriority.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Re-)Caches all event listeners for some {@link Event}.
|
||||
* <p>
|
||||
* This method does nothing if classpath searching is enabled.
|
||||
*
|
||||
* @param event event to (re-)cache. Set to {@code null} to recompute all cached events
|
||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static synchronized void cacheEvent(@Nullable Class<? extends Event> event) {
|
||||
if (!EngineInternals.getInstance().getReflectiveClasspathScanning())
|
||||
return;
|
||||
|
||||
if (event == null)
|
||||
for (Class<? extends Event> cachedEvent : cachedEventListeners.keySet())
|
||||
cacheEvent(cachedEvent);
|
||||
else {
|
||||
LinkedList<@NotNull EventListenerCode> annotatedMethods = getAnnotatedMethods(event);
|
||||
|
||||
if (cachedEventListeners.containsKey(event))
|
||||
cachedEventListeners.replace(event, annotatedMethods);
|
||||
else
|
||||
cachedEventListeners.put(event, annotatedMethods);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event from the event listener cache.
|
||||
* <p>
|
||||
* This method does nothing if classpath searching is enabled.
|
||||
*
|
||||
* @param event event to uncache. Set to {@code null} to clear the entire cache
|
||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static synchronized void uncacheEvent(@Nullable Class<? extends Event> event) {
|
||||
if (!EngineInternals.getInstance().getReflectiveClasspathScanning())
|
||||
return;
|
||||
|
||||
if (event == null)
|
||||
cachedEventListeners.clear();
|
||||
else
|
||||
cachedEventListeners.remove(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes all event listeners.
|
||||
*
|
||||
* @param event event class
|
||||
* @param arguments arguments to pass to event listeners
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static void invokeAnnotatedMethods(@NotNull Class<? extends Event> event, Object... arguments) {
|
||||
if (event != LogEvent.class && EngineConfiguration.getInstance().isDebugEvents())
|
||||
if (arguments.length == 0)
|
||||
Logger.diag("Event " + event.getName() + " was emitted");
|
||||
else
|
||||
Logger.diag("Event " + event.getName() + " was emitted, passing arguments " + ListFormatter.formatArray(arguments));
|
||||
|
||||
Runnable eventCode = () -> {
|
||||
for (EventListenerCode eventListener : getAnnotatedMethods(event)) {
|
||||
try {
|
||||
eventListener.run(arguments);
|
||||
} catch (NoAccessException exception) {
|
||||
Logger.warn("Event listener " + eventListener + " could not be called as the method could not be accessed");
|
||||
} catch (InvalidMethodSignatureException exception) {
|
||||
Logger.warn("Event listener " + eventListener + " has an invalid method signature");
|
||||
} catch (InvocationTargetException exception) {
|
||||
Logger.crash("Event listener " + eventListener + " threw a throwable", exception.getTargetException(), true);
|
||||
} catch (InstanceMethodFromStaticContextException exception) {
|
||||
Logger.warn("Event listener " + eventListener + " is not static. Event listener methods must be static for them to be called.");
|
||||
} catch (StaticInitializerException exception) {
|
||||
Logger.crash("Event listener " + eventListener + " could not be called as the static initializer failed", exception.getThrowable(), true);
|
||||
} catch (Exception exception) {
|
||||
Logger.crash("Event listener " + eventListener + " could not be called as an error occurred during reflection", exception, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (EngineConfiguration.getInstance().isOptimizeEvents())
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Event " + event.getName())
|
||||
.start(eventCode);
|
||||
else
|
||||
eventCode.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all {@link EventListener}s listening on some event.
|
||||
* The classpath will be scanned for listeners, unless cached results exist and {@code !forceScanning}.
|
||||
*
|
||||
* @param event event class
|
||||
* @param forceScanning forces scanning the classpath for listeners. not recommended due to a huge performance penalty
|
||||
* @return list of event listeners
|
||||
* @see #cacheEvent(Class)
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static @NotNull LinkedList<EventListenerCode> getAnnotatedMethods(@NotNull Class<? extends Event> event, boolean forceScanning) {
|
||||
LinkedList<EventListenerCode> eventListeners = new LinkedList<>();
|
||||
|
||||
if (!EngineInternals.getInstance().getReflectiveClasspathScanning())
|
||||
return Objects.requireNonNullElse(cachedEventListeners.get(event), eventListeners);
|
||||
|
||||
if (forceScanning || !cachedEventListeners.containsKey(event)) {
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.setUrls(ClasspathHelper.forJavaClassPath())
|
||||
.setScanners(Scanners.MethodsAnnotated)
|
||||
);
|
||||
|
||||
// Get annotated methods
|
||||
Set<@NotNull Method> annotatedMethods = reflections.getMethodsAnnotatedWith(EventListener.class);
|
||||
|
||||
// Sort event listeners not listening for the specified event out
|
||||
for (Method method : annotatedMethods)
|
||||
if (method.getAnnotation(EventListener.class).event() == event)
|
||||
eventListeners.add(new EventListenerMethod(method));
|
||||
|
||||
// Sort list after event priority
|
||||
eventListeners.sort(Comparator.comparing(method -> Objects.requireNonNull(((EventListenerMethod) method).getAnnotation(EventListener.class)).priority()));
|
||||
} else
|
||||
// Event listeners are cached and !forceScanning, return cached results
|
||||
eventListeners = cachedEventListeners.get(event);
|
||||
|
||||
return eventListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all {@link EventListener}s listening on some event.
|
||||
* The classpath will be scanned for listeners, unless cached results exist.
|
||||
*
|
||||
* @param event event class
|
||||
* @return list of event listeners
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public static @NotNull LinkedList<EventListenerCode> getAnnotatedMethods(@NotNull Class<? extends Event> event) {
|
||||
return getAnnotatedMethods(event, false);
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.logging;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Prints log messages to the console, without any fancy colors or formatting.
|
||||
*
|
||||
* @see Logger
|
||||
* @see LoggingAdapter
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public class PlainLoggingAdapter implements LoggingAdapter {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public PlainLoggingAdapter() {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
||||
format = new EmptyShortcodeParser(format, true).getClean();
|
||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
System.out.println(format);
|
||||
else
|
||||
System.err.println(format);
|
||||
else
|
||||
System.out.println(format);
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A set of built-in {@link de.staropensource.engine.base.implementable.LoggingAdapter}s.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.implementation.logging;
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementations for various interfaces and abstract classes.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
package de.staropensource.engine.base.implementation;
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation;
|
||||
|
||||
import de.staropensource.engine.base.implementable.EventListenerCode;
|
||||
import de.staropensource.engine.base.reflection.Reflect;
|
||||
import de.staropensource.engine.base.reflection.ReflectionMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Interface specifically for executing event listener methods.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public final class EventListenerMethod extends EventListenerCode {
|
||||
/**
|
||||
* Contains the method to call and get.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private final @NotNull ReflectionMethod method;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param method method to execute
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public EventListenerMethod(@NotNull Method method) {
|
||||
this.method = Reflect.reflectOn(method);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void run(@Nullable Object @NotNull [] arguments) throws Exception {
|
||||
method.invoke(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards {@link ReflectionMethod#getAnnotation(Class)}
|
||||
* to the internal {@link ReflectionMethod} instance.
|
||||
*
|
||||
* @param <T> annotation
|
||||
* @param annotation annotation to get
|
||||
* @return annotation or {@code null} on error
|
||||
* @see ReflectionMethod#getAnnotation(Class)
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public <T extends Annotation> @Nullable T getAnnotation(@NotNull Class<T> annotation) {
|
||||
try {
|
||||
return method.getAnnotation(annotation);
|
||||
} catch (NullPointerException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String toString() {
|
||||
return "method " + method.getMethod().getDeclaringClass().getName() + "#" + method.getName();
|
||||
}
|
||||
}
|
|
@ -1,416 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.logging;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.engine.base.implementation.logging.PlainLoggingAdapter;
|
||||
import de.staropensource.engine.base.internal.type.QueuedLogCall;
|
||||
import de.staropensource.engine.base.logging.backend.CrashHandler;
|
||||
import de.staropensource.engine.base.logging.backend.Filterer;
|
||||
import de.staropensource.engine.base.logging.backend.Processor;
|
||||
import de.staropensource.engine.base.logging.backend.async.LoggingQueue;
|
||||
import de.staropensource.engine.base.type.immutable.ImmutableArrayList;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.intellij.lang.annotations.RegExp;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The frontend class for sos!engine's logging system.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Logger {
|
||||
/**
|
||||
* Refers to the active {@link LoggingAdapter} that is used to process and print log messages.
|
||||
*
|
||||
* @see LoggingAdapter
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the active {@link LoggingAdapter}.
|
||||
*
|
||||
* @return active {@link LoggingAdapter}
|
||||
* @see LoggingAdapter
|
||||
* @since v1-alpha0
|
||||
* -- SETTER --
|
||||
* Sets the active {@link LoggingAdapter}.
|
||||
*
|
||||
* @param loggingAdapter new active {@link LoggingAdapter}
|
||||
* @see LoggingAdapter
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private static @NotNull LoggingAdapter loggingAdapter = new PlainLoggingAdapter();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private Logger() {}
|
||||
|
||||
// -----> Internal management methods
|
||||
// These methods forward calls to internal methods so
|
||||
// these can be accessed without exporting a whole package.
|
||||
/**
|
||||
* Handles incoming log calls and either
|
||||
* processes them directly or queues them in.
|
||||
* <p>
|
||||
* **This is an internal method. Use with care.**
|
||||
*
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void handle(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
||||
Processor.handle(level, issuer, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the logging queue.
|
||||
* <p>
|
||||
* **This is an internal method. Use with care.**
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void flush() {
|
||||
LoggingQueue.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallows one or multiple classes.
|
||||
*
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void disallowClass(@RegExp @NotNull String regex) {
|
||||
Filterer.disallowClass(regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallows one or multiple modules.
|
||||
*
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void disallowModule(@RegExp @NotNull String regex) {
|
||||
Filterer.disallowModule(regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallows one or multiple messages.
|
||||
*
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void disallowMessage(@RegExp @NotNull String regex) {
|
||||
Filterer.disallowMessage(regex);
|
||||
}
|
||||
|
||||
|
||||
// -----> Redirection methods
|
||||
/**
|
||||
* Redirects regular log messages.
|
||||
*
|
||||
* @param level level of the log call
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void redirectCall(@NotNull LogLevel level, @NotNull String message) {
|
||||
Processor.handle(level, Thread.currentThread().getStackTrace()[3], message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects crash calls.
|
||||
*
|
||||
* @param message message
|
||||
* @param throwable {@link Throwable} which caused the error
|
||||
* @param fatal if to terminate the engine
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void redirectCall(@NotNull String message, @Nullable Throwable throwable, boolean fatal) {
|
||||
CrashHandler.handleCrash(Thread.currentThread().getStackTrace()[3], message, throwable, fatal);
|
||||
}
|
||||
|
||||
|
||||
// -----> Frontend methods
|
||||
/**
|
||||
* Logs a diagnostic message.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void diag(@NotNull String message) {
|
||||
redirectCall(LogLevel.DIAGNOSTIC, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a verbose message.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void verb(@NotNull String message) {
|
||||
redirectCall(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a silent warning.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void sarn(@NotNull String message) {
|
||||
redirectCall(LogLevel.SILENT_WARNING, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an informational message.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void info(@NotNull String message) {
|
||||
redirectCall(LogLevel.INFORMATIONAL, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a warning.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void warn(@NotNull String message) {
|
||||
redirectCall(LogLevel.WARNING, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void error(@NotNull String message) {
|
||||
redirectCall(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a crash report and optionally crashes the engine.
|
||||
*
|
||||
* @param message message to log
|
||||
* @param throwable {@link Throwable} which caused the crash
|
||||
* @param fatal terminates the engine if {@code true}
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void crash(@NotNull String message, @NotNull Throwable throwable, boolean fatal) {
|
||||
redirectCall(message, throwable, fatal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a crash report and optionally crashes the engine.
|
||||
*
|
||||
* @param message message to log
|
||||
* @param throwable {@link Throwable} which caused the crash
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void crash(@NotNull String message, @NotNull Throwable throwable) {
|
||||
redirectCall(message, throwable, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a crash report and optionally crashes the engine.
|
||||
*
|
||||
* @param message message to log
|
||||
* @param fatal terminates the engine if {@code true}
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void crash(@NotNull String message, boolean fatal) {
|
||||
redirectCall(message, null, fatal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a crash report and optionally crashes the engine.
|
||||
*
|
||||
* @param message message to log
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void crash(@NotNull String message) {
|
||||
redirectCall(message, null, true);
|
||||
}
|
||||
|
||||
|
||||
// -----> Legacy frontend methods
|
||||
// This improves compatibility with old code
|
||||
// still using the old logger frontend.
|
||||
/**
|
||||
* Prints a diagnostic message.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #diag(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void diag(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(LogLevel.DIAGNOSTIC, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a verbose message.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #verb(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void verb(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a silent warning message.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #sarn(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void sarn(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(LogLevel.SILENT_WARNING, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an informational message.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #info(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void info(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(LogLevel.INFORMATIONAL, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning message.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #warn(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void warn(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(LogLevel.WARNING, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an error message.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #error(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void error(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @param throwable the throwable that caused this crash
|
||||
* @param handled declares the throwable has handled, not causing the engine to shutdown
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #crash(String, Throwable, boolean)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message, @NotNull Throwable throwable, boolean handled) {
|
||||
redirectCall(message, throwable, !handled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @param throwable the throwable that caused this crash
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #crash(String, Throwable)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message, @NotNull Throwable throwable) {
|
||||
redirectCall(message, throwable, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param ignoredIssuerClass class of the issuer
|
||||
* @param ignoredIssuerOrigin origin of the issuer
|
||||
* @param ignoredIssuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see #crash(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(message, null, true);
|
||||
}
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.logging.backend;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.EngineInternals;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.engine.base.utility.information.JvmInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static de.staropensource.engine.base.logging.backend.Processor.isFeatureEnabled;
|
||||
|
||||
/**
|
||||
* Handles crashes.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class CrashHandler {
|
||||
/**
|
||||
* Contains all random witty comments.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static final @NotNull String[] WITTYCOMMENTS = new String[]{
|
||||
"Who fucked up here?",
|
||||
"What is it now?",
|
||||
":neofox_woozy:",
|
||||
"Oh no!",
|
||||
"my engine brokey brokey",
|
||||
"weird",
|
||||
"Is this a feature?",
|
||||
"$ git blame",
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private CrashHandler() {}
|
||||
|
||||
/**
|
||||
* Handles crash reports.
|
||||
*
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @param throwable {@link Throwable} which caused the error
|
||||
* @param fatal if to terminate the engine
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void handleCrash(@NotNull StackTraceElement issuer, @NotNull String message, @Nullable Throwable throwable, boolean fatal) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
String outputFinal;
|
||||
|
||||
// Header
|
||||
output
|
||||
.append("==== sos!engine crash report ====")
|
||||
.append("\nDear user: The application or game you just used seems to have run into a problem.")
|
||||
.append("\n Please be so kind and report this crash report to the developers so they can fix the issue.")
|
||||
.append("\nDear developer: FIX YOUR SHIT. If the engine is at fault here, please report the crash")
|
||||
.append("\n to StarOpenSource here: https://git.staropensource.de/StarOpenSource/Engine/issues")
|
||||
.append("\n\n// ")
|
||||
.append(WITTYCOMMENTS[new Random().nextInt(WITTYCOMMENTS.length)])
|
||||
.append("\n\n");
|
||||
|
||||
// Information about the crash
|
||||
output
|
||||
.append("---- Crash Information ----\n")
|
||||
.append("Issuer: ")
|
||||
.append(issuer.getClassName())
|
||||
.append("@")
|
||||
.append(issuer.getModuleName())
|
||||
.append("#")
|
||||
.append(issuer.getMethodName())
|
||||
.append("~")
|
||||
.append(issuer.getLineNumber())
|
||||
|
||||
.append("\nFatal: ")
|
||||
.append(fatal);
|
||||
|
||||
if (throwable == null)
|
||||
output
|
||||
.append("\nCaused by:")
|
||||
.append("\nNo throwable has been passed.");
|
||||
else
|
||||
output
|
||||
.append("\n")
|
||||
.append(Miscellaneous.getStackTraceHeader(throwable))
|
||||
.append("\n")
|
||||
.append(Miscellaneous.getStackTraceAsString(throwable, true))
|
||||
.append("\n");
|
||||
|
||||
output.append("\nMessage: \n")
|
||||
.append(message)
|
||||
.append("\n\n");
|
||||
|
||||
// Environment information
|
||||
output
|
||||
.append("---- Environment ----")
|
||||
.append("\nTime and date: ")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), 2))
|
||||
.append(".")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.MONTH), 2))
|
||||
.append(".")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.YEAR), 4))
|
||||
.append(" ")
|
||||
.append(de.staropensource.engine.base.utility.Math.padNumbers(Calendar.getInstance().get(Calendar.HOUR_OF_DAY), 2))
|
||||
.append(":")
|
||||
.append(de.staropensource.engine.base.utility.Math.padNumbers(Calendar.getInstance().get(Calendar.MINUTE), 2))
|
||||
.append(":")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.SECOND), 2))
|
||||
.append(" [")
|
||||
.append(TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT, Locale.US))
|
||||
.append("]")
|
||||
|
||||
.append("\nUNIX Epoch: ")
|
||||
.append(Math.padNumbers(System.currentTimeMillis(), String.valueOf(Long.MAX_VALUE).length()))
|
||||
|
||||
.append("\nOperating system: ")
|
||||
.append(System.getProperty("os.name"))
|
||||
|
||||
.append("\nCPU architecture: ")
|
||||
.append(System.getProperty("os.arch"))
|
||||
|
||||
.append("\nMemory: ")
|
||||
.append(JvmInformation.getMemoryUsed() / 1024)
|
||||
.append(" MiB")
|
||||
.append("/")
|
||||
.append(JvmInformation.getMemoryLimit() / 1024)
|
||||
.append(" MiB")
|
||||
.append(" (stack ")
|
||||
.append(JvmInformation.getMemoryStack().getUsed() / 1024)
|
||||
.append(" MiB")
|
||||
.append("/")
|
||||
.append(JvmInformation.getMemoryStack().getMax() == -1 ? "∞" : JvmInformation.getMemoryStack().getMax() / 1024)
|
||||
.append(" MiB")
|
||||
.append(", heap ")
|
||||
.append(JvmInformation.getMemoryHeap().getUsed() / 1024)
|
||||
.append(" MiB")
|
||||
.append("/")
|
||||
.append(JvmInformation.getMemoryHeap().getMax() == -1 ? "∞" : JvmInformation.getMemoryStack().getMax() / 1024)
|
||||
.append(" MiB)")
|
||||
|
||||
.append("\nJVM: ")
|
||||
.append(JvmInformation.getImplementationName())
|
||||
.append(" ")
|
||||
.append(JvmInformation.getImplementationVersion())
|
||||
.append(" @ ")
|
||||
.append(JvmInformation.getJavaVersion())
|
||||
.append(" by ")
|
||||
.append(JvmInformation.getImplementationVendor())
|
||||
|
||||
.append("\nJVM arguments: ");
|
||||
|
||||
for (String argument : JvmInformation.getArguments())
|
||||
output
|
||||
.append("\n- '")
|
||||
.append(argument)
|
||||
.append("'");
|
||||
|
||||
output.append("\n\n");
|
||||
|
||||
// Engine
|
||||
output.append("---- sos!engine ----\n");
|
||||
|
||||
if (EngineInformation.getVersioningString() == null)
|
||||
output.append("EngineInformation is not yet initialized");
|
||||
else
|
||||
output
|
||||
.append("Version: ")
|
||||
.append(EngineInformation.getVersioningString())
|
||||
|
||||
.append("\nCommit: ")
|
||||
.append(EngineInformation.getGitCommitIdentifierLong())
|
||||
|
||||
.append("\nDirty: ")
|
||||
.append(EngineInformation.isGitDirty());
|
||||
|
||||
output.append("\n\n");
|
||||
|
||||
// Engine configuration
|
||||
output.append("---- sos!engine configuration ----\n");
|
||||
|
||||
if (EngineConfiguration.getInstance() == null)
|
||||
output.append("EngineConfiguration is not yet initialized");
|
||||
else
|
||||
output
|
||||
.append("EngineConfiguration#debug='")
|
||||
.append(EngineConfiguration.getInstance().isDebug())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#debugEvents='")
|
||||
.append(EngineConfiguration.getInstance().isDebugEvents())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#initialPerformSubsystemInitialization='")
|
||||
.append(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#initialIncludeSubsystemClasses='")
|
||||
.append(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#errorShortcodeParser='")
|
||||
.append(EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#optimizeLogging='")
|
||||
.append(EngineConfiguration.getInstance().isOptimizeLogging())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#optimizeEvents='")
|
||||
.append(EngineConfiguration.getInstance().isOptimizeEvents())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#logLevel='")
|
||||
.append(EngineConfiguration.getInstance().getLogLevel().name())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#logSettings='")
|
||||
.append(EngineConfiguration.getInstance().getLogFeatures())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#logPollingSpeed='")
|
||||
.append(EngineConfiguration.getInstance().getLogPollingSpeed())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#logForceStandardOutput='")
|
||||
.append(EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
.append("'\n")
|
||||
|
||||
.append("EngineConfiguration#hideFullTypePath='")
|
||||
.append(EngineConfiguration.getInstance().isHideFullTypePath());
|
||||
|
||||
output.append("'\n\n");
|
||||
|
||||
// System properties
|
||||
output.append("---- System properties ----");
|
||||
|
||||
for (String property : System.getProperties().stringPropertyNames().stream().sorted().toList())
|
||||
output
|
||||
.append("\n")
|
||||
.append(property)
|
||||
.append("='")
|
||||
.append(System.getProperties().getProperty(property).replace("\n", "\\n"))
|
||||
.append("'");
|
||||
|
||||
output.append("\n\n");
|
||||
|
||||
// Stacktraces of all threads
|
||||
output.append("---- Stacktraces of all threads ----");
|
||||
{
|
||||
Map<Thread, StackTraceElement[]> stacktraces = Thread.getAllStackTraces();
|
||||
|
||||
for (Thread thread : stacktraces.keySet())
|
||||
output
|
||||
.append("\n")
|
||||
.append(thread.getName())
|
||||
.append(" (id=")
|
||||
.append(thread.threadId())
|
||||
.append(" priority=")
|
||||
.append(thread.getPriority())
|
||||
.append(" group=")
|
||||
.append(thread.getThreadGroup() == null ? "<unknown>" : thread.getThreadGroup().getName())
|
||||
.append(" state=")
|
||||
.append(thread.getState().name())
|
||||
.append(" daemon=")
|
||||
.append(thread.isDaemon())
|
||||
.append("):")
|
||||
.append("\n")
|
||||
.append(Miscellaneous.getStackTraceAsString(stacktraces.get(thread), false))
|
||||
.append("\n");
|
||||
}
|
||||
output.append("\n");
|
||||
|
||||
// Footer
|
||||
output
|
||||
.append("Dear user: The application or game you just used seems to have run into a problem.\n")
|
||||
.append(" Please be so kind and report this crash report to the developers so they can fix the issue.\n")
|
||||
.append("Dear developer: FIX YOUR SHIT. If the engine is at fault here, please report the crash\n")
|
||||
.append(" to StarOpenSource here: https://git.staropensource.de/StarOpenSource/Engine/issues\n")
|
||||
.append("==== sos!engine crash report ====");
|
||||
|
||||
// Formatting
|
||||
if (isFeatureEnabled("formatting")) {
|
||||
outputFinal =
|
||||
"<fg:red><bold>"
|
||||
+ output
|
||||
.toString()
|
||||
.replace("<", "\\<")
|
||||
+ "<reset>";
|
||||
} else
|
||||
outputFinal = output.toString();
|
||||
|
||||
// Print
|
||||
Logger.getLoggingAdapter().print(LogLevel.CRASH, issuer, message, outputFinal);
|
||||
|
||||
// Terminate engine
|
||||
// We do a test on the engine state here
|
||||
// to prevent bugs and multiple engine shutdowns.
|
||||
if (fatal)
|
||||
switch (Engine.getInstance().getState()) {
|
||||
case UNKNOWN, EARLY_STARTUP, STARTUP -> {
|
||||
if (EngineInternals.getInstance() == null)
|
||||
Runtime.getRuntime().exit(69);
|
||||
else
|
||||
EngineInternals.getInstance().getShutdownHandler().shutdown((short) 69);
|
||||
}
|
||||
case RUNNING -> Engine.getInstance().shutdown(69);
|
||||
case SHUTDOWN, CRASHED -> {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.logging.backend;
|
||||
|
||||
import org.intellij.lang.annotations.RegExp;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Responsible for filtering log messages out.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class Filterer {
|
||||
/**
|
||||
* Contains a list of all disallowed classes.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
static @NotNull List<@NotNull String> disallowedClasses = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Contains a list of all disallowed modules.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
static @NotNull List<@NotNull String> disallowedModules = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Contains a list of all disallowed messages.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
static @NotNull List<@NotNull String> disallowedMessages = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private Filterer() {}
|
||||
|
||||
/**
|
||||
* Disallows one or multiple classes.
|
||||
*
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void disallowClass(@RegExp @NotNull String regex) {
|
||||
disallowedClasses.add(regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallows one or multiple modules.
|
||||
*
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void disallowModule(@RegExp @NotNull String regex) {
|
||||
disallowedModules.add(regex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallows one or multiple messages.
|
||||
*
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void disallowMessage(@RegExp @NotNull String regex) {
|
||||
disallowedMessages.add(regex);
|
||||
}
|
||||
}
|
|
@ -1,375 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.logging.backend;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeParser;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.logging.backend.async.LoggingQueue;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
||||
import de.staropensource.engine.base.utility.information.JvmInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Processes log messages.
|
||||
*
|
||||
* @see #handle(LogLevel, StackTraceElement, String)
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class Processor {
|
||||
/**
|
||||
* Creates and initializes an instance of this class
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private Processor() {}
|
||||
|
||||
/**
|
||||
* Checks whether the specified feature is enabled.
|
||||
*
|
||||
* @param feature feature to check
|
||||
* @return enabled?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static boolean isFeatureEnabled(@NotNull String feature) {
|
||||
return EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().getLogFeatures().contains(feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles incoming log calls and either
|
||||
* processes them directly or queues them in.
|
||||
*
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void handle(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isOptimizeLogging())
|
||||
LoggingQueue.add(level, issuer, message);
|
||||
else
|
||||
process(level, issuer, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a log call.
|
||||
*
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void process(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
// Filter out
|
||||
if (EngineConfiguration.getInstance() == null) {
|
||||
LogLevel maxLevel = LogLevel.INFORMATIONAL;
|
||||
|
||||
try {
|
||||
maxLevel = LogLevel.valueOf(System.getProperties().getProperty("sosengine.base.logLevel", "informational").toUpperCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
Logger.error("The log level '" + System.getProperties().getProperty("sosengine.base.logLevel", "informational") + "' is not valid");
|
||||
}
|
||||
|
||||
if (level.compareTo(maxLevel) < 0)
|
||||
return;
|
||||
} else if (level.compareTo(EngineConfiguration.getInstance().getLogLevel()) < 0)
|
||||
return;
|
||||
|
||||
for (String classNameDisallowed : Filterer.disallowedClasses)
|
||||
if (issuer.getClassName().matches(classNameDisallowed))
|
||||
return;
|
||||
for (String moduleNameDisallowed : Filterer.disallowedModules)
|
||||
if (issuer.getModuleName().matches(moduleNameDisallowed))
|
||||
return;
|
||||
for (String messageDisallowed : Filterer.disallowedModules)
|
||||
if (message.matches(messageDisallowed))
|
||||
return;
|
||||
|
||||
format(output, level);
|
||||
runtime(output);
|
||||
if (isFeatureEnabled("date") || isFeatureEnabled("time")) {
|
||||
output.append("[");
|
||||
date(output);
|
||||
if (isFeatureEnabled("date"))
|
||||
output.append(" ");
|
||||
time(output);
|
||||
output.append("] ");
|
||||
}
|
||||
output.append("[");
|
||||
level(output, level);
|
||||
format(output, level);
|
||||
output.append(" ");
|
||||
issuerClass(output, level, issuer);
|
||||
issuerModule(output, level, issuer);
|
||||
methodName(output, level, issuer);
|
||||
lineNumber(output, level, issuer);
|
||||
output.append("] ");
|
||||
message(output, message);
|
||||
format(output, "reset");
|
||||
|
||||
// Print
|
||||
Logger.getLoggingAdapter().print(level, issuer, message, output.toString());
|
||||
}
|
||||
|
||||
// -----> Formatting
|
||||
/**
|
||||
* Adds the {@code formatting} feature.
|
||||
* <p>
|
||||
* This method will reset and then color the following
|
||||
* substring in the log level-specific color.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param level level of the log call
|
||||
* @see #format(StringBuilder, String)
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void format(@NotNull StringBuilder builder, @NotNull LogLevel level) {
|
||||
format(builder, "reset");
|
||||
format(builder, switch (level) {
|
||||
case DIAGNOSTIC, VERBOSE -> "fg:blue";
|
||||
case SILENT_WARNING, WARNING -> "fg:yellow";
|
||||
case INFORMATIONAL -> "fg:white";
|
||||
case ERROR -> "fg:red";
|
||||
case CRASH -> "you should not see this";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code formatting} feature.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param component formatting component
|
||||
* @see #format(StringBuilder, LogLevel)
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void format(@NotNull StringBuilder builder, @NotNull String component) {
|
||||
if (isFeatureEnabled("formatting"))
|
||||
builder
|
||||
.append("<")
|
||||
.append(component)
|
||||
.append(">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code formatting} feature.
|
||||
*
|
||||
* @param string string to sanitize
|
||||
* @return sanitized string
|
||||
* @see #format(StringBuilder, LogLevel)
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static @NotNull String sanitizeFormat(@NotNull String string) {
|
||||
if (isFeatureEnabled("formatting"))
|
||||
return string.replace("<", "\\<");
|
||||
else
|
||||
return string;
|
||||
}
|
||||
|
||||
// -----> Features and components
|
||||
/**
|
||||
* Adds the {@code runtime} feature.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void runtime(@NotNull StringBuilder builder) {
|
||||
if (isFeatureEnabled("runtime"))
|
||||
builder
|
||||
.append("[")
|
||||
.append(JvmInformation.getUptime())
|
||||
.append("ms")
|
||||
.append("] ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code time} feature.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void time(@NotNull StringBuilder builder) {
|
||||
if (isFeatureEnabled("time"))
|
||||
builder
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.HOUR_OF_DAY), 2))
|
||||
.append(":")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.MINUTE), 2))
|
||||
.append(":")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.SECOND), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code date} feature.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void date(@NotNull StringBuilder builder) {
|
||||
if (isFeatureEnabled("date"))
|
||||
builder
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), 2))
|
||||
.append(".")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.MONTH), 2))
|
||||
.append(".")
|
||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.YEAR), 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code level} component.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param level level of the log call
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void level(@NotNull StringBuilder builder, @NotNull LogLevel level) {
|
||||
format(builder, "bold");
|
||||
|
||||
builder.append(switch (level) {
|
||||
case DIAGNOSTIC -> "DIAG";
|
||||
case VERBOSE -> "VERB";
|
||||
case SILENT_WARNING -> "SARN";
|
||||
case INFORMATIONAL -> "INFO";
|
||||
case WARNING -> "WARN";
|
||||
case ERROR -> "ERR!";
|
||||
case CRASH -> "CRSH";
|
||||
});
|
||||
|
||||
format(builder, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code issuer class} component.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void issuerClass(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
||||
format(builder, "bold");
|
||||
|
||||
if (isFeatureEnabled("shortIssuerClass")) {
|
||||
String[] classNameSplit = issuer.getClassName().split("\\.");
|
||||
builder.append(classNameSplit[classNameSplit.length - 1]);
|
||||
} else
|
||||
builder.append(issuer.getClassName());
|
||||
|
||||
format(builder, level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code moduleName} and {@code moduleVersion} features.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void issuerModule(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
||||
if (isFeatureEnabled("moduleName") && issuer.getModuleName() != null) {
|
||||
format(builder, "bold");
|
||||
|
||||
builder
|
||||
.append("@")
|
||||
.append(issuer.getModuleName());
|
||||
|
||||
if (isFeatureEnabled("moduleVersion") && issuer.getModuleVersion() != null)
|
||||
builder
|
||||
.append("v")
|
||||
.append(issuer.getModuleVersion());
|
||||
|
||||
format(builder, level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code methodName} feature.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void methodName(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
||||
if (isFeatureEnabled("methodName")) {
|
||||
builder.append("#");
|
||||
format(builder, "bold");
|
||||
builder.append(sanitizeFormat(issuer.getMethodName()));
|
||||
format(builder, level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code lineNumber} feature.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void lineNumber(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
||||
if (isFeatureEnabled("lineNumber")) {
|
||||
builder.append("~");
|
||||
format(builder, "bold");
|
||||
builder.append(issuer.getLineNumber());
|
||||
format(builder, level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@code message} component.
|
||||
*
|
||||
* @param builder {@link StringBuilder} instance to append to
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void message(@NotNull StringBuilder builder, @NotNull String message) {
|
||||
builder.append(sanitizeFormat(handlePlaceholders(
|
||||
message.replace(
|
||||
"\n",
|
||||
"\n" + " ".repeat(new EmptyShortcodeParser(builder.toString(), true).getClean().length())
|
||||
)
|
||||
)));
|
||||
}
|
||||
|
||||
// -----> Utility methods
|
||||
/**
|
||||
* Uses the {@link PlaceholderEngine} to replace
|
||||
* all placeholders within a specified string and
|
||||
* returns it's result. The original string will
|
||||
* be returned if the {@link PlaceholderEngine}
|
||||
* is not yet initialized.
|
||||
*
|
||||
* @param string string to use
|
||||
* @return updated string
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static @NotNull String handlePlaceholders(@NotNull String string) {
|
||||
if (PlaceholderEngine.getInstance() == null)
|
||||
return string;
|
||||
else
|
||||
return PlaceholderEngine.getInstance().process(string);
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.logging.backend.async;
|
||||
|
||||
import de.staropensource.engine.base.internal.type.QueuedLogCall;
|
||||
import de.staropensource.engine.base.logging.backend.Processor;
|
||||
import de.staropensource.engine.base.type.immutable.ImmutableArrayList;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Handles everything related to the logging queue.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class LoggingQueue {
|
||||
/**
|
||||
* Contains the logging queue.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static final @NotNull List<@NotNull QueuedLogCall> queue = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private LoggingQueue() {}
|
||||
|
||||
/**
|
||||
* Adds a new entry to the logging queue.
|
||||
*
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void add(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
||||
queue.add(new QueuedLogCall(level, issuer, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the logging queue.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void flush() {
|
||||
// Get copy of and clear queue
|
||||
List<@NotNull QueuedLogCall> queue = new ImmutableArrayList<>(LoggingQueue.queue);
|
||||
LoggingQueue.queue.clear();
|
||||
|
||||
for (QueuedLogCall queuedCall : queue)
|
||||
Processor.process(queuedCall.level(), queuedCall.issuer(), queuedCall.message());
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.logging.backend.async;
|
||||
|
||||
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.EngineState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Handles the logging thread.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class LoggingThread {
|
||||
/**
|
||||
* Contains the logging thread.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static Thread thread;
|
||||
|
||||
/**
|
||||
* Contains the code of the logging thread.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static final @NotNull Runnable threadCode = () -> {
|
||||
int pollingSpeed;
|
||||
|
||||
while (!(
|
||||
Thread.currentThread().isInterrupted()
|
||||
|| !(EngineConfiguration.getInstance() == null || EngineConfiguration.getInstance().isOptimizeLogging())
|
||||
|| Engine.getInstance().getState() == EngineState.SHUTDOWN
|
||||
|| Engine.getInstance().getState() == EngineState.CRASHED
|
||||
)) {
|
||||
if (EngineConfiguration.getInstance() == null)
|
||||
pollingSpeed = 5;
|
||||
else
|
||||
pollingSpeed = EngineConfiguration.getInstance().getLogPollingSpeed();
|
||||
|
||||
// Flush all log messages
|
||||
LoggingQueue.flush();
|
||||
|
||||
// Sleep for whatever has been configured
|
||||
if (pollingSpeed > 0) {
|
||||
long sleepDuration = System.currentTimeMillis() + pollingSpeed;
|
||||
while (System.currentTimeMillis() < sleepDuration)
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
constructThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private LoggingThread() {}
|
||||
|
||||
/**
|
||||
* Constructs the logging thread.
|
||||
*
|
||||
* @see #thread
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void constructThread() {
|
||||
thread = Thread
|
||||
.ofPlatform()
|
||||
.daemon()
|
||||
.name("Logging thread")
|
||||
.group(Engine.getThreadGroup())
|
||||
.priority(Thread.MAX_PRIORITY)
|
||||
.stackSize(10)
|
||||
.unstarted(threadCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Re-)Starts the logging thread.
|
||||
*
|
||||
* @param allowRestart if the logging thread should be restarted if it's stopped
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void startThread(boolean allowRestart) {
|
||||
if (allowRestart && thread.isAlive()) {
|
||||
// Executing the restart logic in another thread prevents
|
||||
// this thread from being fully blocked while still ensuring
|
||||
// that the logging thread is properly restarted
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Logging thread restart thread")
|
||||
.start(() -> {
|
||||
Logger.diag("Restarting the logging thread");
|
||||
|
||||
// Interrupt thread
|
||||
// This let's our thread code know that it should terminate
|
||||
thread.interrupt();
|
||||
|
||||
// Make sure that the logging thread is dead before reconstructing and starting it
|
||||
while (thread.isAlive())
|
||||
Thread.onSpinWait();
|
||||
|
||||
constructThread();
|
||||
thread.start();
|
||||
});
|
||||
} else
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Thread.State} of the logging thread.
|
||||
*
|
||||
* @return logging thread state
|
||||
* @see Thread.State
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static @NotNull Thread.State getState() {
|
||||
return thread.getState();
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Everything related to making the logging
|
||||
* infrastructure asynchronous.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
package de.staropensource.engine.base.logging.backend.async;
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The backend of sos!engine's logging infrastructure.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
package de.staropensource.engine.base.logging.backend;
|
|
@ -1,301 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* A class dedicated to colors.
|
||||
* Uses the RGBA format, with conversion methods
|
||||
* supporting RGB and RGBA & RGB encoded in
|
||||
* bytes or hex.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Color {
|
||||
/**
|
||||
* Contains the red color value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the red color value.
|
||||
*
|
||||
* @return red color value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the red color value.
|
||||
*
|
||||
* @param red new red color value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private @Range(from = 0, to = 255) int red;
|
||||
/**
|
||||
* Contains the green color value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the green color value.
|
||||
*
|
||||
* @return green color value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the green color value.
|
||||
*
|
||||
* @param green new green color value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private @Range(from = 0, to = 255) int green;
|
||||
/**
|
||||
* Contains the blue color value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the blue color value.
|
||||
*
|
||||
* @return blue color value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the blue color value.
|
||||
*
|
||||
* @param blue new blue color value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private @Range(from = 0, to = 255) int blue;
|
||||
/**
|
||||
* Contains the alpha channel value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the alpha channel value.
|
||||
*
|
||||
* @return alpha channel value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the alpha channel value.
|
||||
*
|
||||
* @param alpha new alpha channel value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private @Range(from = 0, to = 255) int alpha;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param red red color value
|
||||
* @param green green color value
|
||||
* @param blue blue color value
|
||||
* @param alpha alpha channel value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private Color(int red, int green, int blue, int alpha) {
|
||||
this.red = Math.boundNumber(0, 255, red);
|
||||
this.green = Math.boundNumber(0, 255, green);
|
||||
this.blue = Math.boundNumber(0, 255, blue);
|
||||
this.alpha = Math.boundNumber(0, 255, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the a set of numbers in
|
||||
* the RGBA format into a new instance.
|
||||
*
|
||||
* @param red red color value
|
||||
* @param blue blue color value
|
||||
* @param green green color value
|
||||
* @param alpha alpha color value
|
||||
* @return new {@link Color} instance
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static @NotNull Color fromRGBA(@Range(from = 0, to = 255) int red, @Range(from = 0, to = 255) int green,
|
||||
@Range(from = 0, to = 255) int blue, @Range(from = 0, to = 255) int alpha) {
|
||||
return new Color(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the an array of numbers in
|
||||
* the RGBA format into a new instance.
|
||||
*
|
||||
* @param intArray integer array
|
||||
* @return new {@link Color} instance
|
||||
* @throws IndexOutOfBoundsException if the array contains more or less than four integers
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static @NotNull Color fromRGBA(int @NotNull [] intArray) {
|
||||
if (intArray.length != 4)
|
||||
throw new StringIndexOutOfBoundsException("Can't contains more or less than four integers");
|
||||
|
||||
return new Color(intArray[0], intArray[1], intArray[2], intArray[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the a set of numbers in
|
||||
* the RGB format into a new instance.
|
||||
*
|
||||
* @param red red color value
|
||||
* @param blue blue color value
|
||||
* @param green green color value
|
||||
* @return new {@link Color} instance
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static @NotNull Color fromRGB(@Range(from = 0, to = 255) int red, @Range(from = 0, to = 255) int green,
|
||||
@Range(from = 0, to = 255) int blue) {
|
||||
return new Color(red, green, blue, 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the an array of numbers in
|
||||
* the RGBA format into a new instance.
|
||||
*
|
||||
* @param intArray integer array
|
||||
* @return new {@link Color} instance
|
||||
* @throws IndexOutOfBoundsException if the array contains more or less than four integers
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static @NotNull Color fromRGB(int @NotNull [] intArray) {
|
||||
if (intArray.length != 3)
|
||||
throw new StringIndexOutOfBoundsException("Can't contains more or less than four integers");
|
||||
|
||||
return new Color(intArray[0], intArray[1], intArray[2], 255);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of bytes into a new instance.
|
||||
*
|
||||
* @param bytes byte array
|
||||
* @return new {@link Color} instance
|
||||
* @throws IndexOutOfBoundsException if the array contains less than three or more than four bytes
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static @NotNull Color fromBytes(byte @NotNull [] bytes) throws IndexOutOfBoundsException {
|
||||
if (bytes.length == 3)
|
||||
return new Color(bytes[0] & 0xFF, bytes[1] & 0xFF, bytes[2] & 0xFF, 255);
|
||||
else if (bytes.length == 4)
|
||||
return new Color(bytes[0] & 0xFF, bytes[1] & 0xFF, bytes[2] & 0xFF, bytes[3] & 0xFF);
|
||||
else
|
||||
throw new StringIndexOutOfBoundsException("Can't contain less than three or more than four bytes");
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a hex string into a new instance.
|
||||
*
|
||||
* @param hexString hex string
|
||||
* @return new {@link Color} instance
|
||||
* @throws IndexOutOfBoundsException if the string contains less than three or more than four bytes
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static @NotNull Color fromHex(@NotNull String hexString) throws IndexOutOfBoundsException {
|
||||
return fromBytes(HexFormat.of().parseHex(hexString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an identical copy of this instance.
|
||||
*
|
||||
* @return identical copy
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@SneakyThrows
|
||||
public @NotNull Color clone() {
|
||||
return (Color) super.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this instance.
|
||||
*
|
||||
* @return string representation
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return (EngineConfiguration.getInstance().isHideFullTypePath()
|
||||
? getClass().getName().replace(getClass().getPackage() + ".", "")
|
||||
: getClass().getName())
|
||||
+ "(r=" + red + " g=" + green + " b=" + blue + " a=" + alpha + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the colors represented by
|
||||
* this instance into an integer array
|
||||
* in the RGBA format.
|
||||
*
|
||||
* @return {@code int} array with RGBA values
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public int @NotNull [] toRGBA() {
|
||||
return new int[]{ red, green, blue, alpha };
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the colors represented by
|
||||
* this instance into an integer array
|
||||
* in the RGB format.
|
||||
*
|
||||
* @return {@code int} array with RGB values
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public int @NotNull [] toRGB() {
|
||||
return new int[]{ red, green, blue };
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the colors represented by
|
||||
* this instance into a byte array.
|
||||
*
|
||||
* @param includeAlpha whether to include alpha or not
|
||||
* @return RGBA or RGB format as a byte array
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public byte @NotNull [] toBytes(boolean includeAlpha) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(includeAlpha ? 4 : 3);
|
||||
|
||||
buffer
|
||||
.put((byte) red)
|
||||
.put((byte) green)
|
||||
.put((byte) blue);
|
||||
|
||||
if (includeAlpha)
|
||||
buffer.put((byte) alpha);
|
||||
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the colors represented by
|
||||
* this instance into the hex format.
|
||||
*
|
||||
* @param includeAlpha whether to include alpha or not
|
||||
* @return RGBA or RGB format as a hex string
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public @NotNull String toHex(boolean includeAlpha) {
|
||||
return HexFormat.of().formatHex(toBytes(includeAlpha)).toUpperCase(Locale.ROOT);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type;
|
||||
|
||||
/**
|
||||
* Represents various file types.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public enum FileType {
|
||||
/**
|
||||
* The path does not exist.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
VOID,
|
||||
|
||||
/**
|
||||
* It's a regular file.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
FILE,
|
||||
|
||||
/**
|
||||
* It's a directory containing files.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
DIRECTORY,
|
||||
|
||||
/**
|
||||
* The file type is unknown to the sos!engine.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
UNKNOWN
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type.vector;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a 4D double Vector.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Vec4d {
|
||||
/**
|
||||
* The X axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the X axis value.
|
||||
*
|
||||
* @return X axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the X axis value.
|
||||
*
|
||||
* @param x X axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private double x;
|
||||
|
||||
/**
|
||||
* The Y axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the Y axis value.
|
||||
*
|
||||
* @return Y axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the Y axis value.
|
||||
*
|
||||
* @param y Y axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private double y;
|
||||
|
||||
/**
|
||||
* The Z axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the Z axis value.
|
||||
*
|
||||
* @return Z axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the Z axis value.
|
||||
*
|
||||
* @param z Z axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private double z;
|
||||
|
||||
/**
|
||||
* The W axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the W axis value.
|
||||
*
|
||||
* @return W axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the W axis value.
|
||||
*
|
||||
* @param w W axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private double w;
|
||||
|
||||
/**
|
||||
* Creates and initializes a new 4D double vector.
|
||||
*
|
||||
* @param x X axis value
|
||||
* @param y Y axis value
|
||||
* @param z Z axis value
|
||||
* @param w W axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public Vec4d(double x, double y, double z, double w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an identical copy of this vector.
|
||||
*
|
||||
* @return identical copy
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@SneakyThrows
|
||||
public @NotNull Vec4d clone() {
|
||||
return (Vec4d) super.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this vector.
|
||||
*
|
||||
* @return string representation
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return (EngineConfiguration.getInstance().isHideFullTypePath()
|
||||
? getClass().getName().replace(getClass().getPackage() + ".", "")
|
||||
: getClass().getName())
|
||||
+ "(x=" + x + " y=" + y + " z=" + z + " w=" + w + ")";
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type.vector;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a 4D float Vector.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Vec4f {
|
||||
/**
|
||||
* The X axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the X axis value.
|
||||
*
|
||||
* @return X axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the X axis value.
|
||||
*
|
||||
* @param x X axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private float x;
|
||||
|
||||
/**
|
||||
* The Y axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the Y axis value.
|
||||
*
|
||||
* @return Y axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the Y axis value.
|
||||
*
|
||||
* @param y Y axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private float y;
|
||||
|
||||
/**
|
||||
* The Z axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the Z axis value.
|
||||
*
|
||||
* @return Z axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the Z axis value.
|
||||
*
|
||||
* @param z Z axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private float z;
|
||||
|
||||
/**
|
||||
* The W axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the W axis value.
|
||||
*
|
||||
* @return W axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the W axis value.
|
||||
*
|
||||
* @param w W axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private float w;
|
||||
|
||||
/**
|
||||
* Creates and initializes a new 4D float vector.
|
||||
*
|
||||
* @param x X axis value
|
||||
* @param y Y axis value
|
||||
* @param z Z axis value
|
||||
* @param w W axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public Vec4f(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an identical copy of this vector.
|
||||
*
|
||||
* @return identical copy
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@SneakyThrows
|
||||
public @NotNull Vec4f clone() {
|
||||
return (Vec4f) super.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this vector.
|
||||
*
|
||||
* @return string representation
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return (EngineConfiguration.getInstance().isHideFullTypePath()
|
||||
? getClass().getName().replace(getClass().getPackage() + ".", "")
|
||||
: getClass().getName())
|
||||
+ "(x=" + x + " y=" + y + " z=" + z + " w=" + w + ")";
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type.vector;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a 4D integer Vector.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Vec4i {
|
||||
/**
|
||||
* The X axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the X axis value.
|
||||
*
|
||||
* @return X axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the X axis value.
|
||||
*
|
||||
* @param x X axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private int x;
|
||||
|
||||
/**
|
||||
* The Y axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the Y axis value.
|
||||
*
|
||||
* @return Y axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the Y axis value.
|
||||
*
|
||||
* @param y Y axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private int y;
|
||||
|
||||
/**
|
||||
* The Z axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the Z axis value.
|
||||
*
|
||||
* @return Z axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the Z axis value.
|
||||
*
|
||||
* @param z Z axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private int z;
|
||||
|
||||
/**
|
||||
* The W axis value.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* -- GETTER --
|
||||
* Returns the W axis value.
|
||||
*
|
||||
* @return W axis value
|
||||
* @since v1-alpha6
|
||||
* -- SETTER --
|
||||
* Sets the W axis value.
|
||||
*
|
||||
* @param w W axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private int w;
|
||||
|
||||
/**
|
||||
* Creates and initializes a new 4D integer vector.
|
||||
*
|
||||
* @param x X axis value
|
||||
* @param y Y axis value
|
||||
* @param z Z axis value
|
||||
* @param w W axis value
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public Vec4i(int x, int y, int z, int w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an identical copy of this vector.
|
||||
*
|
||||
* @return identical copy
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@SneakyThrows
|
||||
public @NotNull Vec4i clone() {
|
||||
return (Vec4i) super.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this vector.
|
||||
*
|
||||
* @return string representation
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String toString() {
|
||||
return (EngineConfiguration.getInstance().isHideFullTypePath()
|
||||
? getClass().getName().replace(getClass().getPackage() + ".", "")
|
||||
: getClass().getName())
|
||||
+ "(x=" + x + " y=" + y + " z=" + z + " w=" + w + ")";
|
||||
}
|
||||
}
|
|
@ -1,851 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.utility;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import de.staropensource.engine.base.type.FileType;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Provides a simplified way of
|
||||
* accessing files and directories.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration", "unused" })
|
||||
public final class FileAccess {
|
||||
// -----> Static variables
|
||||
/**
|
||||
* Contains a list of all files and directories
|
||||
* which should be deleted at shutdown.
|
||||
* <p>
|
||||
* While this feature is built into Java, in
|
||||
* our testing it did not seem to work correctly.
|
||||
* That's why we're implementing it here.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static @NotNull Path[] scheduledDeletion = new Path[0];
|
||||
|
||||
/**
|
||||
* Contains a {@link FileAccess} instance to
|
||||
* a cache directory provided by the engine.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
* -- GETTER --
|
||||
* Returns a {@link FileAccess} instance to
|
||||
* a cache directory provided by the engine.
|
||||
*
|
||||
* @return cache directory
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@Getter
|
||||
private static FileAccess cacheDirectory;
|
||||
|
||||
// -----> Instance variables
|
||||
/**
|
||||
* Contains the {@link Path} to this file or directory.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
* -- GETTER --
|
||||
* Returns the {@link Path} to this file or directory.
|
||||
* <p>
|
||||
* Please only use this method when you have to.
|
||||
* Use the methods in this class instead, if you can.
|
||||
*
|
||||
* @return associated {@link Path} instance
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private final @NotNull Path path;
|
||||
|
||||
/**
|
||||
* Contains the {@link File} to this file or directory.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
* -- GETTER --
|
||||
* Returns the {@link File} to this file or directory.
|
||||
* <p>
|
||||
* Please only use this method when you have to.
|
||||
* Use the methods in this class instead, if you can.
|
||||
*
|
||||
* @return associated {@link File} instance
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private final @NotNull File file;
|
||||
|
||||
// -----> Constructors
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param path path you wish to access
|
||||
* @throws InvalidPathException if a {@link Path} cannot be created (see {@link FileSystem#getPath(String, String...)})
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public FileAccess(@NotNull String path) throws InvalidPathException {
|
||||
this.path = formatPath(path).toAbsolutePath();
|
||||
this.file = new File(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param path path you wish to access
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public FileAccess(@NotNull Path path) {
|
||||
this.path = path.toAbsolutePath();
|
||||
this.file = this.path.toFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param file {@link File} to the path you wish to access
|
||||
* @throws InvalidPathException if a {@link Path} cannot be created (see {@link FileSystem#getPath(String, String...)})
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public FileAccess(@NotNull File file) throws InvalidPathException {
|
||||
this.path = file.toPath().toAbsolutePath();
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param uri {@link URI} to the path you wish to access
|
||||
* @throws FileSystemNotFoundException if the filesystem is not supported by Java
|
||||
* @throws IllegalArgumentException if the URI is improperly formatted
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public FileAccess(@NotNull URI uri) throws FileSystemNotFoundException, IllegalArgumentException {
|
||||
this.path = Path.of(uri);
|
||||
this.file = new File(uri);
|
||||
}
|
||||
|
||||
|
||||
// -----> Static instance initialization
|
||||
/**
|
||||
* Initializes all uninitialized static
|
||||
* {@link FileAccess} instances.
|
||||
* <p>
|
||||
* Only works during early engine startup.
|
||||
*
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void initializeInstances() throws IOException {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
cacheDirectory = new FileAccess(System.getProperties().getProperty("java.io.tmpdir").replace("\\", "/") + "/sosengine-cache-" + ProcessHandle.current().pid()).createDirectory().deleteOnShutdown();
|
||||
}
|
||||
/**
|
||||
* Deletes all files scheduled for deletion.
|
||||
* <p>
|
||||
* Only works during engine shutdown.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void deleteScheduled() {
|
||||
if (Engine.getInstance().getState() == EngineState.SHUTDOWN || Engine.getInstance().getState() == EngineState.CRASHED) {
|
||||
Logger.verb("Deleting files scheduled for deletion on shutdown");
|
||||
|
||||
for (Path path : scheduledDeletion)
|
||||
try (Stream<Path> stream = Files.walk(path)) {
|
||||
Logger.diag("Deleting file or directory \"" + path + "\"");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||
|
||||
if (Files.exists(path))
|
||||
Logger.error("Deleting file or directory \"" + path + "\" failed");
|
||||
} catch (Exception exception) {
|
||||
Logger.error("File or directory \"" + path + "\" could not be deleted\n" + Miscellaneous.getStackTraceHeader(exception) + "\n" + Miscellaneous.getStackTraceAsString(exception, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----> Path formatting
|
||||
/**
|
||||
* Formats the path into a {@link Path} instance.
|
||||
*
|
||||
* @param path path to format
|
||||
* @return formatted {@link Path}
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static @NotNull Path formatPath(@NotNull String path) {
|
||||
return Path.of(
|
||||
path
|
||||
.replace("/./", "/")
|
||||
.replace("/", File.separator)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unformats the a {@link Path} instance into a string.
|
||||
*
|
||||
* @param path {@link Path} to unformat
|
||||
* @return unformatted path
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static @NotNull String unformatPath(@NotNull Path path) {
|
||||
return path
|
||||
.toString()
|
||||
.replace(File.separator, "/");
|
||||
}
|
||||
|
||||
|
||||
// -----> File getters & setters
|
||||
/**
|
||||
* Returns the absolute path of this file.
|
||||
*
|
||||
* @return absolute path
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String getPath() {
|
||||
return unformatPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file name.
|
||||
*
|
||||
* @param excludeExtension if to remove the extension (e.g. {@code .txt}, {@code .java})
|
||||
* @return file name
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String getFileName(boolean excludeExtension) {
|
||||
if (excludeExtension)
|
||||
return file.getName().replaceFirst("[.][^.]+$", "");
|
||||
else
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this file exists.
|
||||
*
|
||||
* @return exists?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean exists() {
|
||||
return Files.exists(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this file.
|
||||
*
|
||||
* @return file type
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileType getType() {
|
||||
if (!exists())
|
||||
return FileType.VOID;
|
||||
else if (Files.isRegularFile(path))
|
||||
return FileType.FILE;
|
||||
else if (Files.isDirectory(path))
|
||||
return FileType.DIRECTORY;
|
||||
else
|
||||
return FileType.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this file is a symbolic link.
|
||||
*
|
||||
* @return symbolic link?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isSymbolicLink() {
|
||||
return Files.isSymbolicLink(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the file is hidden.
|
||||
*
|
||||
* @return is hidden?
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isHidden() throws IOException {
|
||||
return Files.isHidden(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names of all files and
|
||||
* directories in this directory.
|
||||
*
|
||||
* @return array of file and directory names
|
||||
* @throws UnsupportedOperationException if the file is not a directory
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String @NotNull [] listContents() throws UnsupportedOperationException, IOException {
|
||||
if (getType() != FileType.DIRECTORY)
|
||||
throw new UnsupportedOperationException("The file \"" + path + "\" is not a directory");
|
||||
|
||||
String[] list = file.list();
|
||||
|
||||
if (list == null)
|
||||
throw new IOException("list is null");
|
||||
else
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the destination of the symbolic link.
|
||||
*
|
||||
* @return file type
|
||||
* @throws UnsupportedOperationException if the file is not a symbolic link
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String getLinkDestination() throws IOException {
|
||||
if (!isSymbolicLink())
|
||||
throw new UnsupportedOperationException("The file \"" + path + "\" is not a symbolic link");
|
||||
return unformatPath(Files.readSymbolicLink(path));
|
||||
}
|
||||
|
||||
// -----> Permissions
|
||||
/**
|
||||
* Returns whether or not the file can be read from.
|
||||
*
|
||||
* @return can be read?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isReadable() {
|
||||
return Files.isReadable(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the file can be written to.
|
||||
*
|
||||
* @return can be written?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isWritable() {
|
||||
return Files.isWritable(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the file can be executed.
|
||||
*
|
||||
* @return can be executed?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isExecutable() {
|
||||
return Files.isExecutable(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file's permissions the
|
||||
* POSIX {@code rwxrwxrwx} format.
|
||||
*
|
||||
* @return POSIX permissions format
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String getPosixPermissions() throws IOException {
|
||||
try {
|
||||
return PosixFilePermissions.toString(Files.getPosixFilePermissions(path));
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
// POSIX permissions are not supported
|
||||
// For the Macrohard Windoze users under us
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
if (isReadable())
|
||||
output.append("r");
|
||||
if (isWritable())
|
||||
output.append("w");
|
||||
if (isExecutable())
|
||||
output.append("x");
|
||||
|
||||
// Repeat the same thing two times
|
||||
output.repeat(output, 2);
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file's permissions the
|
||||
* POSIX {@code rwxrwxrwx} format.
|
||||
*
|
||||
* @param permissions POSIX {@code rwxrwxrwx} permission format
|
||||
* @return this instance
|
||||
* @throws IllegalArgumentException if the format of the {@code permissions} argument is invalid
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@SuppressWarnings({ "RegExpSingleCharAlternation", "ResultOfMethodCallIgnored" })
|
||||
public @NotNull FileAccess setPosixPermissions(@NotNull String permissions) throws IllegalArgumentException, IOException {
|
||||
if (
|
||||
permissions.length() != 9
|
||||
|| !permissions.matches("^(r|-)(w|-)(x|-)(r|-)(w|-)(x|-)(r|-)(w|-)(x|-)$")
|
||||
)
|
||||
throw new IllegalArgumentException("Invalid permission format: " + permissions);
|
||||
|
||||
try {
|
||||
Logger.diag("Setting POSIX file permissions for \"" + path + "\" to '" + permissions + "'");
|
||||
Files.setPosixFilePermissions(path, PosixFilePermissions.fromString(permissions));
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
Logger.diag("Setting POSIX file permissions for \"" + path + "\" to '" + permissions.substring(0, 2) + "'");
|
||||
char @NotNull [] chars = permissions.toCharArray();
|
||||
|
||||
for (int permission = 0; permission < 3; permission++) {
|
||||
boolean enabled = chars[permission] != '-';
|
||||
|
||||
switch (permission) {
|
||||
case 0 -> file.setReadable(enabled);
|
||||
case 1 -> file.setWritable(enabled);
|
||||
case 2 -> file.setExecutable(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// -----> Filesystem information
|
||||
/**
|
||||
* Returns the filesystem of this file.
|
||||
*
|
||||
* @return filesystem
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileSystem getFilesystem() {
|
||||
return path.getFileSystem();
|
||||
}
|
||||
/**
|
||||
* Returns whether or not the filesystem is POSIX-compliant.
|
||||
*
|
||||
* @return POSIX compliant?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isFilesystemPosixCompliant() {
|
||||
return path.getFileSystem().supportedFileAttributeViews().contains("posix");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all forbidden file names.
|
||||
* <p>
|
||||
* The required functionality is not yet
|
||||
* implemented. As such, this method
|
||||
* will just return an empty array.
|
||||
*
|
||||
* @return forbidden file names
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public @NotNull String @NotNull [] getRestrictedFileNames() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all forbidden characters in file names.
|
||||
* <p>
|
||||
* The required functionality is not yet
|
||||
* implemented. As such, this method
|
||||
* will just return an empty array.
|
||||
*
|
||||
* @return forbidden characters
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public char @NotNull [] getRestrictedCharacters() {
|
||||
return new char[0];
|
||||
}
|
||||
|
||||
|
||||
// -----> Directory traversal
|
||||
/**
|
||||
* Returns the parent directory.
|
||||
*
|
||||
* @return new {@link FileAccess} instance to the parent directory
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess parent() {
|
||||
return new FileAccess(path.getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses through directories and files.
|
||||
*
|
||||
* @param path path to traverse
|
||||
* @return new {@link FileAccess} instance
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess traverse(@NotNull String path) {
|
||||
return new FileAccess(this.path.resolve(formatPath(path)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses through directories and files.
|
||||
*
|
||||
* @param path path to traverse
|
||||
* @return new {@link FileAccess} instance
|
||||
* @throws FileNotFoundException if the specified path does not exist
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess traverseIfExists(@NotNull String path) throws FileNotFoundException {
|
||||
Path pathResolved = this.path.resolve(formatPath(path));
|
||||
|
||||
if (!Files.exists(pathResolved))
|
||||
throw new FileNotFoundException("Traversal failed as relative path \"" + path + "\" does not exist from absolute path \"" + path + "\"");
|
||||
|
||||
return new FileAccess(pathResolved);
|
||||
}
|
||||
|
||||
|
||||
// -----> File/Directory creation and deletion
|
||||
/**
|
||||
* Deletes the file.
|
||||
* If it doesn't exist, nothing will be done.
|
||||
*
|
||||
* @return this instance
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess delete() {
|
||||
if (exists()) {
|
||||
Logger.diag("Deleting \"" + path + "\"");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this file for deletion at engine shutdown.
|
||||
*
|
||||
* @return this instance
|
||||
* @see Engine#shutdown()
|
||||
* @see Engine#shutdown(int)
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess deleteOnShutdown() {
|
||||
Logger.diag("Marking \"" + path + "\" for deletion at engine shutdown");
|
||||
|
||||
// Append path to scheduledDeletion array
|
||||
List<@NotNull Path> scheduledDeletionList = new ArrayList<>(Arrays.stream(scheduledDeletion).toList());
|
||||
scheduledDeletionList.add(path);
|
||||
scheduledDeletion = scheduledDeletionList.toArray(new Path[0]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the file.
|
||||
* If it already exists, nothing will be done.
|
||||
*
|
||||
* @return this instance
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@SuppressWarnings({"UnusedReturnValue", "ResultOfMethodCallIgnored"})
|
||||
public @NotNull FileAccess createFile() throws IOException {
|
||||
if (!exists()) {
|
||||
Logger.diag("Creating a file at \"" + path + "\"");
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the directory recursively.
|
||||
* If it already exists, nothing will be done.
|
||||
*
|
||||
* @return this instance
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess createDirectory() throws IOException {
|
||||
if (!exists()) {
|
||||
Logger.diag("Creating a directory at \"" + path + "\"");
|
||||
if (!file.mkdirs())
|
||||
throw new IOException("Creating directory \"" + path + "\" recursively failed");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a symbolic link at this location.
|
||||
* If it already exists, nothing will be done.
|
||||
*
|
||||
* @param hard creates a hard link if {@code true} or a symbolic link if {@code false}
|
||||
* @param destination destination of the new link
|
||||
* @return this instance
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public @NotNull FileAccess createLink(boolean hard, @NotNull String destination) throws IOException {
|
||||
if (!exists()) {
|
||||
Logger.diag("Creating a " + (hard ? "hard" : "symbolic") + " link at \"" + path + "\"");
|
||||
|
||||
if (hard)
|
||||
Files.createLink(path, formatPath(destination));
|
||||
else
|
||||
Files.createSymbolicLink(path, formatPath(destination));
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// -----> File locking
|
||||
/**
|
||||
* Returns whether or not this file is locked.
|
||||
*
|
||||
* @return is locked?
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public boolean isLocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks this file.
|
||||
*
|
||||
* @return this instance
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess lock() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks this file.
|
||||
*
|
||||
* @return this instance
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess unlock() {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// -----> Content reading
|
||||
/**
|
||||
* Returns the contents of this file.
|
||||
* <p>
|
||||
* Returns an empty array if this file
|
||||
* is not of type {@link FileType#FILE}.
|
||||
*
|
||||
* @return file contents in bytes
|
||||
* @throws IOException on an IO error
|
||||
* @throws OutOfMemoryError if the file is larger than the allocated amount of memory
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public byte @NotNull [] readBytes() throws IOException, OutOfMemoryError {
|
||||
if (getType() != FileType.FILE)
|
||||
return new byte[0];
|
||||
|
||||
Logger.diag("Reading file \"" + path + "\" (bytes)");
|
||||
return Files.readAllBytes(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of this file.
|
||||
* <p>
|
||||
* Returns an empty list if this file
|
||||
* is not of type {@link FileType#FILE}.
|
||||
*
|
||||
* @return file contents in bytes
|
||||
* @throws IOException on an IO error
|
||||
* @throws OutOfMemoryError if the file is larger than the allocated amount of memory
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull List<@NotNull String> readLines() throws IOException, OutOfMemoryError {
|
||||
if (getType() != FileType.FILE)
|
||||
return new ArrayList<>();
|
||||
|
||||
Logger.diag("Reading file \"" + path + "\" (lines)");
|
||||
return Files.readAllLines(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of this file.
|
||||
* This method will decode the bytes using the
|
||||
* {@link StandardCharsets#UTF_8} character set.
|
||||
* <p>
|
||||
* Returns an empty string if this file
|
||||
* is not of type {@link FileType#FILE}.
|
||||
*
|
||||
* @return file contents as a string
|
||||
* @throws IOException on an IO error
|
||||
* @throws OutOfMemoryError if the file is larger than the allocated amount of memory
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String readContent() throws IOException, OutOfMemoryError {
|
||||
return readContent(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of this file.
|
||||
* <p>
|
||||
* Returns an empty string if this file
|
||||
* is not of type {@link FileType#FILE}.
|
||||
*
|
||||
* @param charset charset to decode the bytes with
|
||||
* @return file contents as a string
|
||||
* @throws IOException on an IO error
|
||||
* @throws OutOfMemoryError if the file is larger than the allocated amount of memory
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String readContent(@NotNull Charset charset) throws IOException, OutOfMemoryError {
|
||||
if (getType() != FileType.FILE)
|
||||
return "";
|
||||
|
||||
Logger.diag("Reading file \"" + path + "\" (string)");
|
||||
return Files.readString(path, charset);
|
||||
}
|
||||
|
||||
|
||||
// -----> Content writing
|
||||
/**
|
||||
* Writes the specified bytes into this file.
|
||||
*
|
||||
* @param bytes bytes to write
|
||||
* @param async allows the operating system to decide when to flush the file to disk if {@code true}, flushes the data to disk immediately if {@code false}
|
||||
* @throws UnsupportedOperationException if the type of this file is neither {@link FileType#VOID} or {@link FileType#FILE}
|
||||
* @throws IOException on an IO error
|
||||
* @return this instance
|
||||
*/
|
||||
public @NotNull FileAccess writeBytes(byte @NotNull [] bytes, boolean async) throws UnsupportedOperationException, IOException {
|
||||
if (getType() == FileType.VOID)
|
||||
createFile();
|
||||
else if (getType() != FileType.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type FileType.VOID or FileType.FILE");
|
||||
|
||||
createFile();
|
||||
Logger.diag("Writing file \"" + path + "\" (bytes, " + (async ? "async" : "dsync") + ")");
|
||||
Files.write(path, bytes, StandardOpenOption.WRITE, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the specified bytes into this file.
|
||||
* This method will encode the string using the
|
||||
* {@link StandardCharsets#UTF_8} character set.
|
||||
*
|
||||
* @param string string to write
|
||||
* @param async allows the operating system to decide when to flush the file to disk if {@code true}, flushes the data to disk immediately if {@code false}
|
||||
* @throws UnsupportedOperationException if the type of this file is neither {@link FileType#VOID} or {@link FileType#FILE}
|
||||
* @throws IOException on an IO error
|
||||
* @return this instance
|
||||
*/
|
||||
public @NotNull FileAccess writeString(@NotNull String string, boolean async) throws UnsupportedOperationException, IOException {
|
||||
return writeString(string, StandardCharsets.UTF_8, async);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the specified bytes into this file.
|
||||
*
|
||||
* @param string string to write
|
||||
* @param charset charset to encode the string in
|
||||
* @param async allows the operating system to decide when to flush the file to disk if {@code true}, flushes the data to disk immediately if {@code false}
|
||||
* @throws UnsupportedOperationException if the type of this file is neither {@link FileType#VOID} or {@link FileType#FILE}
|
||||
* @throws IOException on an IO error
|
||||
* @return this instance
|
||||
*/
|
||||
public @NotNull FileAccess writeString(@NotNull String string, @NotNull Charset charset, boolean async) throws UnsupportedOperationException, IOException {
|
||||
if (getType() == FileType.VOID)
|
||||
createFile();
|
||||
else if (getType() != FileType.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type FileType.VOID or FileType.FILE");
|
||||
|
||||
Logger.diag("Writing file \"" + path + "\" (string, " + (async ? "async" : "dsync") + ")");
|
||||
Files.writeString(path, string, charset, StandardOpenOption.WRITE, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// -----> Content appending
|
||||
/**
|
||||
* Appends the specified bytes to this file.
|
||||
*
|
||||
* @param bytes bytes to append
|
||||
* @param async allows the operating system to decide when to flush the file to disk if {@code true}, flushes the data to disk immediately if {@code false}
|
||||
* @throws UnsupportedOperationException if the type of this file is neither {@link FileType#VOID} or {@link FileType#FILE}
|
||||
* @throws IOException on an IO error
|
||||
* @return this instance
|
||||
*/
|
||||
public @NotNull FileAccess appendBytes(byte @NotNull [] bytes, boolean async) throws UnsupportedOperationException, IOException {
|
||||
if (getType() == FileType.VOID)
|
||||
createFile();
|
||||
else if (getType() != FileType.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type FileType.VOID or FileType.FILE");
|
||||
|
||||
Logger.diag("Appending file \"" + path + "\" (bytes, " + (async ? "async" : "dsync") + ")");
|
||||
Files.write(path, bytes, StandardOpenOption.APPEND, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified string to this file.
|
||||
* This method will encode the string using the
|
||||
* {@link StandardCharsets#UTF_8} character set.
|
||||
*
|
||||
* @param string string to append
|
||||
* @param async allows the operating system to decide when to flush the file to disk if {@code true}, flushes the data to disk immediately if {@code false}
|
||||
* @throws UnsupportedOperationException if the type of this file is neither {@link FileType#VOID} or {@link FileType#FILE}
|
||||
* @throws IOException on an IO error
|
||||
* @return this instance
|
||||
*/
|
||||
public @NotNull FileAccess appendString(@NotNull String string, boolean async) throws UnsupportedOperationException, IOException {
|
||||
return appendString(string, StandardCharsets.UTF_8, async);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the specified string to this file.
|
||||
*
|
||||
* @param string string to append
|
||||
* @param charset charset to encode the string in
|
||||
* @param async allows the operating system to decide when to flush the file to disk if {@code true}, flushes the data to disk immediately if {@code false}
|
||||
* @throws UnsupportedOperationException if the type of this file is neither {@link FileType#VOID} or {@link FileType#FILE}
|
||||
* @throws IOException on an IO error
|
||||
* @return this instance
|
||||
*/
|
||||
public @NotNull FileAccess appendString(@NotNull String string, @NotNull Charset charset, boolean async) throws UnsupportedOperationException, IOException {
|
||||
if (getType() == FileType.VOID)
|
||||
createFile();
|
||||
else if (getType() != FileType.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type FileType.VOID or FileType.FILE");
|
||||
|
||||
Logger.diag("Appending file \"" + path + "\" (string, " + (async ? "async" : "dsync") + ")");
|
||||
Files.writeString(path, string, charset, StandardOpenOption.APPEND, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//package de.staropensource.engine.base.utility.information;
|
||||
|
||||
/**
|
||||
* Provides information about the environment
|
||||
* ie. the operating system, paths, etc..
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
//public final class EnvironmentInformation {
|
||||
//}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A namespace for various things,
|
||||
* not really specified what though.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
package de.staropensource.engine.dynamic;
|
|
@ -17,31 +17,27 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base;
|
||||
package de.staropensource.sosengine.base;
|
||||
|
||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.engine.base.event.*;
|
||||
import de.staropensource.engine.base.exception.IllegalAccessException;
|
||||
import de.staropensource.engine.base.exception.dependency.UnmetDependenciesException;
|
||||
import de.staropensource.engine.base.implementable.ShutdownHandler;
|
||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
||||
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.engine.base.internal.type.DependencySubsystemVector;
|
||||
import de.staropensource.engine.base.logging.PrintStreamService;
|
||||
import de.staropensource.engine.base.logging.*;
|
||||
import de.staropensource.engine.base.logging.backend.async.LoggingQueue;
|
||||
import de.staropensource.engine.base.logging.backend.async.LoggingThread;
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import de.staropensource.engine.base.type.immutable.ImmutableLinkedList;
|
||||
import de.staropensource.engine.base.utility.DependencyResolver;
|
||||
import de.staropensource.engine.base.utility.FileAccess;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.engine.base.utility.information.JvmInformation;
|
||||
import de.staropensource.sosengine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.sosengine.base.implementable.ShutdownHandler;
|
||||
import de.staropensource.sosengine.base.implementable.SubsystemClass;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.utility.information.JvmInformation;
|
||||
import de.staropensource.sosengine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
||||
import de.staropensource.sosengine.base.event.*;
|
||||
import de.staropensource.sosengine.base.exception.IllegalAccessException;
|
||||
import de.staropensource.sosengine.base.exception.dependency.UnmetDependenciesException;
|
||||
import de.staropensource.sosengine.base.internal.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.sosengine.base.internal.type.DependencySubsystemVector;
|
||||
import de.staropensource.sosengine.base.logging.*;
|
||||
import de.staropensource.sosengine.base.type.DependencyVector;
|
||||
import de.staropensource.sosengine.base.type.EngineState;
|
||||
import de.staropensource.sosengine.base.type.immutable.ImmutableLinkedList;
|
||||
import de.staropensource.sosengine.base.utility.DependencyResolver;
|
||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||
import de.staropensource.sosengine.base.utility.PlaceholderEngine;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -60,6 +56,7 @@ import java.util.*;
|
|||
* @see EngineConfiguration
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@EngineSubsystem
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Engine extends SubsystemClass {
|
||||
/**
|
||||
|
@ -88,6 +85,14 @@ public final class Engine extends SubsystemClass {
|
|||
@Getter
|
||||
private static final ThreadGroup threadGroup = new ThreadGroup("sos!engine");
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private static final LoggerInstance logger = new LoggerInstance.Builder().setClazz(Engine.class).setOrigin("ENGINE").setMetadata(EngineInformation.getVersioningCodename()).build();
|
||||
|
||||
/**
|
||||
* Contains the engine state.
|
||||
*
|
||||
|
@ -99,7 +104,7 @@ public final class Engine extends SubsystemClass {
|
|||
* @since v1-alpha2
|
||||
*/
|
||||
@Getter
|
||||
private @NotNull EngineState state;
|
||||
private @NotNull EngineState state = EngineState.UNKNOWN;
|
||||
|
||||
/**
|
||||
* Contains a list of all registered subsystems.
|
||||
|
@ -165,194 +170,151 @@ public final class Engine extends SubsystemClass {
|
|||
}
|
||||
|
||||
// Print warning about shutdown
|
||||
Logger.warn("Trying to shut down engine using shutdown hook.\nThis approach to shutting down the engine and JVM is NOT RECOMMENDED, please use Engine#shutdown() instead.");
|
||||
logger.warn("Trying to shut down engine using shutdown hook.\nThis approach to shutting down the engine and JVM is NOT RECOMMENDED, please use Engine#shutdown() instead.");
|
||||
|
||||
// Shutdown
|
||||
Engine.getInstance().shutdown();
|
||||
|
||||
// Print last message
|
||||
Logger.warn("Engine successfully shut down using shutdown hook. PLEASE USE Engine#shutdown() INSTEAD OF System#exit() or Runtime#exit()!");
|
||||
InitLogger.warn(getClass(), "ENGINE", EngineInformation.getVersioningCodename(), "Engine successfully shut down using shutdown hook. PLEASE USE Engine#shutdown() INSTEAD OF System#exit() or Runtime#exit()!");
|
||||
});
|
||||
|
||||
/**
|
||||
* Initializes the StarOpenSource Engine.
|
||||
*
|
||||
* @throws RuntimeException for all exceptions thrown by this constructor
|
||||
* @since v1-alpha8
|
||||
* @throws IllegalStateException when running in an incompatible environment
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private Engine() throws RuntimeException {
|
||||
try {
|
||||
public Engine() throws IllegalStateException {
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else
|
||||
return;
|
||||
|
||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
||||
state = EngineState.EARLY_STARTUP;
|
||||
|
||||
// For measuring the initialization time
|
||||
long initTimeEarly = System.currentTimeMillis();
|
||||
long initTimeLate = initTimeEarly;
|
||||
|
||||
// Check for incompatible JVM implementations
|
||||
checkJvmIncompatibilities();
|
||||
|
||||
// Display that the engine is initializing
|
||||
Logger.verb("Initializing engine");
|
||||
|
||||
// Start the logging thread
|
||||
Logger.diag("Starting logging infrastructure");
|
||||
LoggingThread.startThread(false);
|
||||
PrintStreamService.initializeStreams();
|
||||
|
||||
// Initialize EngineInternals
|
||||
Logger.diag("Initializing EngineInternals class");
|
||||
new EngineInternals();
|
||||
|
||||
// Load engine configuration
|
||||
Logger.diag("Loading engine configuration");
|
||||
new EngineConfiguration();
|
||||
EngineConfiguration.getInstance().loadConfiguration();
|
||||
|
||||
// Load engine build information
|
||||
Logger.diag("Loading engine build information");
|
||||
EngineInformation.update();
|
||||
logger.info("Initializing engine");
|
||||
initializeClasses(); // Initialize classes
|
||||
if (checkEnvironment()) // Check environment
|
||||
throw new IllegalStateException("Running in an incompatible environment");
|
||||
ensureEnvironment(); // Prepare the environment and ensure safety
|
||||
populateCrashContent(); // Populate crash content
|
||||
cacheEvents(); // Cache event listeners
|
||||
startThreads(); // Start threads
|
||||
|
||||
// Check for reflective classpath scanning compatibility
|
||||
checkReflectiveClasspathScanningCompatibility();
|
||||
|
||||
// Check for Java version incompatibilities
|
||||
checkJavaVersion();
|
||||
|
||||
// Initialize PlaceholderEngine
|
||||
Logger.diag("Initializing PlaceholderEngine");
|
||||
PlaceholderEngine.initialize();
|
||||
|
||||
// Initialize static FileAccess instances
|
||||
Logger.diag("Initializing static FileAccess instances");
|
||||
FileAccess.initializeInstances();
|
||||
|
||||
// Install the safety shutdown hook
|
||||
Logger.diag("Installing safety shutdown hook");
|
||||
EngineInternals.getInstance().installSafetyShutdownHook(true);
|
||||
|
||||
// Cache events
|
||||
Logger.diag("Caching event listeners");
|
||||
cacheEvents();
|
||||
|
||||
// Complete early initialization stage
|
||||
Logger.verb("Completing early initialization stage");
|
||||
logger.verb("Completing early initialization stage");
|
||||
state = EngineState.STARTUP;
|
||||
initTimeEarly = System.currentTimeMillis() - initTimeEarly;
|
||||
|
||||
// Perform automatic subsystem initialization
|
||||
if (EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization()) {
|
||||
// Collect all subsystems
|
||||
Logger.diag("Collecting subsystems");
|
||||
collectSubsystems();
|
||||
if (EngineConfiguration.getInstance().isOptimizeSubsystemInitialization()) {
|
||||
collectSubsystems(); // Collect subsystems
|
||||
|
||||
// Initialize subsystems
|
||||
try {
|
||||
initializeSubsystems();
|
||||
} catch (Exception exception) {
|
||||
Logger.error("Subsystem dependency resolution failed");
|
||||
logger.crash("Subsystem dependency resolution failed", exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Complete late initialization stage
|
||||
Logger.verb("Completing late initialization stage");
|
||||
state = EngineState.RUNNING;
|
||||
initTimeLate = System.currentTimeMillis() - initTimeLate;
|
||||
|
||||
// Print welcome message
|
||||
Logger.info(
|
||||
"""
|
||||
Welcome to the StarOpenSource Engine "%engine_version_codename%" %engine_version%!
|
||||
Running commit %engine_git_commit_id_long% (dirty %engine_git_dirty%).
|
||||
Initialization took %init_time_total%ms (early %init_time_early%ms, late %init_time_late%ms).
|
||||
|
||||
Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
Licensed under the GNU Affero General Public License v3"""
|
||||
.replace("%init_time_total%", String.valueOf(initTimeEarly + initTimeLate))
|
||||
.replace("%init_time_early%", String.valueOf(initTimeEarly))
|
||||
.replace("%init_time_late%", String.valueOf(initTimeLate))
|
||||
);
|
||||
} catch (Exception exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
logger.verb("Completing late initialization stage");
|
||||
state = EngineState.RUNNING;
|
||||
logger.info("Initialized sos!engine %engine_version% (commit %engine_git_commit_id_long%-%engine_git_branch%, dirty %engine_git_dirty%) in " + initTime + "ms\nThe StarOpenSource Engine is licensed under the GNU AGPL v3. Copyright (c) 2024 The StarOpenSource Engine Authors.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the StarOpenSource
|
||||
* Engine, if it isn't already.
|
||||
* Initializes all classes.
|
||||
*
|
||||
* @throws IllegalStateException when running in an incompatible environment
|
||||
* @throws RuntimeException on engine initialization failure
|
||||
* @since v1-alpha6
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static void initialize() throws RuntimeException {
|
||||
try {
|
||||
if (instance == null)
|
||||
new Engine();
|
||||
} catch (RuntimeException exception) {
|
||||
Logger.error("Engine initialization failed");
|
||||
Logger.error(Miscellaneous.getStackTraceHeader(exception.getCause()));
|
||||
for (String line : Miscellaneous.getStackTraceAsString(exception.getCause(), true).split("\n"))
|
||||
Logger.error(line);
|
||||
private void initializeClasses() {
|
||||
logger.verb("Initializing engine classes");
|
||||
new EngineInternals();
|
||||
new PlaceholderEngine();
|
||||
|
||||
throw new RuntimeException("Engine initialization failed", exception.getCause());
|
||||
}
|
||||
EngineInformation.update();
|
||||
PrintStreamService.initializeStreams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the running JVM implementation is not supported by the engine.
|
||||
* Checks if the environment is compatible with the engine build.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private void checkJvmIncompatibilities() {
|
||||
if (System.getProperties().getProperty("sosengine.base.allowUnsupportedJVMInitialization", "false").equals("true")) {
|
||||
Logger.warn("Skipping JVM implementation incompatibilities check");
|
||||
return;
|
||||
}
|
||||
private boolean checkEnvironment() {
|
||||
logger.diag("Checking environment");
|
||||
|
||||
// Substrate VM (GraalVM Community)
|
||||
if (JvmInformation.getImplementationName().equals("Substrate VM") && JvmInformation.getImplementationVendor().equals("GraalVM Community")) {
|
||||
Logger.error("##############################################################################################");
|
||||
Logger.error("## Running in Substrate VM, which is the name of the JVM used by GraalVM native-image. ##");
|
||||
Logger.error("## The StarOpenSource Engine does not support native-image as using reflection in a certain ##");
|
||||
Logger.error("## way seems to cause the Substrate JVM to crash. Workarounds have failed. ##");
|
||||
Logger.error("## This has already been noted in issue #3, which you can view here: ##");
|
||||
Logger.error("## https://git.staropensource.de/StarOpenSource/Engine/issues/3 ##");
|
||||
Logger.error("## ##");
|
||||
Logger.error("## While this is sad, we unfortunately can't do anything against it unless we introduce ##");
|
||||
Logger.error("## annoying and stupid changes into the engine, which we don't want to do. ##");
|
||||
Logger.error("## ##");
|
||||
Logger.error("## We're truly sorry for this inconvenience. The sos!engine will now terminate. ##");
|
||||
Logger.error("##############################################################################################");
|
||||
Runtime.getRuntime().exit(255);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if reflective classpath scanning is supported.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private void checkReflectiveClasspathScanningCompatibility() {
|
||||
// Check if reflective classpath scanning is supported
|
||||
if (System.getProperties().getProperty("sosengine.base.considerEnvironmentUnfriendlyToClasspathScanning", "false").equals("true")) {
|
||||
Logger.warn("Running in an classpath scanning-unfriendly environment, disabling classpath scanning support.");
|
||||
Logger.warn("If shit doesn't work and is expected to be discovered by annotations, you'll need to");
|
||||
Logger.warn("either register it first or have to update some engine configuration setting.");
|
||||
Logger.warn("Please consult sos!engine's documentation for more information about this issue.");
|
||||
EngineInternals.getInstance().overrideReflectiveClasspathScanning(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks and warns if the Java version of the
|
||||
* running JVM is higher than the engine supports.
|
||||
*
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private void checkJavaVersion() {
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the execution safety of the environment.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private void ensureEnvironment() {
|
||||
EngineInternals.getInstance().installSafetyShutdownHook(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method populates {@link CrashHandler#crashContent} with content.
|
||||
*
|
||||
* @see CrashHandler#getCrashContent()
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "ExtractMethodRecommender" })
|
||||
private void populateCrashContent() {
|
||||
logger.diag("Populating crash content");
|
||||
|
||||
// Issuer
|
||||
Map<@NotNull String, @NotNull String> crashContentIssuer = new LinkedHashMap<>();
|
||||
crashContentIssuer.put("Code part", "%issuer_origin%");
|
||||
crashContentIssuer.put("Classpath", "%issuer_path%");
|
||||
crashContentIssuer.put("Additional information", "%issuer_metadata%");
|
||||
crashContentIssuer.put("Message", "%crash_message%");
|
||||
|
||||
// Engine -> Dependencies
|
||||
LinkedList<@NotNull String> crashContentEngineDependencies = new LinkedList<>();
|
||||
crashContentEngineDependencies.add("Subsystem 'base': Reflections: %engine_dependency_reflections%");
|
||||
crashContentEngineDependencies.add("Subsystem 'ansi': Jansi: %engine_dependency_jansi%");
|
||||
crashContentEngineDependencies.add("Subsystem 'slf4j-compat': SLF4J: %engine_dependency_slf4j%");
|
||||
crashContentEngineDependencies.add("Subsystems 'glfw', 'opengl' & 'vulkan': LWJGL: %engine_dependency_lwjgl%");
|
||||
// Engine -> *
|
||||
Map<@NotNull String, @NotNull Object> crashContentEngine = new LinkedHashMap<>();
|
||||
crashContentEngine.put("Version", "%engine_version%");
|
||||
crashContentEngine.put("Dependencies", crashContentEngineDependencies);
|
||||
|
||||
// JVM -> Implementation
|
||||
Map<@NotNull String, @NotNull String> crashContentJvmImplementation = new LinkedHashMap<>();
|
||||
crashContentJvmImplementation.put("Name", "%jvm_implementation_name%");
|
||||
crashContentJvmImplementation.put("Version", "%jvm_implementation_version%");
|
||||
crashContentJvmImplementation.put("Vendor", "%jvm_implementation_vendor%");
|
||||
// JVM -> *
|
||||
Map<@NotNull String, @NotNull Object> crashContentJvm = new LinkedHashMap<>();
|
||||
crashContentJvm.put("Java Version", "%jvm_java%");
|
||||
crashContentJvm.put("Implementation", crashContentJvmImplementation);
|
||||
crashContentJvm.put("Arguments", JvmInformation.getArguments());
|
||||
|
||||
// Operating system
|
||||
Map<@NotNull String, @NotNull String> crashContentOS = new LinkedHashMap<>();
|
||||
crashContentOS.put("Time", "%time_hour%:%time_minute%:%time_second% (%time_zone%, UNIX Epoch: %time_epoch%)");
|
||||
crashContentOS.put("Date", "%date_day%.%date_month%.%date_year%");
|
||||
|
||||
// Add to crash handler
|
||||
CrashHandler.getCrashContent().put("Issuer", crashContentIssuer);
|
||||
CrashHandler.getCrashContent().put("Engine", crashContentEngine);
|
||||
CrashHandler.getCrashContent().put("Java Virtual Machine", crashContentJvm);
|
||||
CrashHandler.getCrashContent().put("Operating system", crashContentOS);
|
||||
CrashHandler.getCrashContent().put("Stacktrace", "\n%stacktrace%");
|
||||
CrashHandler.getCrashContent().put("Stacktrace for all threads", "\n%stacktrace_all%");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -361,14 +323,30 @@ public final class Engine extends SubsystemClass {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
private void cacheEvents() {
|
||||
logger.diag("Caching events");
|
||||
|
||||
// Internal events
|
||||
EventHelper.cacheEvent(InternalEngineShutdownEvent.class);
|
||||
|
||||
// General events
|
||||
EventHelper.cacheEvent(EngineCrashEvent.class);
|
||||
EventHelper.cacheEvent(EngineShutdownEvent.class);
|
||||
EventHelper.cacheEvent(EngineSoftCrashEvent.class);
|
||||
EventHelper.cacheEvent(InternalEngineShutdownEvent.class);
|
||||
EventHelper.cacheEvent(LogEvent.class);
|
||||
EventHelper.cacheEvent(ThrowableCatchEvent.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts engine threads.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public void startThreads() {
|
||||
logger.diag("Starting threads");
|
||||
|
||||
LoggingThread.startThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all subsystems by their {@link EngineSubsystem} annotation.
|
||||
*
|
||||
|
@ -376,11 +354,21 @@ public final class Engine extends SubsystemClass {
|
|||
*/
|
||||
private void collectSubsystems() {
|
||||
ArrayList<@NotNull DependencySubsystemVector> subsystemsMutable = new ArrayList<>();
|
||||
|
||||
// Scan entire classpath using the Reflections library
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.setUrls(ClasspathHelper.forJavaClassPath())
|
||||
.setScanners(Scanners.TypesAnnotated)
|
||||
);
|
||||
|
||||
// Get annotated methods
|
||||
Set<@NotNull Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(EngineSubsystem.class);
|
||||
|
||||
// Initialize classes, get dependency vector and add to 'subsystemsMutable'
|
||||
Object initializedClassRaw;
|
||||
SubsystemClass initializedClass;
|
||||
|
||||
// Check and initialize all classes, get dependency vector and check version, then add to 'subsystemsMutable'
|
||||
for (Class<?> clazz : getRawSubsystemClasses())
|
||||
for (Class<?> clazz : annotatedClasses) {
|
||||
try {
|
||||
// Create new instance
|
||||
initializedClassRaw = clazz.getDeclaredConstructor().newInstance();
|
||||
|
@ -390,52 +378,21 @@ public final class Engine extends SubsystemClass {
|
|||
if (initializedClassRaw instanceof SubsystemClass)
|
||||
initializedClass = (SubsystemClass) initializedClassRaw;
|
||||
else
|
||||
Logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Does not implement " + SubsystemClass.class.getName());
|
||||
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Does not implement " + SubsystemClass.class.getName());
|
||||
|
||||
//noinspection DataFlowIssue // the crash call will prevent a NullPointerException
|
||||
subsystemsMutable.add(new DependencySubsystemVector(initializedClass.getDependencyVector(), initializedClass));
|
||||
} catch (Exception exception) {
|
||||
if (exception.getClass() == IllegalStateException.class && exception.getMessage().startsWith("The version string is invalid: "))
|
||||
Logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Invalid version string: " + exception.getMessage().replace("The version string is invalid: ", ""));
|
||||
Logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Method invocation error", exception);
|
||||
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Invalid version string: " + exception.getMessage().replace("The version string is invalid: ", ""));
|
||||
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Method invocation error", exception);
|
||||
}
|
||||
}
|
||||
|
||||
// Update 'subsystems'
|
||||
subsystems = new ImmutableLinkedList<>(subsystemsMutable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of classes which are potentially
|
||||
* eligible for subsystem initialization.
|
||||
*
|
||||
* @return potential subsystem classes
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private Set<@NotNull Class<?>> getRawSubsystemClasses() {
|
||||
Set<@NotNull Class<?>> classes = new HashSet<>();
|
||||
|
||||
if (EngineInternals.getInstance().getReflectiveClasspathScanning()) {
|
||||
// Scan entire classpath using the Reflections library
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.setUrls(ClasspathHelper.forJavaClassPath())
|
||||
.setScanners(Scanners.TypesAnnotated)
|
||||
);
|
||||
|
||||
// Get annotated methods
|
||||
classes = reflections.getTypesAnnotatedWith(EngineSubsystem.class);
|
||||
} else
|
||||
for (String path : EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses())
|
||||
try {
|
||||
Logger.diag("Resolving class " + path);
|
||||
classes.add(Class.forName(path));
|
||||
} catch (ClassNotFoundException exception) {
|
||||
Logger.error("Failed loading subsystem class " + path + ": Class not found");
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all subsystems.
|
||||
*
|
||||
|
@ -447,11 +404,10 @@ public final class Engine extends SubsystemClass {
|
|||
LinkedList<DependencySubsystemVector> order = new LinkedList<>();
|
||||
|
||||
// Add vectors
|
||||
resolver.addVector(getDependencyVector());
|
||||
resolver.addVectors(subsystems);
|
||||
|
||||
// Resolve dependencies and get order
|
||||
Logger.diag("Resolving subsystem dependencies");
|
||||
logger.verb("Resolving subsystem dependencies");
|
||||
try {
|
||||
for (DependencyVector vector : resolver.resolve().getOrder()) // smol workaround
|
||||
order.add((DependencySubsystemVector) vector);
|
||||
|
@ -466,25 +422,25 @@ public final class Engine extends SubsystemClass {
|
|||
.append("- ")
|
||||
.append(error);
|
||||
|
||||
Logger.crash("Found unresolved dependencies:" + list, throwable);
|
||||
logger.crash("Found unresolved dependencies:" + list, throwable);
|
||||
return;
|
||||
}
|
||||
Logger.crash("An error occurred trying to resolve subsystem dependencies: " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
||||
logger.crash("An error occurred trying to resolve subsystem dependencies: " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
||||
throw throwable;
|
||||
}
|
||||
|
||||
// Initialize subsystems
|
||||
Logger.diag("Initializing engine subsystems");
|
||||
logger.verb("Initializing engine subsystems");
|
||||
long initTime;
|
||||
for (DependencySubsystemVector vector : subsystems) {
|
||||
Logger.diag("Initializing subsystem '" + vector.getSubsystemClass().getName() + "' (" + vector.getSubsystemClass().getClass().getName() + ")");
|
||||
logger.diag("Initializing subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + ")");
|
||||
try {
|
||||
initTime = Miscellaneous.measureExecutionTime(() -> vector.getSubsystemClass().initializeSubsystem());
|
||||
} catch (Throwable throwable) {
|
||||
Logger.crash("An error occurred trying to initialize subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + "): " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
||||
logger.crash("An error occurred trying to initialize subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + "): " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
||||
throw throwable;
|
||||
}
|
||||
Logger.diag("Initialized subsystem '" + vector.getSubsystemClass().getName() + "' (" + vector.getSubsystemClass().getClass().getName() + ") in " + initTime + "ms");
|
||||
logger.diag("Initialized subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + ") in " + initTime + "ms");
|
||||
}
|
||||
|
||||
// Update 'subsystems'
|
||||
|
@ -498,10 +454,13 @@ public final class Engine extends SubsystemClass {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public synchronized void shutdown(@Range(from = 0, to = 255) int exitCode) {
|
||||
if (state == EngineState.UNKNOWN || state == EngineState.SHUTDOWN)
|
||||
return;
|
||||
switch (state) {
|
||||
case UNKNOWN, SHUTDOWN, CRASHED -> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.info("Shutting engine down");
|
||||
logger.info("Shutting engine down");
|
||||
if (state != EngineState.CRASHED)
|
||||
state = EngineState.SHUTDOWN;
|
||||
|
||||
|
@ -512,7 +471,7 @@ public final class Engine extends SubsystemClass {
|
|||
EngineConfiguration.getInstance().loadConfiguration(properties);
|
||||
|
||||
// Flush log messages
|
||||
LoggingQueue.flush();
|
||||
Logger.flushLogMessages();
|
||||
|
||||
// Disable safety shutdown hook
|
||||
try {
|
||||
|
@ -520,17 +479,14 @@ public final class Engine extends SubsystemClass {
|
|||
} catch (Exception ignored) {}
|
||||
|
||||
// Send events
|
||||
Logger.verb("Notifying classes about shutdown");
|
||||
logger.verb("Notifying classes about shutdown");
|
||||
new EngineShutdownEvent().callEvent();
|
||||
|
||||
Logger.verb("Notifying subsystems about shutdown");
|
||||
logger.verb("Notifying subsystems about shutdown");
|
||||
new InternalEngineShutdownEvent().callEvent();
|
||||
|
||||
// Delete scheduled files
|
||||
FileAccess.deleteScheduled();
|
||||
|
||||
// Invoke shutdown handler
|
||||
Logger.verb("Invoking shutdown handler (code " + exitCode + ")");
|
||||
logger.verb("Invoking shutdown handler (code " + exitCode + ")");
|
||||
shutdownHandler.shutdown((short) exitCode);
|
||||
}
|
||||
|
||||
|
@ -550,11 +506,7 @@ public final class Engine extends SubsystemClass {
|
|||
return "base";
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does nothing.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void initializeSubsystem() {}
|
||||
|
||||
|
@ -576,8 +528,8 @@ public final class Engine extends SubsystemClass {
|
|||
* @since v1-alpha2
|
||||
*/
|
||||
public void setState(@NotNull EngineState state) throws IllegalAccessException {
|
||||
if (!Thread.currentThread().getStackTrace()[2].getClassName().startsWith("de.staropensource.engine.base."))
|
||||
throw new IllegalAccessException("Only classes inside the \"de.staropensource.engine.base\" package are allowed to call this method.");
|
||||
if (!Thread.currentThread().getStackTrace()[2].getClassName().startsWith("de.staropensource.sosengine.base."))
|
||||
throw new IllegalAccessException("Only classes inside the \"de.staropensource.sosengine.base\" package are allowed to call this method.");
|
||||
|
||||
this.state = state;
|
||||
}
|
||||
|
@ -607,12 +559,12 @@ public final class Engine extends SubsystemClass {
|
|||
Runtime.getRuntime().addShutdownHook(thread);
|
||||
Runtime.getRuntime().removeShutdownHook(thread);
|
||||
} catch (IllegalStateException exception) {
|
||||
Logger.warn("Terminating JVM: Already shutting down, skipping");
|
||||
logger.warn("Terminating JVM: Already shutting down, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.warn("Terminating JVM");
|
||||
Runtime.getRuntime().exit(exitCode);
|
||||
logger.warn("Terminating JVM");
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,416 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base;
|
||||
|
||||
import de.staropensource.sosengine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.sosengine.base.implementable.Configuration;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.logging.CrashHandler;
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.logging.LoggingThread;
|
||||
import de.staropensource.sosengine.base.type.EngineState;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.type.vector.Vec2f;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Provides the base engine configuration.
|
||||
* <p>
|
||||
* This class does not only provide engine settings but is also
|
||||
* responsible for loading them into memory from {@link Properties} objects.
|
||||
* <p>
|
||||
* Now you might ask why we didn't go with the string-based approach.
|
||||
* The answer is simple: It's a maintenance burden.
|
||||
* Having various settings strings scattered across many classes will cause
|
||||
* trouble at some point, which will cause some strings to be undocumented
|
||||
* or have an inconsistent naming scheme. Containing settings as variables in
|
||||
* one centralized place mitigates this.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class EngineConfiguration extends Configuration {
|
||||
/**
|
||||
* Contains the class instance.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the class instance.
|
||||
*
|
||||
* @return class instance unless {@link Engine} is uninitialized
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static EngineConfiguration instance;
|
||||
|
||||
/**
|
||||
* Contains the group in which setting overrides must begin with..
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the group in which setting overrides must begin with.
|
||||
*
|
||||
* @return property group
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private final @NotNull String group = "sosengine.base.";
|
||||
|
||||
/**
|
||||
* If enabled, allows for unintentional behaviour and excess logging.
|
||||
* Unless you want to debug or work on a sensitive part of the engine, don't enable this!
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debug}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debug
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
/**
|
||||
* If enabled, all called events will be logged.
|
||||
*
|
||||
* @see EventHelper#logCall(Class, Object...)
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debugEvents}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debugEvents
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debugEvents;
|
||||
|
||||
/**
|
||||
* If enabled, very verbose messages about the {@link ShortcodeParser}'s internals will be printed.
|
||||
* Don't enable unless you want to work on it.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debugShortcodeConverter}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debugShortcodeConverter
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debugShortcodeConverter;
|
||||
|
||||
/**
|
||||
* If enabled, invalid shortcodes will be logged by the {@link ShortcodeParser}.
|
||||
* The message will be printed as a {@link LogLevel#SILENT_WARNING}.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @see #loggerLevel
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #errorShortcodeConverter}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #errorShortcodeConverter
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean errorShortcodeConverter;
|
||||
|
||||
/**
|
||||
* If enabled, will makes the {@link Logger} work asynchronous, in a separate platform thread.
|
||||
* Don't disable unless you want your application to run <b>extremely</b> slowly.
|
||||
*
|
||||
* @see #loggerPollingSpeed
|
||||
* @see Thread
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeLogging}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeLogging
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean optimizeLogging;
|
||||
|
||||
/**
|
||||
* If enabled, will make all events asynchronous, in separate virtual threads.
|
||||
* Don't disable unless you want your application to run slower.
|
||||
*
|
||||
* @see VirtualThread
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeEvents}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeEvents
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean optimizeEvents;
|
||||
|
||||
/**
|
||||
* If enabled, will try to automatically initialize every subsystem found though reflection.
|
||||
* <p>
|
||||
* This however may fail in certain situation, where manual subsystem initialization may be required.
|
||||
* For this reason, this can be turned off before the engine initializes.
|
||||
* Please note though that dependency resolution between subsystems will not be done, be careful when
|
||||
* initializing subsystems manually.
|
||||
*
|
||||
* @see Engine
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeSubsystemInitialization}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeSubsystemInitialization
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private boolean optimizeSubsystemInitialization;
|
||||
|
||||
/**
|
||||
* Contains which logger levels are allowed by setting the minimum logger level.
|
||||
*
|
||||
* @see Logger
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerLevel}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerLevel
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private LogLevel loggerLevel;
|
||||
|
||||
/**
|
||||
* Contains the logging template used for creating log messages.
|
||||
*
|
||||
* @see Logger
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerTemplate}
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerTemplate
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private String loggerTemplate;
|
||||
|
||||
/**
|
||||
* Contains how fast the logging thread will poll for queued messages.
|
||||
* This also causes messages to be buffered.
|
||||
* <p>
|
||||
* Only applies if {@code optimizeLogging} is turned on.
|
||||
* Values below {@code 1} will poll for queued messages as fast as it can.
|
||||
* This however has pretty much no benefit. Leave it at {@code 5}, it works quite well.
|
||||
*
|
||||
* @see #optimizeLogging
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerPollingSpeed}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerPollingSpeed
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private int loggerPollingSpeed;
|
||||
|
||||
/**
|
||||
* If enabled, will force the {@link Logger} and {@link CrashHandler} to use <a href="https://www.man7.org/linux/man-pages/man3/stderr.3.html">the standard output</a>
|
||||
* instead of <a href="https://www.man7.org/linux/man-pages/man3/stderr.3.html">the standard error</a> for logging {@code ERROR} and {@code CRASH}.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerForceStandardOutput}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerForceStandardOutput
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean loggerForceStandardOutput;
|
||||
|
||||
/**
|
||||
* If enabled, will enable support for printing log messages on multiple lines.
|
||||
* By enabling this configuration setting, logger throughput will be decreased slightly when encountering a log message with newlines found in it.
|
||||
* This performance hit is negligible though and should not affect application performance, especially with logger multi-threading turned on (see {@link #optimizeLogging}).
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerEnableNewlineSupport}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerEnableNewlineSupport
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private boolean loggerEnableNewlineSupport;
|
||||
|
||||
/**
|
||||
* If enabled, the JVM will immediately shutdown on an engine crash. This will prevent shutdown hooks from executing.
|
||||
* Note: This will also prevent Jansi and potentially other libraries from removing temporary native libraries at shutdown.
|
||||
*
|
||||
* @see CrashHandler
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerImmediateShutdown}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerImmediateShutdown
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean loggerImmediateShutdown;
|
||||
|
||||
/**
|
||||
* Will truncate the path of types when using their {@code toString} method.
|
||||
* <p>
|
||||
* Here's an example: Lets say that you have a {@link Vec2f} and to convert it
|
||||
* to a String, which you can do with {@link Vec2f#toString()}. With this flag disabled
|
||||
* it would return {@code de.staropensource.sosengine.base.types.vectors.Vec2(x=64 y=64)},
|
||||
* with it however it would be {@code Vec2(x=64 y=64)}, which is much smaller.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #hideFullTypePath}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #hideFullTypePath
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private boolean hideFullTypePath;
|
||||
|
||||
/**
|
||||
* Constructs this class.
|
||||
*
|
||||
* @see Engine
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public EngineConfiguration() {
|
||||
super("ENGINE"); // TODO Wait for flexible constructor bodies (JEP 482) to be implemented into the JVM as a stable feature. We don't want to use preview features in production code.
|
||||
|
||||
// Only allow one instance
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else
|
||||
logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
|
||||
|
||||
// Load default configuration
|
||||
loadDefaultConfiguration();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
||||
try {
|
||||
switch (property) {
|
||||
case "debug" -> debug = parser.getBoolean(group + property);
|
||||
case "debugEvents" -> debugEvents = parser.getBoolean(group + property);
|
||||
case "debugShortcodeConverter" -> debugShortcodeConverter = parser.getBoolean(group + property);
|
||||
|
||||
case "errorShortcodeConverter" -> errorShortcodeConverter = parser.getBoolean(group + property);
|
||||
|
||||
case "optimizeLogging" -> {
|
||||
optimizeLogging = parser.getBoolean(group + property);
|
||||
|
||||
// Start logging thread automatically
|
||||
if (optimizeLogging && Engine.getInstance().getState() == EngineState.RUNNING)
|
||||
LoggingThread.startThread();
|
||||
}
|
||||
case "optimizeEvents" -> optimizeEvents = parser.getBoolean(group + property);
|
||||
case "optimizeSubsystemInitialization" -> optimizeSubsystemInitialization = parser.getBoolean(group + property);
|
||||
|
||||
case "loggerLevel" -> {
|
||||
try {
|
||||
loggerLevel = LogLevel.valueOf(parser.getString(group + property).toUpperCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
System.out.println("Logger level " + parser.getString(group + property) + " is not valid");
|
||||
}
|
||||
}
|
||||
case "loggerTemplate" -> loggerTemplate = parser.getString(group + property);
|
||||
case "loggerPollingSpeed" -> loggerPollingSpeed = parser.getInteger(group + property, true);
|
||||
case "loggerForceStandardOutput" -> loggerForceStandardOutput = parser.getBoolean(group + property);
|
||||
case "loggerEnableNewlineSupport" -> loggerEnableNewlineSupport = parser.getBoolean(group + property);
|
||||
case "loggerImmediateShutdown" -> loggerImmediateShutdown = parser.getBoolean(group + property);
|
||||
|
||||
case "hideFullTypePath" -> hideFullTypePath = parser.getBoolean(group + property);
|
||||
}
|
||||
} catch (NullPointerException ignored) {}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void processSettings(@NotNull PropertiesReader parser) {
|
||||
// Disable all debugging switches if 'debug' is disabled
|
||||
if (!debug) {
|
||||
debugEvents = false;
|
||||
debugShortcodeConverter = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void loadDefaultConfiguration() {
|
||||
debug = false;
|
||||
debugEvents = false;
|
||||
debugShortcodeConverter = false;
|
||||
|
||||
errorShortcodeConverter = true;
|
||||
|
||||
optimizeLogging = true;
|
||||
optimizeEvents = true;
|
||||
optimizeSubsystemInitialization = true;
|
||||
|
||||
loggerLevel = LogLevel.INFORMATIONAL;
|
||||
loggerTemplate = "%log_color_primary%[%time_hour%:%time_minute%:%time_second%] [%log_level% %log_path%%log_metadata%] %log_message_prefix%%log_color_primary%%log_color_secondary%%log_message%<reset>";
|
||||
loggerPollingSpeed = 5;
|
||||
loggerForceStandardOutput = false;
|
||||
loggerEnableNewlineSupport = true;
|
||||
loggerImmediateShutdown = false;
|
||||
|
||||
hideFullTypePath = false;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @Nullable Object getSetting(@NotNull String setting) {
|
||||
switch (setting) {
|
||||
case "debug" -> { return debug; }
|
||||
case "debugEvents" -> { return debugEvents; }
|
||||
case "debugShortcodeConverter" -> { return debugShortcodeConverter; }
|
||||
|
||||
case "errorShortcodeConverter" -> { return errorShortcodeConverter; }
|
||||
|
||||
case "optimizeLogging" -> { return optimizeLogging; }
|
||||
case "optimizeEvents" -> { return optimizeEvents; }
|
||||
case "optimizeSubsystemInitialization" -> { return optimizeSubsystemInitialization; }
|
||||
|
||||
case "loggerLevel" -> { return loggerLevel; }
|
||||
case "loggerTemplate" -> { return loggerTemplate; }
|
||||
case "loggerPollingSpeed" -> { return loggerPollingSpeed; }
|
||||
case "loggerForceStandardOutput" -> { return loggerForceStandardOutput; }
|
||||
case "loggerEnableNewlineSupport" -> { return loggerEnableNewlineSupport; }
|
||||
case "loggerImmediateShutdown" -> { return loggerImmediateShutdown; }
|
||||
|
||||
case "hideFullTypePath" -> { return hideFullTypePath; }
|
||||
default -> { return null; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,15 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base;
|
||||
package de.staropensource.sosengine.base;
|
||||
|
||||
import de.staropensource.engine.base.exception.IllegalAccessException;
|
||||
import de.staropensource.engine.base.implementable.EventListenerCode;
|
||||
import de.staropensource.engine.base.implementable.ShutdownHandler;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.EventPriority;
|
||||
import de.staropensource.engine.base.type.InternalAccessArea;
|
||||
import de.staropensource.sosengine.base.implementable.ShutdownHandler;
|
||||
import de.staropensource.sosengine.base.exception.IllegalAccessException;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.type.InternalAccessArea;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -54,6 +51,14 @@ public final class EngineInternals {
|
|||
@Getter
|
||||
private static EngineInternals instance;
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static final LoggerInstance logger = new LoggerInstance.Builder().setClazz(EngineInternals.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Contains all disabled internal access areas.
|
||||
*
|
||||
|
@ -68,31 +73,16 @@ public final class EngineInternals {
|
|||
private final @NotNull List<@NotNull InternalAccessArea> restrictedAreas = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Contains whether the engine should reflectively
|
||||
* search the classpath for events or other annotations.
|
||||
* <p>
|
||||
* If disabled, code will either have to manually call
|
||||
* registration methods or certain classes have to
|
||||
* be created in a certain package, depending on the
|
||||
* use case and application.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @see EventHelper#registerEvent(Class, EventListenerCode)
|
||||
* @see EventHelper#registerEvent(Class, EventListenerCode, EventPriority)
|
||||
* @since v1-alpha5
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private boolean reflectiveClasspathScanning = true;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
EngineInternals() {
|
||||
public EngineInternals() {
|
||||
// Only allow one instance
|
||||
if (instance == null && Engine.getInstance() != null)
|
||||
instance = this;
|
||||
else
|
||||
Logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
|
||||
logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,12 +110,10 @@ public final class EngineInternals {
|
|||
areas.remove(InternalAccessArea.ALL);
|
||||
areas.remove(InternalAccessArea.ALL_READ);
|
||||
areas.remove(InternalAccessArea.ALL_WRITE);
|
||||
areas.remove(InternalAccessArea.ALL_READ_ESSENTIAL);
|
||||
restrictedAreas.addAll(areas);
|
||||
}
|
||||
case ALL_WRITE -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesWriteOnly()).toList());
|
||||
case ALL_READ -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesReadOnly()).toList());
|
||||
case ALL_READ_ESSENTIAL -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesEssentialReadOnly()).toList());
|
||||
case ALL_WRITE -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesWriteOnly()).toList());
|
||||
default -> restrictedAreas.add(area);
|
||||
}
|
||||
}
|
||||
|
@ -137,11 +125,11 @@ public final class EngineInternals {
|
|||
* Highly recommended to keep enabled.
|
||||
*
|
||||
* @param status {@code true} to install, {@code false} otherwise
|
||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#SAFETY_SHUTDOWN_HOOK_UPDATE})
|
||||
* @throws IllegalAccessException when restricted
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public void installSafetyShutdownHook(boolean status) throws IllegalAccessException {
|
||||
isRestricted(InternalAccessArea.SAFETY_SHUTDOWN_HOOK_UPDATE);
|
||||
isRestricted(InternalAccessArea.SAFETY_SHUTDOWN_HOOK);
|
||||
|
||||
try {
|
||||
if (status)
|
||||
|
@ -151,27 +139,13 @@ public final class EngineInternals {
|
|||
} catch (IllegalArgumentException | IllegalStateException ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the engine's shutdown handler.
|
||||
* The shutdown handler is responsible for
|
||||
* shutting down the JVM safely.
|
||||
*
|
||||
* @return shutdown handler
|
||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#SHUTDOWN_HANDLER_GET})
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public @NotNull ShutdownHandler getShutdownHandler() throws IllegalAccessException {
|
||||
isRestricted(InternalAccessArea.SHUTDOWN_HANDLER_GET);
|
||||
return Engine.getInstance().getShutdownHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the engine's shutdown handler.
|
||||
* The shutdown handler is responsible for
|
||||
* shutting down the JVM safely.
|
||||
*
|
||||
* @param shutdownHandler new shutdown handler
|
||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#SHUTDOWN_HANDLER_UPDATE})
|
||||
* @throws IllegalAccessException when restricted
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public void setShutdownHandler(@NotNull ShutdownHandler shutdownHandler) throws IllegalAccessException {
|
||||
|
@ -180,47 +154,16 @@ public final class EngineInternals {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns whether the engine should reflectively
|
||||
* search the classpath for events or other annotations.
|
||||
* <p>
|
||||
* If disabled, code will either have to manually call
|
||||
* registration methods or certain classes have to
|
||||
* be created in a certain package, depending on the
|
||||
* use case and application.
|
||||
* Gets the engine's shutdown handler.
|
||||
* The shutdown handler is responsible for
|
||||
* shutting down the JVM safely.
|
||||
*
|
||||
* @return reflective classpath scanning flag state
|
||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#REFLECTIVE_CLASSPATH_SCANNING_GET})
|
||||
* @see EventHelper#registerEvent(Class, EventListenerCode)
|
||||
* @see EventHelper#registerEvent(Class, EventListenerCode, EventPriority)
|
||||
* @since v1-alpha5
|
||||
* @return shutdown handler
|
||||
* @throws IllegalAccessException when restricted
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public boolean getReflectiveClasspathScanning() throws IllegalAccessException {
|
||||
isRestricted(InternalAccessArea.REFLECTIVE_CLASSPATH_SCANNING_GET);
|
||||
return reflectiveClasspathScanning;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides whether the engine should reflectively
|
||||
* search the classpath for events or other annotations.
|
||||
* <p>
|
||||
* If disabled, code will either have to manually call
|
||||
* registration methods or certain classes have to
|
||||
* be created in a certain package, depending on the
|
||||
* use case and application.
|
||||
* <p>
|
||||
* Enabling reflective classpath scanning in an unsupported
|
||||
* environment may cause minor to extreme side effects,
|
||||
* including but not limited to <b>bugs, exceptions, engine
|
||||
* or even whole JVM crashes</b>. <i>You have been warned!</i>
|
||||
*
|
||||
* @param reflectiveClasspathScanning new reflective classpath scanning
|
||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#REFLECTIVE_CLASSPATH_SCANNING_OVERRIDE})
|
||||
* @see EventHelper#registerEvent(Class, EventListenerCode)
|
||||
* @see EventHelper#registerEvent(Class, EventListenerCode, EventPriority)
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public void overrideReflectiveClasspathScanning(boolean reflectiveClasspathScanning) throws IllegalAccessException {
|
||||
isRestricted(InternalAccessArea.REFLECTIVE_CLASSPATH_SCANNING_OVERRIDE);
|
||||
this.reflectiveClasspathScanning = reflectiveClasspathScanning;
|
||||
public @NotNull ShutdownHandler getShutdownHandler() throws IllegalAccessException {
|
||||
isRestricted(InternalAccessArea.SHUTDOWN_HANDLER_GET);
|
||||
return Engine.getInstance().getShutdownHandler();
|
||||
}
|
||||
}
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.annotation;
|
||||
package de.staropensource.sosengine.base.annotation;
|
||||
|
||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
||||
import de.staropensource.sosengine.base.implementable.SubsystemClass;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.annotation;
|
||||
package de.staropensource.sosengine.base.annotation;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.type.EventPriority;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.type.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.*;
|
|
@ -23,4 +23,4 @@
|
|||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
package de.staropensource.engine.base.annotation;
|
||||
package de.staropensource.sosengine.base.annotation;
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
|
||||
/**
|
||||
* Called in the event of an engine crash.
|
||||
|
@ -29,7 +29,7 @@ import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|||
*/
|
||||
public final class EngineCrashEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
|
||||
/**
|
||||
* Called when the engine is about to shutdown.
|
||||
|
@ -29,7 +29,7 @@ import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|||
*/
|
||||
public final class EngineShutdownEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,11 +17,11 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
|
||||
/**
|
||||
* Called in the event of a soft engine crash
|
||||
|
@ -33,7 +33,7 @@ import de.staropensource.engine.base.logging.Logger;
|
|||
*/
|
||||
public final class EngineSoftCrashEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,11 +17,11 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
*/
|
||||
public final class LogEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,11 +17,11 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public final class ThrowableCatchEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -22,4 +22,4 @@
|
|||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.event;
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception;
|
||||
package de.staropensource.sosengine.base.exception;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -28,14 +28,14 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class IllegalAccessException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public IllegalAccessException() {}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param message message
|
||||
* @since v1-alpha2
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception;
|
||||
package de.staropensource.sosengine.base.exception;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class ParserException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param message parsing error
|
||||
* @since v1-alpha2
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception;
|
||||
package de.staropensource.sosengine.base.exception;
|
||||
|
||||
import de.staropensource.engine.base.type.Tristate;
|
||||
import de.staropensource.sosengine.base.type.Tristate;
|
||||
|
||||
/**
|
||||
* Thrown when converting a {@link Tristate} into a {@link Boolean} fails.
|
||||
|
@ -32,7 +32,7 @@ import de.staropensource.engine.base.type.Tristate;
|
|||
*/
|
||||
public class TristateConversionException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception;
|
||||
package de.staropensource.sosengine.base.exception;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class UnexpectedCheckEndException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param checkOccurrence the sequence of checks that failed
|
||||
* @since v1-alpha2
|
||||
|
@ -38,7 +38,7 @@ public class UnexpectedCheckEndException extends RuntimeException {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.dependency;
|
||||
package de.staropensource.sosengine.base.exception.dependency;
|
||||
|
||||
import de.staropensource.engine.base.utility.DependencyResolver;
|
||||
import de.staropensource.sosengine.base.utility.DependencyResolver;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class DependencyCycleException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param path cycle path
|
||||
* @since v1-alpha1
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.dependency;
|
||||
package de.staropensource.sosengine.base.exception.dependency;
|
||||
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import de.staropensource.engine.base.utility.DependencyResolver;
|
||||
import de.staropensource.sosengine.base.type.DependencyVector;
|
||||
import de.staropensource.sosengine.base.utility.DependencyResolver;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class UnmetDependenciesException extends Exception {
|
|||
private final @NotNull List<@NotNull String> unmetDependencies;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param unmetDependencies map of all unmet dependencies
|
||||
* @see #unmetDependencies
|
|
@ -20,7 +20,7 @@
|
|||
/**
|
||||
* Exceptions related to dependency resolving.
|
||||
*
|
||||
* @see de.staropensource.engine.base.utility.DependencyResolver
|
||||
* @see de.staropensource.sosengine.base.utility.DependencyResolver
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.exception.dependency;
|
||||
package de.staropensource.sosengine.base.exception.dependency;
|
|
@ -22,4 +22,4 @@
|
|||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.exception;
|
||||
package de.staropensource.sosengine.base.exception;
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import de.staropensource.engine.base.type.reflection.ClassType;
|
||||
import de.staropensource.engine.base.utility.ListFormatter;
|
||||
import de.staropensource.sosengine.base.type.reflection.ClassType;
|
||||
import de.staropensource.sosengine.base.utility.ListFormatter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -30,18 +30,18 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class IncompatibleTypeException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param methodName name of the method that failed
|
||||
* @param requiredClassType class type received by the method
|
||||
* @param compatibleTypes class types the method is compatible with
|
||||
*/
|
||||
public IncompatibleTypeException(@NotNull String methodName, @NotNull ClassType requiredClassType, @NotNull ClassType @NotNull [] compatibleTypes) {
|
||||
public IncompatibleTypeException(@NotNull String methodName, @NotNull ClassType requiredClassType, @NotNull ClassType[] compatibleTypes) {
|
||||
super("The method ReflectionClass#" + methodName + " only applies to type(s) " + ListFormatter.formatArray(compatibleTypes) + ", not " + requiredClassType.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param methodName name of the method that failed
|
||||
* @param requiredClassType class type received by the method
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class InstanceMethodFromStaticContextException extends Exception {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param methodName name of the method
|
||||
* @since v1-alpha2
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import de.staropensource.engine.base.reflection.ReflectionClass;
|
||||
import de.staropensource.sosengine.base.reflection.ReflectionClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class InvalidFieldException extends Exception {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param clazz caller {@link ReflectionClass}
|
||||
* @param fieldName name of the invalid field
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import de.staropensource.engine.base.reflection.ReflectionClass;
|
||||
import de.staropensource.sosengine.base.reflection.ReflectionClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class InvalidMethodException extends Exception {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param clazz caller {@link ReflectionClass}
|
||||
* @param fieldName name of the invalid method
|
|
@ -17,23 +17,22 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Thrown when a method could not be found due to an invalid method signature.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public class InvalidMethodSignatureException extends Exception {
|
||||
public class InvalidMethodSignature extends Exception {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param methodName method name
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
public InvalidMethodSignatureException(@NotNull String methodName) {
|
||||
public InvalidMethodSignature(@NotNull String methodName) {
|
||||
super("Method " + methodName + " has a different method signature");
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public class NoAccessException extends Exception {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param type {@code class}, {@code method} or {@code field}
|
||||
* @param name class, method or field name
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -43,7 +43,7 @@ public class StaticInitializerException extends Exception {
|
|||
private final @NotNull Throwable throwable;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param throwable throwable thrown by the static initializer
|
||||
* @since v1-alpha2
|
|
@ -20,7 +20,7 @@
|
|||
/**
|
||||
* Exceptions related to reflection.
|
||||
*
|
||||
* @see de.staropensource.engine.base.reflection
|
||||
* @see de.staropensource.sosengine.base.reflection
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
package de.staropensource.engine.base.exception.reflection;
|
||||
package de.staropensource.sosengine.base.exception.reflection;
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.versioning;
|
||||
package de.staropensource.sosengine.base.exception.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
|
||||
/**
|
||||
* Thrown when trying to compare a {@link VersioningSystem} against another
|
||||
|
@ -29,7 +29,7 @@ import de.staropensource.engine.base.implementable.VersioningSystem;
|
|||
*/
|
||||
public class IncompatibleVersioningSystemException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param required required versioning system ie. the versioning system throwing this error
|
||||
* @param found found versioning system ie. the incompatible one
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.exception.versioning;
|
||||
package de.staropensource.sosengine.base.exception.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -51,7 +51,7 @@ public class InvalidVersionStringException extends Exception {
|
|||
private final @Nullable Throwable throwable;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param versioningSystem versioning system that is unable to parse version strings
|
||||
* @param versionString version string {@code a}
|
||||
|
@ -65,7 +65,7 @@ public class InvalidVersionStringException extends Exception {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param versioningSystem versioning system that is unable to parse version strings
|
||||
* @param versionString version string {@code a}
|
||||
|
@ -78,7 +78,7 @@ public class InvalidVersionStringException extends Exception {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param versioningSystem versioning system that is unable to parse version strings
|
||||
* @param versionString version string {@code a}
|
||||
|
@ -91,7 +91,7 @@ public class InvalidVersionStringException extends Exception {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
* Constructs this exception.
|
||||
*
|
||||
* @param versioningSystem versioning system that is unable to parse version strings
|
||||
* @param versionString version string {@code a}
|
|
@ -18,9 +18,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Exceptions thrown by implementations of {@link de.staropensource.engine.base.implementable.VersioningSystem}s.
|
||||
* Exceptions thrown by implementations of {@link de.staropensource.sosengine.base.implementable.VersioningSystem}s.
|
||||
*
|
||||
* @see de.staropensource.engine.base.implementable.VersioningSystem
|
||||
* @see de.staropensource.sosengine.base.implementable.VersioningSystem
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.exception.versioning;
|
||||
package de.staropensource.sosengine.base.exception.versioning;
|
|
@ -17,9 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.utility.PropertiesReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -36,11 +37,23 @@ import java.util.Properties;
|
|||
*/
|
||||
public abstract class Configuration {
|
||||
/**
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
protected final @NotNull LoggerInstance logger;
|
||||
|
||||
/**
|
||||
* Constructs this class.
|
||||
*
|
||||
* @param origin see {@link LoggerInstance.Builder#setOrigin(String)}
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected Configuration() {
|
||||
public Configuration(@NotNull String origin) {
|
||||
// Set logger instance
|
||||
logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin(origin).build();
|
||||
|
||||
// Load default configuration
|
||||
loadDefaultConfiguration();
|
||||
}
|
||||
|
@ -87,7 +100,7 @@ public abstract class Configuration {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns prefix properties must begin with.
|
||||
* Returns the group in which setting overrides must begin with.
|
||||
*
|
||||
* @return property group
|
||||
* @since v1-alpha2
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
|
||||
/**
|
||||
* Represents an event.
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Interface for implementing custom logger implementations.
|
||||
*
|
||||
* @see Logger#setLoggingAdapter(LoggingAdapter)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public interface LoggingAdapter {
|
||||
/**
|
||||
* Invoked before anything is done with the log message.
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass issuer class
|
||||
* @param issuerOrigin issuer origin
|
||||
* @param issuerMetadata issuer metadata
|
||||
* @param message raw message
|
||||
* @param format unmodified log format
|
||||
* @return new log message, return {@code null} for no change
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@Nullable String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format);
|
||||
|
||||
/**
|
||||
* Invoked after placeholders have been processed and replaced.
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass issuer class
|
||||
* @param issuerOrigin issuer origin
|
||||
* @param issuerMetadata issuer metadata
|
||||
* @param message raw message
|
||||
* @param format unmodified log format
|
||||
* @return new log format
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@NotNull String postPlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format);
|
||||
|
||||
/**
|
||||
* Prints the log message.
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass issuer class
|
||||
* @param issuerOrigin issuer origin
|
||||
* @param issuerMetadata issuer metadata
|
||||
* @param message raw message
|
||||
* @param format unmodified log format
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format);
|
||||
}
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
||||
import de.staropensource.sosengine.base.utility.PlaceholderEngine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
|
@ -17,11 +17,11 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.exception.ParserException;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.exception.ParserException;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -29,7 +29,7 @@ import java.util.LinkedList;
|
|||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Base class for implementing a shortcode parser.
|
||||
* Base class for implementing a shortcode converter.
|
||||
* <p>
|
||||
* This class parses a string and converts it into a list of
|
||||
* components, which can then be in turn be converted to something
|
||||
|
@ -48,9 +48,16 @@ import java.util.Locale;
|
|||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public abstract class ShortcodeParser {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
protected final @NotNull LoggerInstance logger;
|
||||
|
||||
/**
|
||||
* Contains a list of components the parsed text is made out of.
|
||||
*
|
||||
|
@ -61,17 +68,19 @@ public abstract class ShortcodeParser {
|
|||
* @return component list
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
protected final @NotNull LinkedList<String> components;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @param string string to parse
|
||||
* @param ignoreInvalidEscapes if {@code true}, will ignore and treat invalid escapes as text
|
||||
* @throws ParserException on error
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected ShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
public ShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").build();
|
||||
components = parse(string, ignoreInvalidEscapes);
|
||||
}
|
||||
|
||||
|
@ -83,7 +92,7 @@ public abstract class ShortcodeParser {
|
|||
* @param ignoreInvalidEscapes if {@code true}, will ignore and treat invalid escapes as text
|
||||
* @return list of components
|
||||
* @throws ParserException on error
|
||||
* @see EngineConfiguration#errorShortcodeParser
|
||||
* @see EngineConfiguration#errorShortcodeConverter
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected @NotNull LinkedList<@NotNull String> parse(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
|
@ -119,53 +128,110 @@ public abstract class ShortcodeParser {
|
|||
tagActive = false;
|
||||
|
||||
// fg:*
|
||||
if (part.toString().startsWith("fg:"))
|
||||
if (part.toString().startsWith("fg:")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=fg data=" + part.substring(3).toUpperCase());
|
||||
|
||||
if (isValidColor(part.substring(3).toUpperCase()))
|
||||
components.add("COLOR:FOREGROUND:" + part.substring(3).toUpperCase());
|
||||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
Logger.sarn("Invalid shortcode: " + part);
|
||||
if (EngineConfiguration.getInstance().isErrorShortcodeConverter())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
}
|
||||
}
|
||||
|
||||
// bg:*
|
||||
else if (part.toString().startsWith("bg:"))
|
||||
else if (part.toString().startsWith("bg:")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bg data=" + part.substring(3).toUpperCase());
|
||||
|
||||
if (isValidColor(part.substring(3).toUpperCase()))
|
||||
components.add("COLOR:BACKGROUND:" + part.substring(3).toUpperCase());
|
||||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
Logger.sarn("Invalid shortcode: " + part);
|
||||
if (EngineConfiguration.getInstance().isErrorShortcodeConverter())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
}
|
||||
}
|
||||
|
||||
// bold
|
||||
else if (part.toString().equals("bold"))
|
||||
else if (part.toString().equals("bold")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bold");
|
||||
|
||||
// Insert attribute
|
||||
components.add("ATTRIBUTE:BOLD");
|
||||
}
|
||||
|
||||
// italic
|
||||
else if (part.toString().equals("italic"))
|
||||
else if (part.toString().equals("italic")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=italic");
|
||||
|
||||
// Insert attribute
|
||||
components.add("ATTRIBUTE:ITALIC");
|
||||
}
|
||||
|
||||
// strikethrough
|
||||
else if (part.toString().equals("strikethrough"))
|
||||
else if (part.toString().equals("strikethrough")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=strikethrough");
|
||||
|
||||
// Insert attribute
|
||||
components.add("ATTRIBUTE:STRIKETHROUGH");
|
||||
}
|
||||
|
||||
// underline
|
||||
else if (part.toString().equals("underline"))
|
||||
else if (part.toString().equals("underline")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=underline");
|
||||
|
||||
// Insert attribute
|
||||
components.add("ATTRIBUTE:UNDERLINE");
|
||||
// blink
|
||||
else if (part.toString().equals("blink"))
|
||||
}
|
||||
|
||||
// underline
|
||||
else if (part.toString().equals("blink")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=blink");
|
||||
|
||||
// Insert attribute
|
||||
components.add("ATTRIBUTE:BLINK");
|
||||
}
|
||||
|
||||
// reset
|
||||
else if (part.toString().equals("reset"))
|
||||
else if (part.toString().equals("reset")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=reset");
|
||||
|
||||
// Insert reset
|
||||
components.add("RESET");
|
||||
}
|
||||
|
||||
// error case
|
||||
else {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " invalidtag=" + part);
|
||||
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
Logger.sarn("Invalid shortcode: " + part);
|
||||
if (EngineConfiguration.getInstance().isErrorShortcodeConverter())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
|
@ -182,6 +248,9 @@ public abstract class ShortcodeParser {
|
|||
if (character == '<') {
|
||||
if (!part.isEmpty()) {
|
||||
// Tag is starting, insert previous text
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " text=" + part);
|
||||
|
||||
components.add("TEXT:" + part);
|
||||
part = new StringBuilder();
|
||||
}
|
||||
|
@ -195,8 +264,12 @@ public abstract class ShortcodeParser {
|
|||
}
|
||||
|
||||
// Processing ended, insert leftover text
|
||||
if (!part.isEmpty())
|
||||
if (!part.isEmpty()) {
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " endtext=" + part);
|
||||
|
||||
components.add("TEXT:" + part);
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.sosengine.base.Engine;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
/**
|
|
@ -17,28 +17,37 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.engine.base.annotation.EventListener;
|
||||
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import de.staropensource.sosengine.base.Engine;
|
||||
import de.staropensource.sosengine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.sosengine.base.annotation.EventListener;
|
||||
import de.staropensource.sosengine.base.internal.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.type.DependencyVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Abstract class for building subsystem main classes.
|
||||
* Interface for building subsystem main classes.
|
||||
*
|
||||
* @see EngineSubsystem
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public abstract class SubsystemClass {
|
||||
/**
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected SubsystemClass() {}
|
||||
public SubsystemClass() {}
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public final LoggerInstance logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Returns the name of the subsystem.
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base.implementable.helper;
|
||||
|
||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.annotation.EventListener;
|
||||
import de.staropensource.sosengine.base.event.LogEvent;
|
||||
import de.staropensource.sosengine.base.exception.reflection.InstanceMethodFromStaticContextException;
|
||||
import de.staropensource.sosengine.base.exception.reflection.InvalidMethodSignature;
|
||||
import de.staropensource.sosengine.base.exception.reflection.NoAccessException;
|
||||
import de.staropensource.sosengine.base.exception.reflection.StaticInitializerException;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||
import de.staropensource.sosengine.base.reflection.Reflect;
|
||||
import de.staropensource.sosengine.base.reflection.ReflectionMethod;
|
||||
import de.staropensource.sosengine.base.utility.ListFormatter;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Simplifies event logging and calling.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
public final class EventHelper {
|
||||
/**
|
||||
* Holds all cached events.
|
||||
* Should not be modified manually.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private static final @NotNull HashMap<@NotNull Class<? extends Event>, LinkedList<@NotNull ReflectionMethod>> cachedEventListeners = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(EventHelper.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public EventHelper() {}
|
||||
|
||||
/**
|
||||
* Logs an event call.
|
||||
*
|
||||
* @param event event class
|
||||
* @param arguments arguments passed to event listeners
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static void logCall(@NotNull Class<? extends Event> event, @NotNull Object ... arguments) {
|
||||
// Print event call if event debugging is enabled
|
||||
if (EngineConfiguration.getInstance().isDebugEvents())
|
||||
if (arguments.length == 0)
|
||||
logger.diag("Event " + event.getName() + " was emitted");
|
||||
else
|
||||
logger.diag("Event " + event.getName() + " was emitted, passing arguments " + ListFormatter.formatArray(arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all {@link EventListener}s listening on some event.
|
||||
* The classpath will be scanned for listeners, unless cached results exist and {@code !forceScanning}.
|
||||
*
|
||||
* @param event event class
|
||||
* @param forceScanning forces scanning the classpath for listeners. not recommended due to a huge performance penalty
|
||||
* @return list of event listeners
|
||||
* @see #cacheEvent(Class)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static @NotNull LinkedList<ReflectionMethod> getAnnotatedMethods(@NotNull Class<? extends Event> event, boolean forceScanning) {
|
||||
LinkedList<ReflectionMethod> methods = new LinkedList<>();
|
||||
|
||||
if (forceScanning || !cachedEventListeners.containsKey(event)) {
|
||||
Reflections reflections = new Reflections(
|
||||
new ConfigurationBuilder()
|
||||
.setUrls(ClasspathHelper.forJavaClassPath())
|
||||
.setScanners(Scanners.MethodsAnnotated)
|
||||
);
|
||||
|
||||
// Get annotated methods
|
||||
Set<@NotNull Method> annotatedMethods = reflections.getMethodsAnnotatedWith(EventListener.class);
|
||||
|
||||
// Sort event listeners not listening for this event out
|
||||
for (Method method : annotatedMethods)
|
||||
if (method.getAnnotation(EventListener.class).event() == event)
|
||||
methods.add(Reflect.reflectOn(method));
|
||||
|
||||
// Sort 'methods' linked list after event priority
|
||||
methods.sort(Comparator.comparing(method -> method.getAnnotation(EventListener.class).priority()));
|
||||
} else
|
||||
// Event listeners are cached and !forceScanning, return cached results
|
||||
methods = cachedEventListeners.get(event);
|
||||
|
||||
return methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all {@link EventListener}s listening on some event.
|
||||
* The classpath will be scanned for listeners, unless cached results exist.
|
||||
*
|
||||
* @param event event class
|
||||
* @return list of event listeners
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static @NotNull LinkedList<ReflectionMethod> getAnnotatedMethods(@NotNull Class<? extends Event> event) {
|
||||
return getAnnotatedMethods(event, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes all event listeners.
|
||||
*
|
||||
* @param event event class
|
||||
* @param arguments arguments to pass to event listeners
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static void invokeAnnotatedMethods(@NotNull Class<? extends Event> event, Object... arguments) {
|
||||
if (event != LogEvent.class)
|
||||
logCall(event);
|
||||
|
||||
Runnable eventCode = () -> {
|
||||
for (ReflectionMethod method : getAnnotatedMethods(event)) {
|
||||
try {
|
||||
method.invoke(arguments);
|
||||
} catch (NoAccessException exception) {
|
||||
logger.warn("Event listener method " + method.getName() + " could not be called as the method could not be accessed");
|
||||
} catch (InvalidMethodSignature exception) {
|
||||
logger.warn("Event listener method " + method.getName() + " has an invalid method signature");
|
||||
} catch (InvocationTargetException exception) {
|
||||
logger.crash("Event listener method " + method.getName() + " threw a throwable", exception.getTargetException(), true);
|
||||
} catch (InstanceMethodFromStaticContextException exception) {
|
||||
logger.warn("Event listener method " + method.getName() + " is not static. Event listener methods must be static for them to be called.");
|
||||
} catch (StaticInitializerException exception) {
|
||||
logger.crash("Event listener method " + method.getName() + " could not be called as the static initializer failed", exception.getThrowable(), true);
|
||||
} catch (Exception exception) {
|
||||
logger.crash("Event listener method " + method.getName() + " could not be called as an error occurred during reflection", exception, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (EngineConfiguration.getInstance().isOptimizeEvents())
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Event " + event.getName())
|
||||
.start(eventCode);
|
||||
else
|
||||
eventCode.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* (Re-)Caches all event listeners for some {@link Event}.
|
||||
*
|
||||
* @param event event to (re-)cache. Set to {@code null} to recompute all cached events
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static synchronized void cacheEvent(@Nullable Class<? extends Event> event) {
|
||||
if (event == null)
|
||||
for (Class<? extends Event> cachedEvent : cachedEventListeners.keySet())
|
||||
cacheEvent(cachedEvent);
|
||||
else {
|
||||
LinkedList<@NotNull ReflectionMethod> annotatedMethods = getAnnotatedMethods(event);
|
||||
|
||||
if (cachedEventListeners.containsKey(event))
|
||||
cachedEventListeners.replace(event, annotatedMethods);
|
||||
else
|
||||
cachedEventListeners.put(event, annotatedMethods);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an event from the event listener cache.
|
||||
*
|
||||
* @param event event to uncache. Set to {@code null} to clear the entire cache
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static synchronized void uncacheEvent(@Nullable Class<? extends Event> event) {
|
||||
if (event == null)
|
||||
cachedEventListeners.clear();
|
||||
else
|
||||
cachedEventListeners.remove(event);
|
||||
}
|
||||
}
|
|
@ -23,4 +23,4 @@
|
|||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
package de.staropensource.engine.base.implementable.helper;
|
||||
package de.staropensource.sosengine.base.implementable.helper;
|
|
@ -20,8 +20,8 @@
|
|||
/**
|
||||
* Interfaces and abstract classes which can be used for implementing classes.
|
||||
* <p>
|
||||
* These are not to be confused with data types. See {@link de.staropensource.engine.windowing.type}.
|
||||
* These are not to be confused with data types. See {@link de.staropensource.sosengine.base.type}.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
package de.staropensource.engine.windowing.implementable;
|
||||
package de.staropensource.sosengine.base.implementable;
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.sosengine.base.implementation.logging;
|
||||
|
||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.implementation.shortcode.EmptyShortcodeConverter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Prints log messages to the console, without any fancy colors or formatting.
|
||||
*
|
||||
* @see Logger
|
||||
* @see LoggingAdapter
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public class PlainLoggingAdapter implements LoggingAdapter {
|
||||
/**
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public PlainLoggingAdapter() {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @Nullable String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return null; // No modifications necessary
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String postPlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return format; // No modifications necessary
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
format = new EmptyShortcodeConverter(format, true).getClean();
|
||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
||||
System.out.println(format);
|
||||
else
|
||||
System.err.println(format);
|
||||
else
|
||||
System.out.println(format);
|
||||
}
|
||||
}
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.logging;
|
||||
package de.staropensource.sosengine.base.implementation.logging;
|
||||
|
||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
*/
|
||||
public class QuietLoggingAdapter implements LoggingAdapter {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
|
@ -40,5 +40,17 @@ public class QuietLoggingAdapter implements LoggingAdapter {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {}
|
||||
public @Nullable String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String postPlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return format;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {}
|
||||
}
|
|
@ -17,12 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.logging;
|
||||
package de.staropensource.sosengine.base.implementation.logging;
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.sosengine.base.logging.Logger;
|
||||
import de.staropensource.sosengine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
*/
|
||||
public class RawLoggingAdapter implements LoggingAdapter {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
|
@ -44,9 +44,21 @@ public class RawLoggingAdapter implements LoggingAdapter {
|
|||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
||||
public @Nullable String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return null; // No modifications necessary
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String postPlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
return format; // No modifications necessary
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||
if (EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
||||
System.out.println(format);
|
||||
else
|
||||
System.err.println(format);
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A set of built-in {@link de.staropensource.sosengine.base.implementable.LoggingAdapter}s.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.sosengine.base.implementation.logging;
|
|
@ -17,28 +17,28 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.shortcode;
|
||||
package de.staropensource.sosengine.base.implementation.shortcode;
|
||||
|
||||
import de.staropensource.engine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.engine.base.exception.ParserException;
|
||||
import de.staropensource.sosengine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.sosengine.base.exception.ParserException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Cleans the string of any tags.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @since v1-alpha8
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public final class EmptyShortcodeParser extends ShortcodeParser {
|
||||
public final class EmptyShortcodeConverter extends ShortcodeParser {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @param string string to parse
|
||||
* @param ignoreInvalidEscapes if {@code true}, will ignore and treat invalid escapes as text
|
||||
* @throws ParserException on error
|
||||
* @since v1-alpha8
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public EmptyShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
public EmptyShortcodeConverter(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
super(string, ignoreInvalidEscapes);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public final class EmptyShortcodeParser extends ShortcodeParser {
|
|||
* Returns the parsed string without any tags.
|
||||
*
|
||||
* @return cleaned input string
|
||||
* @since v1-alpha8
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public @NotNull String getClean() {
|
||||
StringBuilder output = new StringBuilder();
|
|
@ -22,4 +22,4 @@
|
|||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.implementation.shortcode;
|
||||
package de.staropensource.sosengine.base.implementation.shortcode;
|
|
@ -17,12 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
@ -90,8 +90,7 @@ public final class FourNumberVersioningSystem implements VersioningSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified version string
|
||||
* and if successful, return a new instance.
|
||||
* Parses a four number-based version string.
|
||||
*
|
||||
* @param versionString version string to parse
|
||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
@ -17,11 +17,11 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
@ -53,8 +53,7 @@ public final class OneNumberVersioningSystem implements VersioningSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified version string
|
||||
* and if successful, return a new instance.
|
||||
* Parses a one number-based version string.
|
||||
*
|
||||
* @param versionString version string to parse
|
||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
@ -17,12 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -109,8 +109,7 @@ public final class SemanticVersioningSystem implements VersioningSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified version string
|
||||
* and if successful, return a new instance.
|
||||
* Parses a semantic versioning string.
|
||||
*
|
||||
* @param versionString version string to parse
|
||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
@ -17,12 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.engine.base.type.VersionType;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.sosengine.base.type.VersionType;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -110,8 +110,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified version string
|
||||
* and if successful, return a new instance.
|
||||
* Parses a StarOpenSource versioning string.
|
||||
*
|
||||
* @param versionString version string to parse
|
||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
@ -17,12 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
@ -78,8 +78,7 @@ public final class ThreeNumberVersioningSystem implements VersioningSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified version string
|
||||
* and if successful, return a new instance.
|
||||
* Parses a three number-based version string.
|
||||
*
|
||||
* @param versionString version string to parse
|
||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
@ -17,12 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
||||
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.sosengine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.sosengine.base.exception.versioning.IncompatibleVersioningSystemException;
|
||||
import de.staropensource.sosengine.base.exception.versioning.InvalidVersionStringException;
|
||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
@ -66,8 +66,7 @@ public final class TwoNumberVersioningSystem implements VersioningSystem {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified version string
|
||||
* and if successful, return a new instance.
|
||||
* Parses a two number-based version string.
|
||||
*
|
||||
* @param versionString version string to parse
|
||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
@ -23,4 +23,4 @@
|
|||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
package de.staropensource.engine.base.implementation.versioning;
|
||||
package de.staropensource.sosengine.base.implementation.versioning;
|
|
@ -17,13 +17,13 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.event;
|
||||
package de.staropensource.sosengine.base.internal.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.sosengine.base.implementable.Event;
|
||||
import de.staropensource.sosengine.base.implementable.helper.EventHelper;
|
||||
|
||||
/**
|
||||
* Called when the engine is about to shutdown, after {@link de.staropensource.engine.base.event.EngineShutdownEvent}.
|
||||
* Called when the engine is about to shutdown, after {@link de.staropensource.sosengine.base.event.EngineShutdownEvent}.
|
||||
* <p>
|
||||
* Meant for subsystems to perform cleanup and shutdown routines, not for applications.
|
||||
*
|
||||
|
@ -31,7 +31,7 @@ import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|||
*/
|
||||
public final class InternalEngineShutdownEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Events used for engine-internal communication.
|
||||
* These events are meant to be listened on by the base engine and it's subsystems.
|
||||
*/
|
||||
package de.staropensource.sosengine.base.internal.event;
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.Math;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
@ -34,7 +34,7 @@ import java.util.Calendar;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class DateDay implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.Math;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
@ -34,7 +34,7 @@ import java.util.Calendar;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class DateMonth implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.Math;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
@ -34,7 +34,7 @@ import java.util.Calendar;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class DateYear implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineDependencyJansi implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineDependencyLwjgl implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineDependencyReflections implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineDependencySlf4j implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineGitBranch implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineGitCommitHeader implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineGitCommitIdLong implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
|
@ -17,10 +17,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
package de.staropensource.sosengine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.sosengine.base.implementable.Placeholder;
|
||||
import de.staropensource.sosengine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
@SuppressWarnings({ "unused" })
|
||||
public final class EngineGitCommitIdShort implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Constructs this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue