Skip to content

Commit 4658948

Browse files
committed
harden standalone module installer build
1 parent 79eb531 commit 4658948

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

standalone/build.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
#!/usr/bin/env bash
22
# build.sh — Compiles and packages the NWE Module Installer standalone JAR
33
# Usage: bash standalone/build.sh
4-
54
set -euo pipefail
65

7-
DIR="$(cd "$(dirname "$0")" && pwd)"
6+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
SOURCE="$DIR/NWEModuleInstaller.java"
88
OUT="$DIR/out"
99
JAR="$DIR/nwe-module-installer.jar"
1010

11-
echo "=== Building NWE Module Installer (standalone) ==="
11+
command -v javac >/dev/null 2>&1 || { echo "[FAIL] javac is required." >&2; exit 1; }
12+
command -v jar >/dev/null 2>&1 || { echo "[FAIL] jar is required." >&2; exit 1; }
13+
[[ -f "$SOURCE" ]] || { echo "[FAIL] Missing source: $SOURCE" >&2; exit 1; }
14+
15+
JAVA_MAJOR="$(javac -version 2>&1 | awk '{print $2}' | cut -d. -f1)"
16+
[[ "$JAVA_MAJOR" =~ ^[0-9]+$ && "$JAVA_MAJOR" -ge 21 ]] || {
17+
echo "[FAIL] Java 21+ is required; detected javac $JAVA_MAJOR" >&2
18+
exit 1
19+
}
1220

21+
cleanup() { rm -rf "$OUT"; }
22+
trap cleanup EXIT
23+
24+
printf '%s\n' "=== Building NWE Module Installer (standalone) ==="
1325
mkdir -p "$OUT"
1426

1527
echo "[1/3] Compiling..."
16-
javac -d "$OUT" --release 21 "$DIR/NWEModuleInstaller.java"
28+
javac -d "$OUT" --release 21 "$SOURCE"
1729

1830
echo "[2/3] Creating manifest..."
19-
echo "Main-Class: NWEModuleInstaller" > "$OUT/MANIFEST.MF"
31+
printf 'Manifest-Version: 1.0\nMain-Class: NWEModuleInstaller\n' > "$OUT/MANIFEST.MF"
2032

2133
echo "[3/3] Packaging JAR..."
2234
jar cfm "$JAR" "$OUT/MANIFEST.MF" -C "$OUT" .
2335

24-
rm -rf "$OUT"
25-
26-
echo ""
27-
echo " ✔ Built: $JAR"
28-
echo " Run: java -jar $JAR"
29-
echo ""
36+
[[ -s "$JAR" ]] || { echo "[FAIL] JAR was not created: $JAR" >&2; exit 1; }
37+
echo " Built: $JAR"
38+
echo " Run: java -jar $JAR"
3039
echo "=== Done ==="

0 commit comments

Comments
 (0)