forked from StarOpenSource/Engine
Make even more null safe
This commit is contained in:
parent
d0d98744b0
commit
09dec9c023
15 changed files with 47 additions and 26 deletions
|
@ -123,42 +123,43 @@ public final class Engine implements SubsystemMainClass {
|
|||
@SuppressWarnings("ExtractMethodRecommender")
|
||||
private void populateCrashContent() {
|
||||
// Issuer
|
||||
Map<String, String> crashContentIssuer = new LinkedHashMap<>();
|
||||
Map<@NotNull String, @NotNull String> crashContentIssuer = new LinkedHashMap<>();
|
||||
crashContentIssuer.put("Code part", "%issuer_code_part%");
|
||||
crashContentIssuer.put("Classpath", "%issuer_path%");
|
||||
crashContentIssuer.put("Additional information", "%issuer_info%");
|
||||
crashContentIssuer.put("Message", "%issuer_message%");
|
||||
|
||||
// Engine -> Dependencies
|
||||
Map<String, String> crashContentEngineDependencies = new LinkedHashMap<>();
|
||||
Map<@NotNull String, @NotNull String> crashContentEngineDependencies = new LinkedHashMap<>();
|
||||
crashContentEngineDependencies.put("Lombok", "%engine_dependency_lombok%");
|
||||
crashContentEngineDependencies.put("Jetbrains Annotations", "%engine_dependency_jetbrains_annotations%");
|
||||
crashContentEngineDependencies.put("Jansi", "%engine_dependency_jansi%");
|
||||
crashContentEngineDependencies.put("Reflections", "%engine_dependencies_reflections%");
|
||||
crashContentEngineDependencies.put("SLF4J", "%engine_dependencies_slf4j%");
|
||||
crashContentEngineDependencies.put("LWJGL", "%engine_dependencies_lwjgl%");
|
||||
// Engine -> Plugins
|
||||
Map<String, String> crashContentEnginePlugins = new LinkedHashMap<>();
|
||||
Map<@NotNull String, @NotNull String> crashContentEnginePlugins = new LinkedHashMap<>();
|
||||
crashContentEnginePlugins.put("Shadow", "%engine_plugin_shadow%");
|
||||
crashContentEnginePlugins.put("Lombok", "%engine_plugin_lombok%");
|
||||
// Engine -> *
|
||||
Map<String, Object> crashContentEngine = new LinkedHashMap<>();
|
||||
Map<@NotNull String, @NotNull Object> crashContentEngine = new LinkedHashMap<>();
|
||||
crashContentEngine.put("Version", "%engine_version%");
|
||||
crashContentEngine.put("Dependencies", crashContentEngineDependencies);
|
||||
crashContentEngine.put("Plugins", crashContentEnginePlugins);
|
||||
|
||||
// JVM -> Implementation
|
||||
Map<String, String> crashContentJvmImplementation = new LinkedHashMap<>();
|
||||
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<String, Object> crashContentJvm = new LinkedHashMap<>();
|
||||
Map<@NotNull String, @NotNull Object> crashContentJvm = new LinkedHashMap<>();
|
||||
crashContentJvm.put("Java Version", "%jvm_java%");
|
||||
crashContentJvm.put("Implementation", crashContentJvmImplementation);
|
||||
crashContentJvm.put("Arguments", "%jvm_arguments%");
|
||||
|
||||
// Operating system
|
||||
Map<String, String> crashContentOS = new LinkedHashMap<>();
|
||||
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%");
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
|
|||
* @return property group
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
private static final String group = "sosengine.base.";
|
||||
|
||||
|
@ -215,7 +216,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void loadConfiguration(Properties properties) {
|
||||
public void loadConfiguration(@NotNull Properties properties) {
|
||||
// Define variables
|
||||
PropertyParser parser = new PropertyParser(properties);
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public interface LoggerImpl {
|
|||
* @return new log message
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
String prePlaceholder(@NotNull LogLevel level, @NotNull LogIssuer logIssuer, @NotNull String message);
|
||||
|
||||
/**
|
||||
|
@ -51,6 +52,7 @@ public interface LoggerImpl {
|
|||
* @return new log message
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
String postPlaceholder(@NotNull LogLevel level, @NotNull LogIssuer logIssuer, @NotNull String message);
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.Properties;
|
|||
*
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" })
|
||||
@SuppressWarnings({ "unused" })
|
||||
public interface SubsystemConfiguration {
|
||||
/**
|
||||
* Instance.
|
||||
|
@ -42,6 +42,7 @@ public interface SubsystemConfiguration {
|
|||
*
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
String group = "sosengine.";
|
||||
|
||||
/**
|
||||
|
@ -52,7 +53,7 @@ public interface SubsystemConfiguration {
|
|||
* @see SubsystemConfiguration#loadDefaultConfiguration()
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
void loadConfiguration(Properties properties);
|
||||
void loadConfiguration(@NotNull Properties properties);
|
||||
|
||||
/**
|
||||
* Loads the subsystem configuration from the system properties.
|
||||
|
|
|
@ -27,6 +27,7 @@ import de.staropensource.sosengine.base.types.LogIssuer;
|
|||
import de.staropensource.sosengine.base.utility.ListFormatter;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
|
@ -55,7 +56,7 @@ public class EventHelper {
|
|||
* @param clazz event class
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public static void logCall(Class<? extends Event> clazz, Object ... arguments) {
|
||||
public static void logCall(@NotNull Class<? extends Event> clazz, @NotNull Object ... arguments) {
|
||||
if (EngineConfiguration.getInstance().isDebugEvents())
|
||||
if (arguments.length == 0)
|
||||
Logger.diag(new LogIssuer(clazz), "Event " + clazz.getName() + " called");
|
||||
|
@ -71,7 +72,7 @@ public class EventHelper {
|
|||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public static LinkedList<Method> getAnnotatedMethods(Class<? extends Event> clazz) {
|
||||
public static LinkedList<Method> getAnnotatedMethods(@NotNull Class<? extends Event> clazz) {
|
||||
LinkedList<Method> methods = new LinkedList<>();
|
||||
|
||||
Reflections reflections = new Reflections(
|
||||
|
@ -79,7 +80,7 @@ public class EventHelper {
|
|||
.setUrls(ClasspathHelper.forJavaClassPath())
|
||||
.setScanners(Scanners.MethodsAnnotated)
|
||||
);
|
||||
Set<Method> annotatedMethods = reflections.getMethodsAnnotatedWith(EventListener.class);
|
||||
Set<@NotNull Method> annotatedMethods = reflections.getMethodsAnnotatedWith(EventListener.class);
|
||||
|
||||
for (Method method : annotatedMethods)
|
||||
if (method.getAnnotation(EventListener.class).event() == clazz)
|
||||
|
@ -97,7 +98,7 @@ public class EventHelper {
|
|||
* @param clazz event class
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public static void invokeAnnotatedMethods(Class<? extends Event> clazz) {
|
||||
public static void invokeAnnotatedMethods(@NotNull Class<? extends Event> clazz) {
|
||||
logCall(clazz);
|
||||
|
||||
for (Method method : getAnnotatedMethods(clazz)) {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package de.staropensource.sosengine.base.data.info;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -59,6 +61,7 @@ public final class JvmInformation {
|
|||
* @return the JVM implementation name
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public static String getImplementationName() {
|
||||
return ManagementFactory.getRuntimeMXBean().getVmName();
|
||||
}
|
||||
|
@ -69,6 +72,7 @@ public final class JvmInformation {
|
|||
* @return the JVM implementation version
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public static String getImplementationVersion() {
|
||||
return ManagementFactory.getRuntimeMXBean().getVmVersion();
|
||||
}
|
||||
|
@ -79,6 +83,7 @@ public final class JvmInformation {
|
|||
* @return the JVM implementation vendor
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public static String getImplementationVendor() {
|
||||
return ManagementFactory.getRuntimeMXBean().getVmVendor();
|
||||
}
|
||||
|
@ -99,7 +104,8 @@ public final class JvmInformation {
|
|||
* @return the JVM arguments
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public static List<String> getArguments() {
|
||||
@NotNull
|
||||
public static List<@NotNull String> getArguments() {
|
||||
return ManagementFactory.getRuntimeMXBean().getInputArguments();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ public final class CrashHandler {
|
|||
* @param crashTemplate new crash template
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
@Setter
|
||||
private static String crashTemplate = """
|
||||
|
@ -94,8 +95,9 @@ public final class CrashHandler {
|
|||
* @return crash content
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
private static final LinkedHashMap<Object, Object> crashContent = new LinkedHashMap<>();
|
||||
private static final LinkedHashMap<@NotNull Object, @NotNull Object> crashContent = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -123,7 +125,7 @@ public final class CrashHandler {
|
|||
base = Logger.getLoggerImplementation().prePlaceholder(LogLevel.CRASH, logIssuer, base);
|
||||
|
||||
// Create list of temporary placeholders
|
||||
List<Placeholder> temporaryPlaceholders = new ArrayList<>();
|
||||
List<@NotNull Placeholder> temporaryPlaceholders = new ArrayList<>();
|
||||
temporaryPlaceholders.add(new IssuerMessage(message)); // log_message is out of order to allow for placeholder usage
|
||||
|
||||
// issuer_*
|
||||
|
|
|
@ -45,6 +45,7 @@ public class DefaultLoggerImpl implements LoggerImpl {
|
|||
public DefaultLoggerImpl() {}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@NotNull
|
||||
@Override
|
||||
public String prePlaceholder(@NotNull LogLevel level, @NotNull LogIssuer logIssuer, @NotNull String message) {
|
||||
// No modifications necessary
|
||||
|
@ -52,6 +53,7 @@ public class DefaultLoggerImpl implements LoggerImpl {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@NotNull
|
||||
@Override
|
||||
public String postPlaceholder(@NotNull LogLevel level, @NotNull LogIssuer logIssuer, @NotNull String message) {
|
||||
// No modifications necessary
|
||||
|
|
|
@ -101,7 +101,7 @@ public final class Logger {
|
|||
base = loggerImplementation.prePlaceholder(level, logIssuer, base);
|
||||
|
||||
// Create list of temporary placeholders
|
||||
List<Placeholder> temporaryPlaceholders = new ArrayList<>();
|
||||
List<@NotNull Placeholder> temporaryPlaceholders = new ArrayList<>();
|
||||
temporaryPlaceholders.add(new LogMessage(message)); // log_message is out of order to allow for placeholder usage
|
||||
|
||||
temporaryPlaceholders.add(new LogColorPrimary(level));
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package de.staropensource.sosengine.base.utility;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
|
@ -75,7 +76,7 @@ public final class Miscellaneous {
|
|||
* @see Runnable
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public static long measureExecutionTime(Runnable runnable) {
|
||||
public static long measureExecutionTime(@NotNull Runnable runnable) {
|
||||
long initTime = System.currentTimeMillis();
|
||||
runnable.run();
|
||||
return System.currentTimeMillis() - initTime;
|
||||
|
@ -88,7 +89,7 @@ public final class Miscellaneous {
|
|||
* @param value value to search for
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
public static Set<?> getMapValue(Map<?, ?> map, Object value) {
|
||||
public static Set<?> getMapValue(@NotNull Map<?, ?> map, @Nullable Object value) {
|
||||
return map.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), value)).map(Map.Entry::getKey).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public final class PlaceholderEngine {
|
|||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@Getter
|
||||
@NotNull
|
||||
private List<Placeholder> placeholders = new ArrayList<>();
|
||||
private List<@NotNull Placeholder> placeholders = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -127,7 +127,7 @@ public final class PlaceholderEngine {
|
|||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public String process(@NotNull String text, List<Placeholder> temporaryPlaceholders) {
|
||||
public String process(@NotNull String text, List<@NotNull Placeholder> temporaryPlaceholders) {
|
||||
// Process temporary placeholders
|
||||
for (Placeholder temporaryPlaceholder : temporaryPlaceholders)
|
||||
if (text.contains("%" + temporaryPlaceholder.getName() + "%"))
|
||||
|
|
|
@ -63,6 +63,7 @@ public class StackTraceParser {
|
|||
* @return the stack trace header
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public String getHeader() {
|
||||
if (throwable.getMessage() == null)
|
||||
return "Caused by: " + throwable.getClass().getName();
|
||||
|
@ -76,6 +77,7 @@ public class StackTraceParser {
|
|||
* @return the stack trace
|
||||
* @since 1-alpha0
|
||||
*/
|
||||
@NotNull
|
||||
public String getStackTrace() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.staropensource.sosengine.base.srctests;
|
|||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.types.LogLevel;
|
||||
import de.staropensource.sosengine.unittests.UnitLogger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joor.Reflect;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
|
@ -49,8 +50,8 @@ class EngineConfigurationTest {
|
|||
void testLoadConfiguration() {
|
||||
logger.testCall("testLoadConfiguration");
|
||||
|
||||
Map<String, Object[]> settings = new HashMap<>();
|
||||
Map<String, Object> defaultValues = new HashMap<>();
|
||||
Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>();
|
||||
Map<@NotNull String, @NotNull Object> defaultValues = new HashMap<>();
|
||||
|
||||
settings.put("debug", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("debugShortcodeConverter", new Object[]{ "true", Boolean.TRUE });
|
||||
|
|
|
@ -37,7 +37,7 @@ class PlaceholderEngineTest {
|
|||
void testProcess(String text, String expected) {
|
||||
logger.testCall("testProcess", text, expected);
|
||||
|
||||
List<Placeholder> placeholders = new ArrayList<>();
|
||||
List<@NotNull Placeholder> placeholders = new ArrayList<>();
|
||||
placeholders.add(new Placeholder() {
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package de.staropensource.sosengine.slf4j_compat;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
@ -30,7 +31,7 @@ import java.util.concurrent.ConcurrentMap;
|
|||
*/
|
||||
@SuppressWarnings({ "unused", "JavadocBlankLines" })
|
||||
public class CompatibilityLoggerFactory implements ILoggerFactory {
|
||||
ConcurrentMap<String, Logger> loggerMap;
|
||||
ConcurrentMap<@NotNull String, @NotNull Logger> loggerMap;
|
||||
|
||||
public CompatibilityLoggerFactory() {
|
||||
loggerMap = new ConcurrentHashMap<>();
|
||||
|
|
Loading…
Reference in a new issue