diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/_util.sh | 27 | ||||
| -rwxr-xr-x | tools/build.sh | 5 | ||||
| -rw-r--r-- | tools/package.sh | 75 |
3 files changed, 70 insertions, 37 deletions
diff --git a/tools/_util.sh b/tools/_util.sh index fde4797..a041f2d 100644 --- a/tools/_util.sh +++ b/tools/_util.sh | |||
| @@ -5,15 +5,18 @@ case "$(uname -s)" in | |||
| 5 | *) SEP=":" ;; | 5 | *) SEP=":" ;; |
| 6 | esac | 6 | esac |
| 7 | 7 | ||
| 8 | MODULES="api service ui-console" | 8 | MODULES="api service ui-console ui-desktop" |
| 9 | 9 | ||
| 10 | DEPS_api="" | 10 | DEPS_api="" |
| 11 | DEPS_service="api" | 11 | DEPS_service="api" |
| 12 | DEPS_ui_console="api service" | 12 | DEPS_ui_console="api service" |
| 13 | DEPS_ui_desktop="" | ||
| 13 | 14 | ||
| 14 | RUNTIME_LIB_DIRS="pico jaxb gson" | 15 | RUNTIME_LIB_DIRS="pico jaxb gson openjfx" |
| 15 | 16 | ||
| 16 | MAIN_CLASS="market.guess.ui.console.App" | 17 | EXECUTABLES="ui-console ui-desktop" |
| 18 | MAINCLASS_ui_console="market.guess.ui.console.App" | ||
| 19 | MAINCLASS_ui_desktop="market.guess.ui.desktop.Launcher" | ||
| 17 | 20 | ||
| 18 | JAVA_HOME_DIR=$(java -XshowSettings:properties -version 2>&1 | tr -d '\r' | sed -n 's/^ *java\.home = //p') | 21 | JAVA_HOME_DIR=$(java -XshowSettings:properties -version 2>&1 | tr -d '\r' | sed -n 's/^ *java\.home = //p') |
| 19 | case "$(uname -s)" in | 22 | case "$(uname -s)" in |
| @@ -45,6 +48,24 @@ deps_of() { | |||
| 45 | eval "printf '%s' \"\${$v}\"" | 48 | eval "printf '%s' \"\${$v}\"" |
| 46 | } | 49 | } |
| 47 | 50 | ||
| 51 | mainclass_of() { | ||
| 52 | local v="MAINCLASS_$(echo "$1" | tr '-' '_')" | ||
| 53 | eval "printf '%s' \"\${$v}\"" | ||
| 54 | } | ||
| 55 | |||
| 56 | # JAR manifest lines are capped at 72 bytes; a raw "Key: value" line trips | ||
| 57 | # `line too long` once enough jars are on the Class-Path (openjfx pushed us | ||
| 58 | # over it). Fold per spec: continuation lines start with a single space. | ||
| 59 | write_manifest_attr() { | ||
| 60 | local file="$1" line="$2: $3" | ||
| 61 | : >"$file" | ||
| 62 | while [ "${#line}" -gt 72 ]; do | ||
| 63 | printf '%s\n' "${line:0:72}" >>"$file" | ||
| 64 | line=" ${line:72}" | ||
| 65 | done | ||
| 66 | printf '%s\n\n' "$line" >>"$file" | ||
| 67 | } | ||
| 68 | |||
| 48 | module_cp() { | 69 | module_cp() { |
| 49 | local cp="" | 70 | local cp="" |
| 50 | for d in "$@"; do cp="$cp${cp:+$SEP}build/classes/$d"; done | 71 | for d in "$@"; do cp="$cp${cp:+$SEP}build/classes/$d"; done |
diff --git a/tools/build.sh b/tools/build.sh index 72880ee..b8886b1 100755 --- a/tools/build.sh +++ b/tools/build.sh | |||
| @@ -15,9 +15,10 @@ for m in $MODULES; do | |||
| 15 | cp="${cp:+$cp$SEP}$LIBCP" | 15 | cp="${cp:+$cp$SEP}$LIBCP" |
| 16 | 16 | ||
| 17 | find "$m/src/main/java" -name '*.java' >"$TMP/src.txt" | 17 | find "$m/src/main/java" -name '*.java' >"$TMP/src.txt" |
| 18 | mkdir -p "build/classes/$m" | 18 | mkdir -p "build/classes/$m" "build/generated-sources/$m" |
| 19 | printf ' %-11s sees: %s\n' "$m" "${deps:-<nothing>}" | 19 | printf ' %-11s sees: %s\n' "$m" "${deps:-<nothing>}" |
| 20 | javac --release "$JAVA_RELEASE" -d "build/classes/$m" -cp "$cp" "@$TMP/src.txt" | 20 | javac --release "$JAVA_RELEASE" -d "build/classes/$m" -cp "$cp" \ |
| 21 | -processorpath "$LIBCP" -s "build/generated-sources/$m" "@$TMP/src.txt" | ||
| 21 | done | 22 | done |
| 22 | 23 | ||
| 23 | echo "=== Build OK ===" | 24 | echo "=== Build OK ===" |
diff --git a/tools/package.sh b/tools/package.sh index a85ee6c..186dab5 100644 --- a/tools/package.sh +++ b/tools/package.sh | |||
| @@ -22,63 +22,74 @@ for d in $RUNTIME_LIB_DIRS; do | |||
| 22 | echo " lib/$d/ ($n jars)" | 22 | echo " lib/$d/ ($n jars)" |
| 23 | done | 23 | done |
| 24 | 24 | ||
| 25 | echo "=== Generating console manifest ===" | 25 | echo "=== Generating executable manifests ===" |
| 26 | # Generated from what is actually staged, never hand-maintained. Four silent | 26 | # Generated from what is actually staged, never hand-maintained. Four silent |
| 27 | # failure modes: wildcards match nothing; a missing trailing newline makes jar | 27 | # failure modes: wildcards match nothing; a missing trailing newline makes jar |
| 28 | # drop the line; paths are relative to this jar; and java -jar ignores -cp, so | 28 | # drop the line; paths are relative to this jar; and java -jar ignores -cp, so |
| 29 | # this line is the entire classpath at runtime. | 29 | # this line is the entire classpath at runtime. |
| 30 | MF="$TMP/console-manifest.txt" | 30 | for e in $EXECUTABLES; do |
| 31 | CPLINE="" | 31 | CPLINE="" |
| 32 | for m in $MODULES; do | 32 | for m in $MODULES; do |
| 33 | [ "$m" = ui-console ] && continue | 33 | [ "$m" = "$e" ] && continue |
| 34 | CPLINE="$CPLINE${CPLINE:+ }$m.jar" | 34 | CPLINE="$CPLINE${CPLINE:+ }$m.jar" |
| 35 | done | 35 | done |
| 36 | for d in $RUNTIME_LIB_DIRS; do | 36 | for d in $RUNTIME_LIB_DIRS; do |
| 37 | for j in "$DIST"/lib/"$d"/*.jar; do | 37 | for j in "$DIST"/lib/"$d"/*.jar; do |
| 38 | [ -f "$j" ] || continue | 38 | [ -f "$j" ] || continue |
| 39 | CPLINE="$CPLINE lib/$d/$(basename "$j")" | 39 | CPLINE="$CPLINE lib/$d/$(basename "$j")" |
| 40 | done | ||
| 40 | done | 41 | done |
| 42 | write_manifest_attr "$TMP/$e-manifest.txt" "Class-Path" "$CPLINE" | ||
| 43 | echo " $e: $CPLINE" | ||
| 41 | done | 44 | done |
| 42 | printf 'Class-Path: %s\n\n' "$CPLINE" >"$MF" | ||
| 43 | echo " $CPLINE" | ||
| 44 | 45 | ||
| 45 | echo "=== Packaging ===" | 46 | echo "=== Packaging ===" |
| 46 | for m in $MODULES; do | 47 | for m in $MODULES; do |
| 47 | if [ "$m" = ui-console ]; then | 48 | case " $EXECUTABLES " in |
| 48 | "$JAR" --create --file "$DIST/$m.jar" \ | 49 | *" $m "*) |
| 49 | --main-class "$MAIN_CLASS" --manifest "$MF" -C "build/classes/$m" . | 50 | "$JAR" --create --file "$DIST/$m.jar" --main-class "$(mainclass_of "$m")" \ |
| 50 | else | 51 | --manifest "$TMP/$m-manifest.txt" -C "build/classes/$m" . |
| 52 | ;; | ||
| 53 | *) | ||
| 51 | "$JAR" --create --file "$DIST/$m.jar" -C "build/classes/$m" . | 54 | "$JAR" --create --file "$DIST/$m.jar" -C "build/classes/$m" . |
| 52 | fi | 55 | ;; |
| 56 | esac | ||
| 53 | echo " $DIST/$m.jar" | 57 | echo " $DIST/$m.jar" |
| 54 | done | 58 | done |
| 55 | 59 | ||
| 56 | cat >"$DIST/run.bat" <<'EOF' | 60 | for e in $EXECUTABLES; do |
| 61 | cat >"$DIST/run-${e#ui-}.bat" <<EOF | ||
| 57 | @echo off | 62 | @echo off |
| 58 | cd /d "%~dp0" | 63 | cd /d "%~dp0" |
| 59 | java -jar "%~dp0ui-console.jar" | 64 | java -jar "%~dp0$e.jar" |
| 60 | if errorlevel 1 pause | 65 | if errorlevel 1 pause |
| 61 | EOF | 66 | EOF |
| 67 | done | ||
| 62 | 68 | ||
| 63 | [ -f README.pdf ] && cp README.pdf "$DIST/" | 69 | [ -f README.pdf ] && cp README.pdf "$DIST/" |
| 64 | 70 | ||
| 65 | echo "=== Manifest as it actually landed in the jar ===" | 71 | echo "=== Manifest as it actually landed in the jar ===" |
| 66 | # Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't | 72 | # Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't |
| 67 | # survive, it surfaces here instead of on the grader's machine. | 73 | # survive, it surfaces here instead of on the grader's machine. |
| 68 | rm -rf "$TMP/mf" && mkdir -p "$TMP/mf" | 74 | for e in $EXECUTABLES; do |
| 69 | (cd "$TMP/mf" && "$JAR" -xf "$OLDPWD/$DIST/ui-console.jar" META-INF/MANIFEST.MF) | 75 | rm -rf "$TMP/mf" && mkdir -p "$TMP/mf" |
| 70 | sed 's/^/ /' "$TMP/mf/META-INF/MANIFEST.MF" | 76 | (cd "$TMP/mf" && "$JAR" -xf "$OLDPWD/$DIST/$e.jar" META-INF/MANIFEST.MF) |
| 77 | echo "-- $e.jar --" | ||
| 78 | sed 's/^/ /' "$TMP/mf/META-INF/MANIFEST.MF" | ||
| 71 | 79 | ||
| 72 | grep -q '^Main-Class:' "$TMP/mf/META-INF/MANIFEST.MF" || { | 80 | grep -q '^Main-Class:' "$TMP/mf/META-INF/MANIFEST.MF" || { |
| 73 | echo "*** Main-Class missing ***" | 81 | echo "*** Main-Class missing in $e.jar ***" |
| 74 | exit 1 | 82 | exit 1 |
| 75 | } | 83 | } |
| 76 | grep -q 'Class-Path:' "$TMP/mf/META-INF/MANIFEST.MF" || { | 84 | grep -q 'Class-Path:' "$TMP/mf/META-INF/MANIFEST.MF" || { |
| 77 | echo "*** Class-Path missing ***" | 85 | echo "*** Class-Path missing in $e.jar ***" |
| 78 | exit 1 | 86 | exit 1 |
| 79 | } | 87 | } |
| 88 | done | ||
| 80 | 89 | ||
| 81 | echo "======================================" | 90 | echo "======================================" |
| 82 | echo "Self-contained output in $DIST" | 91 | echo "Self-contained output in $DIST" |
| 83 | echo " cd $DIST && java -jar ui-console.jar" | 92 | for e in $EXECUTABLES; do |
| 93 | echo " cd $DIST && java -jar $e.jar" | ||
| 94 | done | ||
| 84 | echo "======================================" | 95 | echo "======================================" |