diff --git a/home/jashton.nix b/home/jashton.nix index 34237d8..327ba08 100644 --- a/home/jashton.nix +++ b/home/jashton.nix @@ -82,21 +82,24 @@ in (pkgs.writeShellScriptBin "jbuild" '' set -euo pipefail - # Assign first: `cd "$(jroot)"` would swallow a jroot failure, because - # `cd ""` is a successful no-op and set -e never sees the error. + if [ $# -lt 1 ]; then + echo "usage: jrun [args...]" >&2 + exit 1 + fi + ROOT="$(jroot)" cd "$ROOT" mkdir -p bin - SOURCES="$(mktemp)" - trap 'rm -f "$SOURCES"' EXIT - find . -path ./bin -prune -o -name '.*' -prune -o -name '*.java' -print > "$SOURCES" + + SOURCES="$1" + + find "$SOURCES" -name '*.java' -path '*.java' + if [ ! -s "$SOURCES" ]; then - echo "jbuild: no .java files found under $ROOT" >&2 + echo "jbuild: no .java files found under ./$SOURCES" >&2 exit 1 fi - # bin is deliberately NOT on the compile classpath: every source is passed - # explicitly, so a stale .class from a deleted file would silently satisfy - # references that ought to fail. + javac -g --release 21 -encoding UTF-8 -d bin -cp "lib/*" @"$SOURCES" '') @@ -114,14 +117,19 @@ in exit 1 fi ROOT="$(jroot)" - jbuild cd "$ROOT" + jbuild $1 MAIN="$1"; shift - exec java -cp "bin:lib/*" "$MAIN" "$@" + java -cp "bin:lib/*" "$MAIN" "$@" '') (pkgs.writeShellScriptBin "jtest" '' set -euo pipefail + if [ "$#" -lt 1 ]; then + echo "usage: jtest [args...]" + exit 1 + fi + # sort -V so 1.10.2 beats 1.9.0; plain tail -n1 sorts those the wrong way. JUNIT="$(ls -1 "$HOME"/dev/jars/junit-platform-console-standalone-*.jar 2>/dev/null | sort -V | tail -n1 || true)" if [ -z "$JUNIT" ]; then @@ -133,15 +141,15 @@ in # on :5005 (see the "Attach to jtest" config in nvim.nix), so breakpoints # set before running jtest --debug are hit from the very first test. DEBUG_ARGS=() - if [ "''${1:-}" = "--debug" ]; then + if [[ "$1" = "debug" ]]; then DEBUG_ARGS=(-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005) shift echo "jtest: waiting for debugger to attach on 127.0.0.1:5005..." >&2 fi ROOT="$(jroot)" - jbuild cd "$ROOT" + jbuild "$1" if [ $# -eq 0 ]; then exec java "''${DEBUG_ARGS[@]}" -jar "$JUNIT" execute --class-path "bin:lib/*" --scan-class-path --details=tree fi