Compare commits
No commits in common. "develop" and "v1-alpha0" have entirely different histories.
400 changed files with 7466 additions and 43814 deletions
|
@ -1,117 +0,0 @@
|
||||||
name: "⚠️ Bug report"
|
|
||||||
about: "Report a bug in the engine."
|
|
||||||
title: "bug: "
|
|
||||||
labels:
|
|
||||||
- "Bug/New"
|
|
||||||
body:
|
|
||||||
- type: "markdown"
|
|
||||||
id: "text-introduction"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Hey there! Thank you for taking the time to report a bug to us. \
|
|
||||||
This means a lot to us, as that's the only way to get better... and many people don't file bug reports. \
|
|
||||||
Anyway, please answer the following questions accurately, otherwise we may not be able to diagnose the issue. \
|
|
||||||
\
|
|
||||||
**Please check if the same bug report already exists. If so, participate in that one instead. If another issue is similar, make sure to mention the related issues.** \
|
|
||||||
**Please don't censor anything *except* sensitive information. You don't need to be embarrased about your username. You censor your bug report, we censor our answers.**
|
|
||||||
- type: "textarea"
|
|
||||||
id: "bug-description"
|
|
||||||
attributes:
|
|
||||||
label: "Bug description"
|
|
||||||
description: "Explain what the bug is about. Include as many details as possible."
|
|
||||||
placeholder: "My cat spontaneously explodes when I try to download from `https://yourdick.zip`."
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "textarea"
|
|
||||||
id: "bug-log"
|
|
||||||
attributes:
|
|
||||||
label: "Bug log"
|
|
||||||
description: |
|
|
||||||
Please insert the ENTIRE log output here, so we can understand the problem at hand. \
|
|
||||||
You must give us `DIAGNOSTIC` level logs (pass `-Dsosengine.base.loggerLevel=diagnostic` to the JVM) with the default log template.
|
|
||||||
|
|
||||||
**This field can be left empty if the bug does not involve/require log output.**
|
|
||||||
placeholder: "Your log file here..."
|
|
||||||
value: |
|
|
||||||
```plain
|
|
||||||
Your log file here...
|
|
||||||
```
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "textarea"
|
|
||||||
id: "bug-snippet"
|
|
||||||
attributes:
|
|
||||||
label: "Bug snippet"
|
|
||||||
description: |
|
|
||||||
Please insert a snippet of the (application and/or engine) code which you think is causing the issue.
|
|
||||||
|
|
||||||
**This field can be left empty if you intend on supplying a reproduction project.**
|
|
||||||
value: |
|
|
||||||
```java
|
|
||||||
Your code snippet here...
|
|
||||||
```
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "textarea"
|
|
||||||
id: "bug-reproduce"
|
|
||||||
attributes:
|
|
||||||
label: "Bug reproduction guide"
|
|
||||||
description: |
|
|
||||||
Explain how we can reproduce this bug as easy as possible, step by step.
|
|
||||||
|
|
||||||
**This field can be left empty if the bug does not involve/require a reproduction guide.**
|
|
||||||
placeholder: |
|
|
||||||
1. Pass "-Dsosengine.base.optimizeLogging=false" to the JVM
|
|
||||||
2. Override logging implementation
|
|
||||||
2. Initialize engine
|
|
||||||
4. The nearest cat should explode in the next few seconds
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "input"
|
|
||||||
id: "bug-reproduce-project"
|
|
||||||
attributes:
|
|
||||||
label: "Bug reproduction project"
|
|
||||||
description: |
|
|
||||||
Drop a link to some repository or zip file of an example project showcasing the bug.
|
|
||||||
|
|
||||||
**Only supply a repro project if the bug is a bit more advanced, needs specific timing, etc..** \
|
|
||||||
**Also please make sure that the bug actually occurs in the example project!**"
|
|
||||||
placeholder: "https://your.reproduction.project/download/url/here"
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "input"
|
|
||||||
id: "engine-version"
|
|
||||||
attributes:
|
|
||||||
label: "Full engine version"
|
|
||||||
description: |
|
|
||||||
Input the full engine version here.
|
|
||||||
Simply copy the `Initialized sos!engine v<version> (commit <commit>-<branch>, dirty <dirty>) in <inittime>ms` message here.
|
|
||||||
placeholder: "Example: sos!engine v1-alpha4 (commit 05b9644eba5263809b6655dabb92669523a95805-develop, dirty true)"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "dropdown"
|
|
||||||
id: "jvm-java"
|
|
||||||
attributes:
|
|
||||||
label: "Java version"
|
|
||||||
description: "Which Java version is your application compiled against?"
|
|
||||||
options:
|
|
||||||
- "20 and lower"
|
|
||||||
- "21"
|
|
||||||
- "22"
|
|
||||||
- "23"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "input"
|
|
||||||
id: "os"
|
|
||||||
attributes:
|
|
||||||
label: "Operating system"
|
|
||||||
description: "Name the operating system, version (if applicable) and CPU architecture the error occurs on. This may be some Linux distribution, Android or Windoze on `amd64`/`aarch64`/`ppc64`/etc.."
|
|
||||||
placeholder: "Example: Debian trixie (amd64)"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "markdown"
|
|
||||||
id: "text-tysm"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Thank you for filling out this bug report.
|
|
||||||
Please check your answers for *mistaeks* or sensitive information before sending this report.
|
|
|
@ -1,5 +0,0 @@
|
||||||
blank_issues_enabled: false
|
|
||||||
contact_links:
|
|
||||||
- name: "📚 Documentation"
|
|
||||||
about: "Visit the documentation. Maybe you just skipped something important or just haven't found the page you're looking for yet."
|
|
||||||
url: "https://engine.staropensource.de"
|
|
|
@ -1,20 +0,0 @@
|
||||||
name: "👾 Empty"
|
|
||||||
about: "A clean slate. Only use this one for specific, special cases."
|
|
||||||
title: "empty: "
|
|
||||||
labels:
|
|
||||||
- "Empty"
|
|
||||||
body:
|
|
||||||
- type: "markdown"
|
|
||||||
id: "introduction"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
This issue template is meant for specific, special cases, where an empty issue template may be wanted.
|
|
||||||
You should *NOT* use this template to write bug reports, feature or help requests.
|
|
||||||
This issue template should ideally only be used by the repository maintainer.
|
|
||||||
- type: "textarea"
|
|
||||||
id: "content"
|
|
||||||
attributes:
|
|
||||||
label: "Issue content"
|
|
||||||
description: "Write your issue content here."
|
|
||||||
validations:
|
|
||||||
required: true
|
|
|
@ -1,61 +0,0 @@
|
||||||
name: "✨ Feature Request"
|
|
||||||
about: "Request a feature to be implemented in the engine."
|
|
||||||
title: "feat: "
|
|
||||||
labels:
|
|
||||||
- "FeatureRequest/New"
|
|
||||||
body:
|
|
||||||
- type: "markdown"
|
|
||||||
id: "text-introduction"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Hey there! Thank you for taking the time to request a feature to us. \
|
|
||||||
Before filling any of this out, please think for one minute if the feature is really important and necessary enough to implement in the engine. If you're unsure, continue. \
|
|
||||||
Please answer the following questions accurately, or we may not be able to implement the feature as you requested it. \
|
|
||||||
\
|
|
||||||
**Please check if the same feature request already exists. If so, participate in that one instead. If another issue is similar, make sure to mention the related issues.** \
|
|
||||||
**Please don't censor anything *except* sensitive information. You don't need to be embarrased about your username. You censor your bug report, we censor our answers.** \
|
|
||||||
**Submitting a feature request will *not* gurantee it's inclusion into the engine. By submitting a feature request, you are at the grace of the community to pick up your suggestion.**
|
|
||||||
- type: "textarea"
|
|
||||||
id: "feature-description"
|
|
||||||
attributes:
|
|
||||||
label: "Feature description"
|
|
||||||
description: "Explain *what* you want added. Include as many details as possible."
|
|
||||||
placeholder: |
|
|
||||||
Example:
|
|
||||||
I want to do X in my project, which would simplify doing Y.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "textarea"
|
|
||||||
id: "feature-implementation"
|
|
||||||
attributes:
|
|
||||||
label: "Feature implementation"
|
|
||||||
description: |
|
|
||||||
Explain *how* you want it added. Include as many details as possible.
|
|
||||||
Also explore alternative ways of implementing the feature in the engine (if possible).
|
|
||||||
placeholder: |
|
|
||||||
Example:
|
|
||||||
I would propose to <some description on how to implement your feature>.
|
|
||||||
I've also thought on simply <some other description on how to implement your feature>.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "textarea"
|
|
||||||
id: "feature-alternatives"
|
|
||||||
attributes:
|
|
||||||
label: "Feature alternatives"
|
|
||||||
description: |
|
|
||||||
Explain how to implement the feature without building it into the engine directly. Include as many details as possible.
|
|
||||||
|
|
||||||
**Leave empty if it can't simply be solved by creating a subsystem.**
|
|
||||||
placeholder: |
|
|
||||||
Example:
|
|
||||||
I've considered writing a subsystem for this feature.
|
|
||||||
Otherwise it would be possible to use <link to some project> with some configuration.
|
|
||||||
I've also considered using the normal way of doing it by <how to do it using the normal way>.
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "markdown"
|
|
||||||
id: "text-tysm"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Thank you for filling out this feature request form.
|
|
||||||
Please check your answers for *mistaeks* before sending this report.
|
|
|
@ -1,89 +0,0 @@
|
||||||
name: "💬 Help"
|
|
||||||
about: "Request help."
|
|
||||||
title: "help: "
|
|
||||||
labels:
|
|
||||||
- "Help/Wanted"
|
|
||||||
body:
|
|
||||||
- type: "markdown"
|
|
||||||
id: "text-introduction"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Hey there! Seems like you have some kind of issue with the StarOpenSource Engine. \
|
|
||||||
Please answer the following questions accurately, otherwise we may not be able to help you. \
|
|
||||||
\
|
|
||||||
**Please check if the same help request already exists. If so, participate in that one instead. If another issue is similar, make sure to mention the related issues.** \
|
|
||||||
**Please don't censor anything *except* sensitive information. You don't need to be embarrased about your username. You censor your stuff, we censor our answers.**
|
|
||||||
- type: "textarea"
|
|
||||||
id: "help-description"
|
|
||||||
attributes:
|
|
||||||
label: "Problem description"
|
|
||||||
description: "Explain what your problem is as detailed as possible."
|
|
||||||
placeholder: "How can I create a custom LoggerImplementation implementation?"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "textarea"
|
|
||||||
id: "help-log"
|
|
||||||
attributes:
|
|
||||||
label: "Log"
|
|
||||||
description: |
|
|
||||||
Please insert the ENTIRE log output here, so we can understand the problem at hand. \
|
|
||||||
You must give us `DIAGNOSTIC` level logs (pass `-Dsosengine.base.loggerLevel=diagnostic` to the JVM) with the default log template.
|
|
||||||
|
|
||||||
*This field can be left empty if the problem you are faciing does not involve/require log output.**
|
|
||||||
placeholder: "Your log file here..."
|
|
||||||
value: |
|
|
||||||
```plain
|
|
||||||
Your log file here...
|
|
||||||
```
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "textarea"
|
|
||||||
id: "help-snippet"
|
|
||||||
attributes:
|
|
||||||
label: "Code snippet"
|
|
||||||
description: |
|
|
||||||
Please insert a snippet of the application code which you think is causing the issue.
|
|
||||||
|
|
||||||
**This field can be left empty if the problem you are faciing does not involve/require code.**
|
|
||||||
value: |
|
|
||||||
```java
|
|
||||||
Your code snippet here...
|
|
||||||
```
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: "input"
|
|
||||||
id: "engine-version"
|
|
||||||
attributes:
|
|
||||||
label: "Full engine version"
|
|
||||||
description: |
|
|
||||||
Input the full engine version here.
|
|
||||||
Simply copy the `Initialized sos!engine v<version> (commit <commit>-<branch>, dirty <dirty>) in <inittime>ms` message here.
|
|
||||||
placeholder: "Example: sos!engine v1-alpha4 (commit 05b9644eba5263809b6655dabb92669523a95805-develop, dirty true)"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "dropdown"
|
|
||||||
id: "jvm-java"
|
|
||||||
attributes:
|
|
||||||
label: "Java version"
|
|
||||||
description: "Which Java version is your application compiled against?"
|
|
||||||
options:
|
|
||||||
- "20 and lower"
|
|
||||||
- "21"
|
|
||||||
- "22"
|
|
||||||
- "23"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "input"
|
|
||||||
id: "os"
|
|
||||||
attributes:
|
|
||||||
label: "Operating system"
|
|
||||||
description: "Name the operating system, version (if applicable) and CPU architecture the error occurs on. This may be some Linux distribution, Android or Windoze on `amd64`/`aarch64`/`ppc64`/etc.."
|
|
||||||
placeholder: "Example: Debian trixie (amd64)"
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: "markdown"
|
|
||||||
id: "text-tysm"
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
Thank you for filling out this help form.
|
|
||||||
Please check your answers for *mistaeks* or sensitive information before sending this help request.
|
|
|
@ -1,12 +0,0 @@
|
||||||
---
|
|
||||||
name: 'Pull Request'
|
|
||||||
about: 'Submit a pull request.'
|
|
||||||
title: 'new: '
|
|
||||||
ref: 'develop'
|
|
||||||
labels:
|
|
||||||
- 'PRStatus/Open'
|
|
||||||
- 'PR/New'
|
|
||||||
---
|
|
||||||
<!--
|
|
||||||
Please list your changes here.
|
|
||||||
-->
|
|
|
@ -1,125 +0,0 @@
|
||||||
name: build-and-test
|
|
||||||
|
|
||||||
on:
|
|
||||||
- pull_request
|
|
||||||
- push
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: git.staropensource.de/staropensource/actions-docker:java
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: https://code.forgejo.org/actions/checkout@v4
|
|
||||||
- name: Restore Gradle cache
|
|
||||||
uses: actions/cache/restore@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Compile
|
|
||||||
run: ./gradlew --no-daemon jar javadocJar sourceJar
|
|
||||||
- name: Save Gradle cache
|
|
||||||
uses: actions/cache/save@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Upload library JARs
|
|
||||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: jars-libraries
|
|
||||||
path: |
|
|
||||||
**/build/libs/*.jar
|
|
||||||
!**/build/libs/*-javadoc.jar
|
|
||||||
!**/build/libs/*-sources.jar
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Upload API documentation JARs
|
|
||||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: jars-apidocs
|
|
||||||
path: |
|
|
||||||
**/build/libs/*-javadoc.jar
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Upload source JARs
|
|
||||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: jars-sources
|
|
||||||
path: |
|
|
||||||
**/build/libs/*-sources.jar
|
|
||||||
if-no-files-found: error
|
|
||||||
generate-javadoc:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: git.staropensource.de/staropensource/actions-docker:java
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: https://code.forgejo.org/actions/checkout@v4
|
|
||||||
- name: Restore Gradle cache
|
|
||||||
uses: actions/cache/restore@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Generate javadoc
|
|
||||||
run: ./gradlew --no-daemon javadoc javadocAll
|
|
||||||
- name: Save Gradle cache
|
|
||||||
uses: actions/cache/save@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Upload separate javadoc
|
|
||||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: javadoc-separate
|
|
||||||
path: |
|
|
||||||
**/build/docs/javadoc/*
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Upload combined javadoc
|
|
||||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: javadoc-combined
|
|
||||||
path: |
|
|
||||||
build/docs/javadoc/*
|
|
||||||
if-no-files-found: error
|
|
||||||
test:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: git.staropensource.de/staropensource/actions-docker:java
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: https://code.forgejo.org/actions/checkout@v4
|
|
||||||
- name: Restore Gradle cache
|
|
||||||
uses: actions/cache/restore@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Run tests
|
|
||||||
run: ./gradlew --no-daemon test
|
|
||||||
- name: Save Gradle cache
|
|
||||||
uses: actions/cache/save@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
|
@ -1,60 +0,0 @@
|
||||||
name: build-and-test
|
|
||||||
|
|
||||||
on:
|
|
||||||
- pull_request
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
generate-javadoc:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: git.staropensource.de/staropensource/actions-docker:java
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: https://code.forgejo.org/actions/checkout@v4
|
|
||||||
- name: Restore Gradle cache
|
|
||||||
uses: actions/cache/restore@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Generate javadoc
|
|
||||||
run: ./gradlew --no-daemon javadoc
|
|
||||||
- name: Save Gradle cache
|
|
||||||
uses: actions/cache/save@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
test:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: git.staropensource.de/staropensource/actions-docker:java
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: https://code.forgejo.org/actions/checkout@v4
|
|
||||||
- name: Restore Gradle cache
|
|
||||||
uses: actions/cache/restore@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
||||||
- name: Run tests
|
|
||||||
run: ./gradlew --no-daemon test
|
|
||||||
- name: Save Gradle cache
|
|
||||||
uses: actions/cache/save@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.gradle/caches
|
|
||||||
~/.gradle/wrapper
|
|
||||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
||||||
restore-keys: |
|
|
||||||
gradle-${{ runner.os }}-
|
|
15
.gitattributes
vendored
15
.gitattributes
vendored
|
@ -1,15 +0,0 @@
|
||||||
# Documentation
|
|
||||||
*.md linguist-documentation
|
|
||||||
docs/* linguist-documentation
|
|
||||||
|
|
||||||
# Licensing information
|
|
||||||
COPYING linguist-documentation
|
|
||||||
LICENSE linguist-documentation
|
|
||||||
|
|
||||||
# Javadoc
|
|
||||||
*.html linguist-documentation
|
|
||||||
*.css linguist-documentation
|
|
||||||
|
|
||||||
# Gradle configuration
|
|
||||||
*.properties linguist-configuration
|
|
||||||
*.gradle linguist-configuration
|
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,7 +1,6 @@
|
||||||
### Gradle ###
|
### Gradle ###
|
||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
run/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
!**/src/main/**/build/
|
!**/src/main/**/build/
|
||||||
!**/src/test/**/build/
|
!**/src/test/**/build/
|
||||||
|
@ -34,6 +33,7 @@ bin/
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
/nbproject/private/
|
/nbproject/private/
|
||||||
/nbbuild/
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
/nbdist/
|
/nbdist/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
|
|
||||||
|
@ -42,6 +42,3 @@ bin/
|
||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
### Java ###
|
|
||||||
hs_err_pid*.log
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
<component name="CopyrightManager">
|
|
||||||
<settings default="sos!engine" />
|
|
||||||
</component>
|
|
|
@ -1,7 +0,0 @@
|
||||||
<component name="CopyrightManager">
|
|
||||||
<copyright>
|
|
||||||
<option name="allowReplaceRegexp" value="Copyright .* The StarOpenSource Engine Authors" />
|
|
||||||
<option name="notice" value="STAROPENSOURCE ENGINE SOURCE FILE Copyright (c) &#36;today.year The StarOpenSource Engine Authors Licensed under the GNU Affero General Public License v3 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>." />
|
|
||||||
<option name="myName" value="sos!engine" />
|
|
||||||
</copyright>
|
|
||||||
</component>
|
|
|
@ -1,28 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<configuration name="Build test application (native)" type="GradleRunConfiguration" factoryName="Gradle">
|
|
||||||
<ExternalSystemSettings>
|
|
||||||
<option name="executionName" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
|
||||||
<option name="scriptParameters" value="" />
|
|
||||||
<option name="taskDescriptions">
|
|
||||||
<list />
|
|
||||||
</option>
|
|
||||||
<option name="taskNames">
|
|
||||||
<list>
|
|
||||||
<option value="testapp:nativeImage" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
<option name="vmOptions" />
|
|
||||||
</ExternalSystemSettings>
|
|
||||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
|
||||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
|
||||||
<DebugAllEnabled>false</DebugAllEnabled>
|
|
||||||
<RunAsTest>false</RunAsTest>
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="Build test application" type="GradleRunConfiguration" factoryName="Gradle">
|
<configuration name="Build test application" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
|
@ -67,29 +45,7 @@
|
||||||
<RunAsTest>false</RunAsTest>
|
<RunAsTest>false</RunAsTest>
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="Generate JavaDoc (combined)" type="GradleRunConfiguration" factoryName="Gradle">
|
<configuration name="Generate Javadoc" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
<ExternalSystemSettings>
|
|
||||||
<option name="executionName" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
|
||||||
<option name="scriptParameters" value="" />
|
|
||||||
<option name="taskDescriptions">
|
|
||||||
<list />
|
|
||||||
</option>
|
|
||||||
<option name="taskNames">
|
|
||||||
<list>
|
|
||||||
<option value="javadocAll" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
<option name="vmOptions" />
|
|
||||||
</ExternalSystemSettings>
|
|
||||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
|
||||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
|
||||||
<DebugAllEnabled>false</DebugAllEnabled>
|
|
||||||
<RunAsTest>false</RunAsTest>
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="Generate Javadoc (separate)" type="GradleRunConfiguration" factoryName="Gradle">
|
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
@ -101,28 +57,7 @@
|
||||||
<option name="taskNames">
|
<option name="taskNames">
|
||||||
<list>
|
<list>
|
||||||
<option value="javadoc" />
|
<option value="javadoc" />
|
||||||
</list>
|
<option value="javadocAll" />
|
||||||
</option>
|
|
||||||
<option name="vmOptions" />
|
|
||||||
</ExternalSystemSettings>
|
|
||||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
|
||||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
|
||||||
<DebugAllEnabled>false</DebugAllEnabled>
|
|
||||||
<RunAsTest>false</RunAsTest>
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
<configuration name="Run test application (native)" type="GradleRunConfiguration" factoryName="Gradle">
|
|
||||||
<ExternalSystemSettings>
|
|
||||||
<option name="executionName" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
|
||||||
<option name="scriptParameters" value="" />
|
|
||||||
<option name="taskDescriptions">
|
|
||||||
<list />
|
|
||||||
</option>
|
|
||||||
<option name="taskNames">
|
|
||||||
<list>
|
|
||||||
<option value="testapp:runNativeimage" />
|
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="vmOptions" />
|
<option name="vmOptions" />
|
||||||
|
@ -144,7 +79,8 @@
|
||||||
</option>
|
</option>
|
||||||
<option name="taskNames">
|
<option name="taskNames">
|
||||||
<list>
|
<list>
|
||||||
<option value="testapp:runShadow" />
|
<option value="shadowJar" />
|
||||||
|
<option value="testapp:run" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="vmOptions" />
|
<option name="vmOptions" />
|
||||||
|
@ -178,14 +114,11 @@
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="Gradle.Clean" />
|
|
||||||
<item itemvalue="Gradle.Run tests" />
|
|
||||||
<item itemvalue="Gradle.Build test application" />
|
<item itemvalue="Gradle.Build test application" />
|
||||||
<item itemvalue="Gradle.Run test application" />
|
<item itemvalue="Gradle.Run test application" />
|
||||||
<item itemvalue="Gradle.Build test application (native)" />
|
<item itemvalue="Gradle.Run tests" />
|
||||||
<item itemvalue="Gradle.Run test application (native)" />
|
<item itemvalue="Gradle.Generate Javadoc" />
|
||||||
<item itemvalue="Gradle.Generate Javadoc (separate)" />
|
<item itemvalue="Gradle.Clean" />
|
||||||
<item itemvalue="Gradle.Generate JavaDoc (combined)" />
|
|
||||||
</list>
|
</list>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
80
README.md
80
README.md
|
@ -1,44 +1,35 @@
|
||||||
# StarOpenSource Engine
|
# StarOpenSource Engine
|
||||||
The StarOpenSource Engine (or sos!engine for short) is a modular, extensible and easy to use Java game and application engine.
|
The StarOpenSource engine (or sos!engine for short) is a modular, extensible and easy to use Java game and application engine.
|
||||||
|
|
||||||
## WARNING
|
|
||||||
The StarOpenSource Engine is under heavy development and is extremely unstable. Code will break often, prepare for potential major refactors when trying the engine out.
|
|
||||||
|
|
||||||
## Index
|
## Index
|
||||||
- [About](#about)
|
- [About](#about)
|
||||||
- [... the engine](#-the-engine)
|
- [About the engine](#about-the-engine)
|
||||||
- [... the repository](#-the-repository)
|
- [About the repository](#about-the-repository)
|
||||||
- [Priorities](#priorities)
|
- [Priorities](#priorities)
|
||||||
- [Documentation](#documentation)
|
- [Documentation](#documentation)
|
||||||
- [Contributing](#contributing)
|
- [Contributing](#contributing)
|
||||||
- [Requirements](#requirements)
|
- [Requirements](#requirements)
|
||||||
- [What IDE to use?](#what-ide-to-use)
|
- [What IDE to use?](#what-ide-to-use)
|
||||||
- [Code style](#code-style)
|
- [Code style](#code-style)
|
||||||
- [Pull request guidelines](#pull-request-guidelines)
|
- [Read this before creating a pull request](#read-this-before-creating-a-pull-request)
|
||||||
- [Making your first contribution](#making-your-first-contribution)
|
- [Making your first contribution](#making-your-first-contribution)
|
||||||
- [Gradle properties](#gradle-properties)
|
|
||||||
|
|
||||||
## About
|
## About
|
||||||
### ... the engine
|
### About the engine
|
||||||
The StarOpenSource Engine is a modular and extensible framework for building applications and games written in [one of the multiple JVM programming languages](https://en.wikipedia.org/wiki/List_of_JVM_languages).
|
The sos!engine is a modular and extensible framework for building applications and games, written in the Java programming language.
|
||||||
The engine consists of various subsystems, each separate and responsible for only a few closely-related tasks.
|
The engine consists of various subsystems, each separate and responsible for only one thing. The engine also houses various useful utilities and classes making development fun, and all that while being lightweight.
|
||||||
\
|
### About the repository
|
||||||
Not only that. The engine also features various useful classes, interfaces and methods making development fun and simpler, while being lightweight.
|
The sos!engine repository is a monorepo, consisting of [the core engine](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/base), official subsystems and [their documentation](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/docs).
|
||||||
### ... the repository
|
|
||||||
The sos!engine repository is a monorepo, consisting of [the core engine](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/base), multiple official subsystems and [their documentation](https://git.staropensource.de/StarOpenSource/Engine/src/branch/develop/docs).
|
|
||||||
### Priorities
|
### Priorities
|
||||||
These are in no particular order.
|
- modular
|
||||||
|
|
||||||
- configurable
|
|
||||||
- [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy) (subsystems concept)
|
|
||||||
- fast
|
|
||||||
- few runtime dependencies (note: we will cut down on some of them during development)
|
|
||||||
- modular & extensible
|
|
||||||
- small & lightweight
|
- small & lightweight
|
||||||
|
- fast
|
||||||
|
- [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy) (subsystems concept)
|
||||||
|
- have as few runtime dependencies as possible (note: we will cut down on some of them during development)
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
You can view the engine documentation at [engine.staropensource.de](https://engine.staropensource.de). It provides information, guides and tutorials about the core engine and subsystems.
|
The official documentation for the StarOpenSource Engine is not yet available, but is planned.
|
||||||
If you want the API reference, you can [visit the Javadoc](https://jd.engine.staropensource.de) for the engine and it's subsystems.
|
You can however [visit the Javadocs](https://jd.engine.staropensource.de).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
### Requirements
|
### Requirements
|
||||||
|
@ -46,44 +37,15 @@ You need the following things to be able to contribute code to the StarOpenSourc
|
||||||
- knowledge of Java
|
- knowledge of Java
|
||||||
- knowledge about the internals of engine
|
- knowledge about the internals of engine
|
||||||
### What IDE to use?
|
### What IDE to use?
|
||||||
We recommend and are using [IntelliJ IDEA Community Edition](https://github.com/JetBrains/intellij-community) for development because it is flexible, extendable, customizable, provides good completions and error detection. It's also open source.
|
We use and recommend using [IntelliJ IDEA Community Edition](https://github.com/JetBrains/intellij-community) for development because it is flexible, extendable, customizable, provides good completions and error detection. It's also open source.
|
||||||
### Code style
|
### Code style
|
||||||
We recommend looking at existing classes and code for a good understanding on how we'd like code to be written.
|
We recommend looking at existing classes.
|
||||||
Here's a quick rundown on the most important things:
|
### Read this before creating a pull request
|
||||||
- Document EVERYTHING. Every single class, field and method, even if private.
|
Before creating a pull request, make sure you've
|
||||||
- Make comments about your code, unless it's extremely simple and easy to understand.
|
- created tests for the functionality you added, changed or removed (if applicable),
|
||||||
- Make sure to add and update `@since` in javadoc comments (update if the javadoc changes a good amount).
|
|
||||||
- Keep stuff simple, no need to elaborate what a logger is. Though remember to not make it *too* simple.
|
|
||||||
- Make sure every field and method has a newline to separate it.
|
|
||||||
- Files must end with a newline or cats might get angry.
|
|
||||||
- Use your brain.
|
|
||||||
### Pull request guidelines
|
|
||||||
Before creating a pull request, make sure you've:
|
|
||||||
- created tests for the functionality you've added, changed or removed (if applicable),
|
|
||||||
- tested your changes,
|
- tested your changes,
|
||||||
- made sure that everything works,
|
- made sure that everything works,
|
||||||
- is compatible with other code in the monorepo, and
|
- is compatible with other code in the monorepo, and
|
||||||
- is compatible with other applications. If not, tell us in your pull request description.
|
- is compatible with other applications. If not, tell us in your pull request description.
|
||||||
### Making your first contribution
|
### Making your first contribution
|
||||||
TODO
|
TODO (probably) until v1-alpha0
|
||||||
### Gradle properties
|
|
||||||
Gradle's behaviour can be changed by changing gradle project properties.
|
|
||||||
To change them, simply append `-P<property>` or `-P<property>=<value>`, like this: `./gradlew -Pjobs=4 test`.
|
|
||||||
#### Parallelism
|
|
||||||
Use the `jobs` property to control how many jobs will get executed simultaneously.
|
|
||||||
On Linux, specify `-Pjobs=$(nproc)`. Defaults to `8`.
|
|
||||||
#### JVM Home
|
|
||||||
You can use the `graalHome` property to specify the `$JAVA_HOME` of your local GraalVM installation.
|
|
||||||
Only used in the `nativeImage` task. Useful if you aren't using GraalVM as your primary JDK.
|
|
||||||
#### Testing
|
|
||||||
You can use the following properties to modify the behaviour of the `test`-task:
|
|
||||||
- `test.control.mode` (default *empty*)
|
|
||||||
- `force-enable`: Disables all test classes except the ones specified
|
|
||||||
- `force-disable`: Enables all test classes except the ones specified
|
|
||||||
- *everything else*: Enables all test classes
|
|
||||||
- `test.control.classes` (default *empty*): A comma-separated, case-sensitive list of test classes
|
|
||||||
which (depending on `test.control.mode`'s value) enable or disable the specified classes.
|
|
||||||
Example: `-Ptest.control.mode=MiscellaneousTest,DependencyResolverTest,EngineConfigurationTest`
|
|
||||||
- `test.control.warning` (default `false`): If `true`, will emit a warning before a restricted test method exits
|
|
||||||
- `test.loggerLevel` (default `silent_warning`): Will set `UnitLogger`'s logger level.
|
|
||||||
Works like `-Dsosengine.base.loggerLevel`. See `UnitLogger#loggerLevel` for more information
|
|
||||||
|
|
|
@ -1,112 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Plugins
|
|
||||||
plugins {
|
|
||||||
id("java")
|
|
||||||
id("io.freefair.lombok") version("${pluginLombok}")
|
|
||||||
id("maven-publish")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dependencies
|
|
||||||
dependencies {
|
|
||||||
// Lombok
|
|
||||||
compileOnly("org.projectlombok:lombok:${dependencyLombok}")
|
|
||||||
annotationProcessor("org.projectlombok:lombok:${dependencyLombok}")
|
|
||||||
|
|
||||||
// JetBrains Annotations
|
|
||||||
compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
|
|
||||||
|
|
||||||
// Jansi
|
|
||||||
implementation("org.fusesource.jansi:jansi:${dependencyJansi}")
|
|
||||||
|
|
||||||
// Project
|
|
||||||
implementation(project(":base"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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") // 你好
|
|
||||||
addStringOption("Xwerror", "-quiet") // Fail build on warning
|
|
||||||
|
|
||||||
setJFlags([
|
|
||||||
"-Duser.language=en_US" // See above
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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/engine")
|
|
||||||
credentials(org.gradle.api.credentials.PasswordCredentials)
|
|
||||||
authentication {
|
|
||||||
//noinspection GroovyAssignabilityCheck
|
|
||||||
basic (BasicAuthentication)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
publications {
|
|
||||||
//noinspection GroovyAssignabilityCheck
|
|
||||||
maven (MavenPublication) {
|
|
||||||
groupId = group
|
|
||||||
artifactId = project.getName()
|
|
||||||
version = version
|
|
||||||
//noinspection GroovyAssignabilityCheck
|
|
||||||
from components.java
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix delombok task
|
|
||||||
delombok.doFirst {
|
|
||||||
File target = file("${project.projectDir}/src/main/module-info.java")
|
|
||||||
File source = file("${project.projectDir}/src/main/java/module-info.java")
|
|
||||||
|
|
||||||
target.delete()
|
|
||||||
source.renameTo(target)
|
|
||||||
}
|
|
||||||
delombok.doLast {
|
|
||||||
File target = file("${project.projectDir}/src/main/java/module-info.java")
|
|
||||||
File source = file("${project.projectDir}/src/main/module-info.java")
|
|
||||||
|
|
||||||
target.delete()
|
|
||||||
source.renameTo(target)
|
|
||||||
}
|
|
|
@ -1,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.ansi;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import org.fusesource.jansi.Ansi;
|
|
||||||
import org.fusesource.jansi.AnsiConsole;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints colored log output using the Jansi library.
|
|
||||||
*
|
|
||||||
* @see Logger
|
|
||||||
* @see LoggingAdapter
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class AnsiLoggingAdapter implements LoggingAdapter {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public AnsiLoggingAdapter() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings({ "resource" }) // Using try-with-resources will cause issues here
|
|
||||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
|
||||||
// Convert to Ansi
|
|
||||||
Ansi output = new AnsiShortcodeParser(format, true).getAnsi();
|
|
||||||
|
|
||||||
// Print message
|
|
||||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
|
||||||
if (EngineConfiguration.getInstance().isLogForceStandardOutput())
|
|
||||||
AnsiConsole.out().println(output);
|
|
||||||
else
|
|
||||||
AnsiConsole.err().println(output);
|
|
||||||
else
|
|
||||||
AnsiConsole.out().println(output);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,107 +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.ansi;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.ShortcodeParser;
|
|
||||||
import de.staropensource.engine.base.exception.ParserException;
|
|
||||||
import org.fusesource.jansi.Ansi;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of the {@link ShortcodeParser} class
|
|
||||||
* with ANSI support using the Jansi library.
|
|
||||||
*
|
|
||||||
* @see ShortcodeParser
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public final class AnsiShortcodeParser extends ShortcodeParser {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @param string string to convert
|
|
||||||
* @param ignoreInvalidEscapes will ignore invalid escapes and print treat them like regular text
|
|
||||||
* @throws ParserException when parsing failed
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public AnsiShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
|
||||||
super(string, ignoreInvalidEscapes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the parsed string as an {@link Ansi} sequence.
|
|
||||||
*
|
|
||||||
* @return {@link Ansi} sequence
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @NotNull Ansi getAnsi() {
|
|
||||||
Ansi ansi = Ansi.ansi();
|
|
||||||
Set<@NotNull String> status = new HashSet<>();
|
|
||||||
|
|
||||||
for (String component : components)
|
|
||||||
if (component.equals("RESET")) {
|
|
||||||
ansi.a(Ansi.Attribute.RESET);
|
|
||||||
status.clear();
|
|
||||||
} else if (component.startsWith("TEXT:"))
|
|
||||||
ansi.a(component.substring(5));
|
|
||||||
else if (component.startsWith("COLOR:"))
|
|
||||||
if (component.startsWith("COLOR:FOREGROUND:"))
|
|
||||||
ansi.fg(Ansi.Color.valueOf(component.substring(17)));
|
|
||||||
else if (component.startsWith("COLOR:BACKGROUND:"))
|
|
||||||
ansi.bg(Ansi.Color.valueOf(component.substring(17)));
|
|
||||||
else if (component.startsWith("ATTRIBUTE:"))
|
|
||||||
if (component.startsWith("ATTRIBUTE:BLINK")) {
|
|
||||||
if (status.contains("ATTRIBUTE:BLINK"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ansi.a(Ansi.Attribute.BLINK_SLOW);
|
|
||||||
status.add("ATTRIBUTE:BLINK");
|
|
||||||
} else if (component.startsWith("ATTRIBUTE:BOLD")) {
|
|
||||||
if (status.contains("ATTRIBUTE:BOLD"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ansi.a(Ansi.Attribute.INTENSITY_BOLD);
|
|
||||||
status.add("ATTRIBUTE:BOLD");
|
|
||||||
} else if (component.startsWith("ATTRIBUTE:ITALIC")) {
|
|
||||||
if (status.contains("ATTRIBUTE:ITALIC"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ansi.a(Ansi.Attribute.ITALIC);
|
|
||||||
status.add("ATTRIBUTE:ITALIC");
|
|
||||||
} else if (component.startsWith("ATTRIBUTE:STRIKETHROUGH")) {
|
|
||||||
if (status.contains("ATTRIBUTE:STRIKETHROUGH"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ansi.a(Ansi.Attribute.STRIKETHROUGH_ON);
|
|
||||||
status.add("ATTRIBUTE:STRIKETHROUGH");
|
|
||||||
} else if (component.startsWith("ATTRIBUTE:UNDERLINE")) {
|
|
||||||
if (status.contains("ATTRIBUTE:UNDERLINE"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ansi.a(Ansi.Attribute.UNDERLINE);
|
|
||||||
status.add("ATTRIBUTE:UNDERLINE");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return ansi;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,86 +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.ansi;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
|
||||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.DependencyVector;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main class of the ANSI Compatibility subsystem.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@EngineSubsystem
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class AnsiSubsystem extends SubsystemClass {
|
|
||||||
/**
|
|
||||||
* Contains the class instance.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the class instance.
|
|
||||||
*
|
|
||||||
* @return class instance unless the subsystem is uninitialized
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static AnsiSubsystem instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes this subsystem.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public AnsiSubsystem() {
|
|
||||||
// Check if subsystem has already initialized
|
|
||||||
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 "ansi";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void initializeSubsystem() {
|
|
||||||
Logger.setLoggingAdapter(new AnsiLoggingAdapter());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull DependencyVector getDependencyVector() {
|
|
||||||
return new DependencyVector.Builder()
|
|
||||||
.setIdentifier("ansi")
|
|
||||||
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
|
|
||||||
.setVersion(EngineInformation.getVersioningString())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
// -> Libraries
|
|
||||||
requires transitive static lombok;
|
|
||||||
requires transitive org.jetbrains.annotations;
|
|
||||||
requires org.fusesource.jansi;
|
|
||||||
|
|
||||||
// API access
|
|
||||||
exports de.staropensource.engine.ansi;
|
|
||||||
|
|
||||||
// Reflection access
|
|
||||||
opens de.staropensource.engine.ansi;
|
|
||||||
}
|
|
|
@ -1,23 +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/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<p>Welcome to the sos!engine API documentation!<br/>
|
|
||||||
You are currently in the documentation for the <b>ansi</b> subsystem, allowing ANSI escape sequences to be used using Jansi.</p>
|
|
||||||
</body>
|
|
|
@ -1 +0,0 @@
|
||||||
../../../../src/main/javadoc/theme.css
|
|
1
base/.gitignore
vendored
1
base/.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
src/main/resources/git.properties
|
|
|
@ -1,2 +0,0 @@
|
||||||
# The `base` subsystem
|
|
||||||
This is not just a subsystem, this is the core engine. It contains data types, logging infrastructure, an event system, a crash reporter and much more stuff required for basic applications.
|
|
|
@ -1,183 +1,49 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.nio.file.Files
|
|
||||||
// Plugins
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id 'java'
|
||||||
id("io.freefair.lombok") version("${pluginLombok}")
|
id 'io.freefair.lombok' version "${pluginLombok}"
|
||||||
id("com.gorylenko.gradle-git-properties") version("${pluginGitProperties}")
|
|
||||||
id("maven-publish")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dependencies
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// -> Runtime
|
// -> Runtime <-
|
||||||
// Lombok
|
// Lombok
|
||||||
compileOnly("org.projectlombok:lombok:${dependencyLombok}")
|
compileOnly 'org.projectlombok:lombok:' + project.dependencyLombok
|
||||||
annotationProcessor("org.projectlombok:lombok:${dependencyLombok}")
|
annotationProcessor 'org.projectlombok:lombok:' + project.dependencyLombok
|
||||||
|
|
||||||
// JetBrains Annotations
|
// JetBrains Annotations
|
||||||
compileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
|
compileOnly 'org.jetbrains:annotations:' + project.dependencyJetbrainsAnnotations
|
||||||
|
|
||||||
|
// ANSI support
|
||||||
|
implementation 'org.fusesource.jansi:jansi:' + project.dependencyJansi
|
||||||
|
|
||||||
// Reflections
|
// Reflections
|
||||||
implementation("org.reflections:reflections:${dependencyReflections}")
|
implementation 'org.reflections:reflections:' + project.dependencyReflections
|
||||||
|
|
||||||
// -> Testing
|
// -> Testing <-
|
||||||
// Jetbrains Annotations
|
// Jetbrains Annotations
|
||||||
testCompileOnly("org.jetbrains:annotations:${dependencyJetbrainsAnnotations}")
|
testCompileOnly 'org.jetbrains:annotations:' + project.dependencyJetbrainsAnnotations
|
||||||
|
|
||||||
// JUnit
|
// JUnit
|
||||||
testImplementation(platform("org.junit:junit-bom:${dependencyJunit}"))
|
testImplementation platform('org.junit:junit-bom:5.' + project.dependencyJunit)
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
|
||||||
// Project
|
// jOOR
|
||||||
testImplementation(project(":testing"))
|
testImplementation 'org.jooq:joor:' + project.dependencyJoor
|
||||||
}
|
}
|
||||||
|
|
||||||
// Javadoc configuration
|
javadoc.options {
|
||||||
javadoc {
|
setMemberLevel(JavadocMemberLevel.PUBLIC)
|
||||||
outputs.upToDateWhen { false } // Force task execution
|
setOverview("src/main/javadoc/overview.html")
|
||||||
dependsOn(delombok) // Make sure the source is delomboked first
|
setLocale("en_US")
|
||||||
|
|
||||||
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") // 你好
|
|
||||||
addStringOption("Xwerror", "-quiet") // Fail build on warning
|
|
||||||
|
|
||||||
setJFlags([
|
setJFlags([
|
||||||
"-Duser.language=en_US" // See above
|
// Force Javadoc to use English translations
|
||||||
|
"-Duser.language=en_US"
|
||||||
])
|
])
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unit testing configuration
|
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
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 {
|
testLogging {
|
||||||
events("passed", "skipped", "failed")
|
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/engine")
|
|
||||||
credentials(org.gradle.api.credentials.PasswordCredentials)
|
|
||||||
authentication {
|
|
||||||
//noinspection GroovyAssignabilityCheck
|
|
||||||
basic (BasicAuthentication)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
publications {
|
|
||||||
//noinspection GroovyAssignabilityCheck
|
|
||||||
maven (MavenPublication) {
|
|
||||||
groupId = group
|
|
||||||
artifactId = project.getName()
|
|
||||||
version = version
|
|
||||||
//noinspection GroovyAssignabilityCheck
|
|
||||||
from components.java
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy gradle.properties file
|
|
||||||
// for inclusion in final build
|
|
||||||
tasks.register("copyGradleProperties") {
|
|
||||||
doFirst {
|
|
||||||
File target = file("${project.projectDir}/src/main/resources/sosengine-gradle.properties")
|
|
||||||
File source = file(project(":").projectDir.getPath() + "/gradle.properties")
|
|
||||||
target.delete()
|
|
||||||
Files.copy(source.toPath(), target.toPath())
|
|
||||||
}
|
|
||||||
|
|
||||||
outputs.upToDateWhen({ false }) // Force task execution
|
|
||||||
}
|
|
||||||
processResources.dependsOn(copyGradleProperties)
|
|
||||||
|
|
||||||
// Git properties configuration
|
|
||||||
// Allows us to embed git commit information in the engine build
|
|
||||||
gitProperties {
|
|
||||||
dotGitDirectory = file("${rootProject.rootDir}/.git")
|
|
||||||
failOnNoGitDirectory = false // Allow continuing if .git directory is missing for the few who use tarballs
|
|
||||||
extProperty = "gitProps"
|
|
||||||
|
|
||||||
dateFormat = "yyyy-MM-dd'T'HH:mmZ"
|
|
||||||
dateFormatTimeZone = "UTC"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("writeGitProperties") { // This task's only purpose is to copy the git.properties from our git properties plugin to the resources directory so it's included in the final build
|
|
||||||
doLast {
|
|
||||||
File target = file("${project.projectDir}/src/main/resources/sosengine-git.properties")
|
|
||||||
File source = file("${project.projectDir}/build/resources/main/git.properties")
|
|
||||||
|
|
||||||
target.delete()
|
|
||||||
source.renameTo(target)
|
|
||||||
}
|
|
||||||
|
|
||||||
outputs.upToDateWhen({ false }) // Force task execution
|
|
||||||
}
|
|
||||||
generateGitProperties.outputs.upToDateWhen({ false }) // Force task execution
|
|
||||||
processResources.dependsOn(writeGitProperties) // Ensure git.properties file is present
|
|
||||||
|
|
||||||
// Fix delombok task
|
|
||||||
delombok.doFirst {
|
|
||||||
File target = file("${project.projectDir}/src/main/module-info.java")
|
|
||||||
File source = file("${project.projectDir}/src/main/java/module-info.java")
|
|
||||||
|
|
||||||
target.delete()
|
|
||||||
source.renameTo(target)
|
|
||||||
}
|
|
||||||
delombok.doLast {
|
|
||||||
File target = file("${project.projectDir}/src/main/java/module-info.java")
|
|
||||||
File source = file("${project.projectDir}/src/main/module-info.java")
|
|
||||||
|
|
||||||
target.delete()
|
|
||||||
source.renameTo(target)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,618 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
|
||||||
import de.staropensource.engine.base.event.*;
|
|
||||||
import de.staropensource.engine.base.exception.IllegalAccessException;
|
|
||||||
import de.staropensource.engine.base.exception.dependency.UnmetDependenciesException;
|
|
||||||
import de.staropensource.engine.base.implementable.ShutdownHandler;
|
|
||||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
|
||||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
||||||
import de.staropensource.engine.base.implementation.versioning.StarOpenSourceVersioningSystem;
|
|
||||||
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
|
|
||||||
import de.staropensource.engine.base.internal.type.DependencySubsystemVector;
|
|
||||||
import de.staropensource.engine.base.logging.PrintStreamService;
|
|
||||||
import de.staropensource.engine.base.logging.*;
|
|
||||||
import de.staropensource.engine.base.logging.backend.async.LoggingQueue;
|
|
||||||
import de.staropensource.engine.base.logging.backend.async.LoggingThread;
|
|
||||||
import de.staropensource.engine.base.type.DependencyVector;
|
|
||||||
import de.staropensource.engine.base.type.EngineState;
|
|
||||||
import de.staropensource.engine.base.type.immutable.ImmutableLinkedList;
|
|
||||||
import de.staropensource.engine.base.utility.DependencyResolver;
|
|
||||||
import de.staropensource.engine.base.utility.FileAccess;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import de.staropensource.engine.base.utility.information.JvmInformation;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
import org.reflections.Reflections;
|
|
||||||
import org.reflections.scanners.Scanners;
|
|
||||||
import org.reflections.util.ClasspathHelper;
|
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main class of the sos!engine.
|
|
||||||
*
|
|
||||||
* @see EngineConfiguration
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class Engine extends SubsystemClass {
|
|
||||||
/**
|
|
||||||
* Contains the class instance.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the class instance.
|
|
||||||
*
|
|
||||||
* @return class instance unless {@link Engine} is uninitialized
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static Engine instance = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the thread group of the engine.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the thread group of the engine.
|
|
||||||
*
|
|
||||||
* @return engine thread group
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static final ThreadGroup threadGroup = new ThreadGroup("sos!engine");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the engine state.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the engine state.
|
|
||||||
*
|
|
||||||
* @return shutdown state
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private @NotNull EngineState state;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains a list of all registered subsystems.
|
|
||||||
* The list is sorted after initialization order.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns a list of all registered subsystems.
|
|
||||||
* The list is sorted after initialization order.
|
|
||||||
*
|
|
||||||
* @return subsystem list
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private @NotNull ImmutableLinkedList<@NotNull DependencySubsystemVector> subsystems = new ImmutableLinkedList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the engine's shutdown handler.
|
|
||||||
* The shutdown handler is responsible for
|
|
||||||
* shutting down the JVM safely.
|
|
||||||
*
|
|
||||||
* @see ShutdownHandler
|
|
||||||
* @since v1-alpha2
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the engine's shutdown handler.
|
|
||||||
* The shutdown handler is responsible for
|
|
||||||
* shutting down the JVM safely.
|
|
||||||
*
|
|
||||||
* @return shutdown handler
|
|
||||||
* @see ShutdownHandler
|
|
||||||
* @since v1-alpha2
|
|
||||||
* -- SETTER --
|
|
||||||
* Sets the engine's shutdown handler.
|
|
||||||
* The shutdown handler is responsible for
|
|
||||||
* shutting down the JVM safely.
|
|
||||||
*
|
|
||||||
* @param shutdownHandler new shutdown handler
|
|
||||||
* @see ShutdownHandler
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@Getter(value = AccessLevel.MODULE)
|
|
||||||
@Setter(value = AccessLevel.MODULE)
|
|
||||||
private @NotNull ShutdownHandler shutdownHandler = new Engine.JvmShutdownHandler();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the JVM shutdown hook thread,
|
|
||||||
* which ensures that the engine is fully shut
|
|
||||||
* down before the JVM exits.
|
|
||||||
*
|
|
||||||
* @see EngineInternals#installSafetyShutdownHook(boolean)
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.MODULE)
|
|
||||||
private final @NotNull Thread safetyShutdownHook = Thread.ofPlatform()
|
|
||||||
.name("Engine shutdown thread")
|
|
||||||
.group(getThreadGroup())
|
|
||||||
.unstarted(() -> {
|
|
||||||
// Check if already shutting down
|
|
||||||
switch (state) {
|
|
||||||
case UNKNOWN, SHUTDOWN, CRASHED -> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.");
|
|
||||||
|
|
||||||
// Shutdown
|
|
||||||
Engine.getInstance().shutdown();
|
|
||||||
|
|
||||||
// Print last message
|
|
||||||
Logger.warn("Engine successfully shut down using shutdown hook. PLEASE USE Engine#shutdown() INSTEAD OF System#exit() or Runtime#exit()!");
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the StarOpenSource Engine.
|
|
||||||
*
|
|
||||||
* @throws RuntimeException for all exceptions thrown by this constructor
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
|
|
||||||
// Load engine build information
|
|
||||||
Logger.diag("Loading engine build information");
|
|
||||||
EngineInformation.update();
|
|
||||||
|
|
||||||
// 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()) {
|
|
||||||
// Collect all subsystems
|
|
||||||
Logger.diag("Collecting subsystems");
|
|
||||||
collectSubsystems();
|
|
||||||
|
|
||||||
// Initialize subsystems
|
|
||||||
try {
|
|
||||||
initializeSubsystems();
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Logger.error("Subsystem dependency resolution failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the StarOpenSource
|
|
||||||
* Engine, if it isn't already.
|
|
||||||
*
|
|
||||||
* @throws IllegalStateException when running in an incompatible environment
|
|
||||||
* @throws RuntimeException on engine initialization failure
|
|
||||||
* @since v1-alpha6
|
|
||||||
*/
|
|
||||||
public static void initialize() throws RuntimeException {
|
|
||||||
try {
|
|
||||||
if (instance == null)
|
|
||||||
new Engine();
|
|
||||||
} catch (RuntimeException exception) {
|
|
||||||
Logger.error("Engine initialization failed");
|
|
||||||
Logger.error(Miscellaneous.getStackTraceHeader(exception.getCause()));
|
|
||||||
for (String line : Miscellaneous.getStackTraceAsString(exception.getCause(), true).split("\n"))
|
|
||||||
Logger.error(line);
|
|
||||||
|
|
||||||
throw new RuntimeException("Engine initialization failed", exception.getCause());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the running JVM implementation is not supported by the engine.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private void checkJvmIncompatibilities() {
|
|
||||||
if (System.getProperties().getProperty("sosengine.base.allowUnsupportedJVMInitialization", "false").equals("true")) {
|
|
||||||
Logger.warn("Skipping JVM implementation incompatibilities check");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Substrate VM (GraalVM Community)
|
|
||||||
if (JvmInformation.getImplementationName().equals("Substrate VM") && JvmInformation.getImplementationVendor().equals("GraalVM Community")) {
|
|
||||||
Logger.error("##############################################################################################");
|
|
||||||
Logger.error("## Running in Substrate VM, which is the name of the JVM used by GraalVM native-image. ##");
|
|
||||||
Logger.error("## The StarOpenSource Engine does not support native-image as using reflection in a certain ##");
|
|
||||||
Logger.error("## way seems to cause the Substrate JVM to crash. Workarounds have failed. ##");
|
|
||||||
Logger.error("## This has already been noted in issue #3, which you can view here: ##");
|
|
||||||
Logger.error("## https://git.staropensource.de/StarOpenSource/Engine/issues/3 ##");
|
|
||||||
Logger.error("## ##");
|
|
||||||
Logger.error("## While this is sad, we unfortunately can't do anything against it unless we introduce ##");
|
|
||||||
Logger.error("## annoying and stupid changes into the engine, which we don't want to do. ##");
|
|
||||||
Logger.error("## ##");
|
|
||||||
Logger.error("## We're truly sorry for this inconvenience. The sos!engine will now terminate. ##");
|
|
||||||
Logger.error("##############################################################################################");
|
|
||||||
Runtime.getRuntime().exit(255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if reflective classpath scanning is supported.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private void checkReflectiveClasspathScanningCompatibility() {
|
|
||||||
// Check if reflective classpath scanning is supported
|
|
||||||
if (System.getProperties().getProperty("sosengine.base.considerEnvironmentUnfriendlyToClasspathScanning", "false").equals("true")) {
|
|
||||||
Logger.warn("Running in an classpath scanning-unfriendly environment, disabling classpath scanning support.");
|
|
||||||
Logger.warn("If shit doesn't work and is expected to be discovered by annotations, you'll need to");
|
|
||||||
Logger.warn("either register it first or have to update some engine configuration setting.");
|
|
||||||
Logger.warn("Please consult sos!engine's documentation for more information about this issue.");
|
|
||||||
EngineInternals.getInstance().overrideReflectiveClasspathScanning(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks and warns if the Java version of the
|
|
||||||
* running JVM is higher than the engine supports.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private void checkJavaVersion() {
|
|
||||||
if (JvmInformation.getJavaVersion() > EngineInformation.getJavaSource())
|
|
||||||
Logger.warn("The StarOpenSource Engine is running on an untested Java version.\nThings may not work as expected or features which can improve performance, stability, compatibility or ease of use may be missing.\nIf you encounter issues, try running a JVM implementing Java " + EngineInformation.getJavaSource());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Caches all base engine events.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private void cacheEvents() {
|
|
||||||
EventHelper.cacheEvent(EngineCrashEvent.class);
|
|
||||||
EventHelper.cacheEvent(EngineShutdownEvent.class);
|
|
||||||
EventHelper.cacheEvent(EngineSoftCrashEvent.class);
|
|
||||||
EventHelper.cacheEvent(InternalEngineShutdownEvent.class);
|
|
||||||
EventHelper.cacheEvent(LogEvent.class);
|
|
||||||
EventHelper.cacheEvent(ThrowableCatchEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collects all subsystems by their {@link EngineSubsystem} annotation.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private void collectSubsystems() {
|
|
||||||
ArrayList<@NotNull DependencySubsystemVector> subsystemsMutable = new ArrayList<>();
|
|
||||||
Object initializedClassRaw;
|
|
||||||
SubsystemClass initializedClass;
|
|
||||||
|
|
||||||
// Check and initialize all classes, get dependency vector and check version, then add to 'subsystemsMutable'
|
|
||||||
for (Class<?> clazz : getRawSubsystemClasses())
|
|
||||||
try {
|
|
||||||
// Create new instance
|
|
||||||
initializedClassRaw = clazz.getDeclaredConstructor().newInstance();
|
|
||||||
initializedClass = null;
|
|
||||||
|
|
||||||
// Check if class implements SubsystemMainClass
|
|
||||||
if (initializedClassRaw instanceof SubsystemClass)
|
|
||||||
initializedClass = (SubsystemClass) initializedClassRaw;
|
|
||||||
else
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update 'subsystems'
|
|
||||||
subsystems = new ImmutableLinkedList<>(subsystemsMutable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of classes which are potentially
|
|
||||||
* eligible for subsystem initialization.
|
|
||||||
*
|
|
||||||
* @return potential subsystem classes
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
private Set<@NotNull Class<?>> getRawSubsystemClasses() {
|
|
||||||
Set<@NotNull Class<?>> classes = new HashSet<>();
|
|
||||||
|
|
||||||
if (EngineInternals.getInstance().getReflectiveClasspathScanning()) {
|
|
||||||
// Scan entire classpath using the Reflections library
|
|
||||||
Reflections reflections = new Reflections(
|
|
||||||
new ConfigurationBuilder()
|
|
||||||
.setUrls(ClasspathHelper.forJavaClassPath())
|
|
||||||
.setScanners(Scanners.TypesAnnotated)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get annotated methods
|
|
||||||
classes = reflections.getTypesAnnotatedWith(EngineSubsystem.class);
|
|
||||||
} else
|
|
||||||
for (String path : EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses())
|
|
||||||
try {
|
|
||||||
Logger.diag("Resolving class " + path);
|
|
||||||
classes.add(Class.forName(path));
|
|
||||||
} catch (ClassNotFoundException exception) {
|
|
||||||
Logger.error("Failed loading subsystem class " + path + ": Class not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return classes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes all subsystems.
|
|
||||||
*
|
|
||||||
* @throws Exception exceptions thrown by the {@link DependencyResolver}
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private void initializeSubsystems() throws Exception {
|
|
||||||
DependencyResolver resolver = new DependencyResolver();
|
|
||||||
LinkedList<DependencySubsystemVector> order = new LinkedList<>();
|
|
||||||
|
|
||||||
// Add vectors
|
|
||||||
resolver.addVector(getDependencyVector());
|
|
||||||
resolver.addVectors(subsystems);
|
|
||||||
|
|
||||||
// Resolve dependencies and get order
|
|
||||||
Logger.diag("Resolving subsystem dependencies");
|
|
||||||
try {
|
|
||||||
for (DependencyVector vector : resolver.resolve().getOrder()) // smol workaround
|
|
||||||
order.add((DependencySubsystemVector) vector);
|
|
||||||
} catch (Throwable throwable) {
|
|
||||||
if (throwable instanceof UnmetDependenciesException exception) {
|
|
||||||
List<@NotNull String> unmetDependencies = exception.getUnmetDependencies();
|
|
||||||
StringBuilder list = new StringBuilder();
|
|
||||||
|
|
||||||
for (String error : unmetDependencies)
|
|
||||||
list
|
|
||||||
.append("\n")
|
|
||||||
.append("- ")
|
|
||||||
.append(error);
|
|
||||||
|
|
||||||
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()));
|
|
||||||
throw throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize subsystems
|
|
||||||
Logger.diag("Initializing engine subsystems");
|
|
||||||
long initTime;
|
|
||||||
for (DependencySubsystemVector vector : subsystems) {
|
|
||||||
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()));
|
|
||||||
throw throwable;
|
|
||||||
}
|
|
||||||
Logger.diag("Initialized subsystem '" + vector.getSubsystemClass().getName() + "' (" + vector.getSubsystemClass().getClass().getName() + ") in " + initTime + "ms");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update 'subsystems'
|
|
||||||
subsystems = new ImmutableLinkedList<>(order);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shuts the engine down.
|
|
||||||
*
|
|
||||||
* @param exitCode code to exit with, from 0-255
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public synchronized void shutdown(@Range(from = 0, to = 255) int exitCode) {
|
|
||||||
if (state == EngineState.UNKNOWN || state == EngineState.SHUTDOWN)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Logger.info("Shutting engine down");
|
|
||||||
if (state != EngineState.CRASHED)
|
|
||||||
state = EngineState.SHUTDOWN;
|
|
||||||
|
|
||||||
// Make engine single-threaded
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.setProperty("sosengine.base.optimizeLogging", "false");
|
|
||||||
properties.setProperty("sosengine.base.optimizeEvents", "false");
|
|
||||||
EngineConfiguration.getInstance().loadConfiguration(properties);
|
|
||||||
|
|
||||||
// Flush log messages
|
|
||||||
LoggingQueue.flush();
|
|
||||||
|
|
||||||
// Disable safety shutdown hook
|
|
||||||
try {
|
|
||||||
Runtime.getRuntime().removeShutdownHook(safetyShutdownHook);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
|
|
||||||
// Send events
|
|
||||||
Logger.verb("Notifying classes about shutdown");
|
|
||||||
new EngineShutdownEvent().callEvent();
|
|
||||||
|
|
||||||
Logger.verb("Notifying subsystems about shutdown");
|
|
||||||
new InternalEngineShutdownEvent().callEvent();
|
|
||||||
|
|
||||||
// Delete scheduled files
|
|
||||||
FileAccess.deleteScheduled();
|
|
||||||
|
|
||||||
// Invoke shutdown handler
|
|
||||||
Logger.verb("Invoking shutdown handler (code " + exitCode + ")");
|
|
||||||
shutdownHandler.shutdown((short) exitCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shuts the engine down.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void shutdown() {
|
|
||||||
if (instance != null)
|
|
||||||
instance.shutdown(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "base";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method does nothing.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void initializeSubsystem() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull DependencyVector getDependencyVector() {
|
|
||||||
return new DependencyVector.Builder()
|
|
||||||
.setIdentifier("engine")
|
|
||||||
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
|
|
||||||
.setVersion(EngineInformation.getVersioningString())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the engine state.
|
|
||||||
*
|
|
||||||
* @param state new state
|
|
||||||
* @throws IllegalAccessException if the caller class is unauthorized
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public void setState(@NotNull EngineState state) throws IllegalAccessException {
|
|
||||||
if (!Thread.currentThread().getStackTrace()[2].getClassName().startsWith("de.staropensource.engine.base."))
|
|
||||||
throw new IllegalAccessException("Only classes inside the \"de.staropensource.engine.base\" package are allowed to call this method.");
|
|
||||||
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default shutdown handler, which causes the JVM to exit.
|
|
||||||
*
|
|
||||||
* @see ShutdownHandler
|
|
||||||
* @see System#exit(int)
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static final class JvmShutdownHandler implements ShutdownHandler {
|
|
||||||
/**
|
|
||||||
* Constructs this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public JvmShutdownHandler() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void shutdown(short exitCode) {
|
|
||||||
// Check if already shutting down
|
|
||||||
try {
|
|
||||||
Thread thread = Thread.ofVirtual().unstarted(() -> {});
|
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(thread);
|
|
||||||
Runtime.getRuntime().removeShutdownHook(thread);
|
|
||||||
} catch (IllegalStateException exception) {
|
|
||||||
Logger.warn("Terminating JVM: Already shutting down, skipping");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.warn("Terminating JVM");
|
|
||||||
Runtime.getRuntime().exit(exitCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,524 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.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.implementable.SubsystemClass;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.logging.backend.async.LoggingThread;
|
|
||||||
import de.staropensource.engine.base.type.EngineState;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import de.staropensource.engine.base.type.vector.Vec2f;
|
|
||||||
import de.staropensource.engine.base.type.vector.Vec2i;
|
|
||||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the base engine configuration.
|
|
||||||
* <p>
|
|
||||||
* This class does not only provide engine settings but is also
|
|
||||||
* responsible for loading them into memory from {@link Properties} objects.
|
|
||||||
* <p>
|
|
||||||
* Now you might ask why we didn't go with the string-based approach.
|
|
||||||
* The answer is simple: It's a maintenance burden.
|
|
||||||
* Having various settings strings scattered across many classes will cause
|
|
||||||
* trouble at some point, which will cause some strings to be undocumented
|
|
||||||
* or have an inconsistent naming scheme. Containing settings as variables in
|
|
||||||
* one centralized place mitigates this.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class EngineConfiguration extends Configuration {
|
|
||||||
/**
|
|
||||||
* Contains the class instance.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the class instance.
|
|
||||||
*
|
|
||||||
* @return class instance unless {@link Engine} is uninitialized
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static EngineConfiguration instance;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the configuration prefix.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the configuration prefix.
|
|
||||||
*
|
|
||||||
* @return property group
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private final @NotNull String group = "sosengine.base.";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 --
|
|
||||||
* 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-alpha0
|
|
||||||
*/
|
|
||||||
private boolean debug;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 --
|
|
||||||
* 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 detailed event logging enabled?
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private boolean debugEvents;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains 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.
|
|
||||||
*
|
|
||||||
* @see Engine
|
|
||||||
* @since v1-alpha5
|
|
||||||
* -- GETTER --
|
|
||||||
* 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 automatically discover and initialize subsystems?
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
private boolean initialPerformSubsystemInitialization;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 --
|
|
||||||
* 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 set of class names to try and initialize as subsystems
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
private Set<@NotNull String> initialIncludeSubsystemClasses;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 #logLevel
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* 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 complain about invalid shortcodes?
|
|
||||||
* @see #getLogLevel()
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private boolean errorShortcodeParser;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 #logPollingSpeed
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* 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 log asynchronously?
|
|
||||||
* @see #getLogPollingSpeed()
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private boolean optimizeLogging;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* 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 emit events asynchronously?
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private boolean optimizeEvents;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* 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 minimum allowed log level
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private LogLevel logLevel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains a comma-separated list of optional
|
|
||||||
* features to add to the final log output.
|
|
||||||
* <p>
|
|
||||||
* Available features (in order of appearance):
|
|
||||||
* <ul>
|
|
||||||
* <li><code>formatting</code></li>
|
|
||||||
* <li><code>runtime</code></li>
|
|
||||||
* <li><code>date</code></li>
|
|
||||||
* <li><code>time</code></li>
|
|
||||||
* <li><code>shortIssuerClass</code></li>
|
|
||||||
* <li><code>moduleName</code></li>
|
|
||||||
* <li><code>moduleVersion</code> (requires <code>moduleName</code>)</li>
|
|
||||||
* <li><code>methodName</code></li>
|
|
||||||
* <li><code>lineNumber</code></li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
* -- GETTER --
|
|
||||||
* 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 optional features to enable
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private Set<@NotNull String> logFeatures;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains how fast the logging thread will
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @see #optimizeLogging
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Contains how fast the logging thread will
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @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 --
|
|
||||||
* 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 truncate class paths?
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private boolean hideFullTypePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs this class.
|
|
||||||
*
|
|
||||||
* @see Engine
|
|
||||||
* @since v1-alpha6
|
|
||||||
*/
|
|
||||||
EngineConfiguration() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
instance = this;
|
|
||||||
|
|
||||||
// Load default configuration
|
|
||||||
loadDefaultConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
protected void matchProperty(@NotNull PropertiesReader parser, @NotNull String property) {
|
|
||||||
try {
|
|
||||||
switch (property) {
|
|
||||||
case "debug" -> debug = parser.getBoolean(group + property);
|
|
||||||
case "debugEvents" -> debugEvents = parser.getBoolean(group + property);
|
|
||||||
|
|
||||||
case "initialPerformSubsystemInitialization" -> initialPerformSubsystemInitialization = parser.getBoolean(group + property);
|
|
||||||
case "initialIncludeSubsystemClasses" -> {
|
|
||||||
initialIncludeSubsystemClasses = new HashSet<>();
|
|
||||||
initialIncludeSubsystemClasses.addAll(Arrays.stream(parser.getString(group + property).split(",")).toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
case "errorShortcodeParser" -> errorShortcodeParser = parser.getBoolean(group + property);
|
|
||||||
|
|
||||||
case "optimizeLogging" -> {
|
|
||||||
optimizeLogging = parser.getBoolean(group + property);
|
|
||||||
|
|
||||||
// Start logging thread automatically
|
|
||||||
if (optimizeLogging && Engine.getInstance().getState() == EngineState.RUNNING) {
|
|
||||||
LoggingThread.startThread(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "optimizeEvents" -> optimizeEvents = parser.getBoolean(group + property);
|
|
||||||
|
|
||||||
case "logLevel" -> {
|
|
||||||
try {
|
|
||||||
logLevel = LogLevel.valueOf(parser.getString(group + property).toUpperCase());
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
Logger.error("The log level '" + parser.getString(group + property) + "' is not valid");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "logFeatures" -> logFeatures = Set.copyOf(Arrays.stream(parser.getString(group + property).split(",")).toList());
|
|
||||||
case "logPollingSpeed" -> logPollingSpeed = parser.getInteger(group + property, true);
|
|
||||||
case "logForceStandardOutput" -> logForceStandardOutput = parser.getBoolean(group + property);
|
|
||||||
|
|
||||||
case "hideFullTypePath" -> hideFullTypePath = parser.getBoolean(group + property);
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
protected void processSettings(@NotNull PropertiesReader parser) {
|
|
||||||
// Disable all debugging switches if 'debug' is disabled
|
|
||||||
if (!debug) {
|
|
||||||
debugEvents = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void loadDefaultConfiguration() {
|
|
||||||
debug = false;
|
|
||||||
debugEvents = false;
|
|
||||||
|
|
||||||
initialPerformSubsystemInitialization = true;
|
|
||||||
initialIncludeSubsystemClasses = new HashSet<>();
|
|
||||||
|
|
||||||
errorShortcodeParser = true;
|
|
||||||
|
|
||||||
optimizeLogging = true;
|
|
||||||
optimizeEvents = true;
|
|
||||||
|
|
||||||
logLevel = LogLevel.INFORMATIONAL;
|
|
||||||
logFeatures = Set.of("formatting", "time", "methodName", "lineNumber");
|
|
||||||
logPollingSpeed = 5;
|
|
||||||
logForceStandardOutput = false;
|
|
||||||
|
|
||||||
hideFullTypePath = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @Nullable Object getSetting(@NotNull String setting) {
|
|
||||||
return switch (setting) {
|
|
||||||
case "debug" -> debug;
|
|
||||||
case "debugEvents" -> debugEvents;
|
|
||||||
|
|
||||||
case "initialPerformSubsystemInitialization" -> initialPerformSubsystemInitialization;
|
|
||||||
case "initialIncludeSubsystemClasses" -> initialIncludeSubsystemClasses;
|
|
||||||
|
|
||||||
case "errorShortcodeParser" -> errorShortcodeParser;
|
|
||||||
|
|
||||||
case "optimizeLogging" -> optimizeLogging;
|
|
||||||
case "optimizeEvents" -> optimizeEvents;
|
|
||||||
|
|
||||||
case "logLevel" -> logLevel;
|
|
||||||
case "logFeatures" -> logFeatures;
|
|
||||||
case "logPollingSpeed" -> logPollingSpeed;
|
|
||||||
case "logForceStandardOutput" -> logForceStandardOutput;
|
|
||||||
|
|
||||||
case "hideFullTypePath" -> hideFullTypePath;
|
|
||||||
default -> null;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,226 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.exception.IllegalAccessException;
|
|
||||||
import de.staropensource.engine.base.implementable.EventListenerCode;
|
|
||||||
import de.staropensource.engine.base.implementable.ShutdownHandler;
|
|
||||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.EventPriority;
|
|
||||||
import de.staropensource.engine.base.type.InternalAccessArea;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class which allows access to the internals
|
|
||||||
* and changing the behaviour of the engine.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class EngineInternals {
|
|
||||||
/**
|
|
||||||
* Contains the class instance.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the class instance.
|
|
||||||
*
|
|
||||||
* @return class instance unless the engine is uninitialized
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static EngineInternals instance;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains all disabled internal access areas.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns all disabled internal access areas.
|
|
||||||
*
|
|
||||||
* @return restricted areas
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private final @NotNull List<@NotNull InternalAccessArea> restrictedAreas = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains whether the engine should reflectively
|
|
||||||
* search the classpath for events or other annotations.
|
|
||||||
* <p>
|
|
||||||
* If disabled, code will either have to manually call
|
|
||||||
* registration methods or certain classes have to
|
|
||||||
* be created in a certain package, depending on the
|
|
||||||
* use case and application.
|
|
||||||
*
|
|
||||||
* @see EventHelper#registerEvent(Class, EventListenerCode)
|
|
||||||
* @see EventHelper#registerEvent(Class, EventListenerCode, EventPriority)
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
private boolean reflectiveClasspathScanning = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha6
|
|
||||||
*/
|
|
||||||
EngineInternals() {
|
|
||||||
// Only allow one instance
|
|
||||||
if (instance == null && Engine.getInstance() != null)
|
|
||||||
instance = this;
|
|
||||||
else
|
|
||||||
Logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether access to the specified area is allowed.
|
|
||||||
*
|
|
||||||
* @param area internal access area to check
|
|
||||||
* @throws IllegalAccessException when restricted
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
private void isRestricted(@NotNull InternalAccessArea area) throws IllegalAccessException {
|
|
||||||
if (restrictedAreas.contains(area))
|
|
||||||
throw new IllegalAccessException("The internal access area " + area.name() + " has been restricted");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restricts access to certain areas of this class.
|
|
||||||
*
|
|
||||||
* @param area area to restrict
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public void restrictAccess(@NotNull InternalAccessArea area) {
|
|
||||||
switch (area) {
|
|
||||||
case ALL -> {
|
|
||||||
List<@NotNull InternalAccessArea> areas = new ArrayList<>(List.of(InternalAccessArea.values()));
|
|
||||||
areas.remove(InternalAccessArea.ALL);
|
|
||||||
areas.remove(InternalAccessArea.ALL_READ);
|
|
||||||
areas.remove(InternalAccessArea.ALL_WRITE);
|
|
||||||
areas.remove(InternalAccessArea.ALL_READ_ESSENTIAL);
|
|
||||||
restrictedAreas.addAll(areas);
|
|
||||||
}
|
|
||||||
case ALL_WRITE -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesWriteOnly()).toList());
|
|
||||||
case ALL_READ -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesReadOnly()).toList());
|
|
||||||
case ALL_READ_ESSENTIAL -> restrictedAreas.addAll(Arrays.stream(InternalAccessArea.valuesEssentialReadOnly()).toList());
|
|
||||||
default -> restrictedAreas.add(area);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Installs or uninstalls the JVM shutdown
|
|
||||||
* hook, which prevents the JVM from exiting
|
|
||||||
* before the engine has fully shut down.
|
|
||||||
* Highly recommended to keep enabled.
|
|
||||||
*
|
|
||||||
* @param status {@code true} to install, {@code false} otherwise
|
|
||||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#SAFETY_SHUTDOWN_HOOK_UPDATE})
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public void installSafetyShutdownHook(boolean status) throws IllegalAccessException {
|
|
||||||
isRestricted(InternalAccessArea.SAFETY_SHUTDOWN_HOOK_UPDATE);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (status)
|
|
||||||
Runtime.getRuntime().addShutdownHook(Engine.getInstance().getSafetyShutdownHook());
|
|
||||||
else
|
|
||||||
Runtime.getRuntime().removeShutdownHook(Engine.getInstance().getSafetyShutdownHook());
|
|
||||||
} catch (IllegalArgumentException | IllegalStateException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the engine's shutdown handler.
|
|
||||||
* The shutdown handler is responsible for
|
|
||||||
* shutting down the JVM safely.
|
|
||||||
*
|
|
||||||
* @return shutdown handler
|
|
||||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#SHUTDOWN_HANDLER_GET})
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public @NotNull ShutdownHandler getShutdownHandler() throws IllegalAccessException {
|
|
||||||
isRestricted(InternalAccessArea.SHUTDOWN_HANDLER_GET);
|
|
||||||
return Engine.getInstance().getShutdownHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the engine's shutdown handler.
|
|
||||||
* The shutdown handler is responsible for
|
|
||||||
* shutting down the JVM safely.
|
|
||||||
*
|
|
||||||
* @param shutdownHandler new shutdown handler
|
|
||||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#SHUTDOWN_HANDLER_UPDATE})
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public void setShutdownHandler(@NotNull ShutdownHandler shutdownHandler) throws IllegalAccessException {
|
|
||||||
isRestricted(InternalAccessArea.SHUTDOWN_HANDLER_UPDATE);
|
|
||||||
Engine.getInstance().setShutdownHandler(shutdownHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the engine should reflectively
|
|
||||||
* search the classpath for events or other annotations.
|
|
||||||
* <p>
|
|
||||||
* If disabled, code will either have to manually call
|
|
||||||
* registration methods or certain classes have to
|
|
||||||
* be created in a certain package, depending on the
|
|
||||||
* use case and application.
|
|
||||||
*
|
|
||||||
* @return reflective classpath scanning flag state
|
|
||||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#REFLECTIVE_CLASSPATH_SCANNING_GET})
|
|
||||||
* @see EventHelper#registerEvent(Class, EventListenerCode)
|
|
||||||
* @see EventHelper#registerEvent(Class, EventListenerCode, EventPriority)
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public boolean getReflectiveClasspathScanning() throws IllegalAccessException {
|
|
||||||
isRestricted(InternalAccessArea.REFLECTIVE_CLASSPATH_SCANNING_GET);
|
|
||||||
return reflectiveClasspathScanning;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overrides whether the engine should reflectively
|
|
||||||
* search the classpath for events or other annotations.
|
|
||||||
* <p>
|
|
||||||
* If disabled, code will either have to manually call
|
|
||||||
* registration methods or certain classes have to
|
|
||||||
* be created in a certain package, depending on the
|
|
||||||
* use case and application.
|
|
||||||
* <p>
|
|
||||||
* Enabling reflective classpath scanning in an unsupported
|
|
||||||
* environment may cause minor to extreme side effects,
|
|
||||||
* including but not limited to <b>bugs, exceptions, engine
|
|
||||||
* or even whole JVM crashes</b>. <i>You have been warned!</i>
|
|
||||||
*
|
|
||||||
* @param reflectiveClasspathScanning new reflective classpath scanning
|
|
||||||
* @throws IllegalAccessException when restricted ({@link InternalAccessArea#REFLECTIVE_CLASSPATH_SCANNING_OVERRIDE})
|
|
||||||
* @see EventHelper#registerEvent(Class, EventListenerCode)
|
|
||||||
* @see EventHelper#registerEvent(Class, EventListenerCode, EventPriority)
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public void overrideReflectiveClasspathScanning(boolean reflectiveClasspathScanning) throws IllegalAccessException {
|
|
||||||
isRestricted(InternalAccessArea.REFLECTIVE_CLASSPATH_SCANNING_OVERRIDE);
|
|
||||||
this.reflectiveClasspathScanning = reflectiveClasspathScanning;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +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.annotation;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks a class as a subsystem main class.
|
|
||||||
* Make sure your subsystem implements {@link SubsystemClass}.
|
|
||||||
*
|
|
||||||
* @see SubsystemClass
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.TYPE)
|
|
||||||
@Documented
|
|
||||||
public @interface EngineSubsystem {}
|
|
|
@ -1,47 +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.event;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Event;
|
|
||||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called in the event of a soft engine crash
|
|
||||||
* ie. when a crash report is thrown but marked
|
|
||||||
* as handled.
|
|
||||||
*
|
|
||||||
* @see Logger#crash(Class, String, String, String, Throwable, boolean)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public final class EngineSoftCrashEvent implements Event {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineSoftCrashEvent() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void callEvent() {
|
|
||||||
EventHelper.invokeAnnotatedMethods(getClass());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.event;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Event;
|
|
||||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called before a new log message is printed.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public final class LogEvent implements Event {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public LogEvent() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @deprecated use the {@code callEvent} method with arguments
|
|
||||||
* @see #callEvent(LogLevel, Class, String, String, String)
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public void callEvent() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emits the event and calls all event listeners.
|
|
||||||
*
|
|
||||||
* @param level level
|
|
||||||
* @param issuerClass issuer class
|
|
||||||
* @param issuerOrigin issuer origin
|
|
||||||
* @param issuerMetadata issuer metadata
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void callEvent(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message) {
|
|
||||||
EventHelper.invokeAnnotatedMethods(getClass(), level, issuerClass, issuerOrigin, issuerMetadata, message);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.event;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Event;
|
|
||||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when an exception is caught by {@link Miscellaneous#executeSafely(Runnable, String)}.
|
|
||||||
*
|
|
||||||
* @see Miscellaneous#executeSafely(Runnable, String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public final class ThrowableCatchEvent implements Event {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public ThrowableCatchEvent() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* @deprecated use the {@code callEvent} method with arguments
|
|
||||||
* @see ThrowableCatchEvent#callEvent(Throwable, String)
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
public void callEvent() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emits the event and calls all event listeners.
|
|
||||||
*
|
|
||||||
* @param throwable caught throwable
|
|
||||||
* @param identifier an identifier given to the runnable
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void callEvent(@NotNull Throwable throwable, @NotNull String identifier) {
|
|
||||||
EventHelper.invokeAnnotatedMethods(getClass(), throwable, identifier);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +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.exception;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.type.Tristate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when converting a {@link Tristate} into a {@link Boolean} fails.
|
|
||||||
* <p>
|
|
||||||
* This exception inherits {@link RuntimeException} on purpose,
|
|
||||||
* as sometimes you may sure/have already validated that the
|
|
||||||
* {@link Tristate} is not {@link Tristate#UNSET}.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class TristateConversionException extends RuntimeException {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public TristateConversionException() {
|
|
||||||
super("Tristate.UNSET cannot be converted into a boolean");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +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.exception;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when a sequence of if checks or switch cases fail unexpectedly.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class UnexpectedCheckEndException extends RuntimeException {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param checkOccurrence the sequence of checks that failed
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public UnexpectedCheckEndException(@NotNull String checkOccurrence) {
|
|
||||||
super("A sequence of if checks or switch cases failed unexpectedly while " + checkOccurrence);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public UnexpectedCheckEndException() {
|
|
||||||
super("A sequence of if checks or switch cases failed unexpectedly");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +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.exception.dependency;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.type.DependencyVector;
|
|
||||||
import de.staropensource.engine.base.utility.DependencyResolver;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when the {@link DependencyResolver} cannot resolve one
|
|
||||||
* or more {@link DependencyVector}s due to unmet dependencies.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public class UnmetDependenciesException extends Exception {
|
|
||||||
/**
|
|
||||||
* Contains the unmet dependencies list supplied to the constructor.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the unmet dependencies list supplied to the constructor.
|
|
||||||
*
|
|
||||||
* @return unmet dependencies list
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
private final @NotNull List<@NotNull String> unmetDependencies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @param unmetDependencies map of all unmet dependencies
|
|
||||||
* @see #unmetDependencies
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public UnmetDependenciesException(@NotNull List<@NotNull String> unmetDependencies) {
|
|
||||||
this.unmetDependencies = unmetDependencies;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +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.exception.reflection;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.type.reflection.ClassType;
|
|
||||||
import de.staropensource.engine.base.utility.ListFormatter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when the invoked method does not apply to the type of the class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class IncompatibleTypeException extends RuntimeException {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param methodName name of the method that failed
|
|
||||||
* @param requiredClassType class type received by the method
|
|
||||||
* @param compatibleTypes class types the method is compatible with
|
|
||||||
*/
|
|
||||||
public IncompatibleTypeException(@NotNull String methodName, @NotNull ClassType requiredClassType, @NotNull ClassType @NotNull [] compatibleTypes) {
|
|
||||||
super("The method ReflectionClass#" + methodName + " only applies to type(s) " + ListFormatter.formatArray(compatibleTypes) + ", not " + requiredClassType.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param methodName name of the method that failed
|
|
||||||
* @param requiredClassType class type received by the method
|
|
||||||
* @param compatibleType class type the method is compatible with
|
|
||||||
*/
|
|
||||||
public IncompatibleTypeException(@NotNull String methodName, @NotNull ClassType requiredClassType, @NotNull ClassType compatibleType) {
|
|
||||||
super("The method ReflectionClass#" + methodName + " only applies to type(s) " + ListFormatter.formatArray(new ClassType[]{ compatibleType }) + ", not " + requiredClassType.name());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +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.exception.reflection;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when trying to call an instance (non-static) method from a static context.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class InstanceMethodFromStaticContextException extends Exception {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param methodName name of the method
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public InstanceMethodFromStaticContextException(@NotNull String methodName) {
|
|
||||||
super("Method " + methodName + " could not be called as the method is non-static and was called from a static context");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +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.exception.reflection;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.reflection.ReflectionClass;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when a field could not be found.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class InvalidFieldException extends Exception {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param clazz caller {@link ReflectionClass}
|
|
||||||
* @param fieldName name of the invalid field
|
|
||||||
*/
|
|
||||||
public InvalidFieldException(@NotNull ReflectionClass clazz, @NotNull String fieldName) {
|
|
||||||
super("Invalid field name \"" + fieldName + "\" in class " + clazz.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +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.exception.reflection;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.reflection.ReflectionClass;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when a method could not be found.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class InvalidMethodException extends Exception {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param clazz caller {@link ReflectionClass}
|
|
||||||
* @param fieldName name of the invalid method
|
|
||||||
*/
|
|
||||||
public InvalidMethodException(@NotNull ReflectionClass clazz, @NotNull String fieldName) {
|
|
||||||
super("Invalid method name \"" + fieldName + "\" in class " + clazz.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +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.exception.reflection;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when a method could not be found due to an invalid method signature.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public class InvalidMethodSignatureException extends Exception {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param methodName method name
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public InvalidMethodSignatureException(@NotNull String methodName) {
|
|
||||||
super("Method " + methodName + " has a different method signature");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +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.exception.reflection;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown if access to some class, method or field has been denied.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public class NoAccessException extends Exception {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param type {@code class}, {@code method} or {@code field}
|
|
||||||
* @param name class, method or field name
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public NoAccessException(@NotNull String type, @NotNull String name) {
|
|
||||||
super("Access to " + type + " " + name + " has been denied");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +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.exception.reflection;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when an exception is thrown by a static initializer.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public class StaticInitializerException extends Exception {
|
|
||||||
/**
|
|
||||||
* Contains the throwable thrown by the static initializer.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the throwable thrown by the static initializer.
|
|
||||||
*
|
|
||||||
* @return throwable thrown by the static initializer
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private final @NotNull Throwable throwable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param throwable throwable thrown by the static initializer
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public StaticInitializerException(@NotNull Throwable throwable) {
|
|
||||||
this.throwable = throwable;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exceptions related to reflection.
|
|
||||||
*
|
|
||||||
* @see de.staropensource.engine.base.reflection
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.exception.reflection;
|
|
|
@ -1,41 +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.exception.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when trying to compare a {@link VersioningSystem} against another
|
|
||||||
* {@link VersioningSystem}, which it does not support.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public class IncompatibleVersioningSystemException extends RuntimeException {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param required required versioning system ie. the versioning system throwing this error
|
|
||||||
* @param found found versioning system ie. the incompatible one
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public IncompatibleVersioningSystemException(VersioningSystem required, VersioningSystem found) {
|
|
||||||
super("The versioning system " + required + " is incompatible with " + found);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,104 +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.exception.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when an invalid version string is supplied
|
|
||||||
* to an implementation of {@link VersioningSystem}.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public class InvalidVersionStringException extends Exception {
|
|
||||||
/**
|
|
||||||
* Contains the throwable supplied to the constructor.
|
|
||||||
*
|
|
||||||
* @see #InvalidVersionStringException(VersioningSystem, String, Throwable)
|
|
||||||
* @see #InvalidVersionStringException(VersioningSystem, String, String, Throwable)
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the throwable supplied by the constructor.
|
|
||||||
*
|
|
||||||
* @return throwable
|
|
||||||
* @see #InvalidVersionStringException(VersioningSystem, String, Throwable)
|
|
||||||
* @see #InvalidVersionStringException(VersioningSystem, String, String, Throwable)
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final @Nullable Throwable throwable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param versioningSystem versioning system that is unable to parse version strings
|
|
||||||
* @param versionString version string {@code a}
|
|
||||||
* @param message some error message
|
|
||||||
* @param throwable throwable that caused the parsing error
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public InvalidVersionStringException(@NotNull VersioningSystem versioningSystem, @NotNull String versionString, @NotNull String message, @NotNull Throwable throwable) {
|
|
||||||
super("Versioning system " + versioningSystem.getName() + " can't parse version string \"" + versionString + "\": " + message);
|
|
||||||
this.throwable = throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param versioningSystem versioning system that is unable to parse version strings
|
|
||||||
* @param versionString version string {@code a}
|
|
||||||
* @param message some error message
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public InvalidVersionStringException(@NotNull VersioningSystem versioningSystem, @NotNull String versionString, @NotNull String message) {
|
|
||||||
super("Versioning system " + versioningSystem.getName() + " can't parse version string \"" + versionString + "\": " + message);
|
|
||||||
throwable = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param versioningSystem versioning system that is unable to parse version strings
|
|
||||||
* @param versionString version string {@code a}
|
|
||||||
* @param throwable throwable that caused the parsing error
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public InvalidVersionStringException(@NotNull VersioningSystem versioningSystem, @NotNull String versionString, @NotNull Throwable throwable) {
|
|
||||||
super("Versioning system " + versioningSystem.getName() + " can't parse version string \"" + versionString + "\"");
|
|
||||||
this.throwable = throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this exception.
|
|
||||||
*
|
|
||||||
* @param versioningSystem versioning system that is unable to parse version strings
|
|
||||||
* @param versionString version string {@code a}
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public InvalidVersionStringException(@NotNull VersioningSystem versioningSystem, @NotNull String versionString) {
|
|
||||||
super("Versioning system " + versioningSystem.getName() + " can't parse version string \"" + versionString + "\"");
|
|
||||||
this.throwable = null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exceptions thrown by implementations of {@link de.staropensource.engine.base.implementable.VersioningSystem}s.
|
|
||||||
*
|
|
||||||
* @see de.staropensource.engine.base.implementable.VersioningSystem
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.exception.versioning;
|
|
|
@ -1,132 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for implementing configuration classes.
|
|
||||||
* <p>
|
|
||||||
* Configuration classes use {@link Properties} objects to modify
|
|
||||||
* their settings as they can be supplied to the JVM's arguments
|
|
||||||
* and can be written to and read from during runtime.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public abstract class Configuration {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this abstract class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
protected Configuration() {
|
|
||||||
// Load default configuration
|
|
||||||
loadDefaultConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all settings from the specified {@link Properties} object.
|
|
||||||
* Unless you want to override settings, consider invoking {@link #loadDefaultConfiguration()} first.
|
|
||||||
*
|
|
||||||
* @param properties {@link Properties} to read from
|
|
||||||
* @see #loadDefaultConfiguration()
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public void loadConfiguration(@NotNull Properties properties) {
|
|
||||||
PropertiesReader parser = new PropertiesReader(properties);
|
|
||||||
|
|
||||||
// Loop through all properties
|
|
||||||
for (String property : properties.stringPropertyNames()) {
|
|
||||||
// Check if property name starts with group
|
|
||||||
if (!property.startsWith(getGroup()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Remove group
|
|
||||||
property = property.substring(getGroup().length());
|
|
||||||
|
|
||||||
// Overwrite matching settings
|
|
||||||
try {
|
|
||||||
matchProperty(parser, property);
|
|
||||||
} catch (NullPointerException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
processSettings(parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all settings from the system properties.
|
|
||||||
* Useful if you want to allow the user to modify settings at startup.
|
|
||||||
*
|
|
||||||
* @see #loadConfiguration(Properties)
|
|
||||||
* @see System#getProperties()
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public void loadConfiguration() {
|
|
||||||
loadConfiguration(System.getProperties());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns prefix properties must begin with.
|
|
||||||
*
|
|
||||||
* @return property group
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public abstract @NotNull String getGroup();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the default subsystem configuration.
|
|
||||||
*
|
|
||||||
* @see #loadConfiguration()
|
|
||||||
* @see #loadConfiguration(Properties)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public abstract void loadDefaultConfiguration();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Matches the given {@code property} against all settings.
|
|
||||||
* If a match has been found, the setting will be overwritten with the property's value.
|
|
||||||
*
|
|
||||||
* @param parser matching {@link PropertiesReader}
|
|
||||||
* @param property property to match
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
protected abstract void matchProperty(@NotNull PropertiesReader parser, @NotNull String property);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows the implementor to process all settings and potentially
|
|
||||||
* modify them before {@link #loadConfiguration(Properties)} returns.
|
|
||||||
*
|
|
||||||
* @param parser matching {@link PropertiesReader}
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
protected abstract void processSettings(@NotNull PropertiesReader parser);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a configuration setting.
|
|
||||||
*
|
|
||||||
* @param setting setting name
|
|
||||||
* @return setting's value or {@code null} if not found
|
|
||||||
*/
|
|
||||||
public abstract @Nullable Object getSetting(@NotNull String setting);
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.helper.EventHelper;
|
|
||||||
import de.staropensource.engine.base.type.EventPriority;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used by {@link EventHelper} to execute event listeners.
|
|
||||||
*
|
|
||||||
* @see Runnable
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public abstract class EventListenerCode {
|
|
||||||
/**
|
|
||||||
* Contains the priority of this
|
|
||||||
* event listener.
|
|
||||||
* <p>
|
|
||||||
* Set automatically by {@link EventHelper},
|
|
||||||
* do not change this manually.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public @NotNull EventPriority priority = EventPriority.DEFAULT;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this abstract class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
protected EventListenerCode() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes the event listener.
|
|
||||||
*
|
|
||||||
* @param arguments arguments passed along by the event
|
|
||||||
* @throws Exception exceptions thrown
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public abstract void run(Object... arguments) throws Exception;
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for implementing custom logger implementations.
|
|
||||||
*
|
|
||||||
* @see Logger#setLoggingAdapter(LoggingAdapter)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public interface LoggingAdapter {
|
|
||||||
/**
|
|
||||||
* Prints a log message.
|
|
||||||
*
|
|
||||||
* @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
|
|
||||||
*/
|
|
||||||
void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format);
|
|
||||||
}
|
|
|
@ -1,218 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.exception.ParserException;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* else, for example, ANSI escape codes.
|
|
||||||
* <p>
|
|
||||||
* The following shortcodes are available and can be used:
|
|
||||||
* <ul>
|
|
||||||
* <li>reset</li>
|
|
||||||
* <li>fg:[black,red,green,yellow,blue,magenta,cyan,white]</li>
|
|
||||||
* <li>bg:[black,red,green,yellow,blue,magenta,cyan,white]</li>
|
|
||||||
* <li>bold</li>
|
|
||||||
* <li>italic</li>
|
|
||||||
* <li>strikethrough</li>
|
|
||||||
* <li>underline</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public abstract class ShortcodeParser {
|
|
||||||
/**
|
|
||||||
* Contains a list of components the parsed text is made out of.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns a list of components the parsed text is made out of.
|
|
||||||
*
|
|
||||||
* @return component list
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
protected final @NotNull LinkedList<String> components;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* @throws ParserException on error
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
protected ShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
|
||||||
components = parse(string, ignoreInvalidEscapes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the input string and returns a list
|
|
||||||
* of components the text is made out of.
|
|
||||||
*
|
|
||||||
* @param string string to parse
|
|
||||||
* @param ignoreInvalidEscapes if {@code true}, will ignore and treat invalid escapes as text
|
|
||||||
* @return list of components
|
|
||||||
* @throws ParserException on error
|
|
||||||
* @see EngineConfiguration#errorShortcodeParser
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
protected @NotNull LinkedList<@NotNull String> parse(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
|
||||||
LinkedList<String> components = new LinkedList<>(); // List of components
|
|
||||||
boolean tagActive = false; // Indicates that a tag is being parsed
|
|
||||||
boolean escape = false; // Indicates whether the last character was a \ character
|
|
||||||
StringBuilder part = new StringBuilder(); // Temporary string. May be a tag, may be regular text
|
|
||||||
|
|
||||||
// Iterate through every character
|
|
||||||
for (char character : string.toCharArray()) {
|
|
||||||
// Escaping
|
|
||||||
if (escape) {
|
|
||||||
if (character == '\\' || character == '<')
|
|
||||||
part.append(character);
|
|
||||||
else if (!(character == 'r' || character == 'n'))
|
|
||||||
if (ignoreInvalidEscapes)
|
|
||||||
part.append("\\").append(character);
|
|
||||||
else
|
|
||||||
throw new ParserException("Invalid escape \\" + character);
|
|
||||||
|
|
||||||
escape = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (character == '\\') {
|
|
||||||
escape = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tagActive) {
|
|
||||||
// A tag is being parsed
|
|
||||||
if (character == '>') {
|
|
||||||
// Tag is ending, disable tag parsing
|
|
||||||
tagActive = false;
|
|
||||||
|
|
||||||
// fg:*
|
|
||||||
if (part.toString().startsWith("fg:"))
|
|
||||||
if (isValidColor(part.substring(3).toUpperCase()))
|
|
||||||
components.add("COLOR:FOREGROUND:" + part.substring(3).toUpperCase());
|
|
||||||
else {
|
|
||||||
// Complain about invalid shortcode
|
|
||||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
|
||||||
Logger.sarn("Invalid shortcode: " + part);
|
|
||||||
|
|
||||||
// Convert tag regular text
|
|
||||||
components.add("TEXT:" + "<" + part + ">");
|
|
||||||
}
|
|
||||||
// bg:*
|
|
||||||
else if (part.toString().startsWith("bg:"))
|
|
||||||
if (isValidColor(part.substring(3).toUpperCase()))
|
|
||||||
components.add("COLOR:BACKGROUND:" + part.substring(3).toUpperCase());
|
|
||||||
else {
|
|
||||||
// Complain about invalid shortcode
|
|
||||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
|
||||||
Logger.sarn("Invalid shortcode: " + part);
|
|
||||||
|
|
||||||
// Convert tag regular text
|
|
||||||
components.add("TEXT:" + "<" + part + ">");
|
|
||||||
}
|
|
||||||
// bold
|
|
||||||
else if (part.toString().equals("bold"))
|
|
||||||
components.add("ATTRIBUTE:BOLD");
|
|
||||||
// italic
|
|
||||||
else if (part.toString().equals("italic"))
|
|
||||||
components.add("ATTRIBUTE:ITALIC");
|
|
||||||
// strikethrough
|
|
||||||
else if (part.toString().equals("strikethrough"))
|
|
||||||
components.add("ATTRIBUTE:STRIKETHROUGH");
|
|
||||||
// underline
|
|
||||||
else if (part.toString().equals("underline"))
|
|
||||||
components.add("ATTRIBUTE:UNDERLINE");
|
|
||||||
// blink
|
|
||||||
else if (part.toString().equals("blink"))
|
|
||||||
components.add("ATTRIBUTE:BLINK");
|
|
||||||
// reset
|
|
||||||
else if (part.toString().equals("reset"))
|
|
||||||
components.add("RESET");
|
|
||||||
|
|
||||||
// error case
|
|
||||||
else {
|
|
||||||
// Complain about invalid shortcode
|
|
||||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isErrorShortcodeParser())
|
|
||||||
Logger.sarn("Invalid shortcode: " + part);
|
|
||||||
|
|
||||||
// Convert tag regular text
|
|
||||||
components.add("TEXT:" + "<" + part + ">");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Empty 'part'
|
|
||||||
part = new StringBuilder();
|
|
||||||
} else
|
|
||||||
// Tag has not ended yet, add character to 'part'
|
|
||||||
// It bloats the code to do it with StringBuilder
|
|
||||||
part.append(character);
|
|
||||||
} else {
|
|
||||||
// Regular text is being parsed
|
|
||||||
if (character == '<') {
|
|
||||||
if (!part.isEmpty()) {
|
|
||||||
// Tag is starting, insert previous text
|
|
||||||
components.add("TEXT:" + part);
|
|
||||||
part = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
tagActive = true; // Enable tag processing
|
|
||||||
} else
|
|
||||||
// Regular text, add character to 'part'
|
|
||||||
// It bloats the code to do it with StringBuilder
|
|
||||||
part.append(character);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processing ended, insert leftover text
|
|
||||||
if (!part.isEmpty())
|
|
||||||
components.add("TEXT:" + part);
|
|
||||||
|
|
||||||
return components;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the specified color is valid
|
|
||||||
*
|
|
||||||
* @return {@code true} if valid, {@code false} otherwise
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private boolean isValidColor(@NotNull String color) {
|
|
||||||
return switch (color.toLowerCase(Locale.ROOT)) {
|
|
||||||
case "black", "white", "red",
|
|
||||||
"green", "blue", "yellow",
|
|
||||||
"magenta", "cyan" -> true;
|
|
||||||
default -> false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for custom shutdown handlers.
|
|
||||||
* <p>
|
|
||||||
* Shutdown handlers are responsible for shutting down
|
|
||||||
* the platform safely after the engine has shut down.
|
|
||||||
*
|
|
||||||
* @see Engine#setShutdownHandler(ShutdownHandler)
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public interface ShutdownHandler {
|
|
||||||
/**
|
|
||||||
* Executes the shutdown handler.
|
|
||||||
*
|
|
||||||
* @param exitCode exit code
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
void shutdown(@Range(from = 0, to = 255) short exitCode);
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine;
|
|
||||||
import de.staropensource.engine.base.annotation.EngineSubsystem;
|
|
||||||
import de.staropensource.engine.base.annotation.EventListener;
|
|
||||||
import de.staropensource.engine.base.event.InternalEngineShutdownEvent;
|
|
||||||
import de.staropensource.engine.base.type.DependencyVector;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract class for building subsystem main classes.
|
|
||||||
*
|
|
||||||
* @see EngineSubsystem
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public abstract class SubsystemClass {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this abstract class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
protected SubsystemClass() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of the subsystem.
|
|
||||||
*
|
|
||||||
* @return subsystem name
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public abstract @NotNull String getName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the subsystem.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public abstract void initializeSubsystem();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a matching {@link DependencyVector}.
|
|
||||||
* Used for dependency resolution during startup.
|
|
||||||
*
|
|
||||||
* @return matching {@link DependencyVector} for the subsystem
|
|
||||||
* @throws IllegalStateException when building the DependencyVector fails, see {@link DependencyVector.Builder#build()}
|
|
||||||
* @see DependencyVector
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public abstract @NotNull DependencyVector getDependencyVector() throws IllegalStateException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called on engine shutdown.
|
|
||||||
*
|
|
||||||
* @see Engine#shutdown()
|
|
||||||
* @see Engine#shutdown(int)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@EventListener(event = InternalEngineShutdownEvent.class)
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
protected static void shutdownSubsystem() {}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for building a versioning system (parser).
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public interface VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Returns the name of the versioning system.
|
|
||||||
*
|
|
||||||
* @return versioning system name
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@NotNull String getName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compares a {@link VersioningSystem} with another.
|
|
||||||
*
|
|
||||||
* @param version {@link VersioningSystem} to compare against
|
|
||||||
* @return {@code 0} if the supplied version is bigger, {@code 1} if equal and {@code 2} if smaller
|
|
||||||
* @throws IncompatibleVersioningSystemException incompatible with the supplied versioning system
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
int compare(@NotNull VersioningSystem version) throws IncompatibleVersioningSystemException;
|
|
||||||
}
|
|
|
@ -1,257 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementable.helper;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.EngineInternals;
|
|
||||||
import de.staropensource.engine.base.annotation.EventListener;
|
|
||||||
import de.staropensource.engine.base.event.LogEvent;
|
|
||||||
import de.staropensource.engine.base.exception.reflection.InstanceMethodFromStaticContextException;
|
|
||||||
import de.staropensource.engine.base.exception.reflection.InvalidMethodSignatureException;
|
|
||||||
import de.staropensource.engine.base.exception.reflection.NoAccessException;
|
|
||||||
import de.staropensource.engine.base.exception.reflection.StaticInitializerException;
|
|
||||||
import de.staropensource.engine.base.implementable.Event;
|
|
||||||
import de.staropensource.engine.base.implementable.EventListenerCode;
|
|
||||||
import de.staropensource.engine.base.internal.implementation.EventListenerMethod;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.EventPriority;
|
|
||||||
import de.staropensource.engine.base.utility.ListFormatter;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.reflections.Reflections;
|
|
||||||
import org.reflections.scanners.Scanners;
|
|
||||||
import org.reflections.util.ClasspathHelper;
|
|
||||||
import org.reflections.util.ConfigurationBuilder;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simplifies event logging and calling.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
public final class EventHelper {
|
|
||||||
/**
|
|
||||||
* Holds all cached events.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
private static final @NotNull Map<@NotNull Class<? extends Event>, LinkedList<@NotNull EventListenerCode>> cachedEventListeners = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
private EventHelper() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new {@link Event}.
|
|
||||||
* <p>
|
|
||||||
* This method does nothing if classpath searching is disabled.
|
|
||||||
*
|
|
||||||
* @param event {@link Event} to register for
|
|
||||||
* @param eventListener {@link EventListenerCode} to register
|
|
||||||
* @param priority priority of the listener
|
|
||||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static synchronized void registerEvent(@NotNull Class<? extends Event> event, @NotNull EventListenerCode eventListener, @NotNull EventPriority priority) {
|
|
||||||
if (EngineInternals.getInstance().getReflectiveClasspathScanning())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Update 'eventListener' priority
|
|
||||||
eventListener.priority = priority;
|
|
||||||
|
|
||||||
// Check if event already exists in map
|
|
||||||
// If not, create entry with a LinkedList
|
|
||||||
if (cachedEventListeners.containsKey(event))
|
|
||||||
if (cachedEventListeners.get(event).contains(eventListener))
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
cachedEventListeners.get(event).add(eventListener);
|
|
||||||
else {
|
|
||||||
LinkedList<@NotNull EventListenerCode> list = new LinkedList<>();
|
|
||||||
list.add(eventListener);
|
|
||||||
cachedEventListeners.put(event, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.diag("Registered event listener " + eventListener + " for event " + event + " with priority " + priority.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new {@link Event}.
|
|
||||||
* <p>
|
|
||||||
* This method does nothing if classpath searching is disabled.
|
|
||||||
*
|
|
||||||
* @param event {@link Event} to register for
|
|
||||||
* @param eventListener {@link EventListenerCode} to register
|
|
||||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static void registerEvent(@NotNull Class<? extends Event> event, @NotNull EventListenerCode eventListener) {
|
|
||||||
registerEvent(event, eventListener, EventPriority.DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Re-)Caches all event listeners for some {@link Event}.
|
|
||||||
* <p>
|
|
||||||
* This method does nothing if classpath searching is enabled.
|
|
||||||
*
|
|
||||||
* @param event event to (re-)cache. Set to {@code null} to recompute all cached events
|
|
||||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static synchronized void cacheEvent(@Nullable Class<? extends Event> event) {
|
|
||||||
if (!EngineInternals.getInstance().getReflectiveClasspathScanning())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event == null)
|
|
||||||
for (Class<? extends Event> cachedEvent : cachedEventListeners.keySet())
|
|
||||||
cacheEvent(cachedEvent);
|
|
||||||
else {
|
|
||||||
LinkedList<@NotNull EventListenerCode> annotatedMethods = getAnnotatedMethods(event);
|
|
||||||
|
|
||||||
if (cachedEventListeners.containsKey(event))
|
|
||||||
cachedEventListeners.replace(event, annotatedMethods);
|
|
||||||
else
|
|
||||||
cachedEventListeners.put(event, annotatedMethods);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an event from the event listener cache.
|
|
||||||
* <p>
|
|
||||||
* This method does nothing if classpath searching is enabled.
|
|
||||||
*
|
|
||||||
* @param event event to uncache. Set to {@code null} to clear the entire cache
|
|
||||||
* @see EngineInternals#getReflectiveClasspathScanning()
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static synchronized void uncacheEvent(@Nullable Class<? extends Event> event) {
|
|
||||||
if (!EngineInternals.getInstance().getReflectiveClasspathScanning())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event == null)
|
|
||||||
cachedEventListeners.clear();
|
|
||||||
else
|
|
||||||
cachedEventListeners.remove(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invokes all event listeners.
|
|
||||||
*
|
|
||||||
* @param event event class
|
|
||||||
* @param arguments arguments to pass to event listeners
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static void invokeAnnotatedMethods(@NotNull Class<? extends Event> event, Object... arguments) {
|
|
||||||
if (event != LogEvent.class && EngineConfiguration.getInstance().isDebugEvents())
|
|
||||||
if (arguments.length == 0)
|
|
||||||
Logger.diag("Event " + event.getName() + " was emitted");
|
|
||||||
else
|
|
||||||
Logger.diag("Event " + event.getName() + " was emitted, passing arguments " + ListFormatter.formatArray(arguments));
|
|
||||||
|
|
||||||
Runnable eventCode = () -> {
|
|
||||||
for (EventListenerCode eventListener : getAnnotatedMethods(event)) {
|
|
||||||
try {
|
|
||||||
eventListener.run(arguments);
|
|
||||||
} catch (NoAccessException exception) {
|
|
||||||
Logger.warn("Event listener " + eventListener + " could not be called as the method could not be accessed");
|
|
||||||
} catch (InvalidMethodSignatureException exception) {
|
|
||||||
Logger.warn("Event listener " + eventListener + " has an invalid method signature");
|
|
||||||
} catch (InvocationTargetException exception) {
|
|
||||||
Logger.crash("Event listener " + eventListener + " threw a throwable", exception.getTargetException(), true);
|
|
||||||
} catch (InstanceMethodFromStaticContextException exception) {
|
|
||||||
Logger.warn("Event listener " + eventListener + " is not static. Event listener methods must be static for them to be called.");
|
|
||||||
} catch (StaticInitializerException exception) {
|
|
||||||
Logger.crash("Event listener " + eventListener + " could not be called as the static initializer failed", exception.getThrowable(), true);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Logger.crash("Event listener " + eventListener + " could not be called as an error occurred during reflection", exception, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (EngineConfiguration.getInstance().isOptimizeEvents())
|
|
||||||
Thread
|
|
||||||
.ofVirtual()
|
|
||||||
.name("Event " + event.getName())
|
|
||||||
.start(eventCode);
|
|
||||||
else
|
|
||||||
eventCode.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all {@link EventListener}s listening on some event.
|
|
||||||
* The classpath will be scanned for listeners, unless cached results exist and {@code !forceScanning}.
|
|
||||||
*
|
|
||||||
* @param event event class
|
|
||||||
* @param forceScanning forces scanning the classpath for listeners. not recommended due to a huge performance penalty
|
|
||||||
* @return list of event listeners
|
|
||||||
* @see #cacheEvent(Class)
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static @NotNull LinkedList<EventListenerCode> getAnnotatedMethods(@NotNull Class<? extends Event> event, boolean forceScanning) {
|
|
||||||
LinkedList<EventListenerCode> eventListeners = new LinkedList<>();
|
|
||||||
|
|
||||||
if (!EngineInternals.getInstance().getReflectiveClasspathScanning())
|
|
||||||
return Objects.requireNonNullElse(cachedEventListeners.get(event), eventListeners);
|
|
||||||
|
|
||||||
if (forceScanning || !cachedEventListeners.containsKey(event)) {
|
|
||||||
Reflections reflections = new Reflections(
|
|
||||||
new ConfigurationBuilder()
|
|
||||||
.setUrls(ClasspathHelper.forJavaClassPath())
|
|
||||||
.setScanners(Scanners.MethodsAnnotated)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get annotated methods
|
|
||||||
Set<@NotNull Method> annotatedMethods = reflections.getMethodsAnnotatedWith(EventListener.class);
|
|
||||||
|
|
||||||
// Sort event listeners not listening for the specified event out
|
|
||||||
for (Method method : annotatedMethods)
|
|
||||||
if (method.getAnnotation(EventListener.class).event() == event)
|
|
||||||
eventListeners.add(new EventListenerMethod(method));
|
|
||||||
|
|
||||||
// Sort list after event priority
|
|
||||||
eventListeners.sort(Comparator.comparing(method -> Objects.requireNonNull(((EventListenerMethod) method).getAnnotation(EventListener.class)).priority()));
|
|
||||||
} else
|
|
||||||
// Event listeners are cached and !forceScanning, return cached results
|
|
||||||
eventListeners = cachedEventListeners.get(event);
|
|
||||||
|
|
||||||
return eventListeners;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all {@link EventListener}s listening on some event.
|
|
||||||
* The classpath will be scanned for listeners, unless cached results exist.
|
|
||||||
*
|
|
||||||
* @param event event class
|
|
||||||
* @return list of event listeners
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public static @NotNull LinkedList<EventListenerCode> getAnnotatedMethods(@NotNull Class<? extends Event> event) {
|
|
||||||
return getAnnotatedMethods(event, false);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.logging;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeParser;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints log messages to the console, without any fancy colors or formatting.
|
|
||||||
*
|
|
||||||
* @see Logger
|
|
||||||
* @see LoggingAdapter
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public class PlainLoggingAdapter implements LoggingAdapter {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public PlainLoggingAdapter() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
|
|
||||||
format = new EmptyShortcodeParser(format, true).getClean();
|
|
||||||
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
|
|
||||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isLogForceStandardOutput())
|
|
||||||
System.out.println(format);
|
|
||||||
else
|
|
||||||
System.err.println(format);
|
|
||||||
else
|
|
||||||
System.out.println(format);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.logging;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An implementation of {@link LoggingAdapter}, which does nothing.
|
|
||||||
* Useful if you want to silence engine startup messages.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public class QuietLoggingAdapter implements LoggingAdapter {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public QuietLoggingAdapter() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.logging;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints log messages to the console, without performing any message changes.
|
|
||||||
* Will reveal shortcodes as they will not be replaced.
|
|
||||||
*
|
|
||||||
* @see Logger
|
|
||||||
* @see LoggingAdapter
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public class RawLoggingAdapter implements LoggingAdapter {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public RawLoggingAdapter() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
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().isLogForceStandardOutput())
|
|
||||||
System.out.println(format);
|
|
||||||
else
|
|
||||||
System.err.println(format);
|
|
||||||
else
|
|
||||||
System.out.println(format);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A set of built-in {@link de.staropensource.engine.base.implementable.LoggingAdapter}s.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.implementation.logging;
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.shortcode;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.ShortcodeParser;
|
|
||||||
import de.staropensource.engine.base.exception.ParserException;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cleans the string of any tags.
|
|
||||||
*
|
|
||||||
* @see ShortcodeParser
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
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-alpha8
|
|
||||||
*/
|
|
||||||
public EmptyShortcodeParser(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException {
|
|
||||||
super(string, ignoreInvalidEscapes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the parsed string without any tags.
|
|
||||||
*
|
|
||||||
* @return cleaned input string
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public @NotNull String getClean() {
|
|
||||||
StringBuilder output = new StringBuilder();
|
|
||||||
|
|
||||||
for (String component : components)
|
|
||||||
if (component.startsWith("TEXT:"))
|
|
||||||
output.append(component.substring(5));
|
|
||||||
|
|
||||||
return output.toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Classes which convert data.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.implementation.shortcode;
|
|
|
@ -1,154 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a four-numbered versioning system, where an application or work is versioning by four arbitrary numbers.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class FourNumberVersioningSystem implements VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Contains the first number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the first number vector.
|
|
||||||
*
|
|
||||||
* @return first number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the second number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the second number vector.
|
|
||||||
*
|
|
||||||
* @return second number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the third number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the third number vector.
|
|
||||||
*
|
|
||||||
* @return third number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the fourth number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the fourth number vector.
|
|
||||||
*
|
|
||||||
* @return fourth number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number4;
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "n4";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the specified version string
|
|
||||||
* and if successful, return a new instance.
|
|
||||||
*
|
|
||||||
* @param versionString version string to parse
|
|
||||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
||||||
*/
|
|
||||||
public FourNumberVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException {
|
|
||||||
String[] separatorList = new String[]{ ".", "-" };
|
|
||||||
String separator = Miscellaneous.getSeparator(versionString, separatorList, 3);
|
|
||||||
|
|
||||||
// Escape separator or throw error if invalid
|
|
||||||
switch (separator) {
|
|
||||||
case "." -> separator = "\\.";
|
|
||||||
case null -> throw new InvalidVersionStringException(this, versionString, "No matching separator could be found. Required are either three dots ('.') or hyphens ('-')");
|
|
||||||
default -> {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split the version string at every separator
|
|
||||||
String[] versionStringSplit = versionString.split(separator);
|
|
||||||
|
|
||||||
// Convert to integers
|
|
||||||
try {
|
|
||||||
this.number1 = Integer.parseUnsignedInt(versionStringSplit[0]);
|
|
||||||
this.number2 = Integer.parseUnsignedInt(versionStringSplit[1]);
|
|
||||||
this.number3 = Integer.parseUnsignedInt(versionStringSplit[2]);
|
|
||||||
this.number4 = Integer.parseUnsignedInt(versionStringSplit[3]);
|
|
||||||
} catch (NumberFormatException exception) {
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Failed converting one of the vectors to an integer", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
|
||||||
if (versionInterface instanceof FourNumberVersioningSystem version) {
|
|
||||||
if (version.getNumber1() < number1)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber1() > number1)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getNumber2() < number2)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber2() > number2)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getNumber3() < number3)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber3() > number3)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getNumber4() < number4)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber4() > number4)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a one-numbered versioning system, where an application or work is versioned by one arbitrary number.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class OneNumberVersioningSystem implements VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Contains the number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the number vector.
|
|
||||||
*
|
|
||||||
* @return number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number;
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "n1";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the specified version string
|
|
||||||
* and if successful, return a new instance.
|
|
||||||
*
|
|
||||||
* @param versionString version string to parse
|
|
||||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
||||||
*/
|
|
||||||
public OneNumberVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException {
|
|
||||||
// Convert to integers
|
|
||||||
try {
|
|
||||||
this.number = Integer.parseUnsignedInt(versionString);
|
|
||||||
} catch (NumberFormatException exception) {
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Failed converting the version string into an integer", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
|
||||||
if (versionInterface instanceof OneNumberVersioningSystem version) {
|
|
||||||
if (version.getNumber() < number)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber() > number)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
} else
|
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,223 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the semantic versioning system (version 2.0.0), where an application
|
|
||||||
* or work is versioning by a {@code MAJOR} version, {@code MINOR} version,
|
|
||||||
* {@code PATCH} version and optionally, a pre-release vector and a build number.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class SemanticVersioningSystem implements VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Contains the {@code MAJOR} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code MAJOR} vector.
|
|
||||||
*
|
|
||||||
* @return {@code MAJOR} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int major;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code MINOR} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code MINOR} vector.
|
|
||||||
*
|
|
||||||
* @return {@code MINOR} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int minor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code PATCH} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code PATCH} vector.
|
|
||||||
*
|
|
||||||
* @return {@code PATCH} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int patch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code PRERELEASE} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code PRERELEASE} vector.
|
|
||||||
*
|
|
||||||
* @return {@code PRERELEASE} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final @Nullable String prerelease;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code BUILD} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code BUILD} vector.
|
|
||||||
*
|
|
||||||
* @return {@code BUILD} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int build;
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "Semantic";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the specified version string
|
|
||||||
* and if successful, return a new instance.
|
|
||||||
*
|
|
||||||
* @param versionString version string to parse
|
|
||||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
||||||
*/
|
|
||||||
public SemanticVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException {
|
|
||||||
String[] separatorList = new String[]{ "." };
|
|
||||||
String separator = Miscellaneous.getSeparator(versionString, separatorList, 2);
|
|
||||||
|
|
||||||
// Escape separator or throw error if invalid
|
|
||||||
switch (separator) {
|
|
||||||
case "." -> separator = "\\.";
|
|
||||||
case null -> throw new InvalidVersionStringException(this, versionString, "No matching separator could be found. Required are two dots ('.')");
|
|
||||||
default -> {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split the version string at every separator
|
|
||||||
List<String> versionStringSplit = new ArrayList<>(Arrays.stream(versionString.split(separator)).toList());
|
|
||||||
|
|
||||||
// Get pre-release and build vectors
|
|
||||||
String build = null;
|
|
||||||
String prerelease = null;
|
|
||||||
if (versionStringSplit.get(2).contains("+")) { // Build vector
|
|
||||||
int position = versionStringSplit.get(2).indexOf("+");
|
|
||||||
build = versionStringSplit.get(2).substring(position + 1);
|
|
||||||
versionStringSplit.set(2, versionStringSplit.get(2).substring(0, position));
|
|
||||||
}
|
|
||||||
if (versionStringSplit.get(2).contains("-")) {
|
|
||||||
int position = versionStringSplit.get(2).indexOf("-");
|
|
||||||
prerelease = versionStringSplit.get(2).substring(position + 1);
|
|
||||||
versionStringSplit.set(2, versionStringSplit.get(2).substring(0, position));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to integers
|
|
||||||
try {
|
|
||||||
this.major = Integer.parseUnsignedInt(versionStringSplit.get(0));
|
|
||||||
this.minor = Integer.parseUnsignedInt(versionStringSplit.get(1));
|
|
||||||
this.patch = Integer.parseUnsignedInt(versionStringSplit.get(2));
|
|
||||||
this.prerelease = prerelease;
|
|
||||||
if (build == null)
|
|
||||||
this.build = 0;
|
|
||||||
else
|
|
||||||
this.build = Integer.parseUnsignedInt(build);
|
|
||||||
} catch (NumberFormatException exception) {
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Failed converting one of the vectors to an integer", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
|
||||||
if (versionInterface instanceof SemanticVersioningSystem version) {
|
|
||||||
if (version.getMajor() < major)
|
|
||||||
return 0;
|
|
||||||
if (version.getMajor() > major)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getMinor() < minor)
|
|
||||||
return 0;
|
|
||||||
if (version.getMinor() > minor)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getPatch() < patch)
|
|
||||||
return 0;
|
|
||||||
if (version.getPatch() > patch)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getPrerelease() == null && prerelease != null)
|
|
||||||
return 2;
|
|
||||||
else if (version.getPrerelease() != null && prerelease == null)
|
|
||||||
return 0;
|
|
||||||
else if (version.getPrerelease() != null)
|
|
||||||
switch (prerelease) {
|
|
||||||
case "alpha" -> {
|
|
||||||
switch (version.getPrerelease()) {
|
|
||||||
case "beta", "releasecandidate", "release-candidate", "rc" -> {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "beta" -> {
|
|
||||||
switch (version.getPrerelease()) {
|
|
||||||
case "alpha" -> {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case "releasecandidate", "release-candidate", "rc" -> {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "releasecandidate", "release-candidate", "rc" -> {
|
|
||||||
switch (version.getPrerelease()) {
|
|
||||||
case "alpha", "beta" -> {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version.getBuild() < build)
|
|
||||||
return 0;
|
|
||||||
if (version.getBuild() > build)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,264 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
|
||||||
import de.staropensource.engine.base.type.VersionType;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the StarOpenSource versioning system (version 2), where an application
|
|
||||||
* or work is versioning by a {@code VERSION} vector, {@code TYPE} version type,
|
|
||||||
* {@code TYPERELEASE} vector and optionally, a {@code FORK} vector and
|
|
||||||
* {@code COMPANION} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class StarOpenSourceVersioningSystem implements VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Contains the {@code VERSION} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code VERSION} vector.
|
|
||||||
*
|
|
||||||
* @return {@code VERSION} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code TYPE} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code TYPE} vector.
|
|
||||||
*
|
|
||||||
* @return {@code TYPE} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final VersionType type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code TYPERELEASE} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code TYPERELEASE}- vector.
|
|
||||||
*
|
|
||||||
* @return {@code TYPERELEASE} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int typerelease;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@code COMPANION} vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the {@code COMPANION} vector.
|
|
||||||
*
|
|
||||||
* @return {@code COMPANION} vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final @Nullable String companion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the FORK vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the FORK vector.
|
|
||||||
*
|
|
||||||
* @return FORK vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final String fork;
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "StarOpenSource";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the specified version string
|
|
||||||
* and if successful, return a new instance.
|
|
||||||
*
|
|
||||||
* @param versionString version string to parse
|
|
||||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
||||||
*/
|
|
||||||
public StarOpenSourceVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException {
|
|
||||||
// Split the version string at every separator
|
|
||||||
StringBuilder charSequence = new StringBuilder();
|
|
||||||
/*
|
|
||||||
* 0 = 'v'
|
|
||||||
* 1 = version vector
|
|
||||||
* 3 = type vector
|
|
||||||
* 4 = typerelease vector
|
|
||||||
* 5 = companion vector
|
|
||||||
* 6 = fork vector
|
|
||||||
*/
|
|
||||||
int parsingId = 0;
|
|
||||||
List<String> versionStringSplit = new ArrayList<>();
|
|
||||||
String companion = null;
|
|
||||||
String fork = null;
|
|
||||||
|
|
||||||
// Iterate through all characters
|
|
||||||
for (Character character : versionString.toCharArray()) {
|
|
||||||
switch (parsingId) {
|
|
||||||
case 0 -> { // 'v' character
|
|
||||||
if (character != 'v')
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Does not start with the character 'v'");
|
|
||||||
parsingId++;
|
|
||||||
}
|
|
||||||
case 1 -> { // Version vector
|
|
||||||
if (character == '-') {
|
|
||||||
versionStringSplit.add(charSequence.toString());
|
|
||||||
charSequence = new StringBuilder();
|
|
||||||
parsingId++;
|
|
||||||
} else
|
|
||||||
charSequence.append(character);
|
|
||||||
}
|
|
||||||
case 2 -> { // Type vector
|
|
||||||
charSequence.append(character);
|
|
||||||
|
|
||||||
if (charSequence.toString().equals("alpha") || charSequence.toString().equals("beta") || charSequence.toString().equals("release")) {
|
|
||||||
versionStringSplit.add(charSequence.toString());
|
|
||||||
charSequence = new StringBuilder();
|
|
||||||
parsingId++;
|
|
||||||
} else if (versionStringSplit.size() == 2 && versionStringSplit.get(1).contains("releasec") && charSequence.toString().equals("andidate")) {
|
|
||||||
versionStringSplit.set(1, versionStringSplit.get(1) + charSequence);
|
|
||||||
charSequence = new StringBuilder();
|
|
||||||
parsingId++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 3 -> { // Typerelease vector
|
|
||||||
if (character == '-' || character == '+') {
|
|
||||||
versionStringSplit.add(charSequence.toString());
|
|
||||||
charSequence = new StringBuilder();
|
|
||||||
parsingId++;
|
|
||||||
if (character == '+')
|
|
||||||
parsingId++;
|
|
||||||
} else
|
|
||||||
if (character == 'c' && versionStringSplit.get(1).equals("release")) {
|
|
||||||
versionStringSplit.set(1, versionStringSplit.get(1) + character);
|
|
||||||
parsingId--;
|
|
||||||
} else
|
|
||||||
charSequence.append(character);
|
|
||||||
}
|
|
||||||
case 4 -> { // Fork vector
|
|
||||||
if (character == '+') {
|
|
||||||
fork = charSequence.toString();
|
|
||||||
charSequence = new StringBuilder();
|
|
||||||
parsingId++;
|
|
||||||
} else
|
|
||||||
charSequence.append(character);
|
|
||||||
}
|
|
||||||
case 5 -> // Companion vector
|
|
||||||
charSequence.append(character);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (parsingId) {
|
|
||||||
case 0, 1, 2 -> throw new InvalidVersionStringException(this, versionString, "Required vectors not found");
|
|
||||||
case 3 -> {
|
|
||||||
if (charSequence.isEmpty())
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Required vectors not found");
|
|
||||||
else {
|
|
||||||
if (versionStringSplit.size() == 2 && versionStringSplit.get(1).contains("releasec") && charSequence.toString().equals("andidate")) {
|
|
||||||
versionStringSplit.set(1, versionStringSplit.get(1) + charSequence);
|
|
||||||
} else
|
|
||||||
versionStringSplit.add(charSequence.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 5 -> {
|
|
||||||
if (charSequence.isEmpty())
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Fork vector not found");
|
|
||||||
else
|
|
||||||
fork = charSequence.toString();
|
|
||||||
}
|
|
||||||
case 6 -> {
|
|
||||||
if (charSequence.isEmpty())
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Companion vector not found");
|
|
||||||
else
|
|
||||||
companion = charSequence.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rewrite type
|
|
||||||
if (versionStringSplit.get(1).equals("releasecandidate"))
|
|
||||||
versionStringSplit.set(1, "RELEASE_CANDIDATE");
|
|
||||||
else
|
|
||||||
versionStringSplit.set(1, versionStringSplit.get(1).toUpperCase(Locale.ROOT));
|
|
||||||
|
|
||||||
|
|
||||||
// Update variables
|
|
||||||
try {
|
|
||||||
this.version = Integer.parseUnsignedInt(versionStringSplit.get(0));
|
|
||||||
this.type = VersionType.valueOf(versionStringSplit.get(1));
|
|
||||||
this.typerelease = Integer.parseUnsignedInt(versionStringSplit.get(2));
|
|
||||||
this.companion = companion;
|
|
||||||
this.fork = fork;
|
|
||||||
} catch (NumberFormatException exception) {
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Failed converting one of the vectors to an integer", exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.version == 0)
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "The version vector must start at 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
|
||||||
if (versionInterface instanceof StarOpenSourceVersioningSystem versionCompare) {
|
|
||||||
if (versionCompare.getVersion() < this.version)
|
|
||||||
return 0;
|
|
||||||
if (versionCompare.getVersion() > this.version)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (type.compareTo(versionCompare.getType()) > 0)
|
|
||||||
return 0;
|
|
||||||
if (type.compareTo(versionCompare.getType()) < 0)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (versionCompare.getTyperelease() < typerelease)
|
|
||||||
return 0;
|
|
||||||
if (versionCompare.getTyperelease() > typerelease)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,136 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a three-numbered versioning system, where an application or work is versioning by three arbitrary numbers.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class ThreeNumberVersioningSystem implements VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Contains the first number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the first number vector.
|
|
||||||
*
|
|
||||||
* @return first number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the second number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the second number vector.
|
|
||||||
*
|
|
||||||
* @return second number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the third number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the third number vector.
|
|
||||||
*
|
|
||||||
* @return third number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number3;
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "n3";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the specified version string
|
|
||||||
* and if successful, return a new instance.
|
|
||||||
*
|
|
||||||
* @param versionString version string to parse
|
|
||||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
||||||
*/
|
|
||||||
public ThreeNumberVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException {
|
|
||||||
String[] separatorList = new String[]{ ".", "-" };
|
|
||||||
String separator = Miscellaneous.getSeparator(versionString, separatorList, 2);
|
|
||||||
|
|
||||||
// Escape separator or throw error if invalid
|
|
||||||
switch (separator) {
|
|
||||||
case "." -> separator = "\\.";
|
|
||||||
case null -> throw new InvalidVersionStringException(this, versionString, "No matching separator could be found. Required are either two dots ('.') or hyphens ('-')");
|
|
||||||
default -> {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split the version string at every separator
|
|
||||||
String[] versionStringSplit = versionString.split(separator);
|
|
||||||
|
|
||||||
// Convert to integers
|
|
||||||
try {
|
|
||||||
this.number1 = Integer.parseUnsignedInt(versionStringSplit[0]);
|
|
||||||
this.number2 = Integer.parseUnsignedInt(versionStringSplit[1]);
|
|
||||||
this.number3 = Integer.parseUnsignedInt(versionStringSplit[2]);
|
|
||||||
} catch (NumberFormatException exception) {
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Failed converting one of the vectors to an integer", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
|
||||||
if (versionInterface instanceof ThreeNumberVersioningSystem version) {
|
|
||||||
if (version.getNumber1() < number1)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber1() > number1)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getNumber2() < number2)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber2() > number2)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getNumber3() < number3)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber3() > number3)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,118 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.VersioningSystem;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.IncompatibleVersioningSystemException;
|
|
||||||
import de.staropensource.engine.base.exception.versioning.InvalidVersionStringException;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Range;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a two-numbered versioning system, where an application or work is versioning by two arbitrary numbers.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class TwoNumberVersioningSystem implements VersioningSystem {
|
|
||||||
/**
|
|
||||||
* Contains the first number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the first number vector.
|
|
||||||
*
|
|
||||||
* @return first number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the second number vector.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the second number vector.
|
|
||||||
*
|
|
||||||
* @return second number vector
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final int number2;
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String getName() {
|
|
||||||
return "n2";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the specified version string
|
|
||||||
* and if successful, return a new instance.
|
|
||||||
*
|
|
||||||
* @param versionString version string to parse
|
|
||||||
* @throws InvalidVersionStringException if the version string is invalid
|
|
||||||
*/
|
|
||||||
public TwoNumberVersioningSystem(@NotNull String versionString) throws InvalidVersionStringException {
|
|
||||||
String[] separatorList = new String[]{ ".", "-" };
|
|
||||||
String separator = Miscellaneous.getSeparator(versionString, separatorList, 1);
|
|
||||||
|
|
||||||
// Escape separator or throw error if invalid
|
|
||||||
switch (separator) {
|
|
||||||
case "." -> separator = "\\.";
|
|
||||||
case null -> throw new InvalidVersionStringException(this, versionString, "No matching separator could be found. Required are either one dot ('.') or hyphen ('-')");
|
|
||||||
default -> {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split the version string at every separator
|
|
||||||
String[] versionStringSplit = versionString.split(separator);
|
|
||||||
|
|
||||||
// Convert to integers
|
|
||||||
try {
|
|
||||||
this.number1 = Integer.parseUnsignedInt(versionStringSplit[0]);
|
|
||||||
this.number2 = Integer.parseUnsignedInt(versionStringSplit[1]);
|
|
||||||
} catch (NumberFormatException exception) {
|
|
||||||
throw new InvalidVersionStringException(this, versionString, "Failed converting one of the vectors to an integer", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Range(from = 0, to = 2)
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VersioningSystem versionInterface) throws IncompatibleVersioningSystemException {
|
|
||||||
if (versionInterface instanceof TwoNumberVersioningSystem version) {
|
|
||||||
if (version.getNumber1() < number1)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber1() > number1)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
if (version.getNumber2() < number2)
|
|
||||||
return 0;
|
|
||||||
if (version.getNumber2() > number2)
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
throw new IncompatibleVersioningSystemException(this, versionInterface);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Built-in versioning systems which
|
|
||||||
* can be used to represent versions of some work.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.implementation.versioning;
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.internal.implementation;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.EventListenerCode;
|
|
||||||
import de.staropensource.engine.base.reflection.Reflect;
|
|
||||||
import de.staropensource.engine.base.reflection.ReflectionMethod;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface specifically for executing event listener methods.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public final class EventListenerMethod extends EventListenerCode {
|
|
||||||
/**
|
|
||||||
* Contains the method to call and get.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
private final @NotNull ReflectionMethod method;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @param method method to execute
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public EventListenerMethod(@NotNull Method method) {
|
|
||||||
this.method = Reflect.reflectOn(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public void run(@Nullable Object @NotNull [] arguments) throws Exception {
|
|
||||||
method.invoke(arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forwards {@link ReflectionMethod#getAnnotation(Class)}
|
|
||||||
* to the internal {@link ReflectionMethod} instance.
|
|
||||||
*
|
|
||||||
* @param <T> annotation
|
|
||||||
* @param annotation annotation to get
|
|
||||||
* @return annotation or {@code null} on error
|
|
||||||
* @see ReflectionMethod#getAnnotation(Class)
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
public <T extends Annotation> @Nullable T getAnnotation(@NotNull Class<T> annotation) {
|
|
||||||
try {
|
|
||||||
return method.getAnnotation(annotation);
|
|
||||||
} catch (NullPointerException exception) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "method " + method.getMethod().getDeclaringClass().getName() + "#" + method.getName();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interfaces and abstract classes which can be used for implementing classes.
|
|
||||||
*
|
|
||||||
* @since v1-alpha5
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.internal.implementation;
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_branch} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitBranch implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitBranch() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_branch%", EngineInformation.getGitBranch());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_header} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitHeader implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitHeader() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_header%", EngineInformation.getGitCommitHeader());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_id_short} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitIdShort implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitIdShort() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_id_short%", EngineInformation.getGitCommitIdentifierShort());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_time_day} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitTimeDay implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitTimeDay() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_time_day%", String.valueOf(EngineInformation.getGitCommitTime().getDayOfMonth()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_time_hour} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitTimeHour implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitTimeHour() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_time_hour%", String.valueOf(EngineInformation.getGitCommitTime().getHour()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_time_minute} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitTimeMinute implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitTimeMinute() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_time_minute%", String.valueOf(EngineInformation.getGitCommitTime().getMinute()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_time_month} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitTimeMonth implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitTimeMonth() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_time_month%", String.valueOf(EngineInformation.getGitCommitTime().getMonth()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_time_second} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitTimeSecond implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitTimeSecond() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_time_second%", String.valueOf(EngineInformation.getGitCommitTime().getSecond()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commit_time_year} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitTimeYear implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitTimeYear() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commit_time_year%", String.valueOf(EngineInformation.getGitCommitTime().getYear()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_commits} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommits implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommits() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_commits%", String.valueOf(EngineInformation.getGitCommitCount()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_committer_email} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitCommitterEmail implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitCommitterEmail() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_committer_email%", EngineInformation.getGitCommitterEmail());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_git_dirty} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineGitDirty implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public EngineGitDirty() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_git_dirty%", String.valueOf(EngineInformation.isGitDirty()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +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;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.Placeholder;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the {@code engine_version_codename} placeholder.
|
|
||||||
*
|
|
||||||
* @see Placeholder
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused" })
|
|
||||||
public final class EngineVersionCodename implements Placeholder {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this event.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public EngineVersionCodename() {}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public @NotNull String replace(@NotNull String text) {
|
|
||||||
return text.replace("%engine_version_codename%", EngineInformation.getVersioningCodename());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Built-in placeholders for various things.
|
|
||||||
* <p>
|
|
||||||
* Placeholder classes in subpackages may only be targeted for
|
|
||||||
* specific use cases.
|
|
||||||
*
|
|
||||||
* @see de.staropensource.engine.base.utility.PlaceholderEngine
|
|
||||||
* @see de.staropensource.engine.base.implementable.Placeholder
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.internal.implementation.placeholder;
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Engine-internal stuff, not part of the API.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.internal;
|
|
|
@ -1,205 +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.reflection;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.exception.reflection.NoAccessException;
|
|
||||||
import de.staropensource.engine.base.reflection.ReflectionField;
|
|
||||||
import de.staropensource.engine.base.reflection.ReflectionMethod;
|
|
||||||
|
|
||||||
import java.lang.reflect.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for widening access permissions on reflection objects.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public final class ReflectionAccessWidener {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private ReflectionAccessWidener() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows access to an {@link AccessibleObject}.
|
|
||||||
* <p>
|
|
||||||
* Stolen from <a href="https://github.com/jOOQ/jOOR">the jOOR library</a>.
|
|
||||||
* All credits to them.
|
|
||||||
*
|
|
||||||
* @param <T> extender of {@link AccessibleObject}
|
|
||||||
* @param accessible object to allow access to
|
|
||||||
*/
|
|
||||||
public static <T extends AccessibleObject> void allowAccess(T accessible) {
|
|
||||||
if (accessible == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (accessible instanceof Member member)
|
|
||||||
if (Modifier.isPublic(member.getModifiers()) && Modifier.isPublic(member.getDeclaringClass().getModifiers()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
//noinspection deprecation // no, it's what we want
|
|
||||||
if (!accessible.isAccessible())
|
|
||||||
accessible.setAccessible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlocks modifications to some field.
|
|
||||||
*
|
|
||||||
* @param reflectionField {@link ReflectionField} to unlock
|
|
||||||
* @return updated modifiers. pass those to {@link #lockModifications(ReflectionField, int)} to lock the field again
|
|
||||||
* @throws NoSuchFieldException if the {@code modifiers} field is missing
|
|
||||||
* @throws NoAccessException if access to the field has been denied
|
|
||||||
* @see #lockModifications(ReflectionField, int)
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static int unlockModifications(ReflectionField reflectionField) throws NoSuchFieldException, NoAccessException {
|
|
||||||
int updatedModifiers = 0;
|
|
||||||
Field field = reflectionField.getField();
|
|
||||||
|
|
||||||
Field modifiersField;
|
|
||||||
try {
|
|
||||||
modifiersField = field.getClass().getDeclaredField("modifiers");
|
|
||||||
} catch (NoSuchFieldException exception) {
|
|
||||||
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
if ((field.getModifiers() & Modifier.FINAL) == Modifier.FINAL)
|
|
||||||
updatedModifiers = ~Modifier.FINAL;
|
|
||||||
if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC)
|
|
||||||
updatedModifiers = updatedModifiers & ~Modifier.STATIC;
|
|
||||||
|
|
||||||
try {
|
|
||||||
modifiersField.setInt(field, field.getModifiers() & ~updatedModifiers);
|
|
||||||
} catch (IllegalAccessException exception) {
|
|
||||||
throw new NoAccessException("field", field.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatedModifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlocks modifications to some method.
|
|
||||||
*
|
|
||||||
* @param reflectionMethod {@link ReflectionMethod} to unlock
|
|
||||||
* @return updated modifiers. pass those to {@link #lockModifications(ReflectionMethod, int)} to lock the method again
|
|
||||||
* @throws NoSuchFieldException if the {@code modifiers} field is missing
|
|
||||||
* @throws NoAccessException if access to the method has been denied
|
|
||||||
* @see #lockModifications(ReflectionMethod, int)
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static int unlockModifications(ReflectionMethod reflectionMethod) throws NoSuchFieldException, NoAccessException {
|
|
||||||
Method method = reflectionMethod.getMethod();
|
|
||||||
int updatedModifiers = method.getModifiers();
|
|
||||||
|
|
||||||
Field modifiersField;
|
|
||||||
try {
|
|
||||||
modifiersField = method.getClass().getDeclaredField("modifiers");
|
|
||||||
} catch (NoSuchFieldException exception) {
|
|
||||||
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
if (Modifier.isFinal(method.getModifiers()))
|
|
||||||
updatedModifiers = ~Modifier.FINAL;
|
|
||||||
if (Modifier.isStatic(method.getModifiers()))
|
|
||||||
updatedModifiers = updatedModifiers & ~Modifier.STATIC;
|
|
||||||
if (!Modifier.isPublic(method.getModifiers())) {
|
|
||||||
if (Modifier.isProtected(method.getModifiers()))
|
|
||||||
updatedModifiers = updatedModifiers & ~Modifier.PROTECTED;
|
|
||||||
if (Modifier.isPrivate(method.getModifiers()))
|
|
||||||
updatedModifiers = updatedModifiers & ~Modifier.PRIVATE;
|
|
||||||
|
|
||||||
updatedModifiers = updatedModifiers & ~Modifier.PUBLIC;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
modifiersField.setInt(method, method.getModifiers() & ~updatedModifiers);
|
|
||||||
} catch (IllegalAccessException exception) {
|
|
||||||
throw new NoAccessException("method", method.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatedModifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Locks modifications to some field.
|
|
||||||
*
|
|
||||||
* @param reflectionField {@link ReflectionField} to lock
|
|
||||||
* @param updatedModifiers original modifiers
|
|
||||||
* @throws NoSuchFieldException if the {@code modifiers} field is missing
|
|
||||||
* @throws NoAccessException if access to the field has been denied
|
|
||||||
* @see #unlockModifications(ReflectionField)
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static void lockModifications(ReflectionField reflectionField, int updatedModifiers) throws NoSuchFieldException, NoAccessException {
|
|
||||||
Field field = reflectionField.getField();
|
|
||||||
|
|
||||||
Field modifiersField;
|
|
||||||
try {
|
|
||||||
modifiersField = field.getClass().getDeclaredField("modifiers");
|
|
||||||
} catch (NoSuchFieldException exception) {
|
|
||||||
throw new NoSuchFieldException("Field \"modifiers\" not present inside field " + field.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
modifiersField.setInt(field, field.getModifiers() & ~updatedModifiers);
|
|
||||||
} catch (IllegalAccessException exception) {
|
|
||||||
throw new NoAccessException("field", field.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiersField.setAccessible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Locks modifications to some method.
|
|
||||||
*
|
|
||||||
* @param reflectionMethod {@link ReflectionMethod} to lock
|
|
||||||
* @param updatedModifiers original modifiers
|
|
||||||
* @throws NoSuchFieldException if the {@code modifiers} field is missing
|
|
||||||
* @throws NoAccessException if access to the method has been denied
|
|
||||||
* @see #unlockModifications(ReflectionMethod)
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static void lockModifications(ReflectionMethod reflectionMethod, int updatedModifiers) throws NoSuchFieldException, NoAccessException {
|
|
||||||
Method method = reflectionMethod.getMethod();
|
|
||||||
|
|
||||||
Field modifiersField;
|
|
||||||
try {
|
|
||||||
modifiersField = method.getClass().getDeclaredField("modifiers");
|
|
||||||
} catch (NoSuchFieldException exception) {
|
|
||||||
throw new NoSuchFieldException("Field \"modifiers\" not present inside method " + method.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiersField.setAccessible(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
modifiersField.setInt(method, method.getModifiers() & ~updatedModifiers);
|
|
||||||
} catch (IllegalAccessException exception) {
|
|
||||||
throw new NoAccessException("method", method.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
modifiersField.setAccessible(false);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility classes used during reflection.
|
|
||||||
*
|
|
||||||
* @see de.staropensource.engine.base.reflection.Reflect
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.internal.reflection;
|
|
|
@ -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.type;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.implementable.SubsystemClass;
|
|
||||||
import de.staropensource.engine.base.type.DependencyVector;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a dependency vector with an additional {@code mainClass} field.
|
|
||||||
* Used during the subsystem initialization process to easily determine the
|
|
||||||
* initialization order without much extra code and performance loss.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class DependencySubsystemVector extends DependencyVector {
|
|
||||||
/**
|
|
||||||
* Contains the associated {@link SubsystemClass}.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the associated {@link SubsystemClass}.
|
|
||||||
*
|
|
||||||
* @return associated {@link SubsystemClass}
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
private final SubsystemClass subsystemClass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
* Reuses an existing {@link DependencyVector}.
|
|
||||||
*
|
|
||||||
* @param vector existing dependency vector to reuse
|
|
||||||
* @param subsystemClass {@link SubsystemClass} to associate
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
public DependencySubsystemVector(@NotNull DependencyVector vector, @NotNull SubsystemClass subsystemClass) {
|
|
||||||
super(subsystemClass.getName(), vector.getVersioningSystem(), vector.getVersion(), vector.getDependencies(), vector.getProvides());
|
|
||||||
this.subsystemClass = subsystemClass;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Engine-internal data types, usually for passing
|
|
||||||
* data around classes more efficiently.
|
|
||||||
*
|
|
||||||
* @since v1-alpha1
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.internal.type;
|
|
|
@ -1,416 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.logging;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.implementable.LoggingAdapter;
|
|
||||||
import de.staropensource.engine.base.implementation.logging.PlainLoggingAdapter;
|
|
||||||
import de.staropensource.engine.base.internal.type.QueuedLogCall;
|
|
||||||
import de.staropensource.engine.base.logging.backend.CrashHandler;
|
|
||||||
import de.staropensource.engine.base.logging.backend.Filterer;
|
|
||||||
import de.staropensource.engine.base.logging.backend.Processor;
|
|
||||||
import de.staropensource.engine.base.logging.backend.async.LoggingQueue;
|
|
||||||
import de.staropensource.engine.base.type.immutable.ImmutableArrayList;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.intellij.lang.annotations.RegExp;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The frontend class for sos!engine's logging system.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "JavadocDeclaration" })
|
|
||||||
public final class Logger {
|
|
||||||
/**
|
|
||||||
* Refers to the active {@link LoggingAdapter} that is used to process and print log messages.
|
|
||||||
*
|
|
||||||
* @see LoggingAdapter
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the active {@link LoggingAdapter}.
|
|
||||||
*
|
|
||||||
* @return active {@link LoggingAdapter}
|
|
||||||
* @see LoggingAdapter
|
|
||||||
* @since v1-alpha0
|
|
||||||
* -- SETTER --
|
|
||||||
* Sets the active {@link LoggingAdapter}.
|
|
||||||
*
|
|
||||||
* @param loggingAdapter new active {@link LoggingAdapter}
|
|
||||||
* @see LoggingAdapter
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private static @NotNull LoggingAdapter loggingAdapter = new PlainLoggingAdapter();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private Logger() {}
|
|
||||||
|
|
||||||
// -----> Internal management methods
|
|
||||||
// These methods forward calls to internal methods so
|
|
||||||
// these can be accessed without exporting a whole package.
|
|
||||||
/**
|
|
||||||
* Handles incoming log calls and either
|
|
||||||
* processes them directly or queues them in.
|
|
||||||
* <p>
|
|
||||||
* **This is an internal method. Use with care.**
|
|
||||||
*
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void handle(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
|
||||||
Processor.handle(level, issuer, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flushes the logging queue.
|
|
||||||
* <p>
|
|
||||||
* **This is an internal method. Use with care.**
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void flush() {
|
|
||||||
LoggingQueue.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallows one or multiple classes.
|
|
||||||
*
|
|
||||||
* @param regex regex
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void disallowClass(@RegExp @NotNull String regex) {
|
|
||||||
Filterer.disallowClass(regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallows one or multiple modules.
|
|
||||||
*
|
|
||||||
* @param regex regex
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void disallowModule(@RegExp @NotNull String regex) {
|
|
||||||
Filterer.disallowModule(regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallows one or multiple messages.
|
|
||||||
*
|
|
||||||
* @param regex regex
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void disallowMessage(@RegExp @NotNull String regex) {
|
|
||||||
Filterer.disallowMessage(regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----> Redirection methods
|
|
||||||
/**
|
|
||||||
* Redirects regular log messages.
|
|
||||||
*
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void redirectCall(@NotNull LogLevel level, @NotNull String message) {
|
|
||||||
Processor.handle(level, Thread.currentThread().getStackTrace()[3], message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirects crash calls.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @param throwable {@link Throwable} which caused the error
|
|
||||||
* @param fatal if to terminate the engine
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void redirectCall(@NotNull String message, @Nullable Throwable throwable, boolean fatal) {
|
|
||||||
CrashHandler.handleCrash(Thread.currentThread().getStackTrace()[3], message, throwable, fatal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----> Frontend methods
|
|
||||||
/**
|
|
||||||
* Logs a diagnostic message.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void diag(@NotNull String message) {
|
|
||||||
redirectCall(LogLevel.DIAGNOSTIC, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs a verbose message.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void verb(@NotNull String message) {
|
|
||||||
redirectCall(LogLevel.VERBOSE, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs a silent warning.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void sarn(@NotNull String message) {
|
|
||||||
redirectCall(LogLevel.SILENT_WARNING, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs an informational message.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void info(@NotNull String message) {
|
|
||||||
redirectCall(LogLevel.INFORMATIONAL, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs a warning.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void warn(@NotNull String message) {
|
|
||||||
redirectCall(LogLevel.WARNING, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs an error.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void error(@NotNull String message) {
|
|
||||||
redirectCall(LogLevel.ERROR, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a crash report and optionally crashes the engine.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @param throwable {@link Throwable} which caused the crash
|
|
||||||
* @param fatal terminates the engine if {@code true}
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void crash(@NotNull String message, @NotNull Throwable throwable, boolean fatal) {
|
|
||||||
redirectCall(message, throwable, fatal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a crash report and optionally crashes the engine.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @param throwable {@link Throwable} which caused the crash
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void crash(@NotNull String message, @NotNull Throwable throwable) {
|
|
||||||
redirectCall(message, throwable, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a crash report and optionally crashes the engine.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @param fatal terminates the engine if {@code true}
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void crash(@NotNull String message, boolean fatal) {
|
|
||||||
redirectCall(message, null, fatal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a crash report and optionally crashes the engine.
|
|
||||||
*
|
|
||||||
* @param message message to log
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void crash(@NotNull String message) {
|
|
||||||
redirectCall(message, null, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----> Legacy frontend methods
|
|
||||||
// This improves compatibility with old code
|
|
||||||
// still using the old logger frontend.
|
|
||||||
/**
|
|
||||||
* Prints a diagnostic message.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #diag(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void diag(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(LogLevel.DIAGNOSTIC, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a verbose message.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #verb(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void verb(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(LogLevel.VERBOSE, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a silent warning message.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #sarn(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void sarn(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(LogLevel.SILENT_WARNING, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints an informational message.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #info(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void info(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(LogLevel.INFORMATIONAL, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a warning message.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #warn(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void warn(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(LogLevel.WARNING, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints an error message.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #error(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void error(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(LogLevel.ERROR, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crashes the entire engine.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @param throwable the throwable that caused this crash
|
|
||||||
* @param handled declares the throwable has handled, not causing the engine to shutdown
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #crash(String, Throwable, boolean)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message, @NotNull Throwable throwable, boolean handled) {
|
|
||||||
redirectCall(message, throwable, !handled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crashes the entire engine.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @param throwable the throwable that caused this crash
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #crash(String, Throwable)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message, @NotNull Throwable throwable) {
|
|
||||||
redirectCall(message, throwable, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crashes the entire engine.
|
|
||||||
*
|
|
||||||
* @param ignoredIssuerClass class of the issuer
|
|
||||||
* @param ignoredIssuerOrigin origin of the issuer
|
|
||||||
* @param ignoredIssuerMetadata metadata about the issuer
|
|
||||||
* @param message message
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see #crash(String)
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public static void crash(@NotNull Class<?> ignoredIssuerClass, @NotNull String ignoredIssuerOrigin, @Nullable String ignoredIssuerMetadata, @NotNull String message) {
|
|
||||||
redirectCall(message, null, true);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,264 +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 lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Legacy frontend.
|
|
||||||
* <p>
|
|
||||||
* This improves compatibility with old code
|
|
||||||
* still using the old logger frontend.
|
|
||||||
*
|
|
||||||
* @deprecated The old logging system has been deprecated and replaced by a new one
|
|
||||||
* @see Logger
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public final class LoggerInstance {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private LoggerInstance() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a diagnostic message.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void diag(@NotNull String message) {
|
|
||||||
Logger.diag(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a verbose message.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void verb(@NotNull String message) {
|
|
||||||
Logger.verb(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a silent warning message.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void sarn(@NotNull String message) {
|
|
||||||
Logger.sarn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints an informational message.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void info(@NotNull String message) {
|
|
||||||
Logger.info(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a warning message.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void warn(@NotNull String message) {
|
|
||||||
Logger.warn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints an error message.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void error(@NotNull String message) {
|
|
||||||
Logger.error(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crashes the entire engine.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @param throwable throwable that caused the crash
|
|
||||||
* @param handled declares the throwable has handled
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void crash(@NotNull String message, @NotNull Throwable throwable, boolean handled) {
|
|
||||||
Logger.crash(message, throwable, !handled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crashes the entire engine.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @param throwable throwable that caused the crash
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void crash(@NotNull String message, @NotNull Throwable throwable) {
|
|
||||||
Logger.crash(message, throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crashes the entire engine.
|
|
||||||
*
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
public void crash(@NotNull String message) {
|
|
||||||
Logger.crash(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides an API for building {@link LoggerInstance}s more easily.
|
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private @Nullable Class<?> clazz = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the origin of the issuer.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private @Nullable String origin = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains metadata about the issuer.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private @Nullable String metadata = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public Builder() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a new {@link LoggerInstance} instance.
|
|
||||||
*
|
|
||||||
* @return new {@link LoggerInstance} instance
|
|
||||||
* @throws IllegalStateException if {@link #clazz} is unset
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public LoggerInstance build() throws IllegalStateException {
|
|
||||||
// Check for required fields
|
|
||||||
if (clazz == null)
|
|
||||||
throw new IllegalStateException("The class is unset");
|
|
||||||
|
|
||||||
// Set defaults
|
|
||||||
if (origin == null || origin.isBlank())
|
|
||||||
origin = "APPLICATION";
|
|
||||||
if (metadata == null || metadata.isBlank())
|
|
||||||
metadata = null;
|
|
||||||
|
|
||||||
return new LoggerInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the class of the issuer.
|
|
||||||
*
|
|
||||||
* @return class of the issuer
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @Nullable Class<?> getClazz() {
|
|
||||||
return clazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the origin of the issuer.
|
|
||||||
*
|
|
||||||
* @return origin of the issuer
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @Nullable String getOrigin() {
|
|
||||||
return origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns metadata about the issuer.
|
|
||||||
*
|
|
||||||
* @return metadata about the issuer
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @Nullable String getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the class of the issuer.
|
|
||||||
*
|
|
||||||
* @param clazz new class of the issuer
|
|
||||||
* @return builder instance
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @NotNull Builder setClazz(@Nullable Class<?> clazz) {
|
|
||||||
this.clazz = clazz;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the origin of the issuer.
|
|
||||||
*
|
|
||||||
* @param origin new origin of the issuer
|
|
||||||
* @return builder instance
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @NotNull Builder setOrigin(@Nullable String origin) {
|
|
||||||
this.origin = origin;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the metadata about the issuer.
|
|
||||||
*
|
|
||||||
* @param metadata new metadata about the issuer
|
|
||||||
* @return builder instance
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public @NotNull Builder setMetadata(@Nullable String metadata) {
|
|
||||||
this.metadata = metadata;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,283 +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.type.EngineState;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains {@link PrintStream}s for the standard
|
|
||||||
* output and standard error streams, which redirect
|
|
||||||
* their input into the engine's logging infrastructure.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "unused", "JavadocDeclaration" })
|
|
||||||
public final class PrintStreamService {
|
|
||||||
/**
|
|
||||||
* Contains the diagnostic stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#info(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the diagnostic stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#info(String)}
|
|
||||||
*
|
|
||||||
* @return diagnostic stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream diag = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the verbose stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the verbose stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @return verbose stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream verb = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the silent warning stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the silent warning stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @return silent warning stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream sarn = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the informational stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#info(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the informational stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#info(String)}
|
|
||||||
*
|
|
||||||
* @return informational stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream info = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the warning stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the warning stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @return warning stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream warn = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the error stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#info(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the error stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#info(String)}
|
|
||||||
*
|
|
||||||
* @return error stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream error = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the crash stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the crash stream.
|
|
||||||
* Anything sent will be redirected to
|
|
||||||
* {@link Logger#error(String)}
|
|
||||||
*
|
|
||||||
* @return crash stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
private static PrintStream crash = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
private PrintStreamService() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes all {@link PrintStream}s offered by this class.
|
|
||||||
* <p>
|
|
||||||
* Only works during early engine startup.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void initializeStreams() {
|
|
||||||
if (Engine.getInstance() == null || Engine.getInstance().getState() != EngineState.EARLY_STARTUP)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create streams
|
|
||||||
diag = LogStream.createPrintStream(LogLevel.DIAGNOSTIC);
|
|
||||||
verb = LogStream.createPrintStream(LogLevel.VERBOSE);
|
|
||||||
sarn = LogStream.createPrintStream(LogLevel.SILENT_WARNING);
|
|
||||||
info = LogStream.createPrintStream(LogLevel.INFORMATIONAL);
|
|
||||||
warn = LogStream.createPrintStream(LogLevel.WARNING);
|
|
||||||
error = LogStream.createPrintStream(LogLevel.ERROR);
|
|
||||||
crash = LogStream.createPrintStream(LogLevel.CRASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the standard output stream.
|
|
||||||
*
|
|
||||||
* @return standard output stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public static @NotNull PrintStream getStdOut() {
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the standard error stream.
|
|
||||||
*
|
|
||||||
* @return standard error stream
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public static @NotNull PrintStream getStdErr() {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extends {@link PrintStream} to allow for redirecting log messages.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
private static final class LogStream extends OutputStream {
|
|
||||||
/**
|
|
||||||
* Contains the current sequence of characters written.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
private @NotNull StringBuilder sequence = new StringBuilder();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the {@link LogLevel} to write log messages in.
|
|
||||||
*
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
private final @NotNull LogLevel level;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs this class.
|
|
||||||
*
|
|
||||||
* @param level level to write log messages in
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public LogStream(@NotNull LogLevel level) {
|
|
||||||
this.level = level;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link LogStream} and returns a {@link PrintStream}
|
|
||||||
* using the newly created {@link LogStream} instance.
|
|
||||||
*
|
|
||||||
* @param level level to write log messages in
|
|
||||||
* @return {@link PrintStream} using a newly created {@link LogStream} instance
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public static @NotNull PrintStream createPrintStream(@NotNull LogLevel level) {
|
|
||||||
//noinspection resource // obvious why
|
|
||||||
return new LogStream(level).toPrintStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@link PrintStream} using this {@link LogStream} instance.
|
|
||||||
*
|
|
||||||
* @return {@link PrintStream} using this instance
|
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
|
||||||
public @NotNull PrintStream toPrintStream() {
|
|
||||||
return new PrintStream(this, true, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public synchronized void write(int byteChar) {
|
|
||||||
// Convert to String and append to 'sequence'
|
|
||||||
sequence.append(new String(new byte[]{ (byte) byteChar }, StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
sequence = new StringBuilder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,338 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.logging.backend;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine;
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.EngineInternals;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import de.staropensource.engine.base.utility.Math;
|
|
||||||
import de.staropensource.engine.base.utility.Miscellaneous;
|
|
||||||
import de.staropensource.engine.base.utility.information.EngineInformation;
|
|
||||||
import de.staropensource.engine.base.utility.information.JvmInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static de.staropensource.engine.base.logging.backend.Processor.isFeatureEnabled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles crashes.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public final class CrashHandler {
|
|
||||||
/**
|
|
||||||
* Contains all random witty comments.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static final @NotNull String[] WITTYCOMMENTS = new String[]{
|
|
||||||
"Who fucked up here?",
|
|
||||||
"What is it now?",
|
|
||||||
":neofox_woozy:",
|
|
||||||
"Oh no!",
|
|
||||||
"my engine brokey brokey",
|
|
||||||
"weird",
|
|
||||||
"Is this a feature?",
|
|
||||||
"$ git blame",
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private CrashHandler() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles crash reports.
|
|
||||||
*
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @param message message
|
|
||||||
* @param throwable {@link Throwable} which caused the error
|
|
||||||
* @param fatal if to terminate the engine
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void handleCrash(@NotNull StackTraceElement issuer, @NotNull String message, @Nullable Throwable throwable, boolean fatal) {
|
|
||||||
StringBuilder output = new StringBuilder();
|
|
||||||
String outputFinal;
|
|
||||||
|
|
||||||
// Header
|
|
||||||
output
|
|
||||||
.append("==== sos!engine crash report ====")
|
|
||||||
.append("\nDear user: The application or game you just used seems to have run into a problem.")
|
|
||||||
.append("\n Please be so kind and report this crash report to the developers so they can fix the issue.")
|
|
||||||
.append("\nDear developer: FIX YOUR SHIT. If the engine is at fault here, please report the crash")
|
|
||||||
.append("\n to StarOpenSource here: https://git.staropensource.de/StarOpenSource/Engine/issues")
|
|
||||||
.append("\n\n// ")
|
|
||||||
.append(WITTYCOMMENTS[new Random().nextInt(WITTYCOMMENTS.length)])
|
|
||||||
.append("\n\n");
|
|
||||||
|
|
||||||
// Information about the crash
|
|
||||||
output
|
|
||||||
.append("---- Crash Information ----\n")
|
|
||||||
.append("Issuer: ")
|
|
||||||
.append(issuer.getClassName())
|
|
||||||
.append("@")
|
|
||||||
.append(issuer.getModuleName())
|
|
||||||
.append("#")
|
|
||||||
.append(issuer.getMethodName())
|
|
||||||
.append("~")
|
|
||||||
.append(issuer.getLineNumber())
|
|
||||||
|
|
||||||
.append("\nFatal: ")
|
|
||||||
.append(fatal);
|
|
||||||
|
|
||||||
if (throwable == null)
|
|
||||||
output
|
|
||||||
.append("\nCaused by:")
|
|
||||||
.append("\nNo throwable has been passed.");
|
|
||||||
else
|
|
||||||
output
|
|
||||||
.append("\n")
|
|
||||||
.append(Miscellaneous.getStackTraceHeader(throwable))
|
|
||||||
.append("\n")
|
|
||||||
.append(Miscellaneous.getStackTraceAsString(throwable, true))
|
|
||||||
.append("\n");
|
|
||||||
|
|
||||||
output.append("\nMessage: \n")
|
|
||||||
.append(message)
|
|
||||||
.append("\n\n");
|
|
||||||
|
|
||||||
// Environment information
|
|
||||||
output
|
|
||||||
.append("---- Environment ----")
|
|
||||||
.append("\nTime and date: ")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), 2))
|
|
||||||
.append(".")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.MONTH), 2))
|
|
||||||
.append(".")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.YEAR), 4))
|
|
||||||
.append(" ")
|
|
||||||
.append(de.staropensource.engine.base.utility.Math.padNumbers(Calendar.getInstance().get(Calendar.HOUR_OF_DAY), 2))
|
|
||||||
.append(":")
|
|
||||||
.append(de.staropensource.engine.base.utility.Math.padNumbers(Calendar.getInstance().get(Calendar.MINUTE), 2))
|
|
||||||
.append(":")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.SECOND), 2))
|
|
||||||
.append(" [")
|
|
||||||
.append(TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT, Locale.US))
|
|
||||||
.append("]")
|
|
||||||
|
|
||||||
.append("\nUNIX Epoch: ")
|
|
||||||
.append(Math.padNumbers(System.currentTimeMillis(), String.valueOf(Long.MAX_VALUE).length()))
|
|
||||||
|
|
||||||
.append("\nOperating system: ")
|
|
||||||
.append(System.getProperty("os.name"))
|
|
||||||
|
|
||||||
.append("\nCPU architecture: ")
|
|
||||||
.append(System.getProperty("os.arch"))
|
|
||||||
|
|
||||||
.append("\nMemory: ")
|
|
||||||
.append(JvmInformation.getMemoryUsed() / 1024)
|
|
||||||
.append(" MiB")
|
|
||||||
.append("/")
|
|
||||||
.append(JvmInformation.getMemoryLimit() / 1024)
|
|
||||||
.append(" MiB")
|
|
||||||
.append(" (stack ")
|
|
||||||
.append(JvmInformation.getMemoryStack().getUsed() / 1024)
|
|
||||||
.append(" MiB")
|
|
||||||
.append("/")
|
|
||||||
.append(JvmInformation.getMemoryStack().getMax() == -1 ? "∞" : JvmInformation.getMemoryStack().getMax() / 1024)
|
|
||||||
.append(" MiB")
|
|
||||||
.append(", heap ")
|
|
||||||
.append(JvmInformation.getMemoryHeap().getUsed() / 1024)
|
|
||||||
.append(" MiB")
|
|
||||||
.append("/")
|
|
||||||
.append(JvmInformation.getMemoryHeap().getMax() == -1 ? "∞" : JvmInformation.getMemoryStack().getMax() / 1024)
|
|
||||||
.append(" MiB)")
|
|
||||||
|
|
||||||
.append("\nJVM: ")
|
|
||||||
.append(JvmInformation.getImplementationName())
|
|
||||||
.append(" ")
|
|
||||||
.append(JvmInformation.getImplementationVersion())
|
|
||||||
.append(" @ ")
|
|
||||||
.append(JvmInformation.getJavaVersion())
|
|
||||||
.append(" by ")
|
|
||||||
.append(JvmInformation.getImplementationVendor())
|
|
||||||
|
|
||||||
.append("\nJVM arguments: ");
|
|
||||||
|
|
||||||
for (String argument : JvmInformation.getArguments())
|
|
||||||
output
|
|
||||||
.append("\n- '")
|
|
||||||
.append(argument)
|
|
||||||
.append("'");
|
|
||||||
|
|
||||||
output.append("\n\n");
|
|
||||||
|
|
||||||
// Engine
|
|
||||||
output.append("---- sos!engine ----\n");
|
|
||||||
|
|
||||||
if (EngineInformation.getVersioningString() == null)
|
|
||||||
output.append("EngineInformation is not yet initialized");
|
|
||||||
else
|
|
||||||
output
|
|
||||||
.append("Version: ")
|
|
||||||
.append(EngineInformation.getVersioningString())
|
|
||||||
|
|
||||||
.append("\nCommit: ")
|
|
||||||
.append(EngineInformation.getGitCommitIdentifierLong())
|
|
||||||
|
|
||||||
.append("\nDirty: ")
|
|
||||||
.append(EngineInformation.isGitDirty());
|
|
||||||
|
|
||||||
output.append("\n\n");
|
|
||||||
|
|
||||||
// Engine configuration
|
|
||||||
output.append("---- sos!engine configuration ----\n");
|
|
||||||
|
|
||||||
if (EngineConfiguration.getInstance() == null)
|
|
||||||
output.append("EngineConfiguration is not yet initialized");
|
|
||||||
else
|
|
||||||
output
|
|
||||||
.append("EngineConfiguration#debug='")
|
|
||||||
.append(EngineConfiguration.getInstance().isDebug())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#debugEvents='")
|
|
||||||
.append(EngineConfiguration.getInstance().isDebugEvents())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#initialPerformSubsystemInitialization='")
|
|
||||||
.append(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#initialIncludeSubsystemClasses='")
|
|
||||||
.append(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#errorShortcodeParser='")
|
|
||||||
.append(EngineConfiguration.getInstance().isErrorShortcodeParser())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#optimizeLogging='")
|
|
||||||
.append(EngineConfiguration.getInstance().isOptimizeLogging())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#optimizeEvents='")
|
|
||||||
.append(EngineConfiguration.getInstance().isOptimizeEvents())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#logLevel='")
|
|
||||||
.append(EngineConfiguration.getInstance().getLogLevel().name())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#logSettings='")
|
|
||||||
.append(EngineConfiguration.getInstance().getLogFeatures())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#logPollingSpeed='")
|
|
||||||
.append(EngineConfiguration.getInstance().getLogPollingSpeed())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#logForceStandardOutput='")
|
|
||||||
.append(EngineConfiguration.getInstance().isLogForceStandardOutput())
|
|
||||||
.append("'\n")
|
|
||||||
|
|
||||||
.append("EngineConfiguration#hideFullTypePath='")
|
|
||||||
.append(EngineConfiguration.getInstance().isHideFullTypePath());
|
|
||||||
|
|
||||||
output.append("'\n\n");
|
|
||||||
|
|
||||||
// System properties
|
|
||||||
output.append("---- System properties ----");
|
|
||||||
|
|
||||||
for (String property : System.getProperties().stringPropertyNames().stream().sorted().toList())
|
|
||||||
output
|
|
||||||
.append("\n")
|
|
||||||
.append(property)
|
|
||||||
.append("='")
|
|
||||||
.append(System.getProperties().getProperty(property).replace("\n", "\\n"))
|
|
||||||
.append("'");
|
|
||||||
|
|
||||||
output.append("\n\n");
|
|
||||||
|
|
||||||
// Stacktraces of all threads
|
|
||||||
output.append("---- Stacktraces of all threads ----");
|
|
||||||
{
|
|
||||||
Map<Thread, StackTraceElement[]> stacktraces = Thread.getAllStackTraces();
|
|
||||||
|
|
||||||
for (Thread thread : stacktraces.keySet())
|
|
||||||
output
|
|
||||||
.append("\n")
|
|
||||||
.append(thread.getName())
|
|
||||||
.append(" (id=")
|
|
||||||
.append(thread.threadId())
|
|
||||||
.append(" priority=")
|
|
||||||
.append(thread.getPriority())
|
|
||||||
.append(" group=")
|
|
||||||
.append(thread.getThreadGroup() == null ? "<unknown>" : thread.getThreadGroup().getName())
|
|
||||||
.append(" state=")
|
|
||||||
.append(thread.getState().name())
|
|
||||||
.append(" daemon=")
|
|
||||||
.append(thread.isDaemon())
|
|
||||||
.append("):")
|
|
||||||
.append("\n")
|
|
||||||
.append(Miscellaneous.getStackTraceAsString(stacktraces.get(thread), false))
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
output.append("\n");
|
|
||||||
|
|
||||||
// Footer
|
|
||||||
output
|
|
||||||
.append("Dear user: The application or game you just used seems to have run into a problem.\n")
|
|
||||||
.append(" Please be so kind and report this crash report to the developers so they can fix the issue.\n")
|
|
||||||
.append("Dear developer: FIX YOUR SHIT. If the engine is at fault here, please report the crash\n")
|
|
||||||
.append(" to StarOpenSource here: https://git.staropensource.de/StarOpenSource/Engine/issues\n")
|
|
||||||
.append("==== sos!engine crash report ====");
|
|
||||||
|
|
||||||
// Formatting
|
|
||||||
if (isFeatureEnabled("formatting")) {
|
|
||||||
outputFinal =
|
|
||||||
"<fg:red><bold>"
|
|
||||||
+ output
|
|
||||||
.toString()
|
|
||||||
.replace("<", "\\<")
|
|
||||||
+ "<reset>";
|
|
||||||
} else
|
|
||||||
outputFinal = output.toString();
|
|
||||||
|
|
||||||
// Print
|
|
||||||
Logger.getLoggingAdapter().print(LogLevel.CRASH, issuer, message, outputFinal);
|
|
||||||
|
|
||||||
// Terminate engine
|
|
||||||
// We do a test on the engine state here
|
|
||||||
// to prevent bugs and multiple engine shutdowns.
|
|
||||||
if (fatal)
|
|
||||||
switch (Engine.getInstance().getState()) {
|
|
||||||
case UNKNOWN, EARLY_STARTUP, STARTUP -> {
|
|
||||||
if (EngineInternals.getInstance() == null)
|
|
||||||
Runtime.getRuntime().exit(69);
|
|
||||||
else
|
|
||||||
EngineInternals.getInstance().getShutdownHandler().shutdown((short) 69);
|
|
||||||
}
|
|
||||||
case RUNNING -> Engine.getInstance().shutdown(69);
|
|
||||||
case SHUTDOWN, CRASHED -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,91 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.logging.backend;
|
|
||||||
|
|
||||||
import org.intellij.lang.annotations.RegExp;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Responsible for filtering log messages out.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public final class Filterer {
|
|
||||||
/**
|
|
||||||
* Contains a list of all disallowed classes.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
static @NotNull List<@NotNull String> disallowedClasses = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains a list of all disallowed modules.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
static @NotNull List<@NotNull String> disallowedModules = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains a list of all disallowed messages.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
static @NotNull List<@NotNull String> disallowedMessages = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private Filterer() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallows one or multiple classes.
|
|
||||||
*
|
|
||||||
* @param regex regex
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void disallowClass(@RegExp @NotNull String regex) {
|
|
||||||
disallowedClasses.add(regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallows one or multiple modules.
|
|
||||||
*
|
|
||||||
* @param regex regex
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void disallowModule(@RegExp @NotNull String regex) {
|
|
||||||
disallowedModules.add(regex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallows one or multiple messages.
|
|
||||||
*
|
|
||||||
* @param regex regex
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void disallowMessage(@RegExp @NotNull String regex) {
|
|
||||||
disallowedMessages.add(regex);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,375 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.logging.backend;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeParser;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.logging.backend.async.LoggingQueue;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import de.staropensource.engine.base.utility.Math;
|
|
||||||
import de.staropensource.engine.base.utility.PlaceholderEngine;
|
|
||||||
import de.staropensource.engine.base.utility.information.JvmInformation;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes log messages.
|
|
||||||
*
|
|
||||||
* @see #handle(LogLevel, StackTraceElement, String)
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public final class Processor {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private Processor() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the specified feature is enabled.
|
|
||||||
*
|
|
||||||
* @param feature feature to check
|
|
||||||
* @return enabled?
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static boolean isFeatureEnabled(@NotNull String feature) {
|
|
||||||
return EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().getLogFeatures().contains(feature);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles incoming log calls and either
|
|
||||||
* processes them directly or queues them in.
|
|
||||||
*
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void handle(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
|
||||||
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().isOptimizeLogging())
|
|
||||||
LoggingQueue.add(level, issuer, message);
|
|
||||||
else
|
|
||||||
process(level, issuer, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processes a log call.
|
|
||||||
*
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void process(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
|
||||||
StringBuilder output = new StringBuilder();
|
|
||||||
|
|
||||||
// Filter out
|
|
||||||
if (EngineConfiguration.getInstance() == null) {
|
|
||||||
LogLevel maxLevel = LogLevel.INFORMATIONAL;
|
|
||||||
|
|
||||||
try {
|
|
||||||
maxLevel = LogLevel.valueOf(System.getProperties().getProperty("sosengine.base.logLevel", "informational").toUpperCase());
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
Logger.error("The log level '" + System.getProperties().getProperty("sosengine.base.logLevel", "informational") + "' is not valid");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level.compareTo(maxLevel) < 0)
|
|
||||||
return;
|
|
||||||
} else if (level.compareTo(EngineConfiguration.getInstance().getLogLevel()) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (String classNameDisallowed : Filterer.disallowedClasses)
|
|
||||||
if (issuer.getClassName().matches(classNameDisallowed))
|
|
||||||
return;
|
|
||||||
for (String moduleNameDisallowed : Filterer.disallowedModules)
|
|
||||||
if (issuer.getModuleName().matches(moduleNameDisallowed))
|
|
||||||
return;
|
|
||||||
for (String messageDisallowed : Filterer.disallowedModules)
|
|
||||||
if (message.matches(messageDisallowed))
|
|
||||||
return;
|
|
||||||
|
|
||||||
format(output, level);
|
|
||||||
runtime(output);
|
|
||||||
if (isFeatureEnabled("date") || isFeatureEnabled("time")) {
|
|
||||||
output.append("[");
|
|
||||||
date(output);
|
|
||||||
if (isFeatureEnabled("date"))
|
|
||||||
output.append(" ");
|
|
||||||
time(output);
|
|
||||||
output.append("] ");
|
|
||||||
}
|
|
||||||
output.append("[");
|
|
||||||
level(output, level);
|
|
||||||
format(output, level);
|
|
||||||
output.append(" ");
|
|
||||||
issuerClass(output, level, issuer);
|
|
||||||
issuerModule(output, level, issuer);
|
|
||||||
methodName(output, level, issuer);
|
|
||||||
lineNumber(output, level, issuer);
|
|
||||||
output.append("] ");
|
|
||||||
message(output, message);
|
|
||||||
format(output, "reset");
|
|
||||||
|
|
||||||
// Print
|
|
||||||
Logger.getLoggingAdapter().print(level, issuer, message, output.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----> Formatting
|
|
||||||
/**
|
|
||||||
* Adds the {@code formatting} feature.
|
|
||||||
* <p>
|
|
||||||
* This method will reset and then color the following
|
|
||||||
* substring in the log level-specific color.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param level level of the log call
|
|
||||||
* @see #format(StringBuilder, String)
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void format(@NotNull StringBuilder builder, @NotNull LogLevel level) {
|
|
||||||
format(builder, "reset");
|
|
||||||
format(builder, switch (level) {
|
|
||||||
case DIAGNOSTIC, VERBOSE -> "fg:blue";
|
|
||||||
case SILENT_WARNING, WARNING -> "fg:yellow";
|
|
||||||
case INFORMATIONAL -> "fg:white";
|
|
||||||
case ERROR -> "fg:red";
|
|
||||||
case CRASH -> "you should not see this";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code formatting} feature.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param component formatting component
|
|
||||||
* @see #format(StringBuilder, LogLevel)
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void format(@NotNull StringBuilder builder, @NotNull String component) {
|
|
||||||
if (isFeatureEnabled("formatting"))
|
|
||||||
builder
|
|
||||||
.append("<")
|
|
||||||
.append(component)
|
|
||||||
.append(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code formatting} feature.
|
|
||||||
*
|
|
||||||
* @param string string to sanitize
|
|
||||||
* @return sanitized string
|
|
||||||
* @see #format(StringBuilder, LogLevel)
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static @NotNull String sanitizeFormat(@NotNull String string) {
|
|
||||||
if (isFeatureEnabled("formatting"))
|
|
||||||
return string.replace("<", "\\<");
|
|
||||||
else
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----> Features and components
|
|
||||||
/**
|
|
||||||
* Adds the {@code runtime} feature.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void runtime(@NotNull StringBuilder builder) {
|
|
||||||
if (isFeatureEnabled("runtime"))
|
|
||||||
builder
|
|
||||||
.append("[")
|
|
||||||
.append(JvmInformation.getUptime())
|
|
||||||
.append("ms")
|
|
||||||
.append("] ");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code time} feature.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void time(@NotNull StringBuilder builder) {
|
|
||||||
if (isFeatureEnabled("time"))
|
|
||||||
builder
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.HOUR_OF_DAY), 2))
|
|
||||||
.append(":")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.MINUTE), 2))
|
|
||||||
.append(":")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.SECOND), 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code date} feature.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void date(@NotNull StringBuilder builder) {
|
|
||||||
if (isFeatureEnabled("date"))
|
|
||||||
builder
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), 2))
|
|
||||||
.append(".")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.MONTH), 2))
|
|
||||||
.append(".")
|
|
||||||
.append(Math.padNumbers(Calendar.getInstance().get(Calendar.YEAR), 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code level} component.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param level level of the log call
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void level(@NotNull StringBuilder builder, @NotNull LogLevel level) {
|
|
||||||
format(builder, "bold");
|
|
||||||
|
|
||||||
builder.append(switch (level) {
|
|
||||||
case DIAGNOSTIC -> "DIAG";
|
|
||||||
case VERBOSE -> "VERB";
|
|
||||||
case SILENT_WARNING -> "SARN";
|
|
||||||
case INFORMATIONAL -> "INFO";
|
|
||||||
case WARNING -> "WARN";
|
|
||||||
case ERROR -> "ERR!";
|
|
||||||
case CRASH -> "CRSH";
|
|
||||||
});
|
|
||||||
|
|
||||||
format(builder, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code issuer class} component.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void issuerClass(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
|
||||||
format(builder, "bold");
|
|
||||||
|
|
||||||
if (isFeatureEnabled("shortIssuerClass")) {
|
|
||||||
String[] classNameSplit = issuer.getClassName().split("\\.");
|
|
||||||
builder.append(classNameSplit[classNameSplit.length - 1]);
|
|
||||||
} else
|
|
||||||
builder.append(issuer.getClassName());
|
|
||||||
|
|
||||||
format(builder, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code moduleName} and {@code moduleVersion} features.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void issuerModule(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
|
||||||
if (isFeatureEnabled("moduleName") && issuer.getModuleName() != null) {
|
|
||||||
format(builder, "bold");
|
|
||||||
|
|
||||||
builder
|
|
||||||
.append("@")
|
|
||||||
.append(issuer.getModuleName());
|
|
||||||
|
|
||||||
if (isFeatureEnabled("moduleVersion") && issuer.getModuleVersion() != null)
|
|
||||||
builder
|
|
||||||
.append("v")
|
|
||||||
.append(issuer.getModuleVersion());
|
|
||||||
|
|
||||||
format(builder, level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code methodName} feature.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void methodName(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
|
||||||
if (isFeatureEnabled("methodName")) {
|
|
||||||
builder.append("#");
|
|
||||||
format(builder, "bold");
|
|
||||||
builder.append(sanitizeFormat(issuer.getMethodName()));
|
|
||||||
format(builder, level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code lineNumber} feature.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void lineNumber(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
|
|
||||||
if (isFeatureEnabled("lineNumber")) {
|
|
||||||
builder.append("~");
|
|
||||||
format(builder, "bold");
|
|
||||||
builder.append(issuer.getLineNumber());
|
|
||||||
format(builder, level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the {@code message} component.
|
|
||||||
*
|
|
||||||
* @param builder {@link StringBuilder} instance to append to
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void message(@NotNull StringBuilder builder, @NotNull String message) {
|
|
||||||
builder.append(sanitizeFormat(handlePlaceholders(
|
|
||||||
message.replace(
|
|
||||||
"\n",
|
|
||||||
"\n" + " ".repeat(new EmptyShortcodeParser(builder.toString(), true).getClean().length())
|
|
||||||
)
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----> Utility methods
|
|
||||||
/**
|
|
||||||
* Uses the {@link PlaceholderEngine} to replace
|
|
||||||
* all placeholders within a specified string and
|
|
||||||
* returns it's result. The original string will
|
|
||||||
* be returned if the {@link PlaceholderEngine}
|
|
||||||
* is not yet initialized.
|
|
||||||
*
|
|
||||||
* @param string string to use
|
|
||||||
* @return updated string
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static @NotNull String handlePlaceholders(@NotNull String string) {
|
|
||||||
if (PlaceholderEngine.getInstance() == null)
|
|
||||||
return string;
|
|
||||||
else
|
|
||||||
return PlaceholderEngine.getInstance().process(string);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.logging.backend.async;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.internal.type.QueuedLogCall;
|
|
||||||
import de.staropensource.engine.base.logging.backend.Processor;
|
|
||||||
import de.staropensource.engine.base.type.immutable.ImmutableArrayList;
|
|
||||||
import de.staropensource.engine.base.type.logging.LogLevel;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles everything related to the logging queue.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public final class LoggingQueue {
|
|
||||||
/**
|
|
||||||
* Contains the logging queue.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static final @NotNull List<@NotNull QueuedLogCall> queue = Collections.synchronizedList(new ArrayList<>());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private LoggingQueue() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new entry to the logging queue.
|
|
||||||
*
|
|
||||||
* @param level level of the log call
|
|
||||||
* @param issuer {@link StackTraceElement} of the issuer
|
|
||||||
* @param message message
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void add(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message) {
|
|
||||||
queue.add(new QueuedLogCall(level, issuer, message));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flushes the logging queue.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void flush() {
|
|
||||||
// Get copy of and clear queue
|
|
||||||
List<@NotNull QueuedLogCall> queue = new ImmutableArrayList<>(LoggingQueue.queue);
|
|
||||||
LoggingQueue.queue.clear();
|
|
||||||
|
|
||||||
for (QueuedLogCall queuedCall : queue)
|
|
||||||
Processor.process(queuedCall.level(), queuedCall.issuer(), queuedCall.message());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,142 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.staropensource.engine.base.logging.backend.async;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine;
|
|
||||||
import de.staropensource.engine.base.EngineConfiguration;
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import de.staropensource.engine.base.type.EngineState;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the logging thread.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public final class LoggingThread {
|
|
||||||
/**
|
|
||||||
* Contains the logging thread.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static Thread thread;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the code of the logging thread.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static final @NotNull Runnable threadCode = () -> {
|
|
||||||
int pollingSpeed;
|
|
||||||
|
|
||||||
while (!(
|
|
||||||
Thread.currentThread().isInterrupted()
|
|
||||||
|| !(EngineConfiguration.getInstance() == null || EngineConfiguration.getInstance().isOptimizeLogging())
|
|
||||||
|| Engine.getInstance().getState() == EngineState.SHUTDOWN
|
|
||||||
|| Engine.getInstance().getState() == EngineState.CRASHED
|
|
||||||
)) {
|
|
||||||
if (EngineConfiguration.getInstance() == null)
|
|
||||||
pollingSpeed = 5;
|
|
||||||
else
|
|
||||||
pollingSpeed = EngineConfiguration.getInstance().getLogPollingSpeed();
|
|
||||||
|
|
||||||
// Flush all log messages
|
|
||||||
LoggingQueue.flush();
|
|
||||||
|
|
||||||
// Sleep for whatever has been configured
|
|
||||||
if (pollingSpeed > 0) {
|
|
||||||
long sleepDuration = System.currentTimeMillis() + pollingSpeed;
|
|
||||||
while (System.currentTimeMillis() < sleepDuration)
|
|
||||||
Thread.onSpinWait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static {
|
|
||||||
constructThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private LoggingThread() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs the logging thread.
|
|
||||||
*
|
|
||||||
* @see #thread
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
private static void constructThread() {
|
|
||||||
thread = Thread
|
|
||||||
.ofPlatform()
|
|
||||||
.daemon()
|
|
||||||
.name("Logging thread")
|
|
||||||
.group(Engine.getThreadGroup())
|
|
||||||
.priority(Thread.MAX_PRIORITY)
|
|
||||||
.stackSize(10)
|
|
||||||
.unstarted(threadCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Re-)Starts the logging thread.
|
|
||||||
*
|
|
||||||
* @param allowRestart if the logging thread should be restarted if it's stopped
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static void startThread(boolean allowRestart) {
|
|
||||||
if (allowRestart && thread.isAlive()) {
|
|
||||||
// Executing the restart logic in another thread prevents
|
|
||||||
// this thread from being fully blocked while still ensuring
|
|
||||||
// that the logging thread is properly restarted
|
|
||||||
Thread
|
|
||||||
.ofVirtual()
|
|
||||||
.name("Logging thread restart thread")
|
|
||||||
.start(() -> {
|
|
||||||
Logger.diag("Restarting the logging thread");
|
|
||||||
|
|
||||||
// Interrupt thread
|
|
||||||
// This let's our thread code know that it should terminate
|
|
||||||
thread.interrupt();
|
|
||||||
|
|
||||||
// Make sure that the logging thread is dead before reconstructing and starting it
|
|
||||||
while (thread.isAlive())
|
|
||||||
Thread.onSpinWait();
|
|
||||||
|
|
||||||
constructThread();
|
|
||||||
thread.start();
|
|
||||||
});
|
|
||||||
} else
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the {@link Thread.State} of the logging thread.
|
|
||||||
*
|
|
||||||
* @return logging thread state
|
|
||||||
* @see Thread.State
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
public static @NotNull Thread.State getState() {
|
|
||||||
return thread.getState();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Everything related to making the logging
|
|
||||||
* infrastructure asynchronous.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.logging.backend.async;
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* STAROPENSOURCE ENGINE SOURCE FILE
|
|
||||||
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
|
||||||
* Licensed under the GNU Affero General Public License v3
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The backend of sos!engine's logging infrastructure.
|
|
||||||
*
|
|
||||||
* @since v1-alpha8
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.logging.backend;
|
|
|
@ -1,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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The engine's logging infrastructure.
|
|
||||||
*
|
|
||||||
* @see de.staropensource.engine.base.logging.Logger
|
|
||||||
* @since v1-alpha0
|
|
||||||
*/
|
|
||||||
package de.staropensource.engine.base.logging;
|
|
|
@ -1,86 +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.reflection;
|
|
||||||
|
|
||||||
import de.staropensource.engine.base.logging.Logger;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows getting the classpath as {@link URL}s.
|
|
||||||
* <p>
|
|
||||||
* This entire class has been stolen from
|
|
||||||
* <a href="https://github.com/ronmamo/reflections">the Reflections library</a>.
|
|
||||||
* All credits to them.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public final class ClasspathAccess {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private ClasspathAccess() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the classpath as a collection of {@link URL}s.
|
|
||||||
*
|
|
||||||
* @return collection of classpath urls
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static @NotNull Collection<URL> getClasspathURLs() {
|
|
||||||
Collection<URL> urls = new ArrayList<>();
|
|
||||||
String javaClassPath = System.getProperty("java.class.path");
|
|
||||||
|
|
||||||
if (javaClassPath != null)
|
|
||||||
for (String path : javaClassPath.split(File.pathSeparator))
|
|
||||||
try {
|
|
||||||
urls.add(new File(path).toURI().toURL());
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Logger.crash("Failed converting classpath to URL", exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fixURLs(urls);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixes slowdowns which {@link URL}s may cause.
|
|
||||||
* <p>
|
|
||||||
* Visit <a href="http://michaelscharf.blogspot.co.il/2006/11/javaneturlequals-and-hashcode-make.html">this blog post</a> for more information.
|
|
||||||
*
|
|
||||||
* @param urls unfixed urls
|
|
||||||
* @return fixed urls
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private static @NotNull Collection<URL> fixURLs(@NotNull Collection<URL> urls) {
|
|
||||||
Map<String, URL> distinct = new LinkedHashMap<>(urls.size());
|
|
||||||
for (URL url : urls) {
|
|
||||||
distinct.put(url.toExternalForm(), url);
|
|
||||||
}
|
|
||||||
return distinct.values();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +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.reflection;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The class you'd likely want to use for reflection.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public final class Reflect {
|
|
||||||
/**
|
|
||||||
* Creates and initializes an instance of this class.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
private Reflect() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflect on a {@link Class}.
|
|
||||||
*
|
|
||||||
* @param clazz class to reflect on
|
|
||||||
* @return new {@link ReflectionClass}
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static @NotNull ReflectionClass reflectOn(@NotNull Class<?> clazz) {
|
|
||||||
return new ReflectionClass(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflect on a {@link Method}.
|
|
||||||
*
|
|
||||||
* @param method method to reflect on
|
|
||||||
* @return new {@link ReflectionMethod}
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static ReflectionMethod reflectOn(@NotNull Method method) {
|
|
||||||
return new ReflectionMethod(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflect on a {@link Field}.
|
|
||||||
*
|
|
||||||
* @param field field to reflect on
|
|
||||||
* @return new {@link ReflectionField}
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
public static @NotNull ReflectionField reflectOn(@NotNull Field field) {
|
|
||||||
return new ReflectionField(field);
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue