summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKostya <mail@sartin.in>2026-08-18 06:52:47 +0000
committerKostya <mail@sartin.in>2026-08-18 06:52:47 +0000
commitd2688a197bd680580699f05e8194f9180e4832fa (patch)
tree0531ef505b0637c9c4bcc17ab6183a6089e26889 /tools
parent13a221ffaefc169d028c7eab6f21ac88052d1d40 (diff)
downloadguess-market-d2688a197bd680580699f05e8194f9180e4832fa.tar.gz
guess-market-d2688a197bd680580699f05e8194f9180e4832fa.tar.xz
guess-market-d2688a197bd680580699f05e8194f9180e4832fa.zip
Add XML schema validation, split build scripts by module, rename BuyMenuCommand to PlaceOrderMenuCommand
Introduces XMLValidatorV1 and deserializer/adapter classes for events, ledgers, markets, users, and trading mechanisms. Replaces the monolithic build.bat/run.sh scripts with per-module tools (_util.sh, build.sh, package.sh, test.sh) that compile in dependency order.
Diffstat (limited to 'tools')
-rw-r--r--tools/_util.sh47
-rw-r--r--tools/build.bat72
-rwxr-xr-xtools/build.sh70
-rw-r--r--tools/package.sh82
-rw-r--r--tools/run.bat16
-rw-r--r--tools/run.sh12
-rw-r--r--tools/test.sh47
7 files changed, 192 insertions, 154 deletions
diff --git a/tools/_util.sh b/tools/_util.sh
new file mode 100644
index 0000000..4650616
--- /dev/null
+++ b/tools/_util.sh
@@ -0,0 +1,47 @@
1JAVA_RELEASE=25
2
3case "$(uname -s)" in
4 CYGWIN*|MINGW*|MSYS*) SEP=";" ;;
5 *) SEP=":" ;;
6esac
7
8MODULES="api service ui-console"
9
10DEPS_api=""
11DEPS_service="api"
12DEPS_ui_console="api service"
13
14RUNTIME_LIB_DIRS="pico jaxb gson"
15
16MAIN_CLASS="market.guess.ui.console.App"
17
18JAVA_HOME_DIR=$(java -XshowSettings:properties -version 2>&1 | sed -n 's/^ *java\.home = //p')
19JAR="$JAVA_HOME_DIR/bin/jar"
20[ -x "$JAR" ] || JAR="$JAVA_HOME_DIR/bin/jar.exe"
21if [ ! -x "$JAR" ]; then
22 echo "Could not locate the 'jar' tool under $JAVA_HOME_DIR" >&2
23 exit 1
24fi
25
26is_shippable_jar() {
27 case "$1" in *-sources.jar | *-javadoc.jar) return 1 ;; *) return 0 ;; esac
28}
29LIBCP=""
30for j in lib/*/*.jar; do
31 is_shippable_jar "$j" || continue
32 LIBCP="$LIBCP${LIBCP:+$SEP}$j"
33done
34
35TMP="${TMPDIR:-/tmp}/gm-build"
36mkdir -p "$TMP"
37
38deps_of() {
39 local v="DEPS_$(echo "$1" | tr '-' '_')"
40 eval "printf '%s' \"\${$v}\""
41}
42
43module_cp() {
44 local cp=""
45 for d in "$@"; do cp="$cp${cp:+$SEP}build/classes/$d"; done
46 printf '%s' "$cp"
47}
diff --git a/tools/build.bat b/tools/build.bat
deleted file mode 100644
index eb6b460..0000000
--- a/tools/build.bat
+++ /dev/null
@@ -1,72 +0,0 @@
1@echo off
2setlocal enabledelayedexpansion
3
4echo === 1. Cleaning Workspace ===
5if exist bin rmdir /s /q bin
6if exist stage rmdir /s /q stage
7if exist dist rmdir /s /q dist
8mkdir bin\classes
9mkdir bin\test-classes
10mkdir stage
11mkdir dist
12
13echo === 2. Compiling Production Code ===
14dir /s /b src\main\java\*.java > sources.txt
15javac -d bin\classes -cp "lib/*" @sources.txt
16if %errorlevel% neq 0 exit /b %errorlevel%
17
18echo === 3. Compiling Test Code ===
19dir /s /b src\test\java\*.java > test-sources.txt
20javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt
21if %errorlevel% neq 0 exit /b %errorlevel%
22
23echo === 4. Running Automated Tests ===
24set "JUNIT_JAR="
25for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f"
26if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1)
27
28rem JUnit's --class-path does NOT expand lib\* -> build it explicitly
29set "TEST_CP=bin\classes;bin\test-classes"
30for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j"
31
32java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath
33if %errorlevel% neq 0 (
34 echo [X] Tests failed! Aborting build package.
35 exit /b %errorlevel%
36)
37echo [OK] Tests passed successfully!
38
39echo === 5. Extracting Dependencies for Fat JAR ===
40cd stage
41for %%j in (..\lib\*.jar) do (
42 echo %%~nxj | findstr /i "junit-platform-console-standalone" >nul
43 if errorlevel 1 (
44 echo Extracting: %%~nxj
45 jar -xf "%%j"
46 )
47)
48
49rem Strip signatures + manifests (they break repacking) but KEEP
50rem META-INF\services so ServiceLoader-based deps still work at runtime.
51if exist META-INF (
52 del /s /q META-INF\*.SF >nul 2>&1
53 del /s /q META-INF\*.RSA >nul 2>&1
54 del /s /q META-INF\*.DSA >nul 2>&1
55 del /q META-INF\MANIFEST.MF >nul 2>&1
56)
57cd ..
58
59echo === 6. Merging Assets into Fat JAR ===
60rem Merge ONLY production classes on top of the extracted deps
61xcopy /e /q /y /i bin\classes\* stage\ >nul
62rem Package the whole tree (deps + your classes), not just stage\classes
63jar cfe dist/app.jar com.example.App -C stage .
64if %errorlevel% neq 0 exit /b %errorlevel%
65
66del sources.txt test-sources.txt >nul 2>&1
67rmdir /s /q stage
68echo ======================================
69echo Fat JAR Created! Run it with:
70echo java -jar dist/app.jar
71echo ======================================
72pause
diff --git a/tools/build.sh b/tools/build.sh
index 6fdf7e1..72880ee 100755
--- a/tools/build.sh
+++ b/tools/build.sh
@@ -1,61 +1,23 @@
1#!/bin/bash 1#!/bin/bash
2set -e
3
4echo "=== 1. Cleaning Workspace ==="
5rm -rf bin stage
6mkdir -p bin/classes bin/test-classes stage dist # dist was never created
7
8echo "=== 2. Compiling Production Code ==="
9javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java')
10
11echo "=== 3. Compiling Test Code ==="
12# prod classes are in bin/classes, not bin
13javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java')
14 2
15echo "=== 4. Running Automated Tests ==="
16JUNIT_JAR=$(find lib -maxdepth 1 -name 'junit-platform-console-standalone-*.jar' | head -n 1)
17if [ -z "$JUNIT_JAR" ]; then
18 echo "JUnit jar missing."
19 exit 1
20fi
21
22set +e
23java -jar "$JUNIT_JAR" execute \
24 -cp "bin/classes:bin/test-classes:lib/*" \
25 --scan-classpath
26TEST_STATUS=$?
27set -e 3set -e
4cd "$(dirname "$0")/.."
5. tools/_util.sh
28 6
29if [ $TEST_STATUS -ne 0 ]; then 7echo "=== Cleaning build/ ==="
30 echo "❌ Tests failed! Aborting build package." 8rm -rf build
31 exit 1 9mkdir -p build/classes
32fi
33echo "✅ Tests passed successfully!"
34
35echo "=== 5. Extracting Dependencies for Fat JAR ==="
36cd stage
37for jarfile in ../lib/*.jar; do
38 [ -f "$jarfile" ] || continue
39 case "$(basename "$jarfile")" in
40 junit-platform-console-standalone-*) continue ;;
41 esac
42 echo "Extracting: $(basename "$jarfile")"
43 jar -xf "$jarfile"
44done
45 10
46# Strip signatures + manifests (they break repacking), but KEEP 11echo "=== Compiling production code (dependency order) ==="
47# META-INF/services so ServiceLoader-based deps still work at runtime. 12for m in $MODULES; do
48find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true 13 deps=$(deps_of "$m")
49cd .. 14 cp="$(module_cp $deps)"
15 cp="${cp:+$cp$SEP}$LIBCP"
50 16
51echo "=== 6. Merging Assets into Fat JAR ===" 17 find "$m/src/main/java" -name '*.java' >"$TMP/src.txt"
52# Merge YOUR production classes on top of the extracted deps 18 mkdir -p "build/classes/$m"
53cp -r bin/classes/. stage/ 19 printf ' %-11s sees: %s\n' "$m" "${deps:-<nothing>}"
54# Package the whole tree (deps + your classes), not just stage/classes 20 javac --release "$JAVA_RELEASE" -d "build/classes/$m" -cp "$cp" "@$TMP/src.txt"
55jar cfe dist/app.jar com.example.App -C stage . 21done
56 22
57rm -rf stage 23echo "=== Build OK ==="
58echo "======================================"
59echo "🎉 Fat JAR Created! Run it with:"
60echo "java -jar dist/app.jar"
61echo "======================================"
diff --git a/tools/package.sh b/tools/package.sh
new file mode 100644
index 0000000..5877444
--- /dev/null
+++ b/tools/package.sh
@@ -0,0 +1,82 @@
1#!/bin/bash
2
3set -e
4cd "$(dirname "$0")/.."
5. tools/_util.sh
6
7bash tools/build.sh
8
9DIST=build/dist
10rm -rf "$DIST"
11mkdir -p "$DIST"
12
13echo "=== Staging runtime libs beside the jars ==="
14for d in $RUNTIME_LIB_DIRS; do
15 mkdir -p "$DIST/lib/$d"
16 n=0
17 for j in lib/"$d"/*.jar; do
18 is_shippable_jar "$j" || continue # never ship -sources / -javadoc
19 cp "$j" "$DIST/lib/$d/"
20 n=$((n + 1))
21 done
22 echo " lib/$d/ ($n jars)"
23done
24
25echo "=== Generating console manifest ==="
26# Generated from what is actually staged, never hand-maintained. Four silent
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
29# this line is the entire classpath at runtime.
30MF="$TMP/console-manifest.txt"
31CPLINE=""
32for m in $MODULES; do
33 [ "$m" = ui-console ] && continue
34 CPLINE="$CPLINE${CPLINE:+ }$m.jar"
35done
36for d in $RUNTIME_LIB_DIRS; do
37 for j in "$DIST"/lib/"$d"/*.jar; do
38 [ -f "$j" ] || continue
39 CPLINE="$CPLINE lib/$d/$(basename "$j")"
40 done
41done
42printf 'Class-Path: %s\n\n' "$CPLINE" >"$MF"
43echo " $CPLINE"
44
45echo "=== Packaging ==="
46for m in $MODULES; do
47 if [ "$m" = ui-console ]; then
48 "$JAR" --create --file "$DIST/$m.jar" \
49 --main-class "$MAIN_CLASS" --manifest "$MF" -C "build/classes/$m" .
50 else
51 "$JAR" --create --file "$DIST/$m.jar" -C "build/classes/$m" .
52 fi
53 echo " $DIST/$m.jar"
54done
55
56cat >"$DIST/run.bat" <<'EOF'
57@echo off
58cd /d "%~dp0"
59java -jar "%~dp0ui-console.jar"
60if errorlevel 1 pause
61EOF
62
63echo "=== Manifest as it actually landed in the jar ==="
64# Cheapest check that prevents a Level-0: if Main-Class or Class-Path didn't
65# survive, it surfaces here instead of on the grader's machine.
66rm -rf "$TMP/mf" && mkdir -p "$TMP/mf"
67(cd "$TMP/mf" && "$JAR" -xf "$OLDPWD/$DIST/ui-console.jar" META-INF/MANIFEST.MF)
68sed 's/^/ /' "$TMP/mf/META-INF/MANIFEST.MF"
69
70grep -q '^Main-Class:' "$TMP/mf/META-INF/MANIFEST.MF" || {
71 echo "*** Main-Class missing ***"
72 exit 1
73}
74grep -q 'Class-Path:' "$TMP/mf/META-INF/MANIFEST.MF" || {
75 echo "*** Class-Path missing ***"
76 exit 1
77}
78
79echo "======================================"
80echo "Self-contained output in $DIST"
81echo " cd $DIST && java -jar ui-console.jar"
82echo "======================================"
diff --git a/tools/run.bat b/tools/run.bat
deleted file mode 100644
index 8480652..0000000
--- a/tools/run.bat
+++ /dev/null
@@ -1,16 +0,0 @@
1@echo off
2:: clean old binaries
3rmdir /s /q bin
4mkdir bin
5
6:: compile source files and include libraries
7javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java
8
9:: run the application if compilation succeeded
10if %errorlevel% equ 0 (
11 echo --- Running Application ---
12 java -cp "bin/classes;lib/*" com.example.App
13) else (
14 echo Compilation failed.
15)
16pause
diff --git a/tools/run.sh b/tools/run.sh
deleted file mode 100644
index 55f1094..0000000
--- a/tools/run.sh
+++ /dev/null
@@ -1,12 +0,0 @@
1#!/bin/bash
2
3# clean up
4rm -rf bin && mkdir bin
5
6# run the app if compilation succeeded
7if javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java; then
8 echo "--- Running Application ---"
9 java -cp "bin/classes:lib/*" com.example.App
10else
11 echo "Compilation failed."
12fi
diff --git a/tools/test.sh b/tools/test.sh
new file mode 100644
index 0000000..4eaeb82
--- /dev/null
+++ b/tools/test.sh
@@ -0,0 +1,47 @@
1#!/bin/bash
2
3set -e
4cd "$(dirname "$0")/.."
5. tools/_util.sh
6
7[ -d build/classes ] || {
8 echo "No build/classes - run tools/build.sh first"
9 exit 1
10}
11
12JUNIT_JAR=$(ls lib/junit/junit-platform-console-standalone-*.jar 2>/dev/null | head -n 1)
13[ -n "$JUNIT_JAR" ] || {
14 echo "JUnit standalone jar missing from lib/junit/"
15 exit 1
16}
17
18PROD_CP="$(module_cp $MODULES)"
19
20echo "=== Compiling test sources ==="
21: >"$TMP/tests.txt"
22for m in $MODULES; do
23 [ -d "$m/src/test/java" ] && find "$m/src/test/java" -name '*.java' >>"$TMP/tests.txt"
24done
25if [ ! -s "$TMP/tests.txt" ]; then
26 echo " (no test sources)"
27 exit 0
28fi
29
30mkdir -p build/test-classes
31javac --release "$JAVA_RELEASE" -d build/test-classes \
32 -cp "$PROD_CP$SEP$JUNIT_JAR$SEP$LIBCP" "@$TMP/tests.txt"
33
34echo "=== Running tests ==="
35
36TEST_CP="$PROD_CP${SEP}build/test-classes"
37for j in lib/*/*.jar; do
38 case "$j" in *junit-platform-console-standalone*) continue ;; esac
39 TEST_CP="$TEST_CP$SEP$j"
40done
41
42AGENT_JAR=$(ls lib/mockito/byte-buddy-agent-*.jar 2>/dev/null | head -n 1)
43AGENT_ARG=""
44[ -n "$AGENT_JAR" ] && AGENT_ARG="-javaagent:$AGENT_JAR"
45
46java $AGENT_ARG -jar "$JUNIT_JAR" execute \
47 --class-path "$TEST_CP" --scan-class-path --details=summary