#!/bin/bash set -e cd "$(dirname "$0")/.." . tools/_util.sh bash tools/build.sh DIST=build/dist rm -rf "$DIST" mkdir -p "$DIST" echo "=== Staging runtime libs beside the jars ===" for d in $RUNTIME_LIB_DIRS; do mkdir -p "$DIST/lib/$d" n=0 for j in lib/"$d"/*.jar; do is_shippable_jar "$j" || continue # never ship -sources / -javadoc cp "$j" "$DIST/lib/$d/" n=$((n + 1)) done echo " lib/$d/ ($n jars)" done echo "=== Generating console manifest ===" # Generated from what is actually staged, never hand-maintained. Four silent # failure modes: wildcards match nothing; a missing trailing newline makes jar # drop the line; paths are relative to this jar; and java -jar ignores -cp, so # this line is the entire classpath at runtime. MF="$TMP/console-manifest.txt" CPLINE="" for m in $MODULES; do [ "$m" = ui-console ] && continue CPLINE="$CPLINE${CPLINE:+ }$m.jar" done for d in $RUNTIME_LIB_DIRS; do for j in "$DIST"/lib/"$d"/*.jar; do [ -f "$j" ] || continue CPLINE="$CPLINE lib/$d/$(basename "$j")" done done printf 'Class-Path: %s\n\n' "$CPLINE" >"$MF" echo " $CPLINE" echo "=== Packaging ===" for m in $MODULES; do if [ "$m" = ui-console ]; then "$JAR" --create --file "$DIST/$m.jar" \ --main-class "$MAIN_CLASS" --manifest "$MF" -C "build/classes/$m" . else "$JAR" --create --file "$DIST/$m.jar" -C "build/classes/$m" . fi echo " $DIST/$m.jar" done cat >"$DIST/run.bat" <<'EOF' @echo off cd /d "%~dp0" java -jar "%~dp0ui-console.jar" if errorlevel 1 pause EOF [ -f README.pdf ] && cp README.pdf "$DIST/" echo "=== Manifest as it actually landed in the jar ===" # Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't # survive, it surfaces here instead of on the grader's machine. rm -rf "$TMP/mf" && mkdir -p "$TMP/mf" (cd "$TMP/mf" && "$JAR" -xf "$OLDPWD/$DIST/ui-console.jar" META-INF/MANIFEST.MF) sed 's/^/ /' "$TMP/mf/META-INF/MANIFEST.MF" grep -q '^Main-Class:' "$TMP/mf/META-INF/MANIFEST.MF" || { echo "*** Main-Class missing ***" exit 1 } grep -q 'Class-Path:' "$TMP/mf/META-INF/MANIFEST.MF" || { echo "*** Class-Path missing ***" exit 1 } echo "======================================" echo "Self-contained output in $DIST" echo " cd $DIST && java -jar ui-console.jar" echo "======================================"