diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index 719cff5..d2df7bf 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -7,46 +7,55 @@ jobs: # Set up the OS runs-on: ubuntu-latest env: - # Nexus credentials and GitHub token - NEXUS_USERNAME: '${{ secrets.NEXUS_USERNAME }}' - NEXUS_PASSWORD: '${{ secrets.NEXUS_PASSWORD }}' + # Sonatype Credentials & GitHub token + SONATYPE_USERNAME: '${{ secrets.SONATYPE_USERNAME }}' + SONATYPE_PASSWORD: '${{ secrets.SONATYPE_PASSWORD }}' GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' # Set environment - env: 'prod' + ENV: 'prod' + PROJECT_NAME: 'LoggingModule' steps: # Checkout the Code - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Set up git hashes environment variables - name: Git Hashes - uses: Im-Fran/git-hashes-action@v1.0.0 + uses: Im-Fran/git-hashes-action@v1.0.3 # Set up version from tag environment variables - name: Version from Tag Action - uses: Im-Fran/version-from-tag-action@v1.0.1 + uses: Im-Fran/version-from-tag-action@v1.0.3 with: remove-first-character: 'v' # Set up the JDK - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: distribution: adopt java-version: 11 + cache: 'gradle' # Make gradle executable - name: Make gradle executable run: chmod +x gradlew # Clean, Test, Publish and Build (in that order to save the artifact to the action) - name: Test, Deploy and Build with Gradle - run: ./gradlew clean test publish shadow dokkaHtml + run: ./gradlew clean test shadowJar dokkaHtml publish publishToSonatype closeAndReleaseSonatypeStagingRepository -no-daemon # Now we store the artifact in the action - name: Upload the artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: - name: LoggingModule - path: ./build/libs/LoggingModule-${{ env.VERSION }}.jar + name: ${{ env.PROJECT_NAME }} + path: ./build/libs/${{ env.PROJECT_NAME }}-${{ env.VERSION }}.jar + # Here we upload the binary to the release + - name: Upload to release + uses: JasonEtco/upload-to-release@master + with: + args: ./build/libs/${{ env.PROJECT_NAME }}-${{ env.VERSION }}.jar application/java-archive # Now we deploy the documents to GitHub pages - name: Deploy Dokka - uses: JamesIves/github-pages-deploy-action@4.1.7 + uses: JamesIves/github-pages-deploy-action@v4.4.3 with: branch: gh-pages folder: build/dokka - clean: true \ No newline at end of file + clean: true + clean-exclude: | + CNAME diff --git a/.github/workflows/gradle-test.yml b/.github/workflows/gradle-test.yml index 57f370a..751318f 100644 --- a/.github/workflows/gradle-test.yml +++ b/.github/workflows/gradle-test.yml @@ -1,31 +1,32 @@ name: "Test" # Only execute this workflow when a PR is opened or when something is pushed to the master branch -on: [push, pull_request] +on: [pull_request] jobs: testBuilds: strategy: fail-fast: false max-parallel: 4 matrix: - java-version: [11,16,17] + java-version: [11, 16, 17] # Set up OS runs-on: ubuntu-latest # Set up environment variables env: - env: 'local' # Set to local, so it won't deploy the jar to the repos + ENV: "local" # Set to local, so it won't deploy the jar to the repos steps: - # Checkout code - - name: Checkout Code - uses: actions/checkout@v2 - # Setup java and maven - - name: Set up JDK ${{ matrix.java-version }} - uses: actions/setup-java@v2 - with: - distribution: adopt - java-version: ${{ matrix.java-version }} - # Setup executable gradle - - name: Make Gradle executable - run: chmod +x gradlew - # Test building without dokka - - name: Build Jar with Java ${{ matrix.java-version }} - run: ./gradlew clean publish shadow -x dokkaHtml \ No newline at end of file + # Checkout code + - name: Checkout Code + uses: actions/checkout@v4 + # Setup java and maven + - name: Set up JDK ${{ matrix.java-version }} + uses: actions/setup-java@v3 + with: + distribution: adopt + java-version: ${{ matrix.java-version }} + cache: "gradle" + # Setup executable gradle + - name: Make Gradle executable + run: chmod +x gradlew + # Test building without dokka + - name: Build Jar with Java ${{ matrix.java-version }} + run: ./gradlew clean shadowJar test -x dokkaHtml -no-daemon diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index c354d46..b63fdf3 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -6,5 +6,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: gradle/wrapper-validation-action@v1 \ No newline at end of file + - uses: actions/checkout@v4 + - uses: gradle/wrapper-validation-action@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index c03e22a..51a0e4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## v0.3.1 - Snapshot +* Fix module.properties file +* Update README.md + +## v0.3.0 - Snapshot +* Updated to gradle kotlin dsl +* Added sonatype +* Updated dependencies +* Updated workflows +* Added JitPack + +## v0.2.2 - Snapshot +* Added `Logger#debug` method +* Added `Logger#severe(String, Exception)` method +* Updated dependencies +* Minecraft 1.19 Support + ## v0.2.1 - Snapshot * Updated Dependencies diff --git a/README.md b/README.md new file mode 100644 index 0000000..3f9adeb --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +[![](https://jitci.com/gh/TheProgramSrc/SimpleCore-LoggingModule/svg)](https://jitci.com/gh/TheProgramSrc/SimpleCore-LoggingModule) +[![](https://jitpack.io/v/TheProgramSrc/SimpleCore-LoggingModule.svg)](https://jitpack.io/#TheProgramSrc/SimpleCore-LoggingModule) +[![](https://img.shields.io/nexus/s/xyz.theprogramsrc/loggingmodule?server=https%3A%2F%2Fs01.oss.sonatype.org)]() + + +# SimpleCore-LoggingModule +Just a logger for the SimpleCore API + +# Documentation +* [Wiki](https://github.com/TheProgramSrc/SimpleCore-LoggingModule/wiki) +* [JavaDocs](https://docs.theprogramsrc.xyz/SimpleCore-LoggingModule/) \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index e1e9773..0000000 --- a/build.gradle +++ /dev/null @@ -1,114 +0,0 @@ -import org.apache.tools.ant.filters.ReplaceTokens - -plugins { - id 'org.jetbrains.kotlin.jvm' version '1.6.10' - id 'maven-publish' - id 'com.github.johnrengelman.shadow' version '7.1.2' - id 'org.jetbrains.dokka' version '1.6.0' -} - -def projectVersion = (System.getenv("VERSION") ?: '0.2.1-SNAPSHOT').replaceFirst("v", "").replace('/', '') - -group 'xyz.theprogramsrc' -version projectVersion -description 'Just a logger for the SimpleCore API' - -repositories { - mavenCentral() - - maven { url 'https://repo.theprogramsrc.xyz/repository/maven-public/' } - maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } - maven { url 'https://oss.sonatype.org/content/repositories/releases/' } - maven { url 'https://oss.sonatype.org/content/groups/public/' } - maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' } - maven { url 'https://repo.codemc.org/repository/maven-public/' } - maven { url 'https://jitpack.io/' } -} - -dependencies { - compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10' - compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT' - compileOnly 'net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT' - compileOnly 'xyz.theprogramsrc:simplecoreapi:0.1.12-SNAPSHOT' - - compileOnly 'org.apache.logging.log4j:log4j-api:2.17.1' - compileOnly 'org.apache.logging.log4j:log4j-core:2.17.1' - - testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' -} - -shadowJar { - mergeServiceFiles() - exclude('**/*.kotlin_metadata') - exclude('**/*.kotlin_builtins') - - archiveBaseName.set('LoggingModule') - archiveClassifier.set('') -} - -test { - useJUnitPlatform() -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - withSourcesJar() -} - -processResources { - filter ReplaceTokens, tokens: [name: rootProject.name, version: project.version.toString(), description: project.description, git_short: System.getenv("GIT_COMMIT_SHORT_HASH") ?: "unknown", git_full: System.getenv("GIT_COMMIT_LONG_HASH") ?: "unknown"] -} - -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} - -tasks.withType(Copy) { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE -} - -tasks.withType(Jar) { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE -} - -configurations { - testImplementation { - extendsFrom(compileOnly) - } -} - -tasks.named("dokkaHtml") { - outputDirectory.set(file(project.buildDir.absolutePath + '/dokka')) -} - -publishing { - repositories { - if(System.getenv('env') == 'prod'){ - maven { - name = 'TheProgramSrcRepository' - credentials.username = System.getenv('NEXUS_USERNAME') - credentials.password = System.getenv('NEXUS_PASSWORD') - url = uri("https://repo.theprogramsrc.xyz/repository/simplecoreapi-modules/") - } - }else{ - mavenLocal() - } - } - publications { - mavenKotlin(MavenPublication) { publication -> - artifactId = 'loggingmodule' - - from components.java - - pom.withXml { - asNode().appendNode('packaging', 'jar') - if(asNode().get('dependencies')[0] != null){ - asNode().remove(asNode().get('dependencies')[0]) - } - } - } - } -} - -publish.dependsOn clean, test, jar, shadowJar \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..1ce4111 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,193 @@ +import com.github.jengelman.gradle.plugins.shadow.ShadowExtension +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + `maven-publish` + id("io.github.gradle-nexus.publish-plugin") version "1.3.0" + id("com.github.johnrengelman.shadow") version "8.1.1" + id("cl.franciscosolis.blossom-extended") version "1.3.1" + + kotlin("jvm") version "1.9.10" + id("org.jetbrains.dokka") version "1.9.10" +} + +val env = project.rootProject.file(".env").let { file -> + if(file.exists()) file.readLines().filter { it.isNotBlank() && !it.startsWith("#") && it.split("=").size == 2 }.associate { it.split("=")[0] to it.split("=")[1] } else emptyMap() +}.toMutableMap().apply { putAll(System.getenv()) } + +val projectVersion = env["VERSION"] ?: "0.4.1-SNAPSHOT" + +group = "xyz.theprogramsrc" +version = projectVersion +description = "Just a logger for the SimpleCore API" + +repositories { + mavenLocal() + mavenCentral() + + maven("https://s01.oss.sonatype.org/content/groups/public/") + maven("https://oss.sonatype.org/content/repositories/snapshots/") + maven("https://oss.sonatype.org/content/repositories/releases/") + maven("https://oss.sonatype.org/content/groups/public/") + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://repo.codemc.org/repository/maven-public/") + maven("https://jitpack.io/") +} + +dependencies { + compileOnly("xyz.theprogramsrc:simplecoreapi:0.8.0-SNAPSHOT") + + implementation("org.apache.logging.log4j:log4j-api:2.21.0") + implementation("org.apache.logging.log4j:log4j-core:2.21.0") + + testImplementation("org.junit.jupiter:junit-jupiter:5.10.0") +} + +blossom { + replaceToken("@name@", rootProject.name) + replaceToken("@version@", project.version.toString()) + replaceToken("@description@", project.description) + replaceToken("@git_short@", env["GIT_COMMIT_SHORT_HASH"] ?: "unknown") + replaceToken("@git_full@", env["GIT_COMMIT_LONG_HASH"] ?: "unknown") +} + +tasks { + named("shadowJar") { + mergeServiceFiles() + exclude("**/*.kotlin_metadata") + exclude("**/*.kotlin_builtins") + + archiveBaseName.set(rootProject.name) + archiveClassifier.set("") + } + + test { + useJUnitPlatform() + } + + java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + withSourcesJar() + withJavadocJar() + } + + compileKotlin { + kotlinOptions { + jvmTarget = "11" + } + } + + compileTestKotlin { + kotlinOptions { + jvmTarget = "11" + } + } + + compileJava { + options.encoding = "UTF-8" + } + + jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + copy { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + dokkaHtml { + outputDirectory.set(layout.buildDirectory.dir("dokka/")) + } +} + +configurations { + testImplementation { + extendsFrom(configurations.compileOnly.get()) + } +} + +val dokkaJavadocJar by tasks.register("dokkaJavadocJar") { + dependsOn(tasks.dokkaJavadoc, tasks.dokkaHtml) + from(tasks.dokkaJavadoc.flatMap { it.outputDirectory }) + archiveClassifier.set("javadoc") +} + +publishing { + repositories { + if (env["ENV"] == "prod") { + if (env.containsKey("GITHUB_ACTOR") && env.containsKey("GITHUB_TOKEN")) { + maven { + name = "GithubPackages" + url = uri("https://maven.pkg.github.com/TheProgramSrc/SimpleCore-${rootProject.name}") + credentials { + username = env["GITHUB_ACTOR"] + password = env["GITHUB_TOKEN"] + } + } + } + } else { + mavenLocal() + } + } + + publications { + create("shadow") { + project.extensions.configure { + artifactId = rootProject.name.lowercase() + + component(this@create) + artifact(dokkaJavadocJar) + artifact(tasks.kotlinSourcesJar) + + pom { + name.set(rootProject.name) + description.set(project.description) + url.set("https://github.com/TheProgramSrc/SimpleCore-${rootProject.name}") + + licenses { + license { + name.set("GNU GPL v3") + url.set("https://github.com/TheProgramSrc/SimpleCore-${rootProject.name}/blob/master/LICENSE") + } + } + + developers { + developer { + id.set("ImFran") + name.set("Francisco Solis") + email.set("imfran@duck.com") + } + } + + scm { + url.set("https://github.com/TheProgramSrc/SimpleCore-${rootProject.name}") + } + } + } + } + } +} + +if(env["ENV"] == "prod") { + nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + + username.set(env["SONATYPE_USERNAME"]) + password.set(env["SONATYPE_PASSWORD"]) + } + } + } +} + +tasks.withType { + dependsOn(tasks.test, tasks.kotlinSourcesJar, dokkaJavadocJar, tasks.jar, tasks.shadowJar) +} + +tasks.withType { + dependsOn(tasks.test, tasks.kotlinSourcesJar, tasks.jar, dokkaJavadocJar, tasks.shadowJar) +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..35d2cc9 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180..7f93135 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d2880ba..3fa8f86 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 744e882..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,99 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f45d8f1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index cb12792..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'LoggingModule' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..bd180cc --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "LoggingModule" \ No newline at end of file diff --git a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Logger.kt b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Logger.kt index 40f8033..73184a6 100644 --- a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Logger.kt +++ b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Logger.kt @@ -6,6 +6,13 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.logging.Level +/** + * Represents a logger for the logging module. + * @param name The name of the logger + * + * How's this different from other loggers? + * This logger will store the data in isolated folders + */ class Logger(name: String) { private val javaLogger = java.util.logging.Logger.getLogger(name) @@ -31,35 +38,81 @@ class Logger(name: String) { logFile.appendText("[$now] [${level.name}] $message\n") } + /** + * Logs a message at the [Level.INFO] level. + * @param message The message to log + */ fun info(message: String){ javaLogger.info(message) writeToFile(Level.INFO, message) } + /** + * Logs a message at the [Level.WARNING] level. + * @param message The message to log + */ fun warning(message: String){ javaLogger.warning(message) writeToFile(Level.WARNING, message) } + /** + * Logs a message at the [Level.SEVERE] level. + * @param message The message to log + */ fun severe(message: String){ javaLogger.severe(message) writeToFile(Level.SEVERE, message) } + /** + * Logs a message at the [Level.SEVERE] level with an exception. + * @param message The message to log + * @param exception The throwable to log + */ + fun severe(message: String, exception: Exception) { + val newMessage = "$message\n${Utils.getStackTrace(exception)}" + javaLogger.severe(newMessage) + writeToFile(Level.SEVERE, newMessage) + } + + /** + * Logs a message at the [Level.FINE] level. + * @param message The message to log + */ fun fine(message: String){ javaLogger.fine(message) writeToFile(Level.FINE, message) } + /** + * Logs a message at the [Level.FINER] level. + * @param message The message to log + */ fun finer(message: String){ javaLogger.finer(message) writeToFile(Level.FINER, message) } + /** + * Logs a message at the [Level.FINEST] level. + * @param message The message to log + */ fun finest(message: String){ javaLogger.finest(message) writeToFile(Level.FINEST, message) } + /** + * Logs a message at the [Level.ALL] level with the prefix '[DEBUG]'. + * @param message The message to log + */ + fun debug(message: String) { + writeToFile(Level.ALL, "[DEBUG] $message") + if(File(".loggingmodule_debug").exists()) { + javaLogger.log(Level.ALL, "[DEBUG] $message") + } + } + } \ No newline at end of file diff --git a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Main.kt b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Main.kt index 8e5d820..6bf9fc0 100644 --- a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Main.kt +++ b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Main.kt @@ -1,5 +1,22 @@ package xyz.theprogramsrc.loggingmodule -import xyz.theprogramsrc.simplecoreapi.global.module.Module +import xyz.theprogramsrc.simplecoreapi.global.models.module.Module +import xyz.theprogramsrc.simplecoreapi.global.models.module.ModuleDescription -class Main: Module() \ No newline at end of file +class FilesModule: Module { + + override val description: ModuleDescription = + ModuleDescription( + name = "@name@", + version = "@version@", + authors = listOf("Im-Fran") + ) + + override fun onEnable() { + // Do nothing + } + + override fun onDisable() { + // Do nothing + } +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Utils.kt b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Utils.kt new file mode 100644 index 0000000..4dc2d0a --- /dev/null +++ b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/Utils.kt @@ -0,0 +1,16 @@ +package xyz.theprogramsrc.loggingmodule + +import java.io.PrintWriter +import java.io.StringWriter + +object Utils { + + private val cache = mutableMapOf() + + fun getStackTrace(e: Exception): String = cache.computeIfAbsent(e.toString()) { + val sw = StringWriter() + e.printStackTrace(PrintWriter(sw)) + sw.toString() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/filter/LogFilter.kt b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/filter/LogFilter.kt index 2f5c715..ea9cf31 100644 --- a/src/main/kotlin/xyz/theprogramsrc/loggingmodule/filter/LogFilter.kt +++ b/src/main/kotlin/xyz/theprogramsrc/loggingmodule/filter/LogFilter.kt @@ -14,7 +14,7 @@ import org.apache.logging.log4j.message.Message * @param result The result to use if the filter matches * @param filteredStrings The strings that a message must contain to be filtered */ -open class LogFilter(val result: FilterResult = FilterResult.NEUTRAL, val filteredStrings: Array): AbstractFilter() { +open class LogFilter(private val result: FilterResult = FilterResult.NEUTRAL, private val filteredStrings: Array): AbstractFilter() { /** * Extra requirements for a string filter to be matched diff --git a/src/main/resources/module.properties b/src/main/resources/module.properties deleted file mode 100644 index 7678ff7..0000000 --- a/src/main/resources/module.properties +++ /dev/null @@ -1,6 +0,0 @@ -main=xyz.theprogramsrc.loggingmodule.Main -name=LoggingModule -description=@description@ -version=@version@ -author=TheProgramSrc -repository-id=loggingmodule