Move ANSI-related stuff into 'ansi' module

This commit is contained in:
JeremyStar™ 2024-07-29 21:34:10 +02:00
parent 2d61b027b3
commit 9dc0f549d4
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
17 changed files with 340 additions and 52 deletions

135
ansi/build.gradle Normal file
View file

@ -0,0 +1,135 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Contributors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* 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/>.
*/
import java.nio.file.Files
// Plugins
plugins {
id("java")
id("io.freefair.lombok") version("${pluginLombok}")
id("maven-publish")
}
// Project dependencies
dependencies {
// -> Runtime <-
// Lombok
compileOnly("org.projectlombok:lombok:${dependencyLombok}")
annotationProcessor("org.projectlombok:lombok:${dependencyLombok}")
// JetBrains Annotations
compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
// ANSI support
implementation("org.fusesource.jansi:jansi:${dependencyJansi}")
// Project
implementation(project(":base"))
// -> Testing <-
// Jetbrains Annotations
testCompileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
// JUnit
testImplementation(platform("org.junit:junit-bom:${dependencyJunit}"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
// Fix delombok task
delombok.doFirst {
File target = file("${project.projectDir}/src/main/module-info.java")
File source = file("${project.projectDir}/src/main/java/module-info.java")
target.delete()
source.renameTo(target)
}
delombok.doLast {
File target = file("${project.projectDir}/src/main/java/module-info.java")
File source = file("${project.projectDir}/src/main/module-info.java")
target.delete()
source.renameTo(target)
}
// Javadoc configuration
javadoc {
outputs.upToDateWhen { false } // Force task execution
dependsOn(delombok) // Make sure the source is delomboked first
javadoc {
setClasspath(files(project.sourceSets.main.compileClasspath)) // Include dependencies
options {
if (new File(projectDir, "src/main/javadoc/theme.css").exists())
stylesheetFile = new File(projectDir, "src/main/javadoc/theme.css") // Theming is cool :3
setMemberLevel(JavadocMemberLevel.PUBLIC) // Only display public stuff
setOverview("src/main/javadoc/overview.html") // We want a custom overview page to greet the visitor
setLocale("en_US") //
setJFlags([
"-Duser.language=en_US" // See above
])
}
}
}
// Unit testing configuration
test {
useJUnitPlatform()
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()
withSourcesJar()
}
// Build publishing configuration
// Note: You can safely ignore any errors or warnings thrown by your IDE here
publishing {
repositories {
maven {
name = "staropensource"
url = uri("https://mvn.staropensource.de/sosengine")
credentials(org.gradle.api.credentials.PasswordCredentials)
authentication {
//noinspection GroovyAssignabilityCheck
basic (BasicAuthentication)
}
}
}
publications {
//noinspection GroovyAssignabilityCheck
maven (MavenPublication) {
groupId = group
artifactId = "ansi"
version = version
//noinspection GroovyAssignabilityCheck
from components.java
}
}
}

1
ansi/gradle Symbolic link
View file

@ -0,0 +1 @@
../gradle

1
ansi/gradlew vendored Symbolic link
View file

@ -0,0 +1 @@
../gradlew

1
ansi/gradlew.bat vendored Symbolic link
View file

@ -0,0 +1 @@
../gradlew.bat

View file

@ -17,14 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.sosengine.base.logging.implementation;
package de.staropensource.sosengine.ansi;
import de.staropensource.sosengine.base.EngineConfiguration;
import de.staropensource.sosengine.base.classes.LoggerImpl;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.logging.LogIssuer;
import de.staropensource.sosengine.base.types.logging.LogLevel;
import de.staropensource.sosengine.base.utility.converter.AnsiShortcodeConverter;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
import org.jetbrains.annotations.NotNull;
@ -37,13 +36,13 @@ import org.jetbrains.annotations.NotNull;
* @since v1-alpha0
*/
@SuppressWarnings({ "unused" })
public class ColoredLoggerImpl implements LoggerImpl {
public class AnsiLoggerImpl implements LoggerImpl {
/**
* Constructs this class.
*
* @since v1-alpha0
*/
public ColoredLoggerImpl() {}
public AnsiLoggerImpl() {}
/** {@inheritDoc} */
@NotNull

View file

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.sosengine.base.utility.converter;
package de.staropensource.sosengine.ansi;
import de.staropensource.sosengine.base.classes.ShortcodeParserSkeleton;
import de.staropensource.sosengine.base.exceptions.ParserException;

View file

@ -0,0 +1,90 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Contributors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.staropensource.sosengine.ansi;
import de.staropensource.sosengine.base.annotations.EngineSubsystem;
import de.staropensource.sosengine.base.classes.SubsystemMainClass;
import de.staropensource.sosengine.base.data.info.EngineInformation;
import de.staropensource.sosengine.base.data.versioning.StarOpenSourceVersioningSystem;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.types.DependencyVector;
import de.staropensource.sosengine.base.types.logging.LogIssuer;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
/**
* Main object for the ANSI Compatibility subsystem.
*
* @since v1-alpha0
*/
@SuppressWarnings({ "unused", "JavadocDeclaration", "JavadocBlankLines" })
@EngineSubsystem
public final class AnsiSubsystem implements SubsystemMainClass {
/**
* Contains the class instance.
*
* @since v1-alpha0
*
* -- GETTER --
* Returns the class instance.
*
* @return class instance unless the subsystem is uninitialized
* @since v1-alpha0
*/
@Getter
private static AnsiSubsystem instance = null;
/** {@inheritDoc} */
private final LoggerInstance logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE));
/**
* Constructs this subsystem.
*/
public AnsiSubsystem() {
// Check if subsystem has already initialized
if (instance == null)
instance = this;
else {
instance.logger.crash("The subsystem tried to initialize twice");
}
}
/** {@inheritDoc} */
@NotNull
@Override
public String getName() {
return "ansi";
}
/** {@inheritDoc} */
@Override
public void initializeSubsystem() {
Logger.setLoggerImplementation(new AnsiLoggerImpl());
}
/** {@inheritDoc} */
@NotNull
@Override
public DependencyVector getDependencyVector() {
return new DependencyVector("ansi", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
}
}

View file

@ -0,0 +1,23 @@
/*
* STAROPENSOURCE ENGINE SOURCE FILE
* Copyright (c) 2024 The StarOpenSource Engine Contributors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* 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/>.
*/
/**
* Contains the ANSI subsystem code.
*/
package de.staropensource.sosengine.ansi;

View file

@ -0,0 +1,27 @@
/**
* Defines the ANSI subsystem, allowing the engine to
* use ANSI escape codes using the Jansi library.
*
* @since v1-alpha2
*/
module sosengine.ansi {
// Dependencies
// -> Java <-
requires transitive java.management;
// -> Engine <-
requires transitive sosengine.base;
// -> Common stuff <-
requires transitive static lombok;
requires transitive org.jetbrains.annotations;
// -> Subystem-specific dependencies <-
requires org.fusesource.jansi;
// API access
exports de.staropensource.sosengine.ansi;
// Reflection access
opens de.staropensource.sosengine.ansi;
}

View file

@ -36,9 +36,6 @@ dependencies {
// JetBrains Annotations
compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
// ANSI support
implementation("org.fusesource.jansi:jansi:${dependencyJansi}")
// Reflections
implementation("org.reflections:reflections:${dependencyReflections}")

View file

@ -19,14 +19,15 @@
package de.staropensource.sosengine.base;
import de.staropensource.sosengine.base.classes.ShortcodeParserSkeleton;
import de.staropensource.sosengine.base.classes.SubsystemConfiguration;
import de.staropensource.sosengine.base.classes.helpers.EventHelper;
import de.staropensource.sosengine.base.logging.CrashHandler;
import de.staropensource.sosengine.base.logging.Logger;
import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.types.logging.LogIssuer;
import de.staropensource.sosengine.base.types.logging.LogLevel;
import de.staropensource.sosengine.base.types.vectors.Vec2;
import de.staropensource.sosengine.base.utility.converter.AnsiShortcodeConverter;
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
@ -91,7 +92,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #debug}.
*
* @return variable value
* @see EngineConfiguration#debug
* @see #debug
* @since v1-alpha0
*/
private boolean debug;
@ -99,47 +100,47 @@ public final class EngineConfiguration implements SubsystemConfiguration {
/**
* If enabled, all called events will be logged.
*
* @see de.staropensource.sosengine.base.classes.helpers.EventHelper#logCall(Class, Object...)
* @see EventHelper#logCall(Class, Object...)
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@link #debugEvents}.
*
* @return variable value
* @see EngineConfiguration#debugEvents
* @see #debugEvents
* @since v1-alpha0
*/
private boolean debugEvents;
/**
* If enabled, very verbose messages about the {@link AnsiShortcodeConverter}'s internals will be printed.<br/>
* If enabled, very verbose messages about the {@link ShortcodeParserSkeleton}'s internals will be printed.
* Don't enable unless you want to work on it.
*
* @see AnsiShortcodeConverter
* @see ShortcodeParserSkeleton
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@link #debugShortcodeConverter}.
*
* @return variable value
* @see EngineConfiguration#debugShortcodeConverter
* @see #debugShortcodeConverter
* @since v1-alpha0
*/
private boolean debugShortcodeConverter;
/**
* If enabled, invalid shortcodes will be logged by the {@link AnsiShortcodeConverter}.
* The message will be printed as a silent warning.
* If enabled, invalid shortcodes will be logged by the {@link ShortcodeParserSkeleton}.
* The message will be printed as a {@link LogLevel#SILENT_WARNING}.
*
* @see AnsiShortcodeConverter
* @see EngineConfiguration#loggerLevel
* @see ShortcodeParserSkeleton
* @see #loggerLevel
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@link #errorShortcodeConverter}.
*
* @return variable value
* @see EngineConfiguration#errorShortcodeConverter
* @see #errorShortcodeConverter
* @since v1-alpha0
*/
private boolean errorShortcodeConverter;
@ -148,7 +149,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* If enabled, will makes the {@link Logger} work asynchronous, in a separate platform thread.
* Don't disable unless you want your application to run <b>extremely</b> slowly.
*
* @see EngineConfiguration#loggerPollingSpeed
* @see #loggerPollingSpeed
* @see Thread
* @since v1-alpha0
*
@ -156,7 +157,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #optimizeLogging}.
*
* @return variable value
* @see EngineConfiguration#optimizeLogging
* @see #optimizeLogging
* @since v1-alpha0
*/
private boolean optimizeLogging;
@ -172,7 +173,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #optimizeEvents}.
*
* @return variable value
* @see EngineConfiguration#optimizeEvents
* @see #optimizeEvents
* @since v1-alpha0
*/
private boolean optimizeEvents;
@ -192,7 +193,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #optimizeSubsystemInitialization}.
*
* @return variable value
* @see EngineConfiguration#optimizeSubsystemInitialization
* @see #optimizeSubsystemInitialization
* @since v1-alpha2
*/
private boolean optimizeSubsystemInitialization;
@ -207,7 +208,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #loggerLevel}.
*
* @return variable value
* @see EngineConfiguration#loggerLevel
* @see #loggerLevel
* @since v1-alpha0
*/
private LogLevel loggerLevel;
@ -222,7 +223,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #loggerTemplate}
*
* @return variable value
* @see EngineConfiguration#loggerTemplate
* @see #loggerTemplate
* @since v1-alpha0
*/
private String loggerTemplate;
@ -238,7 +239,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #loggerImmediateShutdown}.
*
* @return variable value
* @see EngineConfiguration#loggerImmediateShutdown
* @see #loggerImmediateShutdown
* @since v1-alpha0
*/
private boolean loggerImmediateShutdown;
@ -253,7 +254,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #loggerForceStandardOutput}.
*
* @return variable value
* @see EngineConfiguration#loggerForceStandardOutput
* @see #loggerForceStandardOutput
* @since v1-alpha0
*/
private boolean loggerForceStandardOutput;
@ -262,14 +263,14 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Determines how fast the logging thread will poll for queued messages.
* Only applies if {@code optimizeLogging} is turned on.
*
* @see EngineConfiguration#optimizeLogging
* @see #optimizeLogging
* @since v1-alpha1
*
* -- GETTER --
* Gets the value for {@link #loggerForceStandardOutput}.
*
* @return variable value
* @see EngineConfiguration#loggerForceStandardOutput
* @see #loggerForceStandardOutput
* @since v1-alpha1
*/
private int loggerPollingSpeed;
@ -288,7 +289,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* Gets the value for {@link #hideFullTypePath}.
*
* @return variable value
* @see EngineConfiguration#hideFullTypePath
* @see #hideFullTypePath
* @since v1-alpha2
*/
private boolean hideFullTypePath;

View file

@ -27,7 +27,7 @@ import de.staropensource.sosengine.base.classes.helpers.EventHelper;
import de.staropensource.sosengine.base.events.LogEvent;
import de.staropensource.sosengine.base.internal.placeholders.logger.*;
import de.staropensource.sosengine.base.internal.types.QueuedLogMessage;
import de.staropensource.sosengine.base.logging.implementation.ColoredLoggerImpl;
import de.staropensource.sosengine.base.logging.implementation.PlainLoggerImpl;
import de.staropensource.sosengine.base.types.logging.LogIssuer;
import de.staropensource.sosengine.base.types.logging.LogLevel;
import de.staropensource.sosengine.base.types.logging.LogRule;
@ -75,7 +75,7 @@ public final class Logger {
@NotNull
@Getter
@Setter
private static LoggerImpl loggerImplementation = new ColoredLoggerImpl();
private static LoggerImpl loggerImplementation = new PlainLoggerImpl();
/**
* Refers to the logging thread.

View file

@ -8,7 +8,6 @@ module sosengine.base {
requires transitive java.management;
requires transitive static lombok;
requires transitive org.jetbrains.annotations;
requires org.fusesource.jansi;
requires org.reflections;
// API access

View file

@ -26,13 +26,9 @@ plugins {
// Register task for Javadoc generation for all subsystems
tasks.register("javadocAll", Javadoc) {
// Subprojects to document
def subprojects = [
":base",
":graphics",
":graphics:opengl",
":graphics:vulkan",
":slf4j-compat",
// Subprojects to exclude
def nodoc = [
":testapp",
]
// Task metadata
@ -40,8 +36,23 @@ tasks.register("javadocAll", Javadoc) {
setGroup("documentation")
// Make sure the source is delomboked first
for (String subproject : subprojects)
dependsOn(project(subproject).delombok)
boolean match
for (Project subproject : getSubprojects()) {
match = false
// Check if name is in 'nodoc' list
for (String name : nodoc)
if (subproject.getName() == name)
match = true
if (match)
continue
// Add dependsOn if delombok task is found
try {
dependsOn(subproject.getTasks().named("delombok"))
} catch(UnknownTaskException ignored) {}
}
// Set output directory, source and classpath
setSource(subprojects.collect({ project(it).projectDir.getPath() + "/build/generated/sources/delombok/java/main/" }))
@ -62,7 +73,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 have issues.")
logger.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")

View file

@ -32,6 +32,7 @@ Subsystems on the other hand usually handle complex tasks. They provide abstract
## Available official subsystems
Besides the `base` engine, there is one stable subsystem, two experimental subsystems and one stub subsystem.
### 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.
### Experimental
- [`graphics`](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/graphics): Provides interfaces and classes meant to be extended by Graphics APIs.

View file

@ -17,12 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
rootProject.name = "sosengine"
rootProject.setName("sosengine")
include "base"
include "slf4j-compat"
include "graphics"
include "graphics:glfw"
include "graphics:opengl"
include "graphics:vulkan"
include "testapp"
include("base")
include("ansi")
include("slf4j-compat")
include("graphics")
include("graphics:glfw")
include("graphics:opengl")
include("graphics:vulkan")
include("testapp")

View file

@ -40,6 +40,7 @@ dependencies {
// -> Project <-
implementation(project(":base"))
implementation(project(":ansi"))
implementation(project(":slf4j-compat"))
implementation(project(":graphics"))
implementation(project(":graphics:vulkan"))