diff --git a/build.gradle.kts b/build.gradle.kts index 925ca52..8497846 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,18 @@ +import org.jooq.codegen.GenerationTool +import org.jooq.meta.jaxb.Configuration +import org.jooq.meta.jaxb.Database +import org.jooq.meta.jaxb.Generator +import org.jooq.meta.jaxb.Jdbc +import java.time.Instant + plugins { `java-library` id("com.github.johnrengelman.shadow") version "8.1.1" // Shades and relocates dependencies, See https://imperceptiblethoughts.com/shadow/introduction/ - id("xyz.jpenilla.run-paper") version "2.1.0" // Adds runServer and runMojangMappedServer tasks for testing + id("xyz.jpenilla.run-paper") version "2.2.2" // Adds runServer and runMojangMappedServer tasks for testing id("net.minecrell.plugin-yml.bukkit") version "0.6.0" // Automatic plugin.yml generation - id("io.papermc.paperweight.userdev") version "1.5.5" // Used to develop internal plugins using Mojang mappings + id("io.papermc.paperweight.userdev") version "1.5.9" // Used to develop internal plugins using Mojang mappings, See https://github.com/PaperMC/paperweight + id("org.flywaydb.flyway") version "10.0.0" // Database migrations eclipse idea @@ -58,16 +66,15 @@ dependencies { annotationProcessor("org.jetbrains:annotations:24.0.1") paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") - implementation("space.arim.morepaperlib:morepaperlib:0.4.3") + implementation("space.arim.morepaperlib:morepaperlib:latest.release") implementation("com.github.milkdrinkers:crate:1.1.0") - implementation("com.github.milkdrinkers:colorparser:2.0.0") + implementation("com.github.milkdrinkers:colorparser:2.0.0") { + exclude("net.kyori") + } implementation("dev.jorel:commandapi-bukkit-shade:9.2.0") - implementation("com.zaxxer:HikariCP:5.0.1") - library("org.mariadb.jdbc:mariadb-java-client:3.1.4") - compileOnly("me.clip:placeholderapi:2.11.4") { exclude("me.clip.placeholderapi.libs", "kyori") } @@ -80,9 +87,27 @@ dependencies { compileOnly("com.github.Gecolay.GSit:core:1.5.0") compileOnly(files("lib/HeadsPlus-7.0.14.jar")) compileOnly(files("lib/Skulls.jar")) + + // Database Dependencies + implementation("com.zaxxer:HikariCP:5.1.0") + library("org.flywaydb:flyway-core:10.0.1") + library("org.flywaydb:flyway-mysql:10.0.1") + library("org.flywaydb:flyway-database-hsqldb:10.0.1") + library("org.jooq:jooq:3.18.7") + + // JDBC Drivers + library("org.hsqldb:hsqldb:2.7.2") + library("com.h2database:h2:2.2.224") + library("com.mysql:mysql-connector-j:8.2.0") + library("org.mariadb.jdbc:mariadb-java-client:3.3.0") } tasks { + // NOTE: Use when developing plugins using Mojang mappings + assemble { + dependsOn(reobfJar) + } + build { dependsOn(shadowJar) } @@ -94,6 +119,13 @@ tasks { // See https://openjdk.java.net/jeps/247 for more information. options.release.set(17) options.compilerArgs.addAll(arrayListOf("-Xlint:all", "-Xlint:-processing", "-Xdiags:verbose")) + + // Generate jOOQ sources before compilation + dependsOn(project.tasks.named("generateSources")) + } + + javadoc { + options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything } processResources { @@ -105,24 +137,38 @@ tasks { archiveClassifier.set("") // Shadow classes - // helper function to relocate a package into our package - fun reloc(originPkg: String, targetPkg: String) = relocate(originPkg, "${project.group}.lib.${targetPkg}") + fun reloc(originPkg: String, targetPkg: String) = relocate(originPkg, "${mainPackage}.lib.${targetPkg}") reloc("space.arim.morepaperlib", "morepaperlib") - reloc("dev.jorel.commandapi", "commandapi") reloc("com.github.milkdrinkers.Crate", "crate") reloc("com.github.milkdrinkers.colorparser", "colorparser") + reloc("dev.jorel.commandapi", "commandapi") reloc("com.zaxxer.hikari", "hikaricp") + + mergeServiceFiles { + setPath("META-INF/services/org.flywaydb.core.extensibility.Plugin") // Fix Flyway overriding its own files + } + + minimize() } runServer { // Configure the Minecraft version for our task. - minecraftVersion("1.20.1") + minecraftVersion("1.20.2") // IntelliJ IDEA debugger setup: https://docs.papermc.io/paper/dev/debugging#using-a-remote-debugger - jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005") + jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-DPaper.IgnoreJavaVersion=true", "-Dcom.mojang.eula.agree=true", "-DIReallyKnowWhatIAmDoingISwear") systemProperty("terminal.jline", false) systemProperty("terminal.ansi", true) + + // Automatically install dependencies + downloadPlugins { +// modrinth("carbon", "2.1.0-beta.21") +// github("jpenilla", "MiniMOTD", "v2.0.13", "minimotd-bukkit-2.0.13.jar") +// hangar("squaremap", "1.2.0") +// url("https://download.luckperms.net/1515/bukkit/loader/LuckPerms-Bukkit-5.4.102.jar") + github("MilkBowl", "Vault", "1.7.3", "Vault.jar") + } } } @@ -143,7 +189,91 @@ bukkit { // Options: https://github.com/Minecrell/plugin-yml#bukkit load = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.PluginLoadOrder.POSTWORLD // STARTUP or POSTWORLD depend = listOf("Vault", "Towny") softDepend = listOf("TAB", "Skulls", "HeadsPlus") -}// Apply custom version arg +} + +flyway { + url = "jdbc:h2:${project.layout.buildDirectory.get()}/generated/flyway/db;AUTO_SERVER=TRUE;MODE=MySQL;CASE_INSENSITIVE_IDENTIFIERS=TRUE;IGNORECASE=TRUE" + user = "sa" + password = "" + placeholders = mapOf( // Substitute placeholders for flyway + "tablePrefix" to "", + "columnSuffix" to " VIRTUAL", + "tableDefaults" to "", + "uuidType" to "BINARY(16)", + "inetType" to "VARBINARY(16)", + "binaryType" to "BLOB", + "alterViewStatement" to "ALTER VIEW", + ) + validateMigrationNaming = true + baselineOnMigrate = true + cleanDisabled = false + locations = arrayOf( + "filesystem:src/main/resources/db/migration", + "classpath:db/migration" + ) +} + +task("generateSources") { + this.group = "jooq" + val dir = layout.buildDirectory.dir("generated-src/jooq").get() + + // Ensure database schema has been prepared by Flyway before generating the jOOQ sources + dependsOn.add(tasks.flywayMigrate) + + // Declare Flyway migration scripts as inputs on the jOOQ task + inputs.files(fileTree("src/main/resources/db/migration"), fileTree("src/main/java/${mainPackage}/db/flyway/migration")) + .withPropertyName("migration files") + .withPathSensitivity(PathSensitivity.RELATIVE) + + // jOOQ Generation Task + doLast { + GenerationTool.generate(Configuration() + .withLogging(org.jooq.meta.jaxb.Logging.WARN) + .withJdbc(Jdbc() + .withDriver("org.h2.Driver") + .withUrl(flyway.url) + .withUser(flyway.user) + .withPassword(flyway.password) + ) + .withGenerator(Generator() + .withName("org.jooq.codegen.DefaultGenerator") + .withDatabase(Database() + .withName("org.jooq.meta.h2.H2Database") + .withIncludes(".*") + .withExcludes("(flyway_schema_history)|(?i:information_schema\\..*)|(?i:system_lobs\\..*)") // Exclude db specific files + .withInputSchema("PUBLIC") + .withSchemaVersionProvider("SELECT :schema_name || '_' || MAX(\"version\") FROM \"flyway_schema_history\"") // Grab version from Flyway + ) + .withTarget(org.jooq.meta.jaxb.Target() + .withPackageName("${mainPackage}.db.schema") + .withDirectory(dir.toString()) + .withClean(true) + ) + ) + ) + } + + // Declare outputs + outputs.dir(dir) + .withPropertyName("jooq generated sources") + sourceSets { + get("main").java.srcDir(dir) + } + + // Enable build caching + outputs.cacheIf { true } +} + +buildscript { + dependencies { + classpath("org.jooq:jooq:3.18.7") + classpath("org.jooq:jooq-meta:3.18.7") + classpath("org.jooq:jooq-codegen:3.18.7") + classpath("com.h2database:h2:2.2.224") + } +} + +// Apply custom version arg val versionArg = if (hasProperty("customVersion")) (properties["customVersion"] as String).uppercase() // Uppercase version string else diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4e75374 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,4 @@ +org.gradle.caching=true +org.gradle.parallel=true +org.gradle.daemon=true +org.gradle.jvmargs=-Xmx2048M diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba7..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 42defcc..3fa8f86 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-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 121251c..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -69,33 +69,31 @@ app_path=$0 # Need this for daisy-chained symlinks. while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path [ -h "$app_path" ] do - ls=$(ls -ld "$app_path") + ls=$( ls -ld "$app_path" ) link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; esac done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$(cd "${APP_HOME:-./}" && pwd -P) || exit - -# 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"' +# 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 -warn() { +warn () { echo "$*" } >&2 -die() { +die () { echo echo "$*" echo @@ -107,24 +105,25 @@ 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 + # Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then +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 else JAVACMD=$JAVA_HOME/bin/java fi - if [ ! -x "$JAVACMD" ]; then + if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the @@ -132,30 +131,31 @@ 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. + 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" && ! "$darwin" && ! "$nonstop"; then +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( - max*) + max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$(ulimit -H -n) || + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" - ;; esac - case $MAX_FD in #( - '' | soft) : ;; #( - *) + 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=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" - ;; esac fi @@ -168,25 +168,23 @@ fi # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys"; then - APP_HOME=$(cygpath --path --mixed "$APP_HOME") - CLASSPATH=$(cygpath --path --mixed "$CLASSPATH") +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - JAVACMD=$(cygpath --unix "$JAVACMD") + JAVACMD=$( cygpath --unix "$JAVACMD" ) # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg; do + 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 ;; + 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") + arg=$( cygpath --path --ignore --mixed "$arg" ) fi # 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 @@ -195,25 +193,30 @@ if "$cygwin" || "$msys"; then # 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 + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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 \ - "$@" + "-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 +if ! command -v xargs >/dev/null 2>&1 +then die "xargs is not available" fi @@ -237,10 +240,10 @@ fi # eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | xargs -n1 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | tr '\n' ' ' -)" '"$@"' + )" '"$@"' exec "$JAVACMD" "$@"