From 10e36a8910653a73910b7be654b3467ece511d9b Mon Sep 17 00:00:00 2001 From: Kostya Date: Thu, 6 Aug 2026 21:17:22 +0000 Subject: wireframe --- tools/build.bat | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/build.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/run.bat | 16 +++++++++++++ tools/run.sh | 12 ++++++++++ 4 files changed, 161 insertions(+) create mode 100644 tools/build.bat create mode 100755 tools/build.sh create mode 100644 tools/run.bat create mode 100644 tools/run.sh (limited to 'tools') 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 @@ +@echo off +setlocal enabledelayedexpansion + +echo === 1. Cleaning Workspace === +if exist bin rmdir /s /q bin +if exist stage rmdir /s /q stage +if exist dist rmdir /s /q dist +mkdir bin\classes +mkdir bin\test-classes +mkdir stage +mkdir dist + +echo === 2. Compiling Production Code === +dir /s /b src\main\java\*.java > sources.txt +javac -d bin\classes -cp "lib/*" @sources.txt +if %errorlevel% neq 0 exit /b %errorlevel% + +echo === 3. Compiling Test Code === +dir /s /b src\test\java\*.java > test-sources.txt +javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt +if %errorlevel% neq 0 exit /b %errorlevel% + +echo === 4. Running Automated Tests === +set "JUNIT_JAR=" +for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" +if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) + +rem JUnit's --class-path does NOT expand lib\* -> build it explicitly +set "TEST_CP=bin\classes;bin\test-classes" +for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j" + +java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath +if %errorlevel% neq 0 ( + echo [X] Tests failed! Aborting build package. + exit /b %errorlevel% +) +echo [OK] Tests passed successfully! + +echo === 5. Extracting Dependencies for Fat JAR === +cd stage +for %%j in (..\lib\*.jar) do ( + echo %%~nxj | findstr /i "junit-platform-console-standalone" >nul + if errorlevel 1 ( + echo Extracting: %%~nxj + jar -xf "%%j" + ) +) + +rem Strip signatures + manifests (they break repacking) but KEEP +rem META-INF\services so ServiceLoader-based deps still work at runtime. +if exist META-INF ( + del /s /q META-INF\*.SF >nul 2>&1 + del /s /q META-INF\*.RSA >nul 2>&1 + del /s /q META-INF\*.DSA >nul 2>&1 + del /q META-INF\MANIFEST.MF >nul 2>&1 +) +cd .. + +echo === 6. Merging Assets into Fat JAR === +rem Merge ONLY production classes on top of the extracted deps +xcopy /e /q /y /i bin\classes\* stage\ >nul +rem Package the whole tree (deps + your classes), not just stage\classes +jar cfe dist/app.jar com.example.App -C stage . +if %errorlevel% neq 0 exit /b %errorlevel% + +del sources.txt test-sources.txt >nul 2>&1 +rmdir /s /q stage +echo ====================================== +echo Fat JAR Created! Run it with: +echo java -jar dist/app.jar +echo ====================================== +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 @@ +#!/bin/bash +set -e + +echo "=== 1. Cleaning Workspace ===" +rm -rf bin stage +mkdir -p bin/classes bin/test-classes stage dist # dist was never created + +echo "=== 2. Compiling Production Code ===" +javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java') + +echo "=== 3. Compiling Test Code ===" +# prod classes are in bin/classes, not bin +javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java') + +echo "=== 4. Running Automated Tests ===" +JUNIT_JAR=$(find lib -maxdepth 1 -name 'junit-platform-console-standalone-*.jar' | head -n 1) +if [ -z "$JUNIT_JAR" ]; then + echo "JUnit jar missing." + exit 1 +fi + +set +e +java -jar "$JUNIT_JAR" execute \ + -cp "bin/classes:bin/test-classes:lib/*" \ + --scan-classpath +TEST_STATUS=$? +set -e + +if [ $TEST_STATUS -ne 0 ]; then + echo "❌ Tests failed! Aborting build package." + exit 1 +fi +echo "✅ Tests passed successfully!" + +echo "=== 5. Extracting Dependencies for Fat JAR ===" +cd stage +for jarfile in ../lib/*.jar; do + [ -f "$jarfile" ] || continue + case "$(basename "$jarfile")" in + junit-platform-console-standalone-*) continue ;; + esac + echo "Extracting: $(basename "$jarfile")" + jar -xf "$jarfile" +done + +# Strip signatures + manifests (they break repacking), but KEEP +# META-INF/services so ServiceLoader-based deps still work at runtime. +find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true +cd .. + +echo "=== 6. Merging Assets into Fat JAR ===" +# Merge YOUR production classes on top of the extracted deps +cp -r bin/classes/. stage/ +# Package the whole tree (deps + your classes), not just stage/classes +jar cfe dist/app.jar com.example.App -C stage . + +rm -rf stage +echo "======================================" +echo "🎉 Fat JAR Created! Run it with:" +echo "java -jar dist/app.jar" +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 @@ +@echo off +:: clean old binaries +rmdir /s /q bin +mkdir bin + +:: compile source files and include libraries +javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java + +:: run the application if compilation succeeded +if %errorlevel% equ 0 ( + echo --- Running Application --- + java -cp "bin/classes;lib/*" com.example.App +) else ( + echo Compilation failed. +) +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 @@ +#!/bin/bash + +# clean up +rm -rf bin && mkdir bin + +# run the app if compilation succeeded +if javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java; then + echo "--- Running Application ---" + java -cp "bin/classes:lib/*" com.example.App +else + echo "Compilation failed." +fi -- cgit v1.2.3