Compare commits
36 commits
Author | SHA1 | Date | |
---|---|---|---|
8bd0896415 | |||
20580fb80b | |||
a45f010196 | |||
69cf668c4d | |||
7560e150af | |||
b643735d0b | |||
d12206b925 | |||
dde8972feb | |||
6425442c25 | |||
d1d8e305ed | |||
a6a41f5cec | |||
7cf9a4f418 | |||
ea93d12151 | |||
c533a06148 | |||
4281f946be | |||
5021f2cc35 | |||
edd28bef2f | |||
7c0b7e1e90 | |||
0966a43d5e | |||
2730aa0f61 | |||
ed1c8b9d3e | |||
d3a01c2c66 | |||
a21ef1bc5f | |||
a619746e8d | |||
e42ac8a08e | |||
ffcf4604a4 | |||
6f8d190d6f | |||
c2028cfa33 | |||
40894bedba | |||
6d7701a7c3 | |||
665ea05041 | |||
37ac235662 | |||
01ea995177 | |||
294ec217ea | |||
4c9bfb3732 | |||
f6c99b66e8 |
140 changed files with 4731 additions and 5877 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -42,3 +42,6 @@ bin/
|
|||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
|
||||
### Java ###
|
||||
hs_err_pid*.log
|
||||
|
|
|
@ -26,7 +26,6 @@ import de.staropensource.engine.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.
|
||||
|
@ -43,28 +42,16 @@ public class AnsiLoggingAdapter implements LoggingAdapter {
|
|||
*/
|
||||
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 Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
||||
// Convert to Ansi
|
||||
Ansi output = new AnsiShortcodeConverter(format, true).getAnsi();
|
||||
Ansi output = new AnsiShortcodeParser(format, true).getAnsi();
|
||||
|
||||
// Print message
|
||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
||||
if (EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
AnsiConsole.out().println(output);
|
||||
else
|
||||
AnsiConsole.err().println(output);
|
||||
|
|
|
@ -28,12 +28,13 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Converts shortcodes such as {@code <bold>} or {@code <blink>} into a usable {@link Ansi} escape sequence.
|
||||
* Implementation of the {@link ShortcodeParser} class
|
||||
* with ANSI support using the Jansi library.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class AnsiShortcodeConverter extends ShortcodeParser {
|
||||
public final class AnsiShortcodeParser extends ShortcodeParser {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
|
@ -42,7 +43,7 @@ public final class AnsiShortcodeConverter extends ShortcodeParser {
|
|||
* @throws ParserException when parsing failed
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public AnsiShortcodeConverter(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
public AnsiShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
super(string, ignoreInvalidEscapes);
|
||||
}
|
||||
|
|
@ -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} */
|
||||
|
|
|
@ -27,13 +27,17 @@ 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.internal.event.InternalEngineShutdownEvent;
|
||||
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;
|
||||
|
@ -84,14 +88,6 @@ 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.
|
||||
*
|
||||
|
@ -103,7 +99,7 @@ public final class Engine extends SubsystemClass {
|
|||
* @since v1-alpha2
|
||||
*/
|
||||
@Getter
|
||||
private @NotNull EngineState state = EngineState.UNKNOWN;
|
||||
private @NotNull EngineState state;
|
||||
|
||||
/**
|
||||
* Contains a list of all registered subsystems.
|
||||
|
@ -169,57 +165,116 @@ 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
|
||||
InitLogger.warn(getClass(), "ENGINE", EngineInformation.getVersioningCodename(), "Engine successfully shut down using shutdown hook. PLEASE USE Engine#shutdown() INSTEAD OF System#exit() or Runtime#exit()!");
|
||||
Logger.warn("Engine successfully shut down using shutdown hook. PLEASE USE Engine#shutdown() INSTEAD OF System#exit() or Runtime#exit()!");
|
||||
});
|
||||
|
||||
/**
|
||||
* Initializes the StarOpenSource Engine.
|
||||
*
|
||||
* @throws IllegalStateException when running in an incompatible environment
|
||||
* @since v1-alpha6
|
||||
* @throws RuntimeException for all exceptions thrown by this constructor
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private Engine() throws IllegalStateException {
|
||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
||||
private Engine() throws RuntimeException {
|
||||
try {
|
||||
instance = this;
|
||||
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();
|
||||
|
||||
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
|
||||
// Load engine build information
|
||||
Logger.diag("Loading engine build information");
|
||||
EngineInformation.update();
|
||||
|
||||
logger.verb("Completing early initialization stage");
|
||||
// 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");
|
||||
state = EngineState.STARTUP;
|
||||
initTimeEarly = System.currentTimeMillis() - initTimeEarly;
|
||||
|
||||
// Perform automatic subsystem initialization
|
||||
if (EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization()) {
|
||||
collectSubsystems(); // Collect subsystems
|
||||
// Collect all subsystems
|
||||
Logger.diag("Collecting subsystems");
|
||||
collectSubsystems();
|
||||
|
||||
// Initialize subsystems
|
||||
try {
|
||||
initializeSubsystems();
|
||||
} catch (Exception exception) {
|
||||
logger.error("Subsystem dependency resolution failed");
|
||||
Logger.error("Subsystem dependency resolution failed");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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.");
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,147 +285,74 @@ public final class Engine extends SubsystemClass {
|
|||
* @throws RuntimeException on engine initialization failure
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
public static void initialize() throws IllegalStateException, RuntimeException {
|
||||
public static void initialize() throws RuntimeException {
|
||||
try {
|
||||
if (instance == null)
|
||||
new Engine();
|
||||
} catch (IllegalStateException exception) {
|
||||
throw exception;
|
||||
} catch (Exception exception) {
|
||||
logger.error("Engine initialization failed");
|
||||
logger.error(Miscellaneous.getStackTraceHeader(exception));
|
||||
for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n"))
|
||||
logger.error(line);
|
||||
throw new RuntimeException("Engine initialization failed", exception);
|
||||
} 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);
|
||||
|
||||
throw new RuntimeException("Engine initialization failed", exception.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all classes.
|
||||
* Checks if the running JVM implementation is not supported by the engine.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private void initializeClasses() {
|
||||
logger.verb("Initializing engine classes");
|
||||
new EngineInternals();
|
||||
PlaceholderEngine.initialize();
|
||||
private void checkJvmIncompatibilities() {
|
||||
if (System.getProperties().getProperty("sosengine.base.allowUnsupportedJVMInitialization", "false").equals("true")) {
|
||||
Logger.warn("Skipping JVM implementation incompatibilities check");
|
||||
return;
|
||||
}
|
||||
|
||||
EngineInformation.update();
|
||||
PrintStreamService.initializeStreams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the environment is compatible with the engine build.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private boolean checkEnvironment() {
|
||||
logger.diag("Checking environment");
|
||||
|
||||
// Warn about potential Java incompatibilities
|
||||
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());
|
||||
|
||||
// Shutdown if running in an unsupported JVM
|
||||
// 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("##############################################################################################");
|
||||
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 (checkClasspathScanningSupport()) {
|
||||
logger.warn("Running in an classpath scanning-unfriendly environment, disabling.");
|
||||
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 place classes in some package.");
|
||||
logger.warn("Please consult sos!engine's documentation for more information about this issue.");
|
||||
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);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether scanning the classpath is supported.
|
||||
* Checks and warns if the Java version of the
|
||||
* running JVM is higher than the engine supports.
|
||||
*
|
||||
* @return test results
|
||||
* @since v1-alpha5
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private boolean checkClasspathScanningSupport() {
|
||||
// This may be expanded in the future
|
||||
return EngineConfiguration.getInstance().isInitialForceDisableClasspathScanning();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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%");
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -379,30 +361,14 @@ 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.
|
||||
*
|
||||
|
@ -424,14 +390,14 @@ 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'
|
||||
|
@ -461,10 +427,10 @@ public final class Engine extends SubsystemClass {
|
|||
} else
|
||||
for (String path : EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses())
|
||||
try {
|
||||
logger.diag("Resolving class " + path);
|
||||
Logger.diag("Resolving class " + path);
|
||||
classes.add(Class.forName(path));
|
||||
} catch (ClassNotFoundException exception) {
|
||||
logger.error("Failed loading subsystem class " + path + ": Class not found");
|
||||
Logger.error("Failed loading subsystem class " + path + ": Class not found");
|
||||
}
|
||||
|
||||
return classes;
|
||||
|
@ -485,7 +451,7 @@ public final class Engine extends SubsystemClass {
|
|||
resolver.addVectors(subsystems);
|
||||
|
||||
// Resolve dependencies and get order
|
||||
logger.verb("Resolving subsystem dependencies");
|
||||
Logger.diag("Resolving subsystem dependencies");
|
||||
try {
|
||||
for (DependencyVector vector : resolver.resolve().getOrder()) // smol workaround
|
||||
order.add((DependencySubsystemVector) vector);
|
||||
|
@ -500,25 +466,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.verb("Initializing engine subsystems");
|
||||
Logger.diag("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'
|
||||
|
@ -535,7 +501,7 @@ public final class Engine extends SubsystemClass {
|
|||
if (state == EngineState.UNKNOWN || state == EngineState.SHUTDOWN)
|
||||
return;
|
||||
|
||||
logger.info("Shutting engine down");
|
||||
Logger.info("Shutting engine down");
|
||||
if (state != EngineState.CRASHED)
|
||||
state = EngineState.SHUTDOWN;
|
||||
|
||||
|
@ -546,7 +512,7 @@ public final class Engine extends SubsystemClass {
|
|||
EngineConfiguration.getInstance().loadConfiguration(properties);
|
||||
|
||||
// Flush log messages
|
||||
Logger.flushLogMessages();
|
||||
LoggingQueue.flush();
|
||||
|
||||
// Disable safety shutdown hook
|
||||
try {
|
||||
|
@ -554,14 +520,17 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -581,7 +550,11 @@ public final class Engine extends SubsystemClass {
|
|||
return "base";
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/**
|
||||
* This method does nothing.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Override
|
||||
public void initializeSubsystem() {}
|
||||
|
||||
|
@ -634,12 +607,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");
|
||||
System.exit(exitCode);
|
||||
Logger.warn("Terminating JVM");
|
||||
Runtime.getRuntime().exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
|
||||
package de.staropensource.engine.base;
|
||||
|
||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.engine.base.event.LogEvent;
|
||||
import de.staropensource.engine.base.implementable.Configuration;
|
||||
import de.staropensource.engine.base.implementable.ShortcodeParser;
|
||||
import de.staropensource.engine.base.logging.CrashHandler;
|
||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.logging.LoggingThread;
|
||||
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;
|
||||
|
@ -33,10 +35,7 @@ import lombok.Getter;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Provides the base engine configuration.
|
||||
|
@ -70,11 +69,11 @@ public final class EngineConfiguration extends Configuration {
|
|||
private static EngineConfiguration instance;
|
||||
|
||||
/**
|
||||
* Contains prefix properties must begin with.
|
||||
* Contains the configuration prefix.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns prefix properties must begin with.
|
||||
* Returns the configuration prefix.
|
||||
*
|
||||
* @return property group
|
||||
* @since v1-alpha0
|
||||
|
@ -83,261 +82,329 @@ public final class EngineConfiguration extends Configuration {
|
|||
|
||||
|
||||
/**
|
||||
* 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!
|
||||
* Contains if debugging options should be allowed.
|
||||
* All debugging options will be forcefully set to
|
||||
* {@code false} if this option is set to {@code false}.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debug}.
|
||||
* Returns if debugging options should be allowed.
|
||||
* All debugging options will be forcefully set to
|
||||
* {@code false} if this option is set to {@code false}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debug
|
||||
* @return debugging enabled?
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
/**
|
||||
* If enabled, all called events will be logged.
|
||||
* Contains whether or not to log
|
||||
* events being emitted.
|
||||
* <p>
|
||||
* This will cause all events to
|
||||
* be logged, with the exception
|
||||
* of the {@link LogEvent}.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #debugEvents}.
|
||||
* Returns whether or not to log
|
||||
* events being emitted.
|
||||
* <p>
|
||||
* This will cause all events to
|
||||
* be logged, with the exception
|
||||
* of the {@link LogEvent}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #debugEvents
|
||||
* @return detailed event logging enabled?
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean debugEvents;
|
||||
|
||||
|
||||
/**
|
||||
* If enabled, will try to automatically initialize every
|
||||
* subsystem found though reflection.
|
||||
* Contains whether or not to automatically discover
|
||||
* and initialize any class extending {@link SubsystemClass}
|
||||
* whilst being annotated with {@link EngineSubsystem}.
|
||||
* <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.
|
||||
* This mechanism may fail in certain situations, where
|
||||
* manual subsystem initialization may be desired. Make
|
||||
* sure to disable this setting before engine startup
|
||||
* and then initialize all subsystems manually.
|
||||
*
|
||||
* @see Engine
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha5
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #initialPerformSubsystemInitialization}.
|
||||
* Returns whether or not to automatically discover
|
||||
* and initialize any class extending {@link SubsystemClass}
|
||||
* whilst being annotated with {@link EngineSubsystem}.
|
||||
* <p>
|
||||
* This mechanism may fail in certain situations, where
|
||||
* manual subsystem initialization may be desired. Make
|
||||
* sure to disable this setting before engine startup
|
||||
* and then initialize all subsystems manually.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #initialPerformSubsystemInitialization
|
||||
* @return automatically discover and initialize subsystems?
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private boolean initialPerformSubsystemInitialization;
|
||||
|
||||
/**
|
||||
* If enabled, will force-disable reflective classpath scanning.
|
||||
*
|
||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
||||
* @see EngineInternals#overrideReflectiveClasspathScanning(boolean)
|
||||
* @since v1-alpha5
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #initialForceDisableClasspathScanning}.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #initialForceDisableClasspathScanning
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private boolean initialForceDisableClasspathScanning;
|
||||
|
||||
/**
|
||||
* Will try to load the specified classes as subsystems,
|
||||
* if reflective classpath scanning is disabled.
|
||||
* Contains a set of class names to try to load
|
||||
* and initialize as subsystems. Will only take effect
|
||||
* if {@link #initialPerformSubsystemInitialization} is
|
||||
* turned off.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #initialIncludeSubsystemClasses}.
|
||||
* Returns a set of class names to try to load
|
||||
* and initialize as subsystems. Will only take effect
|
||||
* if {@link #getInitialIncludeSubsystemClasses()} is
|
||||
* turned off.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #initialIncludeSubsystemClasses
|
||||
* @return set of class names to try and initialize as subsystems
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
private Set<@NotNull String> initialIncludeSubsystemClasses;
|
||||
|
||||
|
||||
/**
|
||||
* If enabled, will cause {@link ShortcodeParser} to print
|
||||
* invalid shortcodes as {@link LogLevel#SILENT_WARNING}s.
|
||||
* Contains whether or not to complain about invalid
|
||||
* shortcodes.
|
||||
* <p>
|
||||
* Requires the active log level to be set at least
|
||||
* to {@link LogLevel#SILENT_WARNING} to have effect.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @see #loggerLevel
|
||||
* @see #logLevel
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #errorShortcodeParser}.
|
||||
* Returns whether or not to complain about invalid
|
||||
* shortcodes.
|
||||
* <p>
|
||||
* Requires the active log level to be set at least
|
||||
* to {@link LogLevel#SILENT_WARNING} to have effect.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #errorShortcodeParser
|
||||
* @return complain about invalid shortcodes?
|
||||
* @see #getLogLevel()
|
||||
* @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.
|
||||
* Contains if to log asynchronously.
|
||||
* <p>
|
||||
* If enabled, will cause a logging thread
|
||||
* to spawn. All log messages will be queued
|
||||
* and printed after a set delay
|
||||
* ({@link #logPollingSpeed}).
|
||||
* Highly recommended to keep enabled, or
|
||||
* the performance of your application will
|
||||
* very likely suffer.
|
||||
*
|
||||
* @see #loggerPollingSpeed
|
||||
* @see Thread
|
||||
* @see #logPollingSpeed
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeLogging}.
|
||||
* Returns if to log asynchronously.
|
||||
* <p>
|
||||
* If enabled, will cause a logging thread
|
||||
* to spawn. All log messages will be queued
|
||||
* and printed after a set delay
|
||||
* ({@link #getLogPollingSpeed()}).
|
||||
* Highly recommended to keep enabled, or
|
||||
* the performance of your application will
|
||||
* very likely suffer.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeLogging
|
||||
* @return log asynchronously?
|
||||
* @see #getLogPollingSpeed()
|
||||
* @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.
|
||||
* Contains whether or not to emit events
|
||||
* asynchronously.
|
||||
* <p>
|
||||
* This will cause a
|
||||
* <a href="https://openjdk.org/jeps/444">VirtualThread</a>
|
||||
* to spawn every time an event is emitted.
|
||||
*
|
||||
* @see VirtualThread
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #optimizeEvents}.
|
||||
* Contains whether or not to emit events
|
||||
* asynchronously.
|
||||
* <p>
|
||||
* This will cause a
|
||||
* <a href="https://openjdk.org/jeps/444">VirtualThread</a>
|
||||
* to spawn every time an event is emitted.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #optimizeEvents
|
||||
* @return emit events asynchronously?
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean optimizeEvents;
|
||||
|
||||
|
||||
/**
|
||||
* Contains which logger levels are allowed
|
||||
* by setting the minimum logger level.
|
||||
* Contains the minimum allowed log level.
|
||||
* <p>
|
||||
* The priority list is as follows (from high to low priority):
|
||||
* <ul>
|
||||
* <li>{@link LogLevel#CRASH}</li>
|
||||
* <li>{@link LogLevel#ERROR}</li>
|
||||
* <li>{@link LogLevel#WARNING}</li>
|
||||
* <li>{@link LogLevel#INFORMATIONAL}</li>
|
||||
* <li>{@link LogLevel#SILENT_WARNING}</li>
|
||||
* <li>{@link LogLevel#VERBOSE}</li>
|
||||
* <li>{@link LogLevel#DIAGNOSTIC}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see Logger
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerLevel}.
|
||||
* Returns the minimum allowed log level.
|
||||
* <p>
|
||||
* The priority list is as follows (from high to low priority):
|
||||
* <ul>
|
||||
* <li>{@link LogLevel#CRASH}</li>
|
||||
* <li>{@link LogLevel#ERROR}</li>
|
||||
* <li>{@link LogLevel#WARNING}</li>
|
||||
* <li>{@link LogLevel#INFORMATIONAL}</li>
|
||||
* <li>{@link LogLevel#SILENT_WARNING}</li>
|
||||
* <li>{@link LogLevel#VERBOSE}</li>
|
||||
* <li>{@link LogLevel#DIAGNOSTIC}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerLevel
|
||||
* @return minimum allowed log level
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private LogLevel loggerLevel;
|
||||
private LogLevel logLevel;
|
||||
|
||||
/**
|
||||
* Contains the logging template used for creating log messages.
|
||||
* 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-alpha0
|
||||
* @since v1-alpha8
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #loggerTemplate}
|
||||
* Returns 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>
|
||||
*
|
||||
* @return variable value
|
||||
* @see #loggerTemplate
|
||||
* @since v1-alpha0
|
||||
* @return optional features to enable
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private String loggerTemplate;
|
||||
private Set<@NotNull String> logFeatures;
|
||||
|
||||
/**
|
||||
* Contains how fast the logging thread will
|
||||
* poll for queued messages. This also causes
|
||||
* messages to be buffered.
|
||||
* poll for queued messages in milliseconds.
|
||||
* 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.
|
||||
* 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 be shutdown immediately
|
||||
* after printing a fatal crash report. 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.
|
||||
* Contains how fast the logging thread will
|
||||
* poll for queued messages, in milliseconds.
|
||||
* This also causes messages to be buffered.
|
||||
* <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
|
||||
* 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.
|
||||
*
|
||||
* @return logging thread polling speed in milliseconds
|
||||
* @see #isOptimizeLogging()
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private int logPollingSpeed;
|
||||
|
||||
/**
|
||||
* Contains whether or not to forcefully write
|
||||
* to the standard output instead of the
|
||||
* standard error stream.
|
||||
* <p>
|
||||
* This only applies to the {@link LogLevel#ERROR} and
|
||||
* {@link LogLevel#CRASH} log levels, as these use
|
||||
* the standard error stream by default.
|
||||
*
|
||||
* @see <a href="https://man7.org/linux/man-pages/man3/stderr.3.html">man page about standard streams</a>
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Contains whether or not to forcefully write
|
||||
* to the standard output instead of the
|
||||
* standard error stream.
|
||||
* <p>
|
||||
* This only applies to the {@link LogLevel#ERROR} and
|
||||
* {@link LogLevel#CRASH} log levels, as these use
|
||||
* the standard error stream by default.
|
||||
*
|
||||
* @return force use stdout?
|
||||
* @see <a href="https://man7.org/linux/man-pages/man3/stderr.3.html">man page about standard streams</a>
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private boolean logForceStandardOutput;
|
||||
|
||||
|
||||
/**
|
||||
* Contains if to truncate the full path
|
||||
* of a class when invoking using their
|
||||
* {@link #toString()} method.
|
||||
* <p>
|
||||
* Here's an example: Lets say that you have a
|
||||
* {@link Vec2f} instance and want to convert
|
||||
* it to a String. You can do that by using
|
||||
* {@link Vec2f}'s {@link Vec2f#toString()}
|
||||
* method. With this flag disabled it will
|
||||
* return
|
||||
* {@code de.staropensource.engine.base.types.vectors.}{@link Vec2i}{@code (x=64 y=64)}.
|
||||
* With this flag enabled however the method will return
|
||||
* {@link Vec2i}{@code (x=64 y=64)},
|
||||
* which is much smaller.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Gets the value for {@link #hideFullTypePath}.
|
||||
* Returns if to truncate the full path
|
||||
* of a class when invoking using their
|
||||
* {@link #toString()} method.
|
||||
* <p>
|
||||
* Here's an example: Lets say that you have a
|
||||
* {@link Vec2f} instance and want to convert
|
||||
* it to a String. You can do that by using
|
||||
* {@link Vec2f}'s {@link Vec2f#toString()}
|
||||
* method. With this flag disabled it will
|
||||
* return
|
||||
* {@code de.staropensource.engine.base.types.vectors.}{@link Vec2i}{@code (x=64 y=64)}.
|
||||
* With this flag enabled however the method will return
|
||||
* {@link Vec2i}{@code (x=64 y=64)},
|
||||
* which is much smaller.
|
||||
*
|
||||
* @return variable value
|
||||
* @see #hideFullTypePath
|
||||
* @return truncate class paths?
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private boolean hideFullTypePath;
|
||||
|
@ -349,7 +416,7 @@ public final class EngineConfiguration extends Configuration {
|
|||
* @since v1-alpha6
|
||||
*/
|
||||
EngineConfiguration() {
|
||||
super("ENGINE");
|
||||
super();
|
||||
|
||||
instance = this;
|
||||
|
||||
|
@ -366,7 +433,6 @@ public final class EngineConfiguration extends Configuration {
|
|||
case "debugEvents" -> debugEvents = parser.getBoolean(group + property);
|
||||
|
||||
case "initialPerformSubsystemInitialization" -> initialPerformSubsystemInitialization = parser.getBoolean(group + property);
|
||||
case "initialForceDisableClasspathScanning" -> initialForceDisableClasspathScanning = parser.getBoolean(group + property);
|
||||
case "initialIncludeSubsystemClasses" -> {
|
||||
initialIncludeSubsystemClasses = new HashSet<>();
|
||||
initialIncludeSubsystemClasses.addAll(Arrays.stream(parser.getString(group + property).split(",")).toList());
|
||||
|
@ -378,23 +444,22 @@ public final class EngineConfiguration extends Configuration {
|
|||
optimizeLogging = parser.getBoolean(group + property);
|
||||
|
||||
// Start logging thread automatically
|
||||
if (optimizeLogging && Engine.getInstance().getState() == EngineState.RUNNING)
|
||||
LoggingThread.startThread();
|
||||
if (optimizeLogging && Engine.getInstance().getState() == EngineState.RUNNING) {
|
||||
LoggingThread.startThread(false);
|
||||
}
|
||||
}
|
||||
case "optimizeEvents" -> optimizeEvents = parser.getBoolean(group + property);
|
||||
|
||||
case "loggerLevel" -> {
|
||||
case "logLevel" -> {
|
||||
try {
|
||||
loggerLevel = LogLevel.valueOf(parser.getString(group + property).toUpperCase());
|
||||
logLevel = LogLevel.valueOf(parser.getString(group + property).toUpperCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
System.out.println("Logger level " + parser.getString(group + property) + " is not valid");
|
||||
Logger.error("The log 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 "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);
|
||||
}
|
||||
|
@ -417,7 +482,6 @@ public final class EngineConfiguration extends Configuration {
|
|||
debugEvents = false;
|
||||
|
||||
initialPerformSubsystemInitialization = true;
|
||||
initialForceDisableClasspathScanning = false;
|
||||
initialIncludeSubsystemClasses = new HashSet<>();
|
||||
|
||||
errorShortcodeParser = true;
|
||||
|
@ -425,12 +489,10 @@ public final class EngineConfiguration extends Configuration {
|
|||
optimizeLogging = true;
|
||||
optimizeEvents = 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;
|
||||
logLevel = LogLevel.INFORMATIONAL;
|
||||
logFeatures = Set.of("formatting", "time", "methodName", "lineNumber");
|
||||
logPollingSpeed = 5;
|
||||
logForceStandardOutput = false;
|
||||
|
||||
hideFullTypePath = false;
|
||||
}
|
||||
|
@ -443,7 +505,6 @@ public final class EngineConfiguration extends Configuration {
|
|||
case "debugEvents" -> debugEvents;
|
||||
|
||||
case "initialPerformSubsystemInitialization" -> initialPerformSubsystemInitialization;
|
||||
case "initialForceDisableClasspathScanning" -> initialForceDisableClasspathScanning;
|
||||
case "initialIncludeSubsystemClasses" -> initialIncludeSubsystemClasses;
|
||||
|
||||
case "errorShortcodeParser" -> errorShortcodeParser;
|
||||
|
@ -451,12 +512,10 @@ public final class EngineConfiguration extends Configuration {
|
|||
case "optimizeLogging" -> optimizeLogging;
|
||||
case "optimizeEvents" -> optimizeEvents;
|
||||
|
||||
case "loggerLevel" -> loggerLevel;
|
||||
case "loggerTemplate" -> loggerTemplate;
|
||||
case "loggerPollingSpeed" -> loggerPollingSpeed;
|
||||
case "loggerForceStandardOutput" -> loggerForceStandardOutput;
|
||||
case "loggerEnableNewlineSupport" -> loggerEnableNewlineSupport;
|
||||
case "loggerImmediateShutdown" -> loggerImmediateShutdown;
|
||||
case "logLevel" -> logLevel;
|
||||
case "logFeatures" -> logFeatures;
|
||||
case "logPollingSpeed" -> logPollingSpeed;
|
||||
case "logForceStandardOutput" -> logForceStandardOutput;
|
||||
|
||||
case "hideFullTypePath" -> hideFullTypePath;
|
||||
default -> null;
|
||||
|
|
|
@ -23,7 +23,7 @@ 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.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.EventPriority;
|
||||
import de.staropensource.engine.base.type.InternalAccessArea;
|
||||
import lombok.Getter;
|
||||
|
@ -54,14 +54,6 @@ 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.
|
||||
*
|
||||
|
@ -100,7 +92,7 @@ public final class EngineInternals {
|
|||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.event;
|
||||
package de.staropensource.engine.base.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package de.staropensource.engine.base.implementable;
|
||||
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -37,23 +36,11 @@ import java.util.Properties;
|
|||
*/
|
||||
public abstract class Configuration {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
protected final @NotNull LoggerInstance logger;
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
*
|
||||
* @param origin see {@link LoggerInstance.Builder#setOrigin(String)}
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
protected Configuration(@NotNull String origin) {
|
||||
// Set logger instance
|
||||
logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin(origin).build();
|
||||
|
||||
protected Configuration() {
|
||||
// Load default configuration
|
||||
loadDefaultConfiguration();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class EventListenerCode {
|
|||
public @NotNull EventPriority priority = EventPriority.DEFAULT;
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @since v1-alpha5
|
||||
*/
|
||||
|
|
|
@ -22,7 +22,6 @@ package de.staropensource.engine.base.implementable;
|
|||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Interface for implementing custom logger implementations.
|
||||
|
@ -32,43 +31,13 @@ import org.jetbrains.annotations.Nullable;
|
|||
*/
|
||||
public interface LoggingAdapter {
|
||||
/**
|
||||
* Invoked before anything is done with the log message.
|
||||
* Prints a 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
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message raw message
|
||||
* @param format processed log call output (print this!)
|
||||
* @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);
|
||||
void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ package de.staropensource.engine.base.implementable;
|
|||
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.exception.ParserException;
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
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 converter.
|
||||
* Base class for implementing a shortcode parser.
|
||||
* <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,16 +48,9 @@ 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.
|
||||
*
|
||||
|
@ -68,11 +61,10 @@ public abstract class ShortcodeParser {
|
|||
* @return component list
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
protected final @NotNull LinkedList<String> components;
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @param string string to parse
|
||||
* @param ignoreInvalidEscapes if {@code true}, will ignore and treat invalid escapes as text
|
||||
|
@ -80,7 +72,6 @@ public abstract class ShortcodeParser {
|
|||
* @since v1-alpha2
|
||||
*/
|
||||
protected ShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").build();
|
||||
components = parse(string, ignoreInvalidEscapes);
|
||||
}
|
||||
|
||||
|
@ -134,7 +125,7 @@ public abstract class ShortcodeParser {
|
|||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
Logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
|
@ -146,7 +137,7 @@ public abstract class ShortcodeParser {
|
|||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
Logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
|
@ -174,7 +165,7 @@ public abstract class ShortcodeParser {
|
|||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
Logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
|
|
|
@ -22,8 +22,7 @@ package de.staropensource.engine.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.internal.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -35,15 +34,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
*/
|
||||
public abstract class 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();
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
|
|
|
@ -30,7 +30,8 @@ import de.staropensource.engine.base.exception.reflection.StaticInitializerExcep
|
|||
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.LoggerInstance;
|
||||
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.EventPriority;
|
||||
import de.staropensource.engine.base.utility.ListFormatter;
|
||||
import lombok.Getter;
|
||||
|
@ -52,14 +53,6 @@ import java.util.*;
|
|||
*/
|
||||
@Getter
|
||||
public final class EventHelper {
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Holds all cached events.
|
||||
*
|
||||
|
@ -105,7 +98,7 @@ public final class EventHelper {
|
|||
cachedEventListeners.put(event, list);
|
||||
}
|
||||
|
||||
logger.diag("Registered event listener " + eventListener + " for event " + event + " with priority " + priority.name());
|
||||
Logger.diag("Registered event listener " + eventListener + " for event " + event + " with priority " + priority.name());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,26 +170,26 @@ public final class EventHelper {
|
|||
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");
|
||||
Logger.diag("Event " + event.getName() + " was emitted");
|
||||
else
|
||||
logger.diag("Event " + event.getName() + " was emitted, passing arguments " + ListFormatter.formatArray(arguments));
|
||||
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");
|
||||
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");
|
||||
Logger.warn("Event listener " + eventListener + " has an invalid method signature");
|
||||
} catch (InvocationTargetException exception) {
|
||||
logger.crash("Event listener " + eventListener + " threw a throwable", exception.getTargetException(), true);
|
||||
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.");
|
||||
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);
|
||||
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);
|
||||
Logger.crash("Event listener " + eventListener + " could not be called as an error occurred during reflection", exception, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -23,9 +23,8 @@ 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.EmptyShortcodeConverter;
|
||||
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Prints log messages to the console, without any fancy colors or formatting.
|
||||
|
@ -44,22 +43,10 @@ public class PlainLoggingAdapter implements LoggingAdapter {
|
|||
|
||||
/** {@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();
|
||||
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().isLoggerForceStandardOutput())
|
||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
System.out.println(format);
|
||||
else
|
||||
System.err.println(format);
|
||||
|
|
|
@ -40,17 +40,5 @@ public class QuietLoggingAdapter implements LoggingAdapter {
|
|||
|
||||
/** {@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;
|
||||
}
|
||||
|
||||
/** {@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) {}
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {}
|
||||
}
|
||||
|
|
|
@ -44,21 +44,9 @@ public class RawLoggingAdapter implements LoggingAdapter {
|
|||
|
||||
/** {@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) {
|
||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
||||
if (EngineConfiguration.getInstance().isLoggerForceStandardOutput())
|
||||
if (EngineConfiguration.getInstance().isLogForceStandardOutput())
|
||||
System.out.println(format);
|
||||
else
|
||||
System.err.println(format);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Code of the GLFW subsystem.
|
||||
* Implementations for various interfaces and abstract classes.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
package de.staropensource.engine.windowing.glfw;
|
||||
package de.staropensource.engine.base.implementation;
|
|
@ -27,18 +27,18 @@ import org.jetbrains.annotations.NotNull;
|
|||
* Cleans the string of any tags.
|
||||
*
|
||||
* @see ShortcodeParser
|
||||
* @since v1-alpha1
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class EmptyShortcodeConverter extends ShortcodeParser {
|
||||
public final class EmptyShortcodeParser extends ShortcodeParser {
|
||||
/**
|
||||
* Creates and initializes an instance of 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-alpha1
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public EmptyShortcodeConverter(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
public EmptyShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
||||
super(string, ignoreInvalidEscapes);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public final class EmptyShortcodeConverter extends ShortcodeParser {
|
|||
* Returns the parsed string without any tags.
|
||||
*
|
||||
* @return cleaned input string
|
||||
* @since v1-alpha1
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String getClean() {
|
||||
StringBuilder output = new StringBuilder();
|
|
@ -1,24 +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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.engine.base.internal.event;
|
|
@ -17,40 +17,30 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder.crashhandler;
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code crash_message} placeholder.
|
||||
* Implements the {@code engine_version_codename} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class CrashMessage implements Placeholder {
|
||||
/**
|
||||
* Contains the message to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
private final String message;
|
||||
|
||||
public final class EngineVersionCodename implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param message message to use
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public CrashMessage(@NotNull String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public EngineVersionCodename() {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%crash_message%", message);
|
||||
return text.replace("%engine_version_codename%", EngineInformation.getVersioningCodename());
|
||||
}
|
||||
}
|
|
@ -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.internal.implementation.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code issuer_class} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class IssuerClass implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer class to use.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @NotNull Class<?> issuerClass;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerClass issuer class to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public IssuerClass(@NotNull Class<?> issuerClass) {
|
||||
this.issuerClass = issuerClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%issuer_class%", issuerClass.getName().replace(issuerClass.getPackageName() + ".", ""));
|
||||
}
|
||||
}
|
|
@ -1,61 +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.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Implements the {@code issuer_metadata} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class IssuerMetadata implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer metadata to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @Nullable String issuerMetadata;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerMetadata issuer metadata to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public IssuerMetadata(@Nullable String issuerMetadata) {
|
||||
this.issuerMetadata = issuerMetadata;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
String replacement = "\\<none>";
|
||||
|
||||
if (issuerMetadata != null)
|
||||
replacement = issuerMetadata;
|
||||
|
||||
return text.replace("%issuer_metadata%", replacement);
|
||||
}
|
||||
}
|
|
@ -1,57 +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.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Implements the {@code issuer_origin} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class IssuerOrigin implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer origin to use.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @NotNull String issuerOrigin;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerOrigin issuer origin to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public IssuerOrigin(@NotNull String issuerOrigin) {
|
||||
this.issuerOrigin = issuerOrigin;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%issuer_origin%", issuerOrigin.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.internal.implementation.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code issuer_package} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class IssuerPackage implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer class to use.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @NotNull Class<?> issuerClass;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerClass issuer class to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public IssuerPackage(@NotNull Class<?> issuerClass) {
|
||||
this.issuerClass = issuerClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%issuer_package%", issuerClass.getPackageName());
|
||||
}
|
||||
}
|
|
@ -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.internal.implementation.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code issuer_path} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class IssuerPath implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer class to use.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @NotNull Class<?> issuerClass;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerClass issuer class to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public IssuerPath(@NotNull Class<?> issuerClass) {
|
||||
this.issuerClass = issuerClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%issuer_path%", issuerClass.getName());
|
||||
}
|
||||
}
|
|
@ -1,101 +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.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Implements the {@code stacktrace} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class Stacktrace implements Placeholder {
|
||||
/**
|
||||
* Contains the {@link Throwable} to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @Nullable Throwable throwable;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param throwable {@link Throwable} to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public Stacktrace(@Nullable Throwable throwable) {
|
||||
this.throwable = throwable;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%stacktrace%", throwable == null ? "No stack trace is available." : getFullStackTrace(throwable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full stack trace.
|
||||
*
|
||||
* @param throwable throwable get the full stack trace of
|
||||
* @return full stack trace
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@NotNull
|
||||
private static String getFullStackTrace(@NotNull Throwable throwable) {
|
||||
return getFullStackTrace(throwable, new StringBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full stack trace.
|
||||
*
|
||||
* @param throwable throwable to operate on
|
||||
* @param stacktrace stacktrace to append and return
|
||||
* @return full stack trace
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@NotNull
|
||||
private static String getFullStackTrace(@NotNull Throwable throwable, @NotNull StringBuilder stacktrace) {
|
||||
// Add newline
|
||||
if (!stacktrace.isEmpty())
|
||||
stacktrace.append("\n");
|
||||
|
||||
// Append stack trace
|
||||
stacktrace
|
||||
.append(Miscellaneous.getStackTraceHeader(throwable))
|
||||
.append("\n")
|
||||
.append(Miscellaneous.getStackTraceAsString(throwable, true));
|
||||
|
||||
// Handle throwables which contain other throwables
|
||||
if (throwable instanceof InvocationTargetException invocationTargetException)
|
||||
getFullStackTrace(invocationTargetException.getTargetException(), stacktrace);
|
||||
|
||||
// Return stack trace
|
||||
return stacktrace
|
||||
.toString()
|
||||
.replace("<", "\\<");
|
||||
}
|
||||
}
|
|
@ -1,71 +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.placeholder.crashhandler;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Implements the {@code stacktrace_all} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class StacktraceAll implements Placeholder {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public StacktraceAll() {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
Map<Thread, StackTraceElement[]> stacktraces = Thread.getAllStackTraces();
|
||||
|
||||
for (Thread thread : stacktraces.keySet()) {
|
||||
if (!output.isEmpty())
|
||||
output.append("\n\n");
|
||||
output
|
||||
.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));
|
||||
}
|
||||
|
||||
return text.replace("%stacktrace_all%", output.toString().replace("<", "\\<"));
|
||||
}
|
||||
}
|
|
@ -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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Placeholders used in the {@link de.staropensource.engine.base.logging.CrashHandler}.
|
||||
*
|
||||
* @see de.staropensource.engine.base.logging.CrashHandler
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder.crashhandler;
|
|
@ -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.internal.implementation.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_class} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogClass implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer class to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @NotNull Class<?> issuerClass;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerClass issuer class to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogClass(@NotNull Class<?> issuerClass) {
|
||||
this.issuerClass = issuerClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%log_class%", issuerClass.getName().replace(issuerClass.getPackageName() + ".", ""));
|
||||
}
|
||||
}
|
|
@ -1,68 +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.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_color_primary} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogColorPrimary implements Placeholder {
|
||||
/**
|
||||
* Contains the {@link LogLevel} to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
private final LogLevel level;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param level {@link LogLevel} to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogColorPrimary(@NotNull LogLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
String color;
|
||||
|
||||
switch (level) {
|
||||
case DIAGNOSTIC, VERBOSE -> color = "<fg:blue>";
|
||||
case SILENT_WARNING, WARNING -> color = "<fg:yellow>";
|
||||
case INFORMATIONAL -> color = "<fg:white>";
|
||||
case ERROR -> color = "<fg:red>";
|
||||
case CRASH -> color = "You should not be seeing this";
|
||||
default -> color = "";
|
||||
}
|
||||
|
||||
return text.replace("%log_color_primary%", color);
|
||||
}
|
||||
}
|
|
@ -1,64 +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.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_color_secondary} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogColorSecondary implements Placeholder {
|
||||
/**
|
||||
* Contains the {@link LogLevel} to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
private final LogLevel level;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param level {@link LogLevel} to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogColorSecondary(@NotNull LogLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
String color;
|
||||
|
||||
switch (level) {
|
||||
case DIAGNOSTIC, SILENT_WARNING -> color = "<italic>";
|
||||
default -> color = "";
|
||||
}
|
||||
|
||||
return text.replace("%log_color_secondary%", color);
|
||||
}
|
||||
}
|
|
@ -1,66 +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.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_level} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogLevelEvent implements Placeholder {
|
||||
/**
|
||||
* Contains the {@link LogLevel} to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
private final LogLevel level;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param level {@link LogLevel} to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogLevelEvent(@NotNull LogLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
String levelText;
|
||||
|
||||
switch (level) {
|
||||
case CRASH -> levelText = "CRSH";
|
||||
case ERROR -> levelText = "ERR!";
|
||||
case SILENT_WARNING -> levelText = "SARN";
|
||||
default -> levelText = level.name().substring(0, 4);
|
||||
}
|
||||
|
||||
return text.replace("%log_level%", levelText);
|
||||
}
|
||||
}
|
|
@ -1,61 +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.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_metadata} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogMetadata implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer metadata to use
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @Nullable String issuerMetadata;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerMetadata issuer metadata to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogMetadata(@Nullable String issuerMetadata) {
|
||||
this.issuerMetadata = issuerMetadata;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
String replacement = "";
|
||||
|
||||
if (issuerMetadata != null && !issuerMetadata.isEmpty())
|
||||
replacement = "/" + issuerMetadata;
|
||||
|
||||
return text.replace("%log_metadata%", replacement);
|
||||
}
|
||||
}
|
|
@ -1,57 +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.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_origin} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogOrigin implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer origin to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @NotNull String issuerOrigin;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerOrigin issuer origin to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogOrigin(@NotNull String issuerOrigin) {
|
||||
this.issuerOrigin = issuerOrigin;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%log_origin%", issuerOrigin.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.internal.implementation.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_package} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogPackage implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer class to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @NotNull Class<?> issuerClass;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerClass issuer class to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogPackage(@NotNull Class<?> issuerClass) {
|
||||
this.issuerClass = issuerClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%log_package%", issuerClass.getPackageName());
|
||||
}
|
||||
}
|
|
@ -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.internal.implementation.placeholder.logger;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implements the {@code log_path} placeholder.
|
||||
*
|
||||
* @see Placeholder
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class LogPath implements Placeholder {
|
||||
/**
|
||||
* Contains the issuer class to use.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
private final Class<?> issuerClass;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @param issuerClass issuer class to use
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public LogPath(@NotNull Class<?> issuerClass) {
|
||||
this.issuerClass = issuerClass;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String replace(@NotNull String text) {
|
||||
return text.replace("%log_path%", issuerClass.getName());
|
||||
}
|
||||
}
|
|
@ -17,28 +17,27 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.event;
|
||||
package de.staropensource.engine.base.internal.type;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.logging.backend.async.LoggingThread;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when the windowing API shuts down.
|
||||
* Represents a queued log call.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @see LoggingThread
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public final class WindowingShutdownEvent implements Event {
|
||||
@SuppressWarnings({ "unused" })
|
||||
public record QueuedLogCall(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public WindowingShutdownEvent() {}
|
||||
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void callEvent() {
|
||||
EventHelper.invokeAnnotatedMethods(getClass());
|
||||
}
|
||||
public QueuedLogCall {}
|
||||
}
|
|
@ -1,51 +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.type;
|
||||
|
||||
import de.staropensource.engine.base.logging.LoggingThread;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a queued log message.
|
||||
*
|
||||
* @param level Level of the log call.
|
||||
* @param issuerClass Class of the issuer.
|
||||
* @param issuerOrigin Origin of the issuer.
|
||||
* @param issuerMetadata Metadata about the issuer.
|
||||
* @param message Message of the log call.
|
||||
* @see LoggingThread#startThread()
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public record QueuedLogMessage(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public QueuedLogMessage {}
|
||||
}
|
|
@ -1,280 +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.Engine;
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.event.EngineCrashEvent;
|
||||
import de.staropensource.engine.base.event.EngineSoftCrashEvent;
|
||||
import de.staropensource.engine.base.internal.implementation.placeholder.crashhandler.*;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Handles engine and application crashes.
|
||||
*
|
||||
* @see Logger
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class CrashHandler {
|
||||
/**
|
||||
* Contains the template used to print a crash report.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Gets the template used to print a crash report.
|
||||
*
|
||||
* @return crash report template
|
||||
* @since v1-alpha0
|
||||
* -- SETTER --
|
||||
* Sets the template used to print a crash report.
|
||||
*
|
||||
* @param crashTemplate new crash template
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private static @NotNull String crashTemplate = """
|
||||
<fg:red><bold>
|
||||
%handled%
|
||||
------------------------
|
||||
sos!engine crash
|
||||
------------------------
|
||||
|
||||
Dear user: The application or game you've tried to use seems to have made an oopsie. Please report this to the developer so they can fix it! Thank you \\<3
|
||||
Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party subsystems are causing problems.
|
||||
If not, please report it at https://git.staropensource.de/StarOpenSource/Engine/issues. Thank you \\<3
|
||||
%content%
|
||||
|
||||
Dear user: The application or game you've tried to use seems to have made an oopsie. Please report this to the developer so they can fix it! Thank you \\<3
|
||||
Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party subsystems are causing problems.
|
||||
If not, please report it at https://git.staropensource.de/StarOpenSource/Engine/issues. Thank you \\<3
|
||||
|
||||
------------------------
|
||||
sos!engine crash
|
||||
------------------------
|
||||
%handled%<reset>
|
||||
""";
|
||||
|
||||
/**
|
||||
* Contains nested {@link LinkedHashMap}s that contain the content printed at the time of a crash.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the nested {@link LinkedHashMap}s that contain the content printed at the time of a crash.
|
||||
*
|
||||
* @return crash content
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static final @NotNull LinkedHashMap<@NotNull Object, @NotNull Object> crashContent = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private CrashHandler() {}
|
||||
|
||||
/**
|
||||
* Handles a crash.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message crash error detail
|
||||
* @param throwable simply to provide stacktrace and further insight into the crash, can be set to {@code null}
|
||||
* @param throwableHandled declares the throwable has handled, not causing the engine to shutdown
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static synchronized void handleCrash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @Nullable Throwable throwable, boolean throwableHandled) {
|
||||
Engine.getInstance().setState(EngineState.CRASHED); // Update engine state
|
||||
|
||||
// Prevent throwable handled warning if set to true but no throwable has been supplied
|
||||
if (throwable == null)
|
||||
throwableHandled = false;
|
||||
|
||||
// Escape message
|
||||
message = message
|
||||
.replace("\n", "\n ")
|
||||
.replace("\\", "\\\\")
|
||||
.replace("<", "\\<");
|
||||
|
||||
// Replace %content% and %handled%
|
||||
String base = crashTemplate
|
||||
.replace("%content%", processCrashContent())
|
||||
.replace("%handled%", throwableHandled ? "!!! This throwable is declared as handled and has been passed down the execution chain !!!" : "");
|
||||
|
||||
// Invoke LoggingAdapter#prePlaceholder
|
||||
String temp = Logger.getLoggingAdapter().prePlaceholder(LogLevel.CRASH, issuerClass, issuerOrigin, issuerMetadata, message, base);
|
||||
if (temp != null)
|
||||
base = temp;
|
||||
|
||||
// Create list of temporary placeholders
|
||||
List<@NotNull Placeholder> temporaryPlaceholders = new ArrayList<>();
|
||||
temporaryPlaceholders.add(new CrashMessage(message)); // log_message is out of order to allow for placeholder usage
|
||||
|
||||
// issuer_*
|
||||
temporaryPlaceholders.add(new IssuerClass(issuerClass));
|
||||
temporaryPlaceholders.add(new IssuerOrigin(issuerOrigin));
|
||||
temporaryPlaceholders.add(new IssuerMetadata(issuerMetadata));
|
||||
temporaryPlaceholders.add(new IssuerPackage(issuerClass));
|
||||
temporaryPlaceholders.add(new IssuerPath(issuerClass));
|
||||
// stacktrace*
|
||||
temporaryPlaceholders.add(new Stacktrace(throwable));
|
||||
temporaryPlaceholders.add(new StacktraceAll());
|
||||
|
||||
// Replace placeholders
|
||||
base = PlaceholderEngine.getInstance().process(base, temporaryPlaceholders);
|
||||
|
||||
// Invoke LoggingAdapter#postPlaceholder
|
||||
base = Logger.getLoggingAdapter().postPlaceholder(LogLevel.CRASH, issuerClass, issuerOrigin, issuerMetadata, message, base);
|
||||
|
||||
// Print log message by invoking LoggingAdapter#print
|
||||
Logger.flushLogMessages();
|
||||
Logger.getLoggingAdapter().print(LogLevel.CRASH, issuerClass, issuerOrigin, issuerMetadata, message, base);
|
||||
|
||||
// Emit event
|
||||
if (throwableHandled)
|
||||
new EngineSoftCrashEvent().callEvent();
|
||||
else
|
||||
new EngineCrashEvent().callEvent();
|
||||
|
||||
// Shutdown engine/JVM
|
||||
if (!throwableHandled)
|
||||
if (EngineConfiguration.getInstance().isLoggerImmediateShutdown()) {
|
||||
System.out.println("Halting JVM");
|
||||
Runtime.getRuntime().halt(69);
|
||||
} else
|
||||
Engine.getInstance().shutdown(69);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method for generating the crash message content. Do not call.
|
||||
*
|
||||
* @param map {@link LinkedHashMap} to process
|
||||
* @param indentationSize indentation level
|
||||
* @return crash content string
|
||||
* @see #processCrashContent()
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
/*
|
||||
* Note: This entire method causes a compilation warning as we are using "unchecked or unsecure operations".
|
||||
* We can safely ignore this as this method
|
||||
* 1. checks data types before using them,
|
||||
* 2. only works on Strings, Lists and LinkedHashMaps and not on Files or something which could cause damage, and
|
||||
* 3. we can trust our own engine and possibly subsystems not doing shit in here.
|
||||
* As a subsystem developer you'll likely want useful crash information.
|
||||
*
|
||||
* But hey, if someone breaks this method (which may be possible idk didn't test it) then congrats!
|
||||
*/
|
||||
private static @NotNull String processCrashContent(@NotNull LinkedHashMap<Object, Object> map, int indentationSize) {
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
for (Object key : map.keySet()) {
|
||||
// Ensure key is of type String
|
||||
if (!(key instanceof String))
|
||||
continue;
|
||||
|
||||
// Ensure value is of type String, List or LinkedHashMap
|
||||
if (!(map.get(key) instanceof String
|
||||
|| map.get(key) instanceof List<?>
|
||||
|| map.get(key) instanceof LinkedHashMap<?, ?>))
|
||||
// Invalid content value, skip
|
||||
continue;
|
||||
|
||||
// Add newline
|
||||
if (!content.isEmpty())
|
||||
content.append("\n");
|
||||
|
||||
// Indent key
|
||||
if (indentationSize == 0)
|
||||
content.append("\n");
|
||||
else
|
||||
content
|
||||
.append(" ".repeat(indentationSize))
|
||||
.append("-> ");
|
||||
|
||||
if (map.get(key) == null)
|
||||
// Append key name, there's no content
|
||||
// Format: %key%
|
||||
content.append(key);
|
||||
else if (map.get(key) instanceof String)
|
||||
// Append key and it's value
|
||||
// Format: %key%: %value%
|
||||
content
|
||||
.append(key)
|
||||
.append(": ")
|
||||
.append(map.get(key));
|
||||
else if (map.get(key) instanceof List<?>) {
|
||||
// Append key and list the list's contents
|
||||
content.append(key);
|
||||
|
||||
for (Object item : (List<?>) map.get(key)) {
|
||||
if (item instanceof String)
|
||||
item = ((String) item)
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\"", "\\\"");
|
||||
|
||||
content
|
||||
.append("\n")
|
||||
.append(" ".repeat(indentationSize))
|
||||
.append(" -> ")
|
||||
.append(item);
|
||||
}
|
||||
} else
|
||||
// So this one processes a map recursively
|
||||
// Format:
|
||||
// -> %parent_key%
|
||||
// -> %child_key0%: %child_value0%
|
||||
// -> %child_key1%
|
||||
// -> %nested_key0%: %nested_value0%
|
||||
// -> %nested_key1%: %nested_value1%
|
||||
// -> %child_key2%: %child_value1%
|
||||
//noinspection unchecked
|
||||
content.append(key).append("\n").append(processCrashContent((LinkedHashMap<Object, Object>) map.get(key), indentationSize + 1));
|
||||
}
|
||||
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the content for a crash report. Processes {@code crashContent} and spits out a String.
|
||||
*
|
||||
* @return crash content string
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static String processCrashContent() {
|
||||
return processCrashContent(crashContent, 0);
|
||||
}
|
||||
}
|
|
@ -1,201 +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.internal.implementation.placeholder.logger.LogLevelEvent;
|
||||
import de.staropensource.engine.base.internal.implementation.placeholder.logger.LogPath;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Provides logging capabilities during engine startup.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public final class InitLogger {
|
||||
/**
|
||||
* Contains the logging template used during startup.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static final @NotNull String template = "%log_level% %log_path% %log_message%";
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private InitLogger() {}
|
||||
|
||||
/**
|
||||
* {@link Logger#log(LogLevel, Class, String, String, String)} and {@link Logger#processLogMessage(LogLevel, Class, String, String, String)} combined into one method.
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static synchronized void log(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
// Dismiss if level is not allowed
|
||||
if ((EngineConfiguration.getInstance() != null && level.compareTo(EngineConfiguration.getInstance().getLoggerLevel()) < 0) || level.compareTo(LogLevel.INFORMATIONAL) < 0)
|
||||
return;
|
||||
|
||||
// Invoke LoggingAdapter#prePlaceholder
|
||||
String base = Logger.getLoggingAdapter().prePlaceholder(level, issuerClass, issuerOrigin, issuerMetadata, message, template);
|
||||
if (base == null)
|
||||
base = template;
|
||||
|
||||
// Replace placeholders
|
||||
// This is done manually to avoid depending on PlaceholderEngine
|
||||
base = new LogLevelEvent(level).replace(base);
|
||||
base = new LogPath(issuerClass).replace(base);
|
||||
base = base.replace("%log_message%", message.replace("\n", ""));
|
||||
|
||||
// Invoke LoggingAdapter#postPlaceholder
|
||||
base = Logger.getLoggingAdapter().postPlaceholder(level, issuerClass, issuerOrigin, issuerMetadata, message, base);
|
||||
|
||||
// Print log message by invoking LoggingAdapter#print
|
||||
Logger.getLoggingAdapter().print(level, issuerClass, issuerOrigin, issuerMetadata, message, base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a diagnostic message.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void diag(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.DIAGNOSTIC, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a verbose message.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void verb(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.VERBOSE, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a silent warning message.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void sarn(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.SILENT_WARNING, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an informational message.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void info(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.INFORMATIONAL, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a warning message.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void warn(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.WARNING, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints an error message.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void error(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.ERROR, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata 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
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void crash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull Throwable throwable, boolean handled) {
|
||||
Logger.crash(issuerClass, issuerOrigin, issuerMetadata, message, throwable, handled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @param throwable the throwable that caused this crash
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void crash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull Throwable throwable) {
|
||||
Logger.crash(issuerClass, issuerOrigin, issuerMetadata, message, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
public static void crash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
Logger.crash(issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
}
|
||||
}
|
|
@ -19,46 +19,31 @@
|
|||
|
||||
package de.staropensource.engine.base.logging;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.event.LogEvent;
|
||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.implementation.logging.PlainLoggingAdapter;
|
||||
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeConverter;
|
||||
import de.staropensource.engine.base.internal.implementation.placeholder.logger.*;
|
||||
import de.staropensource.engine.base.internal.type.QueuedLogMessage;
|
||||
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 de.staropensource.engine.base.type.logging.LogRule;
|
||||
import de.staropensource.engine.base.type.logging.LogRuleType;
|
||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
||||
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.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Provides the engine's logging infrastructure, except for
|
||||
* crash handling, which is handled by {@link CrashHandler}.
|
||||
* The frontend class for sos!engine's logging system.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @see CrashHandler
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class Logger {
|
||||
/**
|
||||
* Contains a list of {@link QueuedLogMessage}s.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
private static final LinkedList<QueuedLogMessage> queuedMessages = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* Refers to the active {@link LoggingAdapter} that is used to process and print log messages.
|
||||
*
|
||||
|
@ -82,286 +67,350 @@ public final class Logger {
|
|||
private static @NotNull LoggingAdapter loggingAdapter = new PlainLoggingAdapter();
|
||||
|
||||
/**
|
||||
* Contains all active {@link LogRule}s.
|
||||
* Creates and initializes an instance of this class
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns all active {@link LogRule}s.
|
||||
*
|
||||
* @return active rules
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static final List<LogRule> activeRules = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
* @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.
|
||||
/**
|
||||
* Prints all queued log messages.
|
||||
* Handles incoming log calls and either
|
||||
* processes them directly or queues them in.
|
||||
* <p>
|
||||
* **This is an internal method. Use with care.**
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* @param level level of the log call
|
||||
* @param issuer {@link StackTraceElement} of the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static synchronized void flushLogMessages() {
|
||||
// Only execute code if queued messages list is not empty
|
||||
if (!queuedMessages.isEmpty()) {
|
||||
// Clone queued messages and clear original to avoid issues
|
||||
//noinspection unchecked
|
||||
LinkedList<QueuedLogMessage> queuedMessagesCloned = (LinkedList<QueuedLogMessage>) queuedMessages.clone();
|
||||
queuedMessages.clear();
|
||||
|
||||
// Invoke processLogMessage method for every queued message
|
||||
for (QueuedLogMessage queuedLogMessage : queuedMessagesCloned) {
|
||||
processLogMessage(queuedLogMessage.level(), queuedLogMessage.issuerClass(), queuedLogMessage.issuerOrigin(), queuedLogMessage.issuerMetadata(), queuedLogMessage.message());
|
||||
}
|
||||
}
|
||||
public static void handle(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
||||
Processor.handle(level, issuer, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a log message.
|
||||
* Flushes the logging queue.
|
||||
* <p>
|
||||
* **This is an internal method. Use with care.**
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha1
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static void processLogMessage(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
// Evaluate active rules
|
||||
for (LogRule rule : activeRules) {
|
||||
if (rule.evaluate(level, issuerClass, issuerOrigin, issuerMetadata, message)) {
|
||||
if (rule.getType() == LogRuleType.WHITELIST) break; // Continue processing
|
||||
if (rule.getType() == LogRuleType.BLACKLIST) return; // Cancel processing
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke LoggingAdapter#prePlaceholder
|
||||
String format = loggingAdapter.prePlaceholder(level, issuerClass, issuerOrigin, issuerMetadata, message, EngineConfiguration.getInstance().getLoggerTemplate());
|
||||
if (format == null)
|
||||
format = EngineConfiguration.getInstance().getLoggerTemplate();
|
||||
|
||||
// Replace placeholders using PlaceholderEngine
|
||||
format = PlaceholderEngine.getInstance().process(format);
|
||||
|
||||
// Replace logger placeholders (no colors)
|
||||
format = new LogClass(issuerClass).replace(format);
|
||||
format = new LogLevelEvent(level).replace(format);
|
||||
format = new LogMetadata(issuerMetadata).replace(format);
|
||||
format = new LogOrigin(issuerOrigin).replace(format);
|
||||
format = new LogPackage(issuerClass).replace(format);
|
||||
format = new LogPath(issuerClass).replace(format);
|
||||
|
||||
// Handle newlines
|
||||
if (EngineConfiguration.getInstance().isLoggerEnableNewlineSupport() && message.contains("\n"))
|
||||
try (Scanner scanner = new Scanner(message)) {
|
||||
int indexPrefix = format.indexOf("%log_message_prefix%");
|
||||
int indexMessage = format.indexOf("%log_message%");
|
||||
StringBuilder formatNew = new StringBuilder();
|
||||
String prefix;
|
||||
String suffix;
|
||||
String formatShadow;
|
||||
|
||||
if (indexMessage == -1)
|
||||
crash(Logger.class, "ENGINE", null, "The log format must contain %log_message%");
|
||||
|
||||
prefix = indexPrefix == -1 ? "" : format.substring(indexPrefix + 20, indexMessage);
|
||||
suffix = format.substring(indexMessage + 13);
|
||||
formatShadow = " "
|
||||
.repeat(new EmptyShortcodeConverter(
|
||||
format.substring(0, indexPrefix == -1 ? indexMessage : indexPrefix)
|
||||
.replace("%log_color_primary%", "")
|
||||
.replace("%log_color_secondary%", ""), false
|
||||
).getClean().length());
|
||||
|
||||
while (scanner.hasNextLine()) {
|
||||
if (formatNew.isEmpty())
|
||||
formatNew.append(format, 0, indexPrefix == -1 ? indexMessage : indexPrefix);
|
||||
else
|
||||
formatNew
|
||||
.append("\n")
|
||||
.append(formatShadow);
|
||||
|
||||
formatNew
|
||||
.append(prefix)
|
||||
.append(scanner.nextLine())
|
||||
.append(suffix);
|
||||
}
|
||||
|
||||
format = formatNew.toString();
|
||||
}
|
||||
else
|
||||
// No newline found, use performance-efficient replacing
|
||||
format = format
|
||||
.replace("%log_message_prefix%", "")
|
||||
.replace("%log_message%", message.replace("\n", "\\n"));
|
||||
|
||||
// Replace placeholders involving colors
|
||||
format = new LogColorPrimary(level).replace(format);
|
||||
format = new LogColorSecondary(level).replace(format);
|
||||
|
||||
// Replace placeholders using PlaceholderEngine again
|
||||
format = PlaceholderEngine.getInstance().process(format);
|
||||
|
||||
// Invoke LoggingAdapter#postPlaceholder
|
||||
format = loggingAdapter.postPlaceholder(level, issuerClass, issuerOrigin, issuerMetadata, message, format);
|
||||
|
||||
// Call event
|
||||
if (!(issuerClass.getName().equals("de.staropensource.engine.slf4j_compat.CompatibilityLogger")
|
||||
|| issuerClass.equals(EventHelper.class)))
|
||||
new LogEvent().callEvent(level, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
|
||||
// Print log message by invoking LoggingAdapter#print
|
||||
loggingAdapter.print(level, issuerClass, issuerOrigin, issuerMetadata, message, format);
|
||||
public static void flush() {
|
||||
LoggingQueue.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for all log messages.
|
||||
* Disallows one or multiple classes.
|
||||
*
|
||||
* @param level level
|
||||
* @param issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @since v1-alpha0
|
||||
* @param regex regex
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private static synchronized void log(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
// Check if engine has initialized
|
||||
if (Engine.getInstance() == null) return;
|
||||
|
||||
// Dismiss if level is not allowed
|
||||
if (level.compareTo(EngineConfiguration.getInstance().getLoggerLevel()) < 0)
|
||||
return;
|
||||
|
||||
if (EngineConfiguration.getInstance().isOptimizeLogging())
|
||||
// Optimizations enabled, add to message queue
|
||||
queuedMessages.add(new QueuedLogMessage(level, issuerClass, issuerOrigin, issuerMetadata, message));
|
||||
else
|
||||
// Optimizations disabled, print right away
|
||||
processLogMessage(level, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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
|
||||
*/
|
||||
public static void diag(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.DIAGNOSTIC, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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
|
||||
*/
|
||||
public static void verb(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.VERBOSE, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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
|
||||
*/
|
||||
public static void sarn(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.SILENT_WARNING, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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
|
||||
*/
|
||||
public static void info(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.INFORMATIONAL, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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
|
||||
*/
|
||||
public static void warn(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.WARNING, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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
|
||||
*/
|
||||
public static void error(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
log(LogLevel.ERROR, issuerClass, issuerOrigin, issuerMetadata, message);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata 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
|
||||
* @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
|
||||
*/
|
||||
public static void crash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull Throwable throwable, boolean handled) {
|
||||
CrashHandler.handleCrash(issuerClass, issuerOrigin, issuerMetadata, message, throwable, handled);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message message
|
||||
* @param throwable the throwable that caused this crash
|
||||
* @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
|
||||
*/
|
||||
public static void crash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull Throwable throwable) {
|
||||
CrashHandler.handleCrash(issuerClass, issuerOrigin, issuerMetadata, message, throwable, false);
|
||||
@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 issuerClass class of the issuer
|
||||
* @param issuerOrigin origin of the issuer
|
||||
* @param issuerMetadata metadata about the issuer
|
||||
* @param message 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 #crash(String)
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static void crash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
||||
CrashHandler.handleCrash(issuerClass, issuerOrigin, issuerMetadata, message, null, false);
|
||||
@Deprecated(forRemoval = true)
|
||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
||||
redirectCall(message, null, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,69 +19,29 @@
|
|||
|
||||
package de.staropensource.engine.base.logging;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Removes the need to add {@code getClass} to all calls to {@link Logger}.
|
||||
* Legacy frontend.
|
||||
* <p>
|
||||
* This improves compatibility with old code
|
||||
* still using the old logger frontend.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see Logger
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
@Deprecated(forRemoval = true)
|
||||
public final class LoggerInstance {
|
||||
/**
|
||||
* Contains the {@link Class} of the issuer.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Returns the {@link Class} of the issuer.
|
||||
*
|
||||
* @return class of the issuer
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @NotNull Class<?> clazz;
|
||||
|
||||
/**
|
||||
* Contains the metadata about the issuer.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Returns the metadata about the issuer.
|
||||
*
|
||||
* @return metadata about the issuer
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @Nullable String metadata;
|
||||
|
||||
/**
|
||||
* Contains the origin of the issuer.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Returns the origin of the issuer.
|
||||
*
|
||||
* @return origin of the issuer
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final @NotNull String origin;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param clazz class of the issuer
|
||||
* @param origin origin of the issuer
|
||||
* @param metadata metadata about the issuer
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private LoggerInstance(@NotNull Class<?> clazz, @NotNull String origin, @Nullable String metadata) {
|
||||
this.clazz = clazz;
|
||||
this.origin = origin;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
private LoggerInstance() {}
|
||||
|
||||
/**
|
||||
* Prints a diagnostic message.
|
||||
|
@ -90,10 +50,7 @@ public final class LoggerInstance {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public void diag(@NotNull String message) {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
InitLogger.diag(clazz, origin, metadata, message);
|
||||
else
|
||||
Logger.diag(clazz, origin, metadata, message);
|
||||
Logger.diag(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,10 +60,7 @@ public final class LoggerInstance {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public void verb(@NotNull String message) {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
InitLogger.verb(clazz, origin, metadata, message);
|
||||
else
|
||||
Logger.verb(clazz, origin, metadata, message);
|
||||
Logger.verb(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,10 +70,7 @@ public final class LoggerInstance {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public void sarn(@NotNull String message) {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
InitLogger.sarn(clazz, origin, metadata, message);
|
||||
else
|
||||
Logger.sarn(clazz, origin, metadata, message);
|
||||
Logger.sarn(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,10 +80,7 @@ public final class LoggerInstance {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public void info(@NotNull String message) {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
InitLogger.info(clazz, origin, metadata, message);
|
||||
else
|
||||
Logger.info(clazz, origin, metadata, message);
|
||||
Logger.info(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,10 +90,7 @@ public final class LoggerInstance {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public void warn(@NotNull String message) {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
InitLogger.warn(clazz, origin, metadata, message);
|
||||
else
|
||||
Logger.warn(clazz, origin, metadata, message);
|
||||
Logger.warn(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,10 +100,7 @@ public final class LoggerInstance {
|
|||
* @since v1-alpha0
|
||||
*/
|
||||
public void error(@NotNull String message) {
|
||||
if (Engine.getInstance().getState() == EngineState.EARLY_STARTUP)
|
||||
InitLogger.error(clazz, origin, metadata, message);
|
||||
else
|
||||
Logger.error(clazz, origin, metadata, message);
|
||||
Logger.error(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,11 +109,10 @@ public final class LoggerInstance {
|
|||
* @param message message
|
||||
* @param throwable throwable that caused the crash
|
||||
* @param handled declares the throwable has handled
|
||||
* @see CrashHandler
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public void crash(@NotNull String message, @NotNull Throwable throwable, boolean handled) {
|
||||
Logger.crash(clazz, origin, metadata, message, throwable, handled);
|
||||
Logger.crash(message, throwable, !handled);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,52 +120,50 @@ public final class LoggerInstance {
|
|||
*
|
||||
* @param message message
|
||||
* @param throwable throwable that caused the crash
|
||||
* @see CrashHandler
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public void crash(@NotNull String message, @NotNull Throwable throwable) {
|
||||
Logger.crash(clazz, origin, metadata, message, throwable);
|
||||
Logger.crash(message, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crashes the entire engine.
|
||||
*
|
||||
* @param message message
|
||||
* @see CrashHandler
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public void crash(@NotNull String message) {
|
||||
Logger.crash(clazz, origin, metadata, message);
|
||||
Logger.crash(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an API for building {@link LoggerInstance}s more easily.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
||||
* @see Logger
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
@SuppressWarnings({ "unused" })
|
||||
public static final class Builder {
|
||||
/**
|
||||
* Contains the class of the issuer.
|
||||
*
|
||||
* @see LoggerInstance#clazz
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private @Nullable Class<?> clazz = null;
|
||||
|
||||
/**
|
||||
* Contains the origin of the issuer.
|
||||
*
|
||||
* @see LoggerInstance#origin
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private @Nullable String origin = null;
|
||||
|
||||
/**
|
||||
* Contains metadata about the issuer.
|
||||
*
|
||||
* @see LoggerInstance#metadata
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
private @Nullable String metadata = null;
|
||||
|
||||
|
@ -253,14 +192,13 @@ public final class LoggerInstance {
|
|||
if (metadata == null || metadata.isBlank())
|
||||
metadata = null;
|
||||
|
||||
return new LoggerInstance(clazz, origin, metadata);
|
||||
return new LoggerInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of the issuer.
|
||||
*
|
||||
* @return class of the issuer
|
||||
* @see LoggerInstance#clazz
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public @Nullable Class<?> getClazz() {
|
||||
|
@ -271,7 +209,6 @@ public final class LoggerInstance {
|
|||
* Returns the origin of the issuer.
|
||||
*
|
||||
* @return origin of the issuer
|
||||
* @see LoggerInstance#origin
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public @Nullable String getOrigin() {
|
||||
|
@ -282,7 +219,6 @@ public final class LoggerInstance {
|
|||
* Returns metadata about the issuer.
|
||||
*
|
||||
* @return metadata about the issuer
|
||||
* @see LoggerInstance#metadata
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public @Nullable String getMetadata() {
|
||||
|
@ -294,7 +230,6 @@ public final class LoggerInstance {
|
|||
*
|
||||
* @param clazz new class of the issuer
|
||||
* @return builder instance
|
||||
* @see LoggerInstance#clazz
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public @NotNull Builder setClazz(@Nullable Class<?> clazz) {
|
||||
|
@ -307,7 +242,6 @@ public final class LoggerInstance {
|
|||
*
|
||||
* @param origin new origin of the issuer
|
||||
* @return builder instance
|
||||
* @see LoggerInstance#origin
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public @NotNull Builder setOrigin(@Nullable String origin) {
|
||||
|
@ -320,7 +254,6 @@ public final class LoggerInstance {
|
|||
*
|
||||
* @param metadata new metadata about the issuer
|
||||
* @return builder instance
|
||||
* @see LoggerInstance#metadata
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
public @NotNull Builder setMetadata(@Nullable String metadata) {
|
||||
|
|
|
@ -1,144 +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.Engine;
|
||||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Controls the logging thread of the engine.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
@Slf4j
|
||||
public class LoggingThread {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
protected static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(LoggingThread.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Contains the logic of the logging thread.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static final @NotNull Runnable loggingThreadLogic = () -> {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
// Stop thread when engine is shutting down
|
||||
if (Engine.getInstance().getState() == EngineState.SHUTDOWN
|
||||
|| Engine.getInstance().getState() == EngineState.CRASHED
|
||||
|| !EngineConfiguration.getInstance().isOptimizeLogging())
|
||||
return;
|
||||
|
||||
// Process all log messages
|
||||
Logger.flushLogMessages();
|
||||
|
||||
// Sleep for whatever has been configured
|
||||
if (EngineConfiguration.getInstance().getLoggerPollingSpeed() > 0) {
|
||||
long sleepDuration = System.currentTimeMillis() + EngineConfiguration.getInstance().getLoggerPollingSpeed();
|
||||
while (System.currentTimeMillis() < sleepDuration)
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Contains a reference to the logging thread.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static Thread loggingThread;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class
|
||||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private LoggingThread() {}
|
||||
|
||||
/**
|
||||
* Reconstructs the {@link #loggingThread} thread.
|
||||
*
|
||||
* @throws IllegalStateException if the logging thread's state is not {@link Thread.State#TERMINATED}
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static void reconstructThread() throws IllegalStateException {
|
||||
if (loggingThread != null && loggingThread.getState() != Thread.State.TERMINATED)
|
||||
throw new IllegalStateException("The logging thread needs to be terminated before reconstruction");
|
||||
|
||||
loggingThread = Thread
|
||||
.ofPlatform()
|
||||
.daemon()
|
||||
.name("Logging thread")
|
||||
.group(Engine.getThreadGroup())
|
||||
.stackSize(10)
|
||||
.unstarted(loggingThreadLogic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the logging thread.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* @throws IllegalStateException if thread reconstruction fails because the thread isn't {@link Thread.State#TERMINATED}, see {@link #reconstructThread()}
|
||||
* @see #loggingThread
|
||||
*/
|
||||
public static void startThread() {
|
||||
if (loggingThread == null)
|
||||
reconstructThread();
|
||||
|
||||
if (loggingThread.isAlive()) {
|
||||
// Executing the thread restart logic prevents blocking the current thread
|
||||
// while still ensuring that the logging thread is properly restarted
|
||||
Thread
|
||||
.ofVirtual()
|
||||
.name("Logging thread restart thread")
|
||||
.start(() -> {
|
||||
logger.diag("Restarting the logging thread");
|
||||
|
||||
loggingThread.interrupt();
|
||||
|
||||
// Make sure that the logging thread is dead before reconstructing and starting it
|
||||
while (loggingThread.isAlive())
|
||||
Thread.onSpinWait();
|
||||
|
||||
reconstructThread();
|
||||
loggingThread.start();
|
||||
});
|
||||
} else
|
||||
loggingThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Thread.State} of the logging thread.
|
||||
*
|
||||
* @return logging thread state
|
||||
* @since v1-alpha4
|
||||
* @see Thread.State
|
||||
*/
|
||||
public static @NotNull Thread.State getState() {
|
||||
return loggingThread.getState();
|
||||
}
|
||||
}
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package de.staropensource.engine.base.logging;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.type.EngineState;
|
||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -34,26 +36,18 @@ import java.nio.charset.StandardCharsets;
|
|||
*
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
@SuppressWarnings({ "unused", "JavadocDeclaration" })
|
||||
public final class PrintStreamService {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(PrintStreamService.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Contains the diagnostic stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#info(Class, String, String, String)}
|
||||
* {@link Logger#info(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the diagnostic stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#info(Class, String, String, String)}
|
||||
* {@link Logger#info(String)}
|
||||
*
|
||||
* @return diagnostic stream
|
||||
* @since v1-alpha4
|
||||
|
@ -64,13 +58,13 @@ public final class PrintStreamService {
|
|||
/**
|
||||
* Contains the verbose stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the verbose stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @return verbose stream
|
||||
* @since v1-alpha4
|
||||
|
@ -81,13 +75,13 @@ public final class PrintStreamService {
|
|||
/**
|
||||
* Contains the silent warning stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the silent warning stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @return silent warning stream
|
||||
* @since v1-alpha4
|
||||
|
@ -98,13 +92,13 @@ public final class PrintStreamService {
|
|||
/**
|
||||
* Contains the informational stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#info(Class, String, String, String)}
|
||||
* {@link Logger#info(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the informational stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#info(Class, String, String, String)}
|
||||
* {@link Logger#info(String)}
|
||||
*
|
||||
* @return informational stream
|
||||
* @since v1-alpha4
|
||||
|
@ -115,13 +109,13 @@ public final class PrintStreamService {
|
|||
/**
|
||||
* Contains the warning stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the warning stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @return warning stream
|
||||
* @since v1-alpha4
|
||||
|
@ -132,13 +126,13 @@ public final class PrintStreamService {
|
|||
/**
|
||||
* Contains the error stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#info(Class, String, String, String)}
|
||||
* {@link Logger#info(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the error stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#info(Class, String, String, String)}
|
||||
* {@link Logger#info(String)}
|
||||
*
|
||||
* @return error stream
|
||||
* @since v1-alpha4
|
||||
|
@ -149,13 +143,13 @@ public final class PrintStreamService {
|
|||
/**
|
||||
* Contains the crash stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the crash stream.
|
||||
* Anything sent will be redirected to
|
||||
* {@link Logger#error(Class, String, String, String)}
|
||||
* {@link Logger#error(String)}
|
||||
*
|
||||
* @return crash stream
|
||||
* @since v1-alpha4
|
||||
|
@ -172,18 +166,14 @@ public final class PrintStreamService {
|
|||
|
||||
/**
|
||||
* Initializes all {@link PrintStream}s offered by this class.
|
||||
* <p>
|
||||
* Only works during early engine startup.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public static void initializeStreams() {
|
||||
// Close all existing streams
|
||||
if (diag != null) diag.close();
|
||||
if (verb != null) verb.close();
|
||||
if (sarn != null) sarn.close();
|
||||
if (info != null) info.close();
|
||||
if (warn != null) warn.close();
|
||||
if (error != null) error.close();
|
||||
if (crash != null) crash.close();
|
||||
if (Engine.getInstance() == null || Engine.getInstance().getState() != EngineState.EARLY_STARTUP)
|
||||
return;
|
||||
|
||||
// Create streams
|
||||
diag = LogStream.createPrintStream(LogLevel.DIAGNOSTIC);
|
||||
|
@ -277,13 +267,13 @@ public final class PrintStreamService {
|
|||
// Check for newline
|
||||
if (sequence.indexOf("\n") != -1) {
|
||||
switch (level) {
|
||||
case DIAGNOSTIC -> logger.diag(sequence.toString());
|
||||
case VERBOSE -> logger.verb(sequence.toString());
|
||||
case SILENT_WARNING -> logger.sarn(sequence.toString());
|
||||
case INFORMATIONAL -> logger.info(sequence.toString());
|
||||
case WARNING -> logger.warn(sequence.toString());
|
||||
case ERROR -> logger.error(sequence.toString());
|
||||
case CRASH -> logger.crash(sequence.toString());
|
||||
case DIAGNOSTIC -> Logger.diag(sequence.toString());
|
||||
case VERBOSE -> Logger.verb(sequence.toString());
|
||||
case SILENT_WARNING -> Logger.sarn(sequence.toString());
|
||||
case INFORMATIONAL -> Logger.info(sequence.toString());
|
||||
case WARNING -> Logger.warn(sequence.toString());
|
||||
case ERROR -> Logger.error(sequence.toString());
|
||||
case CRASH -> Logger.crash(sequence.toString());
|
||||
}
|
||||
|
||||
sequence = new StringBuilder();
|
||||
|
|
|
@ -0,0 +1,338 @@
|
|||
/*
|
||||
* 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 -> {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,375 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* 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());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
|
@ -18,8 +18,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Contains classes starting with {@code Api*}.
|
||||
* Everything related to making the logging
|
||||
* infrastructure asynchronous.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
package de.staropensource.engine.windowing.implementable.api;
|
||||
package de.staropensource.engine.base.logging.backend.async;
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Data types in form of enums and classes.
|
||||
* The backend of sos!engine's logging infrastructure.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
package de.staropensource.engine.windowing.glfw.type;
|
||||
package de.staropensource.engine.base.logging.backend;
|
|
@ -18,11 +18,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* The engine's custom logging infrastructure.
|
||||
* The engine's logging infrastructure.
|
||||
*
|
||||
* @see de.staropensource.engine.base.logging.Logger
|
||||
* @see de.staropensource.engine.base.logging.LoggerInstance
|
||||
* @see de.staropensource.engine.base.logging.CrashHandler
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
package de.staropensource.engine.base.logging;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package de.staropensource.engine.base.reflection;
|
||||
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -39,14 +39,6 @@ import java.util.Map;
|
|||
* @since v1-alpha2
|
||||
*/
|
||||
public final class ClasspathAccess {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(ClasspathAccess.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
|
@ -69,7 +61,7 @@ public final class ClasspathAccess {
|
|||
try {
|
||||
urls.add(new File(path).toURI().toURL());
|
||||
} catch (Exception exception) {
|
||||
logger.crash("Failed converting classpath to URL", exception);
|
||||
Logger.crash("Failed converting classpath to URL", exception);
|
||||
}
|
||||
|
||||
return fixURLs(urls);
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
|
||||
package de.staropensource.engine.base.type;
|
||||
|
||||
import de.staropensource.engine.base.logging.InitLogger;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
|
||||
/**
|
||||
* Determines in which state the engine is currently in.
|
||||
*
|
||||
|
@ -29,58 +26,52 @@ import de.staropensource.engine.base.logging.Logger;
|
|||
*/
|
||||
public enum EngineState {
|
||||
/**
|
||||
* The state of the engine is currently unknown.
|
||||
* The engine likely has not been initialized yet.
|
||||
* Indicates that the state of the engine is
|
||||
* currently unknown. The engine is most likely
|
||||
* not initialized yet.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
UNKNOWN,
|
||||
|
||||
/**
|
||||
* The engine is in early startup.
|
||||
* The engine is largely uninitialized and
|
||||
* the logging infrastructure is not yet ready
|
||||
* to be used.
|
||||
* <p>
|
||||
* This state is used to indicate that the
|
||||
* {@link InitLogger} shall be used instead
|
||||
* of {@link Logger}.
|
||||
* Indicates that the engine is largely
|
||||
* uninitialized and unsafe to use.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
EARLY_STARTUP,
|
||||
|
||||
/**
|
||||
* The engine is starting up.
|
||||
* Some parts of the engine may not be initialized
|
||||
* yet and may be unsafe to access. The logging
|
||||
* infrastructure is ready to be used though and is
|
||||
* safe to access.
|
||||
* Indicates that the core engine has fully
|
||||
* initialized, except for all subsystems.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
STARTUP,
|
||||
|
||||
/**
|
||||
* The engine is in normal operation mode.
|
||||
* Indicates that the engine is running
|
||||
* and operating normally.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
RUNNING,
|
||||
|
||||
/**
|
||||
* The engine has crashed, either by itself or the application.
|
||||
* Indicates that the engine or the
|
||||
* application has crashed.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
CRASHED,
|
||||
|
||||
/**
|
||||
* The engine is shutting down.
|
||||
* Some parts of the engine may have already
|
||||
* shut down and may be unsafe to access.
|
||||
* Indicates that the engine is shutting
|
||||
* down. The engine is unusable in this
|
||||
* state and should not be used.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
SHUTDOWN,
|
||||
}
|
||||
|
|
|
@ -17,10 +17,39 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.base.type;
|
||||
|
||||
/**
|
||||
* Placeholders used in the {@link de.staropensource.engine.base.logging.Logger}.
|
||||
* Represents various file types.
|
||||
*
|
||||
* @see de.staropensource.engine.base.logging.Logger
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
package de.staropensource.engine.base.internal.implementation.placeholder.logger;
|
||||
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
|
||||
}
|
|
@ -46,7 +46,7 @@ public abstract class LogRule {
|
|||
private final @NotNull LogRuleType type;
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @param type rule type
|
||||
*/
|
||||
|
|
|
@ -22,7 +22,7 @@ package de.staropensource.engine.base.utility;
|
|||
import de.staropensource.engine.base.exception.dependency.DependencyCycleException;
|
||||
import de.staropensource.engine.base.exception.dependency.UnmetDependenciesException;
|
||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
@ -39,14 +39,6 @@ import java.util.*;
|
|||
*/
|
||||
@SuppressWarnings({ "unused", "UnusedReturnValue", "JavadocDeclaration" })
|
||||
public final class DependencyResolver {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
private final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").setMetadata(String.valueOf(hashCode())).build();
|
||||
|
||||
/**
|
||||
* List of {@link DependencyVector}s to resolve.
|
||||
*
|
||||
|
@ -275,7 +267,7 @@ public final class DependencyResolver {
|
|||
try {
|
||||
versioningSystemResolved = vectorDependency.getVersioningSystem().getDeclaredConstructor(String.class).newInstance(vectorDependency.getVersion());
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||
logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
Logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -287,7 +279,7 @@ public final class DependencyResolver {
|
|||
try {
|
||||
versioningSystemEquals = vectorDependency.getVersioningSystem().getDeclaredConstructor(String.class).newInstance(versionEqual.toString());
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||
logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
Logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -303,7 +295,7 @@ public final class DependencyResolver {
|
|||
try {
|
||||
versioningSystemSmaller = vectorDependency.getVersioningSystem().getDeclaredConstructor(String.class).newInstance(versionSmaller.toString());
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||
logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
Logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
break;
|
||||
}
|
||||
if (!versionBigger.isEmpty())
|
||||
|
@ -311,7 +303,7 @@ public final class DependencyResolver {
|
|||
try {
|
||||
versioningSystemBigger = vectorDependency.getVersioningSystem().getDeclaredConstructor(String.class).newInstance(versionBigger.toString());
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||
logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
Logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + vectorDependency.getVersioningSystem().getName(), exception);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,851 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ package de.staropensource.engine.base.utility;
|
|||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.implementable.Placeholder;
|
||||
import de.staropensource.engine.base.internal.implementation.placeholder.*;
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -50,14 +49,6 @@ public final class PlaceholderEngine {
|
|||
@Getter
|
||||
private static PlaceholderEngine instance;
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
private final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Contains all global placeholders.
|
||||
*
|
||||
|
@ -106,6 +97,7 @@ public final class PlaceholderEngine {
|
|||
placeholders.add(new EngineGitDirty());
|
||||
// engine_version*
|
||||
placeholders.add(new EngineVersion());
|
||||
placeholders.add(new EngineVersionCodename());
|
||||
placeholders.add(new EngineVersionVersion());
|
||||
placeholders.add(new EngineVersionType());
|
||||
placeholders.add(new EngineVersionTyperelease());
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package de.staropensource.engine.base.utility;
|
||||
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.Tristate;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -49,14 +49,6 @@ public final class PropertiesReader {
|
|||
@Getter
|
||||
private static final @NotNull PropertiesReader instance = new PropertiesReader(System.getProperties());
|
||||
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
private final @NotNull LoggerInstance logger;
|
||||
|
||||
/**
|
||||
* Contains the {@link Properties} used by this parser instance to read properties.
|
||||
*
|
||||
|
@ -80,7 +72,6 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public PropertiesReader(@NotNull Properties properties) {
|
||||
this.properties = properties;
|
||||
this.logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").setMetadata(String.valueOf(properties.hashCode())).build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,7 +85,7 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public @NotNull String getString(@NotNull String name) throws NullPointerException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get String from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get String from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get String from property '" + name + "': Property does not exist");
|
||||
}
|
||||
return properties.getProperty(name);
|
||||
|
@ -111,7 +102,7 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public boolean getBoolean(@NotNull String name) throws NullPointerException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Boolean from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Boolean from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Boolean from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
|
@ -136,7 +127,7 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public @NotNull Tristate getTristate(@NotNull String name) throws NullPointerException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Tristate from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Tristate from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Tristate from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
|
@ -165,14 +156,14 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public byte getByte(@NotNull String name) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Byte from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Byte from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Byte from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
try {
|
||||
return Byte.parseByte(properties.getProperty(name));
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.sarn("Unable to get Byte from property '" + name + "': String cannot be parsed as a Byte.");
|
||||
Logger.sarn("Unable to get Byte from property '" + name + "': String cannot be parsed as a Byte.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
@ -189,14 +180,14 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public short getShort(@NotNull String name) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Short from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Short from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Short from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
try {
|
||||
return Short.parseShort(properties.getProperty(name));
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.sarn("Unable to get Short from property '" + name + "': String cannot be parsed as a Short.");
|
||||
Logger.sarn("Unable to get Short from property '" + name + "': String cannot be parsed as a Short.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +205,7 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public int getInteger(@NotNull String name, boolean unsigned) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Integer from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Integer from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Integer from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
|
@ -224,7 +215,7 @@ public final class PropertiesReader {
|
|||
else
|
||||
return Integer.parseInt(properties.getProperty(name));
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.sarn("Unable to get Integer from property '" + name + "': String cannot be parsed as an Integer.");
|
||||
Logger.sarn("Unable to get Integer from property '" + name + "': String cannot be parsed as an Integer.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
@ -242,7 +233,7 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public long getLong(@NotNull String name, boolean unsigned) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Long from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Long from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Long from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
|
@ -252,7 +243,7 @@ public final class PropertiesReader {
|
|||
else
|
||||
return Long.parseLong(properties.getProperty(name));
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.sarn("Unable to get Long from property '" + name + "': String cannot be parsed as a Long.");
|
||||
Logger.sarn("Unable to get Long from property '" + name + "': String cannot be parsed as a Long.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
@ -269,14 +260,14 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public float getFloat(@NotNull String name) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Float from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Float from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Float from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
try {
|
||||
return Float.parseFloat(properties.getProperty(name));
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.sarn("Unable to get Float from property '" + name + "': String cannot be parsed as a Float.");
|
||||
Logger.sarn("Unable to get Float from property '" + name + "': String cannot be parsed as a Float.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
@ -293,17 +284,17 @@ public final class PropertiesReader {
|
|||
*/
|
||||
public double getDouble(@NotNull String name) throws NullPointerException, NumberFormatException {
|
||||
if (properties.getProperty(name) == null) {
|
||||
logger.sarn("Unable to get Double from property '" + name + "': Property does not exist");
|
||||
Logger.sarn("Unable to get Double from property '" + name + "': Property does not exist");
|
||||
throw new NullPointerException("Unable to get Double from property '" + name + "': Property does not exist");
|
||||
}
|
||||
|
||||
try {
|
||||
return Double.parseDouble(properties.getProperty(name));
|
||||
} catch (NullPointerException exception) {
|
||||
logger.sarn("Unable to get Double from property '" + name + "': String is null.");
|
||||
Logger.sarn("Unable to get Double from property '" + name + "': String is null.");
|
||||
throw exception;
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.sarn("Unable to get Double from property '" + name + "': String cannot be parsed as a Double.");
|
||||
Logger.sarn("Unable to get Double from property '" + name + "': String cannot be parsed as a Double.");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,10 @@
|
|||
|
||||
package de.staropensource.engine.base.utility.information;
|
||||
|
||||
import de.staropensource.engine.base.Engine;
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.VersionType;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -44,14 +41,6 @@ import java.util.Properties;
|
|||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class EngineInformation {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(EngineInformation.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Contains the engine's version codename.
|
||||
*
|
||||
|
@ -348,14 +337,14 @@ public final class EngineInformation {
|
|||
* @since v1-alpha1
|
||||
*/
|
||||
public static synchronized void update() {
|
||||
logger.diag("Updating engine information");
|
||||
Logger.diag("Updating engine information");
|
||||
|
||||
// Load properties from bundled gradle.properties
|
||||
Properties gradleProperties = new Properties();
|
||||
InputStream gradleStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosengine-gradle.properties");
|
||||
|
||||
if (gradleStream == null) {
|
||||
logger.crash("Unable to load build information: The bundled gradle.properties file could not be found.");
|
||||
Logger.crash("Unable to load build information: The bundled gradle.properties file could not be found.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -363,7 +352,7 @@ public final class EngineInformation {
|
|||
gradleProperties.load(gradleStream);
|
||||
gradleStream.close();
|
||||
} catch (IOException exception) {
|
||||
logger.crash("Unable to load build information: InputStream 'gradleStream' failed", exception);
|
||||
Logger.crash("Unable to load build information: InputStream 'gradleStream' failed", exception);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -372,7 +361,7 @@ public final class EngineInformation {
|
|||
Properties gitProperties = new Properties();
|
||||
InputStream gitStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosengine-git.properties");
|
||||
if (gitStream == null) {
|
||||
logger.error("Unable to load build information: The bundled git.properties file could not be found. Did you download a tarball?");
|
||||
Logger.error("Unable to load build information: The bundled git.properties file could not be found. Did you download a tarball?");
|
||||
|
||||
// Fake information
|
||||
gitProperties.setProperty("git.total.commit.count", "0");
|
||||
|
@ -390,7 +379,7 @@ public final class EngineInformation {
|
|||
gitProperties.load(gitStream);
|
||||
gitStream.close();
|
||||
} catch (IOException exception) {
|
||||
logger.crash("Unable to load build information: InputStream 'gitStream' failed", exception);
|
||||
Logger.crash("Unable to load build information: InputStream 'gitStream' failed", exception);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -427,9 +416,7 @@ public final class EngineInformation {
|
|||
calendar.setTime(date);
|
||||
gitCommitTime = calendar.toZonedDateTime();
|
||||
} catch (ParseException exception) {
|
||||
System.out.println("Unable to load build information: Can't parse \"" + gitParser.getString("git.commit.time") + "\" using format \"yyyy-MM-dd'T'HH:mmZ\"");
|
||||
System.out.println(Miscellaneous.getStackTraceHeader(exception) + "\n" + Miscellaneous.getStackTraceAsString(exception, true));
|
||||
Engine.getInstance().shutdown(69);
|
||||
Logger.crash("Unable to load build information: Can't parse \"" + gitParser.getString("git.commit.time") + "\" using format \"yyyy-MM-dd'T'HH:mmZ\"", exception);
|
||||
return;
|
||||
}
|
||||
gitCommitterName = gitParser.getString("git.commit.user.name");
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 {
|
||||
//}
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
package de.staropensource.engine.base.utility.information;
|
||||
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.immutable.ImmutableArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
@ -33,14 +34,6 @@ import java.util.List;
|
|||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public final class JvmInformation {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(JvmInformation.class).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
|
@ -68,7 +61,7 @@ public final class JvmInformation {
|
|||
try {
|
||||
return Integer.parseInt(version);
|
||||
} catch (NumberFormatException exception) {
|
||||
logger.crash("Could not parse Java version: Integer conversion failed for string \"" + version + "\"", exception, true);
|
||||
Logger.crash("Could not parse Java version: Integer conversion failed for string \"" + version + "\"", exception, true);
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
@ -117,11 +110,11 @@ public final class JvmInformation {
|
|||
* Returns all arguments passed to the JVM.
|
||||
* This excludes all arguments passed to the application.
|
||||
*
|
||||
* @return JVM arguments
|
||||
* @return immutable list with all JVM arguments
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
public static @NotNull List<@NotNull String> getArguments() {
|
||||
return ManagementFactory.getRuntimeMXBean().getInputArguments();
|
||||
return new ImmutableArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,13 +18,13 @@ module sosengine.base {
|
|||
exports de.staropensource.engine.base.implementable;
|
||||
exports de.staropensource.engine.base.implementable.helper;
|
||||
exports de.staropensource.engine.base.utility.information;
|
||||
exports de.staropensource.engine.base.implementation.shortcode;
|
||||
exports de.staropensource.engine.base.implementation.versioning;
|
||||
exports de.staropensource.engine.base.event;
|
||||
exports de.staropensource.engine.base.exception;
|
||||
exports de.staropensource.engine.base.exception.dependency;
|
||||
exports de.staropensource.engine.base.exception.reflection;
|
||||
exports de.staropensource.engine.base.exception.versioning;
|
||||
exports de.staropensource.engine.base.internal.event; // Internal: Required for subsystems
|
||||
exports de.staropensource.engine.base.logging;
|
||||
exports de.staropensource.engine.base.implementation.logging;
|
||||
exports de.staropensource.engine.base.reflection;
|
||||
|
@ -34,7 +34,6 @@ module sosengine.base {
|
|||
exports de.staropensource.engine.base.type.reflection;
|
||||
exports de.staropensource.engine.base.type.vector;
|
||||
exports de.staropensource.engine.base.utility;
|
||||
exports de.staropensource.engine.base.implementation.shortcode;
|
||||
|
||||
// Reflection access
|
||||
opens de.staropensource.engine.base;
|
||||
|
@ -42,13 +41,13 @@ module sosengine.base {
|
|||
opens de.staropensource.engine.base.implementable;
|
||||
opens de.staropensource.engine.base.implementable.helper;
|
||||
opens de.staropensource.engine.base.utility.information;
|
||||
opens de.staropensource.engine.base.implementation.shortcode;
|
||||
opens de.staropensource.engine.base.implementation.versioning;
|
||||
opens de.staropensource.engine.base.event;
|
||||
opens de.staropensource.engine.base.exception;
|
||||
opens de.staropensource.engine.base.exception.dependency;
|
||||
opens de.staropensource.engine.base.exception.reflection;
|
||||
opens de.staropensource.engine.base.exception.versioning;
|
||||
opens de.staropensource.engine.base.internal.event; // Internal: Required for subsystems
|
||||
opens de.staropensource.engine.base.logging;
|
||||
opens de.staropensource.engine.base.implementation.logging;
|
||||
opens de.staropensource.engine.base.reflection;
|
||||
|
@ -58,5 +57,4 @@ module sosengine.base {
|
|||
opens de.staropensource.engine.base.type.reflection;
|
||||
opens de.staropensource.engine.base.type.vector;
|
||||
opens de.staropensource.engine.base.utility;
|
||||
opens de.staropensource.engine.base.implementation.shortcode;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
@ -53,11 +54,10 @@ class EngineConfigurationTest extends TestBase {
|
|||
settings.put("debug", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("debugEvents", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("errorShortcodeParser", new Object[]{ "false", Boolean.FALSE });
|
||||
settings.put("loggerLevel", new Object[]{ "verbose", LogLevel.VERBOSE });
|
||||
settings.put("loggerTemplate", new Object[]{ "%log_path% says: %message%", "%log_path% says: %message%" });
|
||||
settings.put("loggerImmediateShutdown", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("loggerForceStandardOutput", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("loggerPollingSpeed", new Object[]{ "9999", 9999 });
|
||||
settings.put("logLevel", new Object[]{ "verbose", LogLevel.VERBOSE });
|
||||
settings.put("logFeatures", new Object[]{ "formatting,runtime,time", Set.of("formatting", "runtime", "time") });
|
||||
settings.put("logForceStandardOutput", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("logPollingSpeed", new Object[]{ "9999", 9999 });
|
||||
settings.put("optimizeLogging", new Object[]{ "false", Boolean.FALSE });
|
||||
settings.put("optimizeEvents", new Object[]{ "false", Boolean.FALSE });
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ package de.staropensource.engine.base.srctests.utility;
|
|||
import de.staropensource.engine.base.EngineConfiguration;
|
||||
import de.staropensource.engine.base.annotation.EventListener;
|
||||
import de.staropensource.engine.base.event.ThrowableCatchEvent;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.testing.TestBase;
|
||||
import de.staropensource.engine.base.utility.Math;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
|
@ -125,7 +126,7 @@ public class MiscellaneousTest extends TestBase {
|
|||
return;
|
||||
|
||||
throwableCaught = false;
|
||||
Miscellaneous.executeSafely(() -> System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0");
|
||||
Miscellaneous.executeSafely(() -> Logger.info("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0");
|
||||
|
||||
assertFalse(throwableCaught, "Event was triggered");
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ tasks.register("javadocAll", Javadoc) {
|
|||
":base",
|
||||
":ansi",
|
||||
":slf4j-compat",
|
||||
":windowing",
|
||||
":windowing:glfw",
|
||||
":rendering",
|
||||
":notification",
|
||||
]
|
||||
|
||||
|
@ -63,7 +62,7 @@ tasks.register("javadocAll", Javadoc) {
|
|||
|
||||
// Fix module collisions
|
||||
doFirst {
|
||||
logger.log(LogLevel.WARN, "If this task fails, make sure to reset all module-info.java files using git or you may encounter issues.")
|
||||
getLogger().log(LogLevel.WARN, "If this task fails, make sure to reset all module-info.java files using git or you may encounter issues.")
|
||||
|
||||
for (String subproject : subprojects) {
|
||||
File source = new File(project(subproject).projectDir.getPath() + "/src/main/java/module-info.java")
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"position": 2,
|
||||
"link": {
|
||||
"type": "generated-index",
|
||||
"description": "Contains pages explaining how to setup the sos!engine in your project."
|
||||
"description": "Provides a complete guide on how to get started with the StarOpenSource Engine."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,20 @@ To initialize the sos!engine, simply add this to the initialization code of your
|
|||
```java
|
||||
Engine.initialize();
|
||||
```
|
||||
... or if you want error handling (recommended):
|
||||
```java
|
||||
try {
|
||||
Engine.initialize();
|
||||
} catch (Exception exception) {
|
||||
// Make sure this kills your
|
||||
// game or application. This
|
||||
// example is assuming that this
|
||||
// code lives inside a Main class.
|
||||
return;
|
||||
}
|
||||
```
|
||||
|
||||
This is enough to initialize the engine and all installed subsystems. No need to manually initialize them.
|
||||
This is enough to initialize the core engine and all subsystems found in the classpath. No need to manually initialize them.
|
||||
|
||||
## Printing something
|
||||
Now you'll probably want to print some log output. Before you try using `System.out#println`,
|
||||
|
@ -19,104 +31,43 @@ provides it's own logging implementation and is HIGHLY recommended to be used ov
|
|||
There are eight log levels you can use:
|
||||
<table>
|
||||
<tr>
|
||||
<th>Level</th>
|
||||
<th>Description</th>
|
||||
<th>LEVEL</th>
|
||||
<th>METHOD NAME</th>
|
||||
<th>DESCRIPTION</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>DIAGNOSTIC</th>
|
||||
<th>Provide detailed information about what is happening</th>
|
||||
<th>`DIAGNOSTIC`</th>
|
||||
<th>`diag`</th>
|
||||
<th>Detailed information about what is happening</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>VERBOSE</th>
|
||||
<th>Additional information that may not be useful</th>
|
||||
<th>`VERBOSE`</th>
|
||||
<th>`verb`</th>
|
||||
<th>Additional information about what is happening</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>SILENT_WARNING</th>
|
||||
<th>Warnings that can be ignored or are caused by invalid (API) user input</th>
|
||||
<th>`SILENT_WARNING`</th>
|
||||
<th>`sarn`</th>
|
||||
<th>Less important warnings. Useful for logging parsing errors and such</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>INFORMATIONAL</th>
|
||||
<th>`INFORMATIONAL`</th>
|
||||
<th>`info`</th>
|
||||
<th>Useful information about what is happening</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>WARNING</th>
|
||||
<th>Warnings about dangerous or weird behaviour</th>
|
||||
<th>`WARNING`</th>
|
||||
<th>`warn`</th>
|
||||
<th>Warnings about dangerous, deprecated or weird behaviour</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ERROR</th>
|
||||
<th>`ERROR`</th>
|
||||
<th>`error`</th>
|
||||
<th>Non-fatal errors</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>CRASH</th>
|
||||
<th>`CRASH`</th>
|
||||
<th>`crash`</th>
|
||||
<th>Fatal errors which may or may not halt the running program (see below)</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Here's an example:
|
||||
```java
|
||||
Logger.info(getClass(), "APPLICATION", null, "Hello World!");
|
||||
// ^ ^ ^ ^
|
||||
// | | | |
|
||||
// | | | --- The message you want to print.
|
||||
// | | -------- Metadata string (can be null). If your class/method processes data or something, you can include it here.
|
||||
// | ---------------------- Origin of the message. It identifies from which part of your application the message came.
|
||||
// -------------------------------------- Log priority/type. In this case, we want to emit an informational message
|
||||
```
|
||||
|
||||
Now, why do I need to supply so many arguments just for a simple "Hello World!"?
|
||||
It's simple: It describes the class issuing the log call.
|
||||
|
||||
Here's an example:
|
||||
```java
|
||||
class ExampleClass() {
|
||||
private @NotNull String string;
|
||||
|
||||
public ExampleClass(@NotNull String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public boolean checkForEscapes() {
|
||||
Logger.diag(getClass(), "APPLICATION", string, "Checking for escapes");
|
||||
return string.contains("\\");
|
||||
}
|
||||
|
||||
public boolean checkIfEmpty() {
|
||||
Logger.diag(getClass(), "APPLICATION", string, "Checking if empty");
|
||||
return string.isEmpty();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now that's nice and all, but it's annoying to pass three arguments describing your class to log methods
|
||||
and will – over time – make log messages unorganized and unmaintainable. That's not good. That's why
|
||||
the `LoggerInstance` class exists. It's purpose is to pass these to every log call you make. The only
|
||||
thing you need to do it to is to pass it some data about your class and it does the job for you.
|
||||
|
||||
Here's an example of the code before, but with `LoggerInstance`:
|
||||
```java
|
||||
class ExampleClass() {
|
||||
private @NotNull LoggerInstance logger;
|
||||
private @NotNull String string;
|
||||
|
||||
public ExampleClass(@NotNull String string) {
|
||||
this.string = string;
|
||||
logger = LoggerInstance.Builder()
|
||||
.setClass(getClass())
|
||||
.setOrigin("APPLICATION") // If you intend on 'origin' being set to "APPLICATION", you can leave this out. This has just been included for completeness.
|
||||
.setMetadata(string) // Include the string we are doing stuff with as metadata
|
||||
.build();
|
||||
}
|
||||
|
||||
public boolean checkForEscapes() {
|
||||
logger.diag("Checking for escapes");
|
||||
return string.contains("\\");
|
||||
}
|
||||
|
||||
public boolean checkIfEmpty() {
|
||||
logger.diag("Checking if empty");
|
||||
return string.isEmpty();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
As you can see, it's much simpler. No need to pass that to every call now!
|
||||
|
|
|
@ -80,7 +80,7 @@ dependencies {
|
|||
... and add this property to the `settings.gradle` file:
|
||||
```properties
|
||||
# Set this to the engine version you want to use
|
||||
dependencyStarOpenSourceEngine=1-alpha6
|
||||
dependencyStarOpenSourceEngine=1-alpha8
|
||||
```
|
||||
|
||||
## Maven
|
||||
|
@ -99,13 +99,12 @@ Add StarOpenSource's maven repository to your `pom.xml` file first:
|
|||
After that declare the engine as a dependency in your project:
|
||||
|
||||
```xml
|
||||
|
||||
<dependencies>
|
||||
<!-- sos!engine base -->
|
||||
<dependency>
|
||||
<groupId>de.staropensource.engine</groupId>
|
||||
<artifactId>base</artifactId>
|
||||
<version>1-alpha6</version>
|
||||
<version>1-alpha8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- sos!engine subsystems -->
|
||||
|
@ -113,35 +112,35 @@ After that declare the engine as a dependency in your project:
|
|||
<dependency>
|
||||
<groupId>de.staropensource.engine</groupId>
|
||||
<artifactId>ansi</artifactId>
|
||||
<version>v1-alpha6</version>
|
||||
<version>1-alpha8</version>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- SLF4J compatibility
|
||||
<dependency>
|
||||
<groupId>de.staropensource.engine</groupId>
|
||||
<artifactId>slf4j-compat</artifactId>
|
||||
<version>1-alpha6</version>
|
||||
<version>1-alpha8</version>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- creating and managing windows, requires a Windowing API implementation
|
||||
<dependency>
|
||||
<groupId>de.staropensource.engine</groupId>
|
||||
<artifactId>windowing</artifactId>
|
||||
<version>v1-alpha6</version>
|
||||
<version>1-alpha8</version>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- Windowing API implementation using GLFW
|
||||
<dependency>
|
||||
<groupId>de.staropensource.engine</groupId>
|
||||
<artifactId>glfw</artifactId>
|
||||
<version>v1-alpha6</version>
|
||||
<version>1-alpha8</version>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- sending and receiving notifications inside your application
|
||||
<dependency>
|
||||
<groupId>de.staropensource.engine</groupId>
|
||||
<artifactId>notification</artifactId>
|
||||
<version>v1-alpha6</version>
|
||||
<version>1-alpha8</version>
|
||||
</dependency>
|
||||
-->
|
||||
</dependencies>
|
||||
|
|
|
@ -67,3 +67,21 @@ The engine API documentation covers the core engine and all official subsystems.
|
|||
- [windowing](https://jd.engine.staropensource.de/v1-alpha6/windowing/)
|
||||
- [windowing:glfw](https://jd.engine.staropensource.de/v1-alpha6/windowing:glfw/)
|
||||
- [notification](https://jd.engine.staropensource.de/v1-alpha6/notification/)
|
||||
- v1-alpha7
|
||||
- [All subsystem](https://jd.engine.staropensource.de/v1-alpha7/all/)
|
||||
- [base](https://jd.engine.staropensource.de/v1-alpha7/base/)
|
||||
- [testing](https://jd.engine.staropensource.de/v1-alpha7/testing/)
|
||||
- [ansi](https://jd.engine.staropensource.de/v1-alpha7/ansi/)
|
||||
- [slf4j-compat](https://jd.engine.staropensource.de/v1-alpha7/slf4j-compat/)
|
||||
- [windowing](https://jd.engine.staropensource.de/v1-alpha7/windowing/)
|
||||
- [windowing:glfw](https://jd.engine.staropensource.de/v1-alpha7/windowing:glfw/)
|
||||
- [notification](https://jd.engine.staropensource.de/v1-alpha7/notification/)
|
||||
- v1-alpha8
|
||||
- [All subsystem](https://jd.engine.staropensource.de/v1-alpha8/all/)
|
||||
- [base](https://jd.engine.staropensource.de/v1-alpha8/base/)
|
||||
- [testing](https://jd.engine.staropensource.de/v1-alpha8/testing/)
|
||||
- [ansi](https://jd.engine.staropensource.de/v1-alpha8/ansi/)
|
||||
- [slf4j-compat](https://jd.engine.staropensource.de/v1-alpha8/slf4j-compat/)
|
||||
- [windowing](https://jd.engine.staropensource.de/v1-alpha8/windowing/)
|
||||
- [windowing:glfw](https://jd.engine.staropensource.de/v1-alpha8/windowing:glfw/)
|
||||
- [notification](https://jd.engine.staropensource.de/v1-alpha8/notification/)
|
||||
|
|
|
@ -13,31 +13,81 @@ Welcome to the documentation for the StarOpenSource Engine!
|
|||
|
||||
## What is it?
|
||||
The StarOpenSource Engine (or **sos!engine** for short) is a modular, extensible and easy to use Java game and application engine. \
|
||||
It is responsible for the logging infrastructure, creating and managing windows, playing audio and much more.
|
||||
It is responsible for printing log messages, providing utility methods, creating and managing windows, playing audio and much more.
|
||||
|
||||
## Why another one?
|
||||
Yeah, it's true that there are many game engines and frameworks out there that intend to ease development of applications and games.
|
||||
I ([JeremyStarTM](https://git.staropensource.de/JeremyStarTM)) however have never seen an engine or framework, which can be extended easily, without having to fork it and without a complicated development setup.
|
||||
And I don't mean what you make within the bounds of the engine or framework, no, I mean the engine/framework itself.
|
||||
## There are `n` different game engines and application frameworks. Why another one?
|
||||
True, there are many game engines and application frameworks out there.
|
||||
I ([JeremyStarTM](https://git.staropensource.de/JeremyStarTM)) however have never seen an engine or framework be modular,
|
||||
extendable and easy to configure at the same time. Additionally, we intend on
|
||||
supporting applications and games. This means that you don't need to remember
|
||||
different APIs for your different projects and can instead focus on just one,
|
||||
perfecting your skills along the way.
|
||||
|
||||
## Why Java?
|
||||
Java. Some say it's an awful language. We disagree, strongly.
|
||||
|
||||
While it has some pitfalls, it's almost the embodiment of
|
||||
[OOP](https://en.wikipedia.org/wiki/Object-oriented_programming),
|
||||
providing the perfect base for creating a modular engine
|
||||
and framework like the sos!engine.
|
||||
|
||||
Additionally, because of it's interpreted nature it's easy to
|
||||
modify the bytecode at runtime and perform various things
|
||||
to it before it's executed. This isn't really doable in other
|
||||
programming languages easily. Just see what Minecraft modders are doing
|
||||
to the game using the [Mixin](https://github.com/SpongePowered/Mixin)
|
||||
framework. It's a perfect example.
|
||||
|
||||
Also important to note is Java's portability.
|
||||
Yes, it has it's constrains in some cases (like when accessing files),
|
||||
but these can be worked around easily (see our `FileAccess` class for an example).
|
||||
But generally, the code is portable. There's no need to cross-compile for
|
||||
different CPU architectures and operating systems. You don't have to deal with
|
||||
compilers and their 581^51 ways of configuring them. Just `javac` your source tree,
|
||||
pack your compiled bytecode into a `.jar` and you're good to go.
|
||||
|
||||
Lastly, you can use and mix various languages and compile them to different things.
|
||||
Have Groovy code and want it to interact with Java code? That works!
|
||||
You want to use Ruby to create a game using the sos!engine?
|
||||
[You could do that](https://jruby.org). Want to compile your entire Java codebase
|
||||
to JavaScript for usable on the web? [TeaVM has you covered](https://teavm.org/).
|
||||
Want to compile your Java code into binaries for fast execution?
|
||||
[There exists GraalVM native-image](https://www.graalvm.org/latest/reference-manual/native-image/).
|
||||
Once you've written your Java code you can compile and interact with it however you like.
|
||||
As far as I know no language is as good in this aspect as Java.
|
||||
|
||||
And these are the reasons as to why we use Java over C++, Rust or other languages for example.
|
||||
While yes, performance naturally suffers a bit, the JVM and computers in general have improved
|
||||
heavily in performance over the years. From the slow thing Java once was it's almost as fast as
|
||||
compiled code on modern machines. Most of the time you don't notice the difference. And if
|
||||
performance is your concern, use GraalVM native-image as described above (note: the StarOpenSource Engine
|
||||
does not yet support native-image, see [#3](https://git.staropensource.de/StarOpenSource/Engine/issues/3)).
|
||||
|
||||
## Architecture of the engine
|
||||
The engine consists of the core engine (`base` dependency in your project) and various subsystems (`slf4j-compat`, `windowing`, etc.). \
|
||||
\
|
||||
The job of the base engine is to provide minimal classes and interfaces needed for an application.
|
||||
It contains among other things a default logger implementation, useful methods, event system and a placeholder system. \
|
||||
\
|
||||
Subsystems on the other hand usually handle complex tasks. They provide abstractions for libraries and operating system calls. \
|
||||
"But why are there so many of them?" you might ask. Good question! Subsystems are intended to [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy).
|
||||
The engine is built as a modular system, containing the core engine (called `base`)
|
||||
and various different subsystems.
|
||||
|
||||
## Available official subsystems
|
||||
Besides the `base` engine, there are two stable subsystem and three experimental subsystems.
|
||||
The job of the core engine is to provide a logging system, utility methods, ways
|
||||
for subsystems to seamlessly function and much more required for building applications.
|
||||
|
||||
Subsystems on the other hand usually handle complex tasks.
|
||||
They usually provide abstractions for libraries or handle complicated tasks.
|
||||
"But why are there so many of them?" you might ask. Good question! Subsystems
|
||||
are intended to [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy).
|
||||
This avoids unnecessary bloat, having too many dependencies in your project while reducing the
|
||||
size and memory footprint of your project.
|
||||
|
||||
## Official subsystems
|
||||
Besides the `base` engine, there are two stable subsystem and two experimental subsystems.
|
||||
|
||||
There may be other subsystems out there. Please note though that they are not maintained
|
||||
by the StarOpenSource Project directly and are not automatically updated with the engine.
|
||||
### Stable
|
||||
- [`ansi`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/ansi): Provides an ANSI logging implementation and a ShortcodeParserSkeleton implementation
|
||||
- [`slf4j-compat`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/slf4j-compat): Provides [SLF4J](https://slf4j.org/) compatibility logger that redirects all log calls to the engine.
|
||||
- [`ansi`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/ansi): Provides an ANSI logger and a ShortcodeParserSkeleton implementation for all your terminal formatting needs
|
||||
- [`slf4j-compat`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/slf4j-compat): Provides a [SLF4J](https://slf4j.org/) compatibility logger for redirecting all log calls to the engine's logging system
|
||||
### Experimental
|
||||
- [`windowing`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/windowing): Provides abstract APIs for creating and managing windows and monitors.
|
||||
- [`windowing-glfw`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/windowing/glfw): Windowing API, allowing GLFW to be used for creating windows and recieving input.
|
||||
- [`notification`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/notification): Provides an API for sending and receiving notifications inside a program.
|
||||
- [`rendering`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/rendering): Provides an API for creating, managing and rendering windows
|
||||
- [`notification`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/notification): Provides an API for sending and receiving notifications inside a program
|
||||
|
||||
## API documentation
|
||||
To read the engine API documentation, visit [jd.engine.staropensource.de](https://jd.engine.staropensource.de).
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
"typecheck": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "3.5.2",
|
||||
"@docusaurus/plugin-client-redirects": "^3.5.2",
|
||||
"@docusaurus/plugin-content-docs": "^3.5.2",
|
||||
"@docusaurus/plugin-sitemap": "^3.5.2",
|
||||
"@docusaurus/preset-classic": "3.5.2",
|
||||
"@docusaurus/core": "3.6.1",
|
||||
"@docusaurus/plugin-client-redirects": "^3.6.1",
|
||||
"@docusaurus/plugin-content-docs": "^3.6.1",
|
||||
"@docusaurus/plugin-sitemap": "^3.6.1",
|
||||
"@docusaurus/preset-classic": "3.6.1",
|
||||
"@mdx-js/react": "^3.0.1",
|
||||
"clsx": "^2.1.0",
|
||||
"prism-react-renderer": "^2.3.1",
|
||||
|
@ -27,9 +27,9 @@
|
|||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@docusaurus/module-type-aliases": "3.5.2",
|
||||
"@docusaurus/tsconfig": "3.5.2",
|
||||
"@docusaurus/types": "3.5.2",
|
||||
"@docusaurus/module-type-aliases": "3.6.1",
|
||||
"@docusaurus/tsconfig": "3.6.1",
|
||||
"@docusaurus/types": "3.6.1",
|
||||
"@types/node": "^20.12.5",
|
||||
"typescript": "~5.4.4"
|
||||
},
|
||||
|
|
|
@ -21,28 +21,28 @@
|
|||
versioningCodename=Sugarcookie
|
||||
versioningVersion=1
|
||||
versioningType=alpha
|
||||
versioningTyperelease=6
|
||||
versioningTyperelease=9
|
||||
versioningFork=
|
||||
|
||||
# Java
|
||||
javaSource=22
|
||||
javaSource=21
|
||||
javaTarget=21
|
||||
|
||||
# Plugins
|
||||
pluginShadow=8.1.7
|
||||
pluginLombok=8.6
|
||||
pluginShadow=8.1.8
|
||||
pluginLombok=8.10.2
|
||||
pluginGitProperties=2.4.2
|
||||
pluginNativeImage=v1.4.0
|
||||
pluginNativeImage=v1.4.1
|
||||
|
||||
# Dependencies
|
||||
dependencyLombok=1.18.32
|
||||
dependencyJetbrainsAnnotations=24.1.0
|
||||
dependencyLombok=1.18.34
|
||||
dependencyJetbrainsAnnotations=26.0.1
|
||||
dependencyJansi=2.4.1
|
||||
dependencyReflections=0.10.2
|
||||
dependencySlf4j=2.0.13
|
||||
dependencyLwjgl=3.3.3
|
||||
dependencySlf4j=2.0.16
|
||||
dependencyLwjgl=3.3.4
|
||||
dependencyLwjglNatives=
|
||||
dependencyJunit=5.11.0-M2
|
||||
dependencyJunit=5.11.3
|
||||
|
||||
# etc
|
||||
group = de.staropensource.engine
|
||||
|
|
|
@ -22,6 +22,7 @@ package de.staropensource.engine.notification;
|
|||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
||||
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.engine.base.utility.information.EngineInformation;
|
||||
import lombok.Getter;
|
||||
|
@ -58,7 +59,7 @@ public final class NotificationSubsystem 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} */
|
||||
|
|
|
@ -61,16 +61,17 @@ dependencies {
|
|||
// LWJGL
|
||||
implementation(platform("org.lwjgl:lwjgl-bom:${dependencyLwjgl}"))
|
||||
implementation("org.lwjgl:lwjgl")
|
||||
implementation("org.lwjgl:lwjgl-glfw")
|
||||
implementation("org.lwjgl:lwjgl-stb")
|
||||
implementation("org.lwjgl:lwjgl-glfw")
|
||||
implementation("org.lwjgl:lwjgl-bgfx")
|
||||
runtimeOnly("org.lwjgl:lwjgl::${dependencyLwjglNatives}")
|
||||
runtimeOnly("org.lwjgl:lwjgl-glfw::${dependencyLwjglNatives}")
|
||||
runtimeOnly("org.lwjgl:lwjgl-stb::${dependencyLwjglNatives}")
|
||||
runtimeOnly("org.lwjgl:lwjgl-glfw::${dependencyLwjglNatives}")
|
||||
runtimeOnly("org.lwjgl:lwjgl-bgfx::${dependencyLwjglNatives}")
|
||||
if (project.dependencyLwjglNatives == "natives-macos" || project.dependencyLwjglNatives == "natives-macos-arm64") runtimeOnly("org.lwjgl:lwjgl-vulkan::${dependencyLwjglNatives}")
|
||||
|
||||
// Project
|
||||
implementation(project(":base"))
|
||||
implementation(project(":windowing"))
|
||||
}
|
||||
|
||||
// Javadoc configuration
|
||||
|
@ -96,26 +97,6 @@ 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()
|
0
windowing/gradlew → rendering/gradlew
vendored
0
windowing/gradlew → rendering/gradlew
vendored
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
* 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.rendering;
|
||||
|
||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
||||
import de.staropensource.engine.base.annotation.EventListener;
|
||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
||||
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.utility.Math;
|
||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
||||
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
||||
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
|
||||
import de.staropensource.engine.base.type.DependencyVector;
|
||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
||||
import de.staropensource.engine.rendering.event.InputEvent;
|
||||
import de.staropensource.engine.rendering.event.RenderingErrorEvent;
|
||||
import de.staropensource.engine.rendering.exception.NotOnMainThreadException;
|
||||
import de.staropensource.engine.rendering.type.Window;
|
||||
import de.staropensource.engine.rendering.type.window.VsyncMode;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
/**
|
||||
* Main class of the {@code rendering} subsystem.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@EngineSubsystem
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class RenderingSubsystem extends SubsystemClass {
|
||||
/**
|
||||
* Contains the class instance.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the class instance.
|
||||
*
|
||||
* @return class instance unless the subsystem is uninitialized
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static RenderingSubsystem instance = null;
|
||||
|
||||
/**
|
||||
* The {@link GLFWErrorCallback} to use.
|
||||
* <p>
|
||||
* Only declared publicly for freeing during engine shutdown.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private GLFWErrorCallback errorCallback = null;
|
||||
|
||||
// -----> Subsystem
|
||||
/**
|
||||
* Initializes this subsystem.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public RenderingSubsystem() {
|
||||
// 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");
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return "rendering";
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @NotNull DependencyVector getDependencyVector() {
|
||||
return new DependencyVector.Builder()
|
||||
.setIdentifier(getName())
|
||||
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
|
||||
.setVersion(EngineInformation.getVersioningString())
|
||||
.build();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void initializeSubsystem() {
|
||||
if (!Miscellaneous.onMainThread())
|
||||
Logger.crash("Unable to initialize the rendering subsystem whilst running on a non-main thread", new NotOnMainThreadException());
|
||||
|
||||
// Initialize WindowingSubsystemConfiguration and load it
|
||||
new RenderingSubsystemConfiguration().loadConfiguration();
|
||||
|
||||
// Precompute event listeners
|
||||
cacheEvents();
|
||||
initGlfw();
|
||||
|
||||
// Warn about subsystem and API instability
|
||||
Logger.warn("The rendering subsystem is experimental. Subsystem and API stability are not guaranteed.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches all windowing subsystem events.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private void cacheEvents() {
|
||||
EventHelper.cacheEvent(RenderingErrorEvent.class);
|
||||
EventHelper.cacheEvent(InputEvent.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes GLFW.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private void initGlfw() {
|
||||
try {
|
||||
Logger.verb("Initializing GLFW");
|
||||
|
||||
// Set error callback
|
||||
Logger.diag("Setting error callback");
|
||||
errorCallback = GLFWErrorCallback.create((error, description) -> new RenderingErrorEvent().callEvent("GLFW: " + GLFWErrorCallback.getDescription(description) + " [" + error + "]")).set();
|
||||
|
||||
// Set init hints
|
||||
Logger.diag("Setting initialization hints");
|
||||
switch (RenderingSubsystemConfiguration.getInstance().getInitialPlatform()) {
|
||||
case ANY -> glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
|
||||
case WAYLAND -> tryPlatform(GLFW_PLATFORM_WAYLAND);
|
||||
case X11 -> tryPlatform(GLFW_PLATFORM_X11);
|
||||
case WIN32 -> tryPlatform(GLFW_PLATFORM_WIN32);
|
||||
case COCOA -> tryPlatform(GLFW_PLATFORM_COCOA);
|
||||
case NONE -> glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
|
||||
}
|
||||
glfwInitHint(GLFW_WAYLAND_LIBDECOR, RenderingSubsystemConfiguration.getInstance().isInitialDisableLibdecor() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
|
||||
|
||||
// Initialize GLFW
|
||||
Logger.diag("Invoking glfwInit");
|
||||
if (!glfwInit())
|
||||
Logger.crash("Failed to initialize GLFW");
|
||||
} catch (UnsatisfiedLinkError error) {
|
||||
Logger.crash("Failed to load LWJGL native libraries", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts the subsystem down.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@EventListener(event = InternalEngineShutdownEvent.class)
|
||||
@SuppressWarnings({ "unused" })
|
||||
protected static void shutdownSubsystem() {
|
||||
if (instance == null)
|
||||
return;
|
||||
|
||||
Logger.verb("Shutting down");
|
||||
|
||||
long shutdownTime = Miscellaneous.measureExecutionTime(() -> {
|
||||
// Close all windows
|
||||
for (Window window : Window.getWindows())
|
||||
window.close();
|
||||
|
||||
instance.errorCallback.free();
|
||||
glfwTerminate();
|
||||
});
|
||||
|
||||
Logger.info("Shut down in " + shutdownTime + "ms");
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs about rendering errors.
|
||||
*
|
||||
* @see RenderingSubsystemConfiguration#errorRenderingFailures
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@EventListener(event = RenderingErrorEvent.class, priority = EventPriority.EXCLUSIVELY_IMPORTANT)
|
||||
private static void logRenderingError(@NotNull String error) {
|
||||
Logger.error("Rendering error occurred: " + error);
|
||||
}
|
||||
|
||||
// -----> APIs
|
||||
/**
|
||||
* Renders all windows once.
|
||||
* To render all windows continuously, invoke
|
||||
* {@link #runRenderLoop(Runnable)} instead.
|
||||
*
|
||||
* @return map of windows and their {@link Throwable}s
|
||||
* @throws NotOnMainThreadException if not running on the main thread
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public LinkedHashMap<@NotNull Window, @NotNull Throwable> renderWindows() throws NotOnMainThreadException {
|
||||
// Ensure running on the main thread
|
||||
if (!Miscellaneous.onMainThread())
|
||||
throw new NotOnMainThreadException();
|
||||
|
||||
LinkedHashMap<@NotNull Window, @NotNull Throwable> throwables = new LinkedHashMap<>();
|
||||
|
||||
// Update and render all windows
|
||||
for (Window window : Window.getWindows()) {
|
||||
if (!window.isRendering())
|
||||
continue;
|
||||
|
||||
try {
|
||||
window.updateState();
|
||||
window.render();
|
||||
} catch (Throwable throwable) {
|
||||
Logger.error("Rendering window " + window + " failed: Threw throwable " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
||||
throwables.put(window, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
// Poll for events
|
||||
glfwPollEvents();
|
||||
|
||||
return throwables;
|
||||
}
|
||||
/**
|
||||
* Renders all windows continuously.
|
||||
* To render all windows just once, invoke
|
||||
* {@link #renderWindows()} instead.
|
||||
* <p>
|
||||
* Immediately returns when a {@link #renderWindows()} call fails.
|
||||
*
|
||||
* @param frameCode code which shall be invoked before a frame is rendered
|
||||
* @return see {@link #renderWindows()} (on failure)
|
||||
* @throws NotOnMainThreadException if not running on the main thread
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public LinkedHashMap<@NotNull Window, @NotNull Throwable> runRenderLoop(@NotNull Runnable frameCode) throws NotOnMainThreadException {
|
||||
// Ensure running on the main thread
|
||||
if (!Miscellaneous.onMainThread())
|
||||
throw new NotOnMainThreadException();
|
||||
|
||||
// Define variables
|
||||
AtomicReference<LinkedHashMap<@NotNull Window, @NotNull Throwable>> output = new AtomicReference<>(new LinkedHashMap<>()); // runRenderLoop output
|
||||
long renderTime; // Amount of time spent rendering
|
||||
long sleepDuration; // Time spent sleeping the thread
|
||||
LinkedList<Long> splitDeltaTime = new LinkedList<>(); // Used for calculating the delta time (render time average over one second)
|
||||
long reportDuration = System.currentTimeMillis() + 1000; // Used for determining when to report frame count and delta time
|
||||
double deltaTime; // Contains the average render time over one second (delta time)
|
||||
|
||||
// Check if delta time and frame count shall be printed to console.
|
||||
// Unless this code is ran 292 billion years into the future,
|
||||
// this should sufficiently disable the reporting feature.
|
||||
if (!RenderingSubsystemConfiguration.getInstance().isDebugFrames())
|
||||
reportDuration = Long.MAX_VALUE;
|
||||
|
||||
// Run while the 'output' is empty
|
||||
while (output.get().isEmpty()) {
|
||||
renderTime = Miscellaneous.measureExecutionTime(() -> {
|
||||
output.set(renderWindows());
|
||||
frameCode.run();
|
||||
});
|
||||
|
||||
if (RenderingSubsystemConfiguration.getInstance().getVsyncMode() != VsyncMode.OFF)
|
||||
// V-Sync is enabled, no need for manual busy waiting
|
||||
sleepDuration = 0L;
|
||||
else
|
||||
// Calculate amount of time the thread should spend sleeping
|
||||
sleepDuration = (long) (1d / RenderingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() * 1000d) - renderTime;
|
||||
// Add render and sleep time to list used for calculating the delta time value
|
||||
splitDeltaTime.add(renderTime + sleepDuration);
|
||||
|
||||
// Busy wait unless V-Sync is enabled
|
||||
if (RenderingSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.OFF && RenderingSubsystemConfiguration.getInstance().getMaximumFramesPerSecond() >= 1) {
|
||||
sleepDuration += System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() < sleepDuration)
|
||||
Thread.onSpinWait();
|
||||
}
|
||||
|
||||
// Calculate delta time and frame count every second
|
||||
if (System.currentTimeMillis() >= reportDuration) {
|
||||
deltaTime = Math.getMeanLong(splitDeltaTime); // Calculate delta time
|
||||
Logger.diag("Delta time average: " + deltaTime + " | Frames/s: " + 1000 / deltaTime); // Print delta time and frame count to console
|
||||
|
||||
reportDuration = System.currentTimeMillis() + 1000; // Update 'reportDuration'
|
||||
splitDeltaTime.clear(); // Clear 'splitDeltaTime' list
|
||||
}
|
||||
}
|
||||
|
||||
return output.get();
|
||||
}
|
||||
|
||||
// -----> Utility methods
|
||||
/**
|
||||
* Checks if the specified platform is compatible,
|
||||
* and if so, specifies it as the platform to use.
|
||||
*
|
||||
* @param platform platform to try
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private void tryPlatform(int platform) {
|
||||
if (glfwPlatformSupported(platform))
|
||||
glfwInitHint(GLFW_PLATFORM, platform);
|
||||
else
|
||||
glfwInitHint(GLFW_PLATFORM, GLFW_ANY_PLATFORM);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
* 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.rendering;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Configuration;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
||||
import de.staropensource.engine.rendering.event.RenderingErrorEvent;
|
||||
import de.staropensource.engine.rendering.type.window.RenderingPlatform;
|
||||
import de.staropensource.engine.rendering.type.window.VsyncMode;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Provides the configuration for the rendering subsystem.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class RenderingSubsystemConfiguration extends Configuration {
|
||||
/**
|
||||
* Contains the class instance.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the class instance.
|
||||
*
|
||||
* @return class instance unless {@link RenderingSubsystem} is uninitialized
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private static RenderingSubsystemConfiguration instance;
|
||||
|
||||
/**
|
||||
* Contains the configuration prefix.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the configuration prefix.
|
||||
*
|
||||
* @return property group
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
public final @NotNull String group = "sosengine.rendering.";
|
||||
|
||||
/**
|
||||
* Contains if debugging options should be allowed.
|
||||
* All debugging options will be forcefully set to
|
||||
* {@code false} if this option is set to {@code false}.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns if debugging options should be allowed.
|
||||
* All debugging options will be forcefully set to
|
||||
* {@code false} if this option is set to {@code false}.
|
||||
*
|
||||
* @return debugging enabled?
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private boolean debug;
|
||||
|
||||
/**
|
||||
* Contains whether or not key presses
|
||||
* and releases should be logged.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns whether or not key presses
|
||||
* and releases should be logged.
|
||||
*
|
||||
* @return log key presses and releases?
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private boolean debugInput;
|
||||
|
||||
/**
|
||||
* Contains whether or not the delta time and
|
||||
* FPS count should be logged to the console
|
||||
* every second.
|
||||
* <p>
|
||||
* Changes will no longer be picked up as
|
||||
* soon as the rendering loop is running.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns whether or not the delta time and
|
||||
* FPS count should be logged to the console
|
||||
* every second.
|
||||
* <p>
|
||||
* Changes will no longer be picked up as
|
||||
* soon as the rendering loop is running.
|
||||
*
|
||||
* @return print delta time and FPS count?
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private boolean debugFrames;
|
||||
|
||||
|
||||
/**
|
||||
* Contains the platform GLFW shall try initialising.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the platform GLFW shall try initialising.
|
||||
*
|
||||
* @return GLFW platform
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private RenderingPlatform initialPlatform;
|
||||
|
||||
/**
|
||||
* Contains whether or not to disable support for
|
||||
* <a href="https://gitlab.freedesktop.org/libdecor/libdecor">libdecor</a>.
|
||||
* <p>
|
||||
* Only affects the {@link RenderingPlatform#WAYLAND} platform.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns whether or not to disable support for
|
||||
* <a href="https://gitlab.freedesktop.org/libdecor/libdecor">libdecor</a>.
|
||||
* <p>
|
||||
* Only affects the {@link RenderingPlatform#WAYLAND} platform.
|
||||
*
|
||||
* @return libdecor support disabled?
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private boolean initialDisableLibdecor;
|
||||
|
||||
|
||||
/**
|
||||
* Contains whether or not rendering
|
||||
* errors should be logged.
|
||||
* <p>
|
||||
* The {@link RenderingErrorEvent} will
|
||||
* be emitted anyway, regardless of the
|
||||
* value of this variable.
|
||||
*
|
||||
* @see RenderingErrorEvent
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns whether or not rendering
|
||||
* errors should be logged.
|
||||
* <p>
|
||||
* The {@link RenderingErrorEvent} will
|
||||
* be emitted anyway, regardless of the
|
||||
* value of this variable.
|
||||
*
|
||||
* @return log rendering failures?
|
||||
* @see RenderingErrorEvent
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private boolean errorRenderingFailures;
|
||||
|
||||
|
||||
/**
|
||||
* Contains which {@link VsyncMode} to use.
|
||||
* <p>
|
||||
* This setting determines if and how V-Sync
|
||||
* will operate, which (if enabled) tries to
|
||||
* synchronize the frame rate to the monitor's
|
||||
* refresh rate. See {@link VsyncMode}
|
||||
* for more information.
|
||||
*
|
||||
* @see VsyncMode
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns which {@link VsyncMode} to use.
|
||||
* <p>
|
||||
* This setting determines if and how V-Sync
|
||||
* will operate, which (if enabled) tries to
|
||||
* synchronize the frame rate to the monitor's
|
||||
* refresh rate. See {@link VsyncMode}
|
||||
* for more information.
|
||||
*
|
||||
* @return active V-Sync mode
|
||||
* @see VsyncMode
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private VsyncMode vsyncMode;
|
||||
|
||||
/**
|
||||
* Contains the maximum value of frames
|
||||
* which can be rendered per second.
|
||||
* <p>
|
||||
* This value will have no effect on
|
||||
* windows with V-Sync enabled.
|
||||
* Set to {@code 0} for effectively
|
||||
* no limit. Not recommended.
|
||||
*
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the maximum value of frames
|
||||
* which can be rendered per second.
|
||||
* <p>
|
||||
* This value will have no effect on
|
||||
* windows with V-Sync enabled.
|
||||
* Set to {@code 0} for effectively
|
||||
* no limit. Not recommended.
|
||||
*
|
||||
* @return maximum amount of frames per second
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private int maximumFramesPerSecond;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @see RenderingSubsystem
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
RenderingSubsystemConfiguration() {
|
||||
instance = this;
|
||||
|
||||
loadDefaultConfiguration();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
||||
switch (property) {
|
||||
case "debug" -> debug = parser.getBoolean(group + property);
|
||||
case "debugInput" -> debugInput = parser.getBoolean(group + property);
|
||||
case "debugFrames" -> debugFrames = parser.getBoolean(group + property);
|
||||
|
||||
case "initialPlatform" -> {
|
||||
try {
|
||||
initialPlatform = RenderingPlatform.valueOf(parser.getString(group + property).toUpperCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
Logger.error("Platform " + parser.getString(group + property) + " is not valid");
|
||||
}
|
||||
}
|
||||
case "initialDisableLibdecor" -> initialDisableLibdecor = parser.getBoolean(group + property);
|
||||
|
||||
case "errorRenderingFailures" -> errorRenderingFailures = parser.getBoolean(group + property);
|
||||
|
||||
case "vsyncMode" -> {
|
||||
try {
|
||||
vsyncMode = VsyncMode.valueOf(parser.getString(group + property).toUpperCase());
|
||||
} catch (IllegalArgumentException exception) {
|
||||
Logger.error("V-Sync mode " + parser.getString(group + property) + " is not valid");
|
||||
}
|
||||
}
|
||||
case "maximumFramesPerSecond" -> maximumFramesPerSecond = parser.getInteger(group + property, true);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void processSettings(@NotNull PropertiesReader parser) {
|
||||
// Disable all debug options if 'debug' is disabled
|
||||
if (!debug) {
|
||||
debugInput = false;
|
||||
debugFrames = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void loadDefaultConfiguration() {
|
||||
debug = false;
|
||||
debugInput = false;
|
||||
debugFrames = false;
|
||||
|
||||
initialPlatform = RenderingPlatform.ANY;
|
||||
initialDisableLibdecor = false;
|
||||
|
||||
errorRenderingFailures = true;
|
||||
|
||||
vsyncMode = VsyncMode.ON;
|
||||
maximumFramesPerSecond = 60;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public @Nullable Object getSetting(@NotNull String setting) {
|
||||
switch (setting) {
|
||||
case "debug" -> { return debug; }
|
||||
case "debugInput" -> { return debugInput; }
|
||||
case "debugFrames" -> { return debugFrames; }
|
||||
|
||||
case "initialPlatform" -> { return initialPlatform; }
|
||||
case "disableLibdecor" -> { return initialDisableLibdecor; }
|
||||
|
||||
case "errorRenderingFailures" -> { return errorRenderingFailures; }
|
||||
|
||||
case "vsyncMode" -> { return vsyncMode; }
|
||||
case "maximumFramesPerSecond" -> { return maximumFramesPerSecond; }
|
||||
default -> { return null; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,13 +17,13 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.glfw.callback;
|
||||
package de.staropensource.engine.rendering.callback;
|
||||
|
||||
import de.staropensource.engine.windowing.implementable.Window;
|
||||
import de.staropensource.engine.windowing.event.InputEvent;
|
||||
import de.staropensource.engine.windowing.glfw.implementable.WindowCallback;
|
||||
import de.staropensource.engine.windowing.type.input.Key;
|
||||
import de.staropensource.engine.windowing.type.input.KeyState;
|
||||
import de.staropensource.engine.rendering.type.Window;
|
||||
import de.staropensource.engine.rendering.event.InputEvent;
|
||||
import de.staropensource.engine.rendering.callback.WindowCallback;
|
||||
import de.staropensource.engine.rendering.type.input.Key;
|
||||
import de.staropensource.engine.rendering.type.input.KeyState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||
|
||||
|
@ -32,7 +32,7 @@ import static org.lwjgl.glfw.GLFW.*;
|
|||
/**
|
||||
* A {@link GLFWKeyCallbackI} implementation, which emits {@link InputEvent}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class KeyCallback extends WindowCallback implements GLFWKeyCallbackI {
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ public final class KeyCallback extends WindowCallback implements GLFWKeyCallback
|
|||
* and making too many allocations, which would potentially decrease
|
||||
* performance.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private static final InputEvent event = new InputEvent();
|
||||
|
||||
|
@ -48,7 +48,7 @@ public final class KeyCallback extends WindowCallback implements GLFWKeyCallback
|
|||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param window {@link Window} class
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public KeyCallback(@NotNull Window window) {
|
||||
super(window);
|
|
@ -17,13 +17,12 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.glfw.callback;
|
||||
package de.staropensource.engine.rendering.callback;
|
||||
|
||||
import de.staropensource.engine.windowing.implementable.Window;
|
||||
import de.staropensource.engine.windowing.event.InputEvent;
|
||||
import de.staropensource.engine.windowing.glfw.implementable.WindowCallback;
|
||||
import de.staropensource.engine.windowing.type.input.Key;
|
||||
import de.staropensource.engine.windowing.type.input.KeyState;
|
||||
import de.staropensource.engine.rendering.type.Window;
|
||||
import de.staropensource.engine.rendering.event.InputEvent;
|
||||
import de.staropensource.engine.rendering.type.input.Key;
|
||||
import de.staropensource.engine.rendering.type.input.KeyState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
|
||||
|
||||
|
@ -32,7 +31,7 @@ import static org.lwjgl.glfw.GLFW.*;
|
|||
/**
|
||||
* A {@link GLFWMouseButtonCallbackI} implementation, which forward them to {@link InputEvent}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class MouseButtonCallback extends WindowCallback implements GLFWMouseButtonCallbackI {
|
||||
/**
|
||||
|
@ -40,7 +39,7 @@ public final class MouseButtonCallback extends WindowCallback implements GLFWMou
|
|||
* and making too many allocations, which would potentially decrease
|
||||
* performance.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private static final InputEvent event = new InputEvent();
|
||||
|
||||
|
@ -48,7 +47,7 @@ public final class MouseButtonCallback extends WindowCallback implements GLFWMou
|
|||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @param window {@link Window} class
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public MouseButtonCallback(@NotNull Window window) {
|
||||
super(window);
|
||||
|
@ -72,7 +71,7 @@ public final class MouseButtonCallback extends WindowCallback implements GLFWMou
|
|||
case GLFW_MOUSE_BUTTON_RIGHT -> Key.MOUSE_RIGHT;
|
||||
case GLFW_MOUSE_BUTTON_4, GLFW_MOUSE_BUTTON_5,
|
||||
GLFW_MOUSE_BUTTON_6, GLFW_MOUSE_BUTTON_7,
|
||||
GLFW_MOUSE_BUTTON_8 -> Key.UNKNOWN_MOUSE;
|
||||
GLFW_MOUSE_BUTTON_8 -> Key.UNKNOWN_MOUSE_BUTTON;
|
||||
default -> throw new IllegalStateException("Mouse button " + key + " is invalid");
|
||||
},
|
||||
// Key state
|
|
@ -17,9 +17,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.glfw.implementable;
|
||||
package de.staropensource.engine.rendering.callback;
|
||||
|
||||
import de.staropensource.engine.windowing.implementable.Window;
|
||||
import de.staropensource.engine.rendering.type.Window;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
* Abstract class used for easily implementing
|
||||
* callbacks which require a {@link Window} instance.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
|
@ -36,21 +36,21 @@ public class WindowCallback {
|
|||
* Refers to the {@link Window} instance
|
||||
* this callback is tied to.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the {@link Window} instance
|
||||
* this callback is tied to.
|
||||
*
|
||||
* @return attached {@link Window} instance
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
private final @NotNull Window attachedWindow;
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @param window {@link Window} class
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public WindowCallback(@NotNull Window window) {
|
||||
this.attachedWindow = window;
|
|
@ -20,6 +20,6 @@
|
|||
/**
|
||||
* Callbacks, which emit {@link de.staropensource.engine.base.implementable.Event}s.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
package de.staropensource.engine.windowing.glfw.callback;
|
||||
package de.staropensource.engine.rendering.callback;
|
|
@ -17,35 +17,28 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.event;
|
||||
package de.staropensource.engine.rendering.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.windowing.WindowingSubsystemConfiguration;
|
||||
import de.staropensource.engine.windowing.implementable.Window;
|
||||
import de.staropensource.engine.windowing.type.input.Key;
|
||||
import de.staropensource.engine.windowing.type.input.KeyState;
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.rendering.RenderingSubsystemConfiguration;
|
||||
import de.staropensource.engine.rendering.type.Window;
|
||||
import de.staropensource.engine.rendering.type.input.Key;
|
||||
import de.staropensource.engine.rendering.type.input.KeyState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Called when a key or button is pressed.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class InputEvent implements Event {
|
||||
/**
|
||||
* Logger instance for this class.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private final LoggerInstance logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").build();
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public InputEvent() {}
|
||||
|
||||
|
@ -64,11 +57,11 @@ public final class InputEvent implements Event {
|
|||
* @param window window the input originated from. May be {@code null}, depending on the windowing API
|
||||
* @param key key
|
||||
* @param state key state
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public void callEvent(@Nullable Window window, @NotNull Key key, @NotNull KeyState state) {
|
||||
if (WindowingSubsystemConfiguration.getInstance().isDebugInput())
|
||||
logger.diag("Got input event: window=" + (window == null ? "\\<null>" : window.getUniqueIdentifier()) + " key=" + key.name() + " state=" + state.name());
|
||||
if (RenderingSubsystemConfiguration.getInstance().isDebugInput())
|
||||
Logger.diag("Got input event: window=" + (window == null ? "\\<null>" : window.getUniqueIdentifier()) + " key=" + key.name() + " state=" + state.name());
|
||||
|
||||
EventHelper.invokeAnnotatedMethods(getClass(), window, key, state);
|
||||
}
|
|
@ -17,29 +17,30 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.event;
|
||||
package de.staropensource.engine.rendering.event;
|
||||
|
||||
import de.staropensource.engine.base.implementable.Event;
|
||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when an error occurs in the renderer API (e.g. OpenGL, Vulkan).
|
||||
* Emitted when a rendering error occurs.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class RenderingErrorEvent implements Event {
|
||||
/**
|
||||
* Creates and initializes an instance of this event.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public RenderingErrorEvent() {}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @deprecated use the {@code callEvent} method with arguments
|
||||
* @see #callEvent(String)
|
||||
* @see #callEvent(String)
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
|
@ -49,7 +50,7 @@ public final class RenderingErrorEvent implements Event {
|
|||
* Emits the event and calls all event listeners.
|
||||
*
|
||||
* @param error error description
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public void callEvent(@NotNull String error) {
|
||||
EventHelper.invokeAnnotatedMethods(getClass(), error);
|
|
@ -20,6 +20,6 @@
|
|||
/**
|
||||
* Events. There's nothing more to say.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
package de.staropensource.engine.windowing.event;
|
||||
package de.staropensource.engine.rendering.event;
|
|
@ -17,18 +17,18 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.exception;
|
||||
package de.staropensource.engine.rendering.exception;
|
||||
|
||||
/**
|
||||
* Thrown when the specified monitor does not exist.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class InvalidMonitorException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public InvalidMonitorException() {}
|
||||
}
|
|
@ -17,18 +17,18 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.exception;
|
||||
package de.staropensource.engine.rendering.exception;
|
||||
|
||||
/**
|
||||
* Thrown when trying to access one or more monitors but none are found.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class NoMonitorsFoundException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public NoMonitorsFoundException() {}
|
||||
}
|
|
@ -17,18 +17,18 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.exception;
|
||||
package de.staropensource.engine.rendering.exception;
|
||||
|
||||
/**
|
||||
* Thrown when trying to communicate with a windowing API over a non-main thread.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class NotOnMainThreadException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public NotOnMainThreadException() {}
|
||||
}
|
|
@ -17,21 +17,21 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.exception;
|
||||
package de.staropensource.engine.rendering.exception;
|
||||
|
||||
import de.staropensource.engine.windowing.implementable.Window;
|
||||
import de.staropensource.engine.rendering.type.Window;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Thrown when a {@link Window} cannot be created.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public final class WindowCreationFailureException extends RuntimeException {
|
||||
/**
|
||||
* Creates and initializes an instance of this exception.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public WindowCreationFailureException() {}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public final class WindowCreationFailureException extends RuntimeException {
|
|||
* Creates and initializes an instance of this exception.
|
||||
*
|
||||
* @param message error message
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public WindowCreationFailureException(@NotNull String message) {
|
||||
super(message);
|
|
@ -23,6 +23,6 @@
|
|||
* These aren't meant for the windowing subsystem,
|
||||
* but instead for windowing APIs, which may throw them.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
package de.staropensource.engine.windowing.exception;
|
||||
package de.staropensource.engine.rendering.exception;
|
|
@ -20,6 +20,6 @@
|
|||
/**
|
||||
* Code of the windowing subsystem.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
package de.staropensource.engine.windowing;
|
||||
package de.staropensource.engine.rendering;
|
|
@ -17,112 +17,107 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.implementable;
|
||||
package de.staropensource.engine.rendering.type;
|
||||
|
||||
import de.staropensource.engine.base.logging.LoggerInstance;
|
||||
import de.staropensource.engine.base.type.vector.Vec2i;
|
||||
import de.staropensource.engine.windowing.WindowingSubsystem;
|
||||
import de.staropensource.engine.windowing.exception.InvalidMonitorException;
|
||||
import de.staropensource.engine.windowing.exception.NoMonitorsFoundException;
|
||||
import lombok.AccessLevel;
|
||||
import de.staropensource.engine.rendering.exception.InvalidMonitorException;
|
||||
import de.staropensource.engine.rendering.exception.NoMonitorsFoundException;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
/**
|
||||
* Abstract class for implementing monitors in a windowing API.
|
||||
* <p>
|
||||
* Note that monitors stop working unannounced when disconnected,
|
||||
* call {@link #isConnected()} before using to avoid unexpected behaviour.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public abstract class Monitor {
|
||||
/**
|
||||
* Contains the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Returns the {@link LoggerInstance} for this instance.
|
||||
*
|
||||
* @return logger instance
|
||||
* @see LoggerInstance
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@Getter(value = AccessLevel.PROTECTED)
|
||||
private final @NotNull LoggerInstance logger;
|
||||
|
||||
public final class Monitor {
|
||||
/**
|
||||
* Contains the unique identifier.
|
||||
* <p>
|
||||
* This identifier is unique to every monitor and does not change during runtime.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the unique identifier.
|
||||
* <p>
|
||||
* This identifier is unique to every monitor and does not change during runtime.
|
||||
*
|
||||
* @return unique identifier
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Getter
|
||||
private final UUID uniqueIdentifier;
|
||||
private final UUID uniqueIdentifier = UUID.randomUUID();
|
||||
|
||||
/**
|
||||
* Contains the monitor identifier.
|
||||
* <p>
|
||||
* This identifier is used by the windowing API to refer to a monitor and may change during runtime.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* @since v1-alpha9
|
||||
* -- GETTER --
|
||||
* Returns the monitor identifier.
|
||||
* <p>
|
||||
* This identifier is used by the windowing API to refer to a monitor and may change during runtime.
|
||||
*
|
||||
* @return monitor identifier
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
* -- SETTER --
|
||||
* Sets the monitor identifier.
|
||||
* <p>
|
||||
* This identifier is used by the windowing API to refer to a monitor and may change during runtime.
|
||||
*
|
||||
* @param identifier new monitor identifier
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@Setter(AccessLevel.PROTECTED)
|
||||
private String identifier = null;
|
||||
private final long identifier;
|
||||
|
||||
/**
|
||||
* Initializes this abstract class.
|
||||
* Creates and initializes an instance of this abstract class.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @throws InvalidMonitorException if the monitor isn't connected
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public Monitor() {
|
||||
this.uniqueIdentifier = UUID.randomUUID();
|
||||
logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("ENGINE").setMetadata(uniqueIdentifier.toString()).build();
|
||||
public Monitor(long identifier) throws InvalidMonitorException {
|
||||
this.identifier = identifier;
|
||||
|
||||
checkConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all connected monitors.
|
||||
* Returns a set of all connected monitors.
|
||||
*
|
||||
* @return connected monitors
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public static @NotNull LinkedHashSet<@NotNull Monitor> getMonitors() throws NoMonitorsFoundException {
|
||||
return WindowingSubsystem.getInstance().getApi().getInternalApi().getMonitors();
|
||||
PointerBuffer monitors = glfwGetMonitors();
|
||||
LinkedHashSet<@NotNull Monitor> output = new LinkedHashSet<>();
|
||||
if (monitors == null)
|
||||
throw new NoMonitorsFoundException();
|
||||
|
||||
while (monitors.hasRemaining())
|
||||
output.add(new Monitor(monitors.get()));
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the monitor is actually connected.
|
||||
* Checks if this monitor is actually connected.
|
||||
* If not, throws an {@link InvalidMonitorException}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public void checkConnected() throws InvalidMonitorException, NoMonitorsFoundException {
|
||||
if (!isConnected())
|
||||
|
@ -130,34 +125,48 @@ public abstract class Monitor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if the monitor is connected or not.
|
||||
* Checks if this monitor is connected.
|
||||
*
|
||||
* @return connection status
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public abstract boolean isConnected() throws NoMonitorsFoundException;
|
||||
public boolean isConnected() throws NoMonitorsFoundException {
|
||||
return glfwGetMonitorName(identifier) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the monitor name.
|
||||
* Returns the name of this monitor.
|
||||
*
|
||||
* @return monitor name
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public abstract @NotNull String getName() throws InvalidMonitorException, NoMonitorsFoundException;
|
||||
public @NotNull String getName() throws InvalidMonitorException, NoMonitorsFoundException {
|
||||
checkConnected();
|
||||
return Objects.requireNonNull(glfwGetMonitorName(identifier));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the monitor size.
|
||||
* Returns size of this monitor.
|
||||
*
|
||||
* @return monitor size
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public abstract @NotNull Vec2i getSize() throws InvalidMonitorException, NoMonitorsFoundException;
|
||||
public @NotNull Vec2i getSize() throws InvalidMonitorException, NoMonitorsFoundException {
|
||||
checkConnected();
|
||||
|
||||
GLFWVidMode videoMode = Objects.requireNonNull(glfwGetVideoMode(identifier));
|
||||
|
||||
return new Vec2i(videoMode.width(), videoMode.height());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the monitor refresh rate.
|
||||
* Returns refresh rate of this monitor in hertz.
|
||||
*
|
||||
* @return monitor refresh rate
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public abstract short getRefreshRate() throws InvalidMonitorException, NoMonitorsFoundException;
|
||||
public short getRefreshRate() throws InvalidMonitorException, NoMonitorsFoundException {
|
||||
checkConnected();
|
||||
return (short) Objects.requireNonNull(glfwGetVideoMode(identifier)).refreshRate();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -17,590 +17,590 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.type.input;
|
||||
package de.staropensource.engine.rendering.type.input;
|
||||
|
||||
/**
|
||||
* Contains a list of keys which can be recognized by the engine.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
public enum Key {
|
||||
/**
|
||||
* An unknown key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
UNKNOWN_KEY,
|
||||
/**
|
||||
* An unknown mouse button.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
UNKNOWN_MOUSE,
|
||||
UNKNOWN_MOUSE_BUTTON,
|
||||
|
||||
/**
|
||||
* The left mouse button.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
MOUSE_LEFT,
|
||||
/**
|
||||
* The middle mouse button.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
MOUSE_MIDDLE,
|
||||
/**
|
||||
* The right mouse button.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
MOUSE_RIGHT,
|
||||
|
||||
/**
|
||||
* The {@code ALT} modifier key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ALT,
|
||||
/**
|
||||
* The {@code '} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
APOSTROPHE,
|
||||
/**
|
||||
* The {@code DOWN} arrow key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ARROW_DOWN,
|
||||
/**
|
||||
* The {@code LEFT} arrow key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ARROW_LEFT,
|
||||
/**
|
||||
* The {@code RIGHT} arrow key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ARROW_RIGHT,
|
||||
/**
|
||||
* The {@code UP} arrow key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ARROW_UP,
|
||||
/**
|
||||
* The {@code \} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
BACKSLASH,
|
||||
/**
|
||||
* The {@code BACKSPACE} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
BACKSPACE,
|
||||
/**
|
||||
* The left {@code [} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
BRACKET_LEFT,
|
||||
/**
|
||||
* The right {@code ]} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
BRACKET_RIGHT,
|
||||
/**
|
||||
* THE {@code CAPSLOCK} KEY.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
CAPS_LOCK,
|
||||
/**
|
||||
* The {@code ,} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
COMMA,
|
||||
/**
|
||||
* The left {@code CTRL} modifier key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
CONTROL_LEFT,
|
||||
/**
|
||||
* The right {@code CTRL} modifier key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
CONTROL_RIGHT,
|
||||
/**
|
||||
* The {@code DEL} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
DELETE,
|
||||
/**
|
||||
* The {@code END} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
END,
|
||||
/**
|
||||
* The {@code ENTER} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ENTER,
|
||||
/**
|
||||
* The {@code =} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
EQUAL,
|
||||
/**
|
||||
* The {@code ESC} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
ESCAPE,
|
||||
/**
|
||||
* The {@code F1} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_1,
|
||||
/**
|
||||
* The {@code F2} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_2,
|
||||
/**
|
||||
* The {@code F3} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_3,
|
||||
/**
|
||||
* The {@code F4} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_4,
|
||||
/**
|
||||
* The {@code F5} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_5,
|
||||
/**
|
||||
* The {@code F6} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_6,
|
||||
/**
|
||||
* The {@code F7} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_7,
|
||||
/**
|
||||
* The {@code F8} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_8,
|
||||
/**
|
||||
* The {@code F9} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_9,
|
||||
/**
|
||||
* The {@code F10} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_10,
|
||||
/**
|
||||
* The {@code F11} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_11,
|
||||
/**
|
||||
* The {@code F12} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_12,
|
||||
/**
|
||||
* The {@code F13} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_13,
|
||||
/**
|
||||
* The {@code F14} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_14,
|
||||
/**
|
||||
* The {@code F15} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_15,
|
||||
/**
|
||||
* The {@code F16} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_16,
|
||||
/**
|
||||
* The {@code F17} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_17,
|
||||
/**
|
||||
* The {@code F18} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_18,
|
||||
/**
|
||||
* The {@code F19} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_19,
|
||||
/**
|
||||
* The {@code F20} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_20,
|
||||
/**
|
||||
* The {@code F21} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_21,
|
||||
/**
|
||||
* The {@code F22} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_22,
|
||||
/**
|
||||
* The {@code F23} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_23,
|
||||
/**
|
||||
* The {@code F24} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_24,
|
||||
/**
|
||||
* The {@code F25} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
FUNCTION_25,
|
||||
/**
|
||||
* The {@code `} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
GRAVE,
|
||||
/**
|
||||
* The {@code HOME} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
HOME,
|
||||
/**
|
||||
* THe {@code INS} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
INSERT,
|
||||
/**
|
||||
* The {@code +} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_ADD,
|
||||
/**
|
||||
* The {@code -} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_DECIMAL,
|
||||
/**
|
||||
* The {@code /} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_DIVIDE,
|
||||
/**
|
||||
* The {@code ENTER} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_ENTER,
|
||||
/**
|
||||
* The {@code =} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_EQUAL,
|
||||
/**
|
||||
* The {@code *} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_MULTIPLY,
|
||||
/**
|
||||
* The number {@code 0} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_0,
|
||||
/**
|
||||
* The number {@code 1} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_1,
|
||||
/**
|
||||
* The number {@code 2} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_2,
|
||||
/**
|
||||
* The number {@code 3} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_3,
|
||||
/**
|
||||
* The number {@code 4} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_4,
|
||||
/**
|
||||
* The number {@code 5} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_5,
|
||||
/**
|
||||
* The number {@code 6} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_6,
|
||||
/**
|
||||
* The number {@code 7} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_7,
|
||||
/**
|
||||
* The number {@code 8} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_8,
|
||||
/**
|
||||
* The number {@code 9} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_NUMBER_9,
|
||||
/**
|
||||
* The {@code -} key on your keypad.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
KEYPAD_SUBTRACT,
|
||||
/**
|
||||
* The letter {@code A} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_A,
|
||||
/**
|
||||
* The letter {@code B} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_B,
|
||||
/**
|
||||
* The letter {@code C} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_C,
|
||||
/**
|
||||
* The letter {@code D} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_D,
|
||||
/**
|
||||
* The letter {@code E} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_E,
|
||||
/**
|
||||
* The letter {@code F} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_F,
|
||||
/**
|
||||
* The letter {@code G} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_G,
|
||||
/**
|
||||
* The letter {@code H} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_H,
|
||||
/**
|
||||
* The letter {@code I} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_I,
|
||||
/**
|
||||
* The letter {@code J} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_J,
|
||||
/**
|
||||
* The letter {@code K} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_K,
|
||||
/**
|
||||
* The letter {@code L} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_L,
|
||||
/**
|
||||
* The letter {@code M} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_M,
|
||||
/**
|
||||
* The letter {@code N} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_N,
|
||||
/**
|
||||
* The letter {@code O} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_O,
|
||||
/**
|
||||
* The letter {@code P} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_P,
|
||||
/**
|
||||
* The letter {@code Q} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_Q,
|
||||
/**
|
||||
* The letter {@code R} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_R,
|
||||
/**
|
||||
* The letter {@code S} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_S,
|
||||
/**
|
||||
* The letter {@code T} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_T,
|
||||
/**
|
||||
* The letter {@code U} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_U,
|
||||
/**
|
||||
* The letter {@code V} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_V,
|
||||
/**
|
||||
* The letter {@code W} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_W,
|
||||
/**
|
||||
* The letter {@code X} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_X,
|
||||
/**
|
||||
* The letter {@code Y} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_Y,
|
||||
/**
|
||||
* The letter {@code Z} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
LETTER_Z,
|
||||
/**
|
||||
* The {@code MENU} key, which brings up the right click menu.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
MENU,
|
||||
/**
|
||||
|
@ -608,151 +608,151 @@ public enum Key {
|
|||
* <p>
|
||||
* Windows users will recognize this key as the Windows key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
META,
|
||||
/**
|
||||
* The {@code -} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
MINUS,
|
||||
/**
|
||||
* The number {@code 0}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_0,
|
||||
/**
|
||||
* The number {@code 1}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_1,
|
||||
/**
|
||||
* The number {@code 2}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_2,
|
||||
/**
|
||||
* The number {@code 3}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_3,
|
||||
/**
|
||||
* The number {@code 4}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_4,
|
||||
/**
|
||||
* The number {@code 5}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_5,
|
||||
/**
|
||||
* The number {@code 6}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_6,
|
||||
/**
|
||||
* The number {@code 7}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_7,
|
||||
/**
|
||||
* The number {@code 8}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_8,
|
||||
/**
|
||||
* The number {@code 9}.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUMBER_9,
|
||||
/**
|
||||
* The {@code NUM} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
NUM_LOCK,
|
||||
/**
|
||||
* The {@code PAGE DOWN} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
PAGE_DOWN,
|
||||
/**
|
||||
* The {@code PAGE UP} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
PAGE_UP,
|
||||
/**
|
||||
* The {@code PAUSE} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
PAUSE,
|
||||
/**
|
||||
* The {@code .} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
PERIOD,
|
||||
/**
|
||||
* The {@code PRINT} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
PRINT,
|
||||
/**
|
||||
* The {@code SCROLL} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
SCROLL_LOCK,
|
||||
/**
|
||||
* The {@code ;} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
SEMICOLON,
|
||||
/**
|
||||
* The left {@code SHIFT} modifier key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
SHIFT_LEFT,
|
||||
/**
|
||||
* The right {@code SHIFT} modifier key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
SHIFT_RIGHT,
|
||||
/**
|
||||
* The {@code /} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
SLASH,
|
||||
/**
|
||||
* The {@code ENTER} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
SPACE,
|
||||
/**
|
||||
* The {@code TAB} key.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
TAB,
|
||||
}
|
|
@ -17,26 +17,26 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.staropensource.engine.windowing.type.input;
|
||||
package de.staropensource.engine.rendering.type.input;
|
||||
|
||||
/**
|
||||
* Contains in which state a key is.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
@SuppressWarnings({ "unused" })
|
||||
public enum KeyState {
|
||||
/**
|
||||
* Indicates that a key is pressed.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
PRESSED,
|
||||
|
||||
/**
|
||||
* Indicates that a key is released.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* @since v1-alpha9
|
||||
*/
|
||||
RELEASED,
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue