diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..584b141 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +* +!gradlew +!gradle/ +!gradle.properties +!settings.gradle.kts +!build-logic/ +!api/ +!agent/ +!patcher/ +!docker/ +**/build/ +**/.gradle/ diff --git a/.gitignore b/.gitignore index e0bd0ea..15fc579 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,13 @@ -# ---> Java -# Compiled class file -*.class +*.md +!README.md +lib +.*/ -# Log file +build/ +out/ +*.class *.log -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # *.jar *.war *.nar @@ -19,51 +15,11 @@ *.zip *.tar.gz *.rar +!gradle/wrapper/gradle-wrapper.jar -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* - -# ---> Lua -# Compiled Lua sources -luac.out - -# luarocks build files -*.src.rock -*.zip -*.tar.gz - -# Object files -*.o -*.os -*.ko -*.obj -*.elf - -# Precompiled Headers -*.gch -*.pch - -# Libraries *.lib -*.a -*.la -*.lo -*.def -*.exp - -# Shared objects (inc. Windows DLLs) +*.exe *.dll *.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..35a8352 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,61 @@ +# ZomboidForge dedicated server image (linux/amd64). +# +# steamcmd downloads the vanilla server during the build; the repository +# contains no game files. +# +# podman build --platform linux/amd64 -t zomboidforge . +# podman build --build-arg PZ_BRANCH=unstable ... # non-public Steam branch + +ARG PZ_BRANCH=public + +# --- Stage 1: vanilla dedicated server ----------------------------------------- +FROM docker.io/steamcmd/steamcmd:debian-13 AS server + +# steamcmd updates itself on its first run. This runs in its own layer so the +# update is cached and separate from the app installation. +RUN steamcmd +quit + +ARG PZ_BRANCH +COPY docker/install-server.sh /usr/local/bin/install-server +RUN install-server /server "${PZ_BRANCH}" + +# --- Stage 2: ZomboidForge build and server jar patching ----------------------- +FROM docker.io/library/eclipse-temurin:25-jdk AS build +WORKDIR /src + +# Gradle distribution download, cached independently of the sources. +COPY gradlew gradle.properties settings.gradle.kts ./ +COPY gradle gradle +RUN ./gradlew --no-daemon --version + +COPY build-logic build-logic +COPY api api +COPY agent agent +COPY patcher patcher +COPY --from=server /server/java/projectzomboid.jar /pz/projectzomboid.jar +RUN ./gradlew --no-daemon -Ppz.jar=/pz/projectzomboid.jar build :patcher:patchServerJar + +# --- Stage 3: runtime ------------------------------------------------------------ +FROM docker.io/library/debian:trixie-slim + +# ca-certificates: required by steamclient.so to connect to Steam. Unpinned so +# the image picks up the current Debian CA bundle. +# hadolint ignore=DL3008 +RUN apt-get update \ + && apt-get install --yes --no-install-recommends ca-certificates \ + && rm --recursive --force /var/lib/apt/lists/* + +RUN useradd --create-home --uid 1000 pz \ + && mkdir /data \ + && chown pz:pz /data + +COPY --from=server /server /opt/pz +COPY --from=build /src/patcher/build/server/projectzomboid.jar /opt/pz/java/projectzomboid.jar +COPY --from=build /src/agent/build/libs/zomboidforge-agent-*.jar /opt/pz/zomboidforge-agent.jar +COPY docker/entrypoint.sh /usr/local/bin/entrypoint + +USER 1000:1000 +VOLUME /data +# 16261/udp game, 16262/udp direct connect, 27015/tcp RCON +EXPOSE 16261/udp 16262/udp 27015/tcp +ENTRYPOINT ["/usr/local/bin/entrypoint"] diff --git a/README.md b/README.md index 1c7ba06..36ddf5b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,43 @@ # ZomboidForge -An official‑client‑compatible, container‑ready Project Zomboid dedicated server with first‑class support for custom Java mods and drop‑in server builds. \ No newline at end of file +An official‑client‑compatible, container‑ready Project Zomboid dedicated server with +first‑class support for custom Java mods and drop‑in server builds. + +## Building + +The container image downloads the vanilla dedicated server (Steam app 380870) with an +anonymous steamcmd login while it builds, and patches it. No game files are part of this +repository. + +```sh +podman build --platform linux/amd64 -t zomboidforge . # or: docker build ... +``` + +## Running + +```sh +podman run -d --name zomboidforge \ + -e ADMIN_PASSWORD=... -e RCON_PASSWORD=... \ + -p 16261:16261/udp -p 16262:16262/udp -p 27015:27015/tcp \ + -v zomboid-data:/data zomboidforge +``` + +| Variable | Default | | +|---|---|---| +| `SERVER_NAME` | `zomboidforge` | Server config name (`/data/Server/.ini`) | +| `ADMIN_PASSWORD` | | Required on the first start, when the admin account is created | +| `RCON_PASSWORD` | | Written into the server ini on every start; RCON is disabled without it | +| `JVM_MAX_HEAP` | `8g` | `-Xmx` | +| `STEAM` | `1` | `0` runs the server without Steam | + +For local testing there is `compose.yaml` (`podman compose up --build`, passwords from `.env`). + +## Development + +Requires JDK 25 (the game's runtime). The Gradle build compiles against a local vanilla +server jar, `lib/server/java/projectzomboid.jar` by default (override with `-Ppz.jar=...`). + +```sh +./gradlew build # compile + tests +./gradlew :patcher:patchServerJar # -> patcher/build/server/projectzomboid.jar +``` diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000..bc0172f --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + `kotlin-dsl` +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 0000000..a04aec7 --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,7 @@ +rootProject.name = "build-logic" + +dependencyResolutionManagement { + repositories { + gradlePluginPortal() + } +} diff --git a/build-logic/src/main/kotlin/ProjectZomboidExtension.kt b/build-logic/src/main/kotlin/ProjectZomboidExtension.kt new file mode 100644 index 0000000..9151ee8 --- /dev/null +++ b/build-logic/src/main/kotlin/ProjectZomboidExtension.kt @@ -0,0 +1,6 @@ +import org.gradle.api.file.RegularFileProperty + +abstract class ProjectZomboidExtension { + /** Vanilla dedicated server projectzomboid.jar. Not bundled or published. */ + abstract val serverJar: RegularFileProperty +} diff --git a/build-logic/src/main/kotlin/zomboidforge.java-conventions.gradle.kts b/build-logic/src/main/kotlin/zomboidforge.java-conventions.gradle.kts new file mode 100644 index 0000000..5368393 --- /dev/null +++ b/build-logic/src/main/kotlin/zomboidforge.java-conventions.gradle.kts @@ -0,0 +1,32 @@ +plugins { + java +} + +val projectZomboid = extensions.create("projectZomboid") +projectZomboid.serverJar.convention( + layout.settingsDirectory.file( + providers.gradleProperty("pz.jar").orElse("lib/server/java/projectzomboid.jar") + ) +) + +java { + // Project Zomboid ships and runs on Java 25 (bundled Zulu jre64; class version 69). + toolchain.languageVersion = JavaLanguageVersion.of(25) +} + +tasks.withType().configureEach { + options.release = 25 + options.encoding = "UTF-8" + options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-options", "-Xlint:-path")) +} + +tasks.withType().configureEach { + manifest.attributes( + "Implementation-Title" to "ZomboidForge", + "Implementation-Version" to project.version, + ) +} + +tasks.withType().configureEach { + useJUnitPlatform() +} diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..62b69e0 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,23 @@ +# Local test setup: `podman compose up --build`. Passwords are read from the +# environment or from .env (gitignored). +services: + zomboidforge: + build: . + image: localhost/zomboidforge:dev + platform: linux/amd64 + environment: + SERVER_NAME: ${SERVER_NAME:-zomboidforgetest} + ADMIN_PASSWORD: ${ADMIN_PASSWORD:-} + RCON_PASSWORD: ${RCON_PASSWORD:-} + JVM_MAX_HEAP: ${JVM_MAX_HEAP:-8g} + ports: + - "16261:16261/udp" + - "16262:16262/udp" + - "27015:27015/tcp" + volumes: + - zomboid-data:/data + # SIGTERM runs GameServer's shutdown hook, which queues a save-and-quit. + stop_grace_period: 2m + +volumes: + zomboid-data: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..f1ec3e0 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +# +# Container entrypoint: starts the patched Project Zomboid dedicated server +# with the ZomboidForge agent. Arguments are passed through to +# zombie.network.GameServer. +# +# Environment variables: +# SERVER_NAME Server config name (/data/Server/.ini). Default: zomboidforge +# ADMIN_PASSWORD Admin account password. Required on the first start only. +# RCON_PASSWORD Written into the server .ini before every start. RCON is disabled when empty. +# JVM_MAX_HEAP Value for -Xmx. Default: 8g (the vanilla ProjectZomboid64.json value) +# STEAM 1 = Steam mode (required for official Steam clients), 0 = no Steam. Default: 1 + +set -o errexit +set -o nounset +set -o pipefail + +readonly INSTALL_DIR="/opt/pz" +readonly DATA_DIR="/data" +readonly AGENT_JAR="${INSTALL_DIR}/zomboidforge-agent.jar" +readonly JAVA="${INSTALL_DIR}/jre64/bin/java" + +readonly SERVER_NAME="${SERVER_NAME:-zomboidforge}" +readonly ADMIN_PASSWORD="${ADMIN_PASSWORD:-}" +readonly RCON_PASSWORD="${RCON_PASSWORD:-}" +readonly JVM_MAX_HEAP="${JVM_MAX_HEAP:-8g}" +readonly STEAM="${STEAM:-1}" + +readonly SERVER_INI="${DATA_DIR}/Server/${SERVER_NAME}.ini" +readonly SERVER_DB="${DATA_DIR}/db/${SERVER_NAME}.db" + +log() { + echo "[entrypoint] $*" >&2 +} + +# Sets = in the server .ini. Creates the file or the key if missing. +# Project Zomboid reads a partial .ini and writes the missing defaults on start. +set_ini_value() { + local key="$1" + local value="$2" + local temp_file="${SERVER_INI}.tmp" + local key_found=false + local line + + mkdir --parents "$(dirname "${SERVER_INI}")" + : > "${temp_file}" + + if [[ -f "${SERVER_INI}" ]]; then + while IFS= read -r line || [[ -n "${line}" ]]; do + if [[ "${line}" == "${key}="* ]]; then + printf '%s=%s\n' "${key}" "${value}" >> "${temp_file}" + key_found=true + else + printf '%s\n' "${line}" >> "${temp_file}" + fi + done < "${SERVER_INI}" + fi + + if [[ "${key_found}" == false ]]; then + printf '%s=%s\n' "${key}" "${value}" >> "${temp_file}" + fi + + mv "${temp_file}" "${SERVER_INI}" +} + +apply_rcon_password() { + if [[ -z "${RCON_PASSWORD}" ]]; then + log "RCON_PASSWORD is not set; RCON stays disabled unless the .ini sets RCONPassword." + return + fi + set_ini_value "RCONPassword" "${RCON_PASSWORD}" +} + +# Without -adminpassword, Project Zomboid blocks on an interactive prompt to +# create the admin account on the first start. +check_admin_password() { + if [[ -z "${ADMIN_PASSWORD}" && ! -f "${SERVER_DB}" ]]; then + log "First start of '${SERVER_NAME}': ADMIN_PASSWORD is required to create the admin account." + exit 1 + fi +} + +main() { + apply_rcon_password + check_admin_password + + # Same JVM setup as the vanilla ProjectZomboid64.json and start-server.sh. + # Java runs directly instead of through the native ProjectZomboid64 launcher. + local jvm_args=( + "-javaagent:${AGENT_JAR}" + "-Djava.awt.headless=true" + "--enable-native-access=ALL-UNNAMED" + "-Xmx${JVM_MAX_HEAP}" + "-XX:+UseZGC" + "-XX:-OmitStackTraceInFastThrow" + "-Dzomboid.steam=${STEAM}" + "-Dzomboid.znetlog=1" + "-Djava.library.path=linux64/" + "-Djava.security.egd=file:/dev/urandom" + "-cp" "java/:java/projectzomboid.jar" + ) + + local server_args=( + "-cachedir=${DATA_DIR}" + "-servername" "${SERVER_NAME}" + ) + if [[ -n "${ADMIN_PASSWORD}" ]]; then + server_args+=("-adminpassword" "${ADMIN_PASSWORD}") + fi + + # Native libraries: game (linux64/), Steam (install root), JVM (jre64/lib). + # libjsig.so chains signal handlers between the JVM and native libraries. + export LD_LIBRARY_PATH="${INSTALL_DIR}/linux64:${INSTALL_DIR}:${INSTALL_DIR}/jre64/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" + export LD_PRELOAD="libjsig.so${LD_PRELOAD:+:${LD_PRELOAD}}" + + cd "${INSTALL_DIR}" + exec "${JAVA}" "${jvm_args[@]}" zombie.network.GameServer "${server_args[@]}" "$@" +} + +main "$@" diff --git a/docker/install-server.sh b/docker/install-server.sh new file mode 100755 index 0000000..6c35950 --- /dev/null +++ b/docker/install-server.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# +# Installs the vanilla Project Zomboid dedicated server (Steam app 380870) +# with steamcmd, using an anonymous login. Runs in the steamcmd image during +# the Docker build. +# +# Usage: install-server.sh +# Steam branch; "public" is the default branch. + +set -o errexit +set -o nounset +set -o pipefail + +readonly APP_ID="380870" +readonly MAX_ATTEMPTS=3 + +readonly INSTALL_DIR="$1" +readonly BRANCH="$2" + +log() { + echo "[install-server] $*" >&2 +} + +main() { + local branch_args=() + if [[ "${BRANCH}" != "public" ]]; then + branch_args=("-beta" "${BRANCH}") + fi + + # app_update can fail with "Missing configuration" right after steamcmd + # updated itself; a repeated attempt succeeds. + local attempt + for (( attempt = 1; attempt <= MAX_ATTEMPTS; attempt++ )); do + log "Installing app ${APP_ID} (branch ${BRANCH}), attempt ${attempt}/${MAX_ATTEMPTS}" + if steamcmd \ + +force_install_dir "${INSTALL_DIR}" \ + +login anonymous \ + +app_update "${APP_ID}" "${branch_args[@]}" validate \ + +quit + then + break + fi + log "steamcmd failed on attempt ${attempt}" + done + + if [[ ! -f "${INSTALL_DIR}/java/projectzomboid.jar" ]]; then + log "Installation failed: ${INSTALL_DIR}/java/projectzomboid.jar not found" + exit 1 + fi + + # Steam's install metadata; not needed at runtime. + rm --recursive --force "${INSTALL_DIR}/steamapps" +} + +main diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..9542bf3 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,10 @@ +group=dev.overlord.zomboidforge +version=0.1.0-SNAPSHOT + +# Vanilla dedicated server jar used for compilation and patching. +# Default: lib/server/java/projectzomboid.jar (relative to the root project). +# The Docker build sets -Ppz.jar. +#pz.jar= + +org.gradle.configuration-cache=true +org.gradle.parallel=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..134b439 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,15 @@ +[versions] +asm = "9.10.1" +junit = "6.1.3" + +[libraries] +asm = { module = "org.ow2.asm:asm", version.ref = "asm" } +asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" } +asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" } +asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" } +junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } +junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" } +junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" } + +[bundles] +asm = ["asm", "asm-tree", "asm-commons", "asm-util"] diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..eddabd2 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9b7cb4a --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,9 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..379a658 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 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. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# gradlew 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 gradlew +# +# 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//platforms/jvm/plugins-application/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 +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 + +# 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +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 ;; +esac + + + +# Determine the Java command to use to start the JVM. +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 + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + 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" && ! "$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 + +# 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" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + 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 + # 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 +fi + + +# 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, 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" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# 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 new file mode 100644 index 0000000..a51ec4f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,82 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem gradlew startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:execute +@rem Setup the command line + + + +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel + +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..b9c08c5 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,13 @@ +pluginManagement { + includeBuild("build-logic") +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} + +rootProject.name = "ZomboidForge" + +include("api", "agent", "patcher")