diff options
| author | Kostya <mail@sartin.in> | 2026-08-06 21:17:22 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-08-06 21:17:22 +0000 |
| commit | 10e36a8910653a73910b7be654b3467ece511d9b (patch) | |
| tree | 08a79d79ab1c2355c02cb49462f164291ef63eda /tools | |
| parent | c3946151d543f568983f1ba16a963ea7dd4b9055 (diff) | |
| download | guess-market-10e36a8910653a73910b7be654b3467ece511d9b.tar.gz guess-market-10e36a8910653a73910b7be654b3467ece511d9b.tar.xz guess-market-10e36a8910653a73910b7be654b3467ece511d9b.zip | |
wireframe
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/build.bat | 72 | ||||
| -rwxr-xr-x | tools/build.sh | 61 | ||||
| -rw-r--r-- | tools/run.bat | 16 | ||||
| -rw-r--r-- | tools/run.sh | 12 |
4 files changed, 161 insertions, 0 deletions
diff --git a/tools/build.bat b/tools/build.bat new file mode 100644 index 0000000..eb6b460 --- /dev/null +++ b/tools/build.bat | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | @echo off | ||
| 2 | setlocal enabledelayedexpansion | ||
| 3 | |||
| 4 | echo === 1. Cleaning Workspace === | ||
| 5 | if exist bin rmdir /s /q bin | ||
| 6 | if exist stage rmdir /s /q stage | ||
| 7 | if exist dist rmdir /s /q dist | ||
| 8 | mkdir bin\classes | ||
| 9 | mkdir bin\test-classes | ||
| 10 | mkdir stage | ||
| 11 | mkdir dist | ||
| 12 | |||
| 13 | echo === 2. Compiling Production Code === | ||
| 14 | dir /s /b src\main\java\*.java > sources.txt | ||
| 15 | javac -d bin\classes -cp "lib/*" @sources.txt | ||
| 16 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 17 | |||
| 18 | echo === 3. Compiling Test Code === | ||
| 19 | dir /s /b src\test\java\*.java > test-sources.txt | ||
| 20 | javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt | ||
| 21 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 22 | |||
| 23 | echo === 4. Running Automated Tests === | ||
| 24 | set "JUNIT_JAR=" | ||
| 25 | for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" | ||
| 26 | if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) | ||
| 27 | |||
| 28 | rem JUnit's --class-path does NOT expand lib\* -> build it explicitly | ||
| 29 | set "TEST_CP=bin\classes;bin\test-classes" | ||
| 30 | for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j" | ||
| 31 | |||
| 32 | java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath | ||
| 33 | if %errorlevel% neq 0 ( | ||
| 34 | echo [X] Tests failed! Aborting build package. | ||
| 35 | exit /b %errorlevel% | ||
| 36 | ) | ||
| 37 | echo [OK] Tests passed successfully! | ||
| 38 | |||
| 39 | echo === 5. Extracting Dependencies for Fat JAR === | ||
| 40 | cd stage | ||
| 41 | for %%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 | |||
| 49 | rem Strip signatures + manifests (they break repacking) but KEEP | ||
| 50 | rem META-INF\services so ServiceLoader-based deps still work at runtime. | ||
| 51 | if 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 | ) | ||
| 57 | cd .. | ||
| 58 | |||
| 59 | echo === 6. Merging Assets into Fat JAR === | ||
| 60 | rem Merge ONLY production classes on top of the extracted deps | ||
| 61 | xcopy /e /q /y /i bin\classes\* stage\ >nul | ||
| 62 | rem Package the whole tree (deps + your classes), not just stage\classes | ||
| 63 | jar cfe dist/app.jar com.example.App -C stage . | ||
| 64 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 65 | |||
| 66 | del sources.txt test-sources.txt >nul 2>&1 | ||
| 67 | rmdir /s /q stage | ||
| 68 | echo ====================================== | ||
| 69 | echo Fat JAR Created! Run it with: | ||
| 70 | echo java -jar dist/app.jar | ||
| 71 | echo ====================================== | ||
| 72 | pause | ||
diff --git a/tools/build.sh b/tools/build.sh new file mode 100755 index 0000000..6fdf7e1 --- /dev/null +++ b/tools/build.sh | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | set -e | ||
| 3 | |||
| 4 | echo "=== 1. Cleaning Workspace ===" | ||
| 5 | rm -rf bin stage | ||
| 6 | mkdir -p bin/classes bin/test-classes stage dist # dist was never created | ||
| 7 | |||
| 8 | echo "=== 2. Compiling Production Code ===" | ||
| 9 | javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java') | ||
| 10 | |||
| 11 | echo "=== 3. Compiling Test Code ===" | ||
| 12 | # prod classes are in bin/classes, not bin | ||
| 13 | javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java') | ||
| 14 | |||
| 15 | echo "=== 4. Running Automated Tests ===" | ||
| 16 | JUNIT_JAR=$(find lib -maxdepth 1 -name 'junit-platform-console-standalone-*.jar' | head -n 1) | ||
| 17 | if [ -z "$JUNIT_JAR" ]; then | ||
| 18 | echo "JUnit jar missing." | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | |||
| 22 | set +e | ||
| 23 | java -jar "$JUNIT_JAR" execute \ | ||
| 24 | -cp "bin/classes:bin/test-classes:lib/*" \ | ||
| 25 | --scan-classpath | ||
| 26 | TEST_STATUS=$? | ||
| 27 | set -e | ||
| 28 | |||
| 29 | if [ $TEST_STATUS -ne 0 ]; then | ||
| 30 | echo "❌ Tests failed! Aborting build package." | ||
| 31 | exit 1 | ||
| 32 | fi | ||
| 33 | echo "✅ Tests passed successfully!" | ||
| 34 | |||
| 35 | echo "=== 5. Extracting Dependencies for Fat JAR ===" | ||
| 36 | cd stage | ||
| 37 | for 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" | ||
| 44 | done | ||
| 45 | |||
| 46 | # Strip signatures + manifests (they break repacking), but KEEP | ||
| 47 | # META-INF/services so ServiceLoader-based deps still work at runtime. | ||
| 48 | find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true | ||
| 49 | cd .. | ||
| 50 | |||
| 51 | echo "=== 6. Merging Assets into Fat JAR ===" | ||
| 52 | # Merge YOUR production classes on top of the extracted deps | ||
| 53 | cp -r bin/classes/. stage/ | ||
| 54 | # Package the whole tree (deps + your classes), not just stage/classes | ||
| 55 | jar cfe dist/app.jar com.example.App -C stage . | ||
| 56 | |||
| 57 | rm -rf stage | ||
| 58 | echo "======================================" | ||
| 59 | echo "🎉 Fat JAR Created! Run it with:" | ||
| 60 | echo "java -jar dist/app.jar" | ||
| 61 | echo "======================================" | ||
diff --git a/tools/run.bat b/tools/run.bat new file mode 100644 index 0000000..8480652 --- /dev/null +++ b/tools/run.bat | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | @echo off | ||
| 2 | :: clean old binaries | ||
| 3 | rmdir /s /q bin | ||
| 4 | mkdir bin | ||
| 5 | |||
| 6 | :: compile source files and include libraries | ||
| 7 | javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java | ||
| 8 | |||
| 9 | :: run the application if compilation succeeded | ||
| 10 | if %errorlevel% equ 0 ( | ||
| 11 | echo --- Running Application --- | ||
| 12 | java -cp "bin/classes;lib/*" com.example.App | ||
| 13 | ) else ( | ||
| 14 | echo Compilation failed. | ||
| 15 | ) | ||
| 16 | pause | ||
diff --git a/tools/run.sh b/tools/run.sh new file mode 100644 index 0000000..55f1094 --- /dev/null +++ b/tools/run.sh | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # clean up | ||
| 4 | rm -rf bin && mkdir bin | ||
| 5 | |||
| 6 | # run the app if compilation succeeded | ||
| 7 | if 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 | ||
| 10 | else | ||
| 11 | echo "Compilation failed." | ||
| 12 | fi | ||