From 72c80bdb021cca4fbb679412f0d333765529fdca Mon Sep 17 00:00:00 2001 From: Oleksandr Vayda Date: Sat, 29 Jul 2023 23:34:45 +0200 Subject: [PATCH] issue #726 New scripts to run examples - greatly simplified, no Maven or Ant dependency. --- examples/pom.xml | 60 +++++++---------------- examples/run-example.xml | 102 --------------------------------------- examples/run.cmd | 38 +++++++++++++++ examples/run.sh | 36 ++++++++++++++ 4 files changed, 91 insertions(+), 145 deletions(-) delete mode 100644 examples/run-example.xml create mode 100644 examples/run.cmd create mode 100755 examples/run.sh diff --git a/examples/pom.xml b/examples/pom.xml index 902b6871..fe15d3d1 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -94,53 +94,27 @@ + + org.apache.maven.plugins + maven-dependency-plugin + 3.6.0 + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + - - examples - - true - - - - - maven-antrun-plugin - - - test - - run - - - - - - - - - - - - - - ant-contrib - ant-contrib - 1.0b3 - - - ant - ant - - - - - - - - - google diff --git a/examples/run-example.xml b/examples/run-example.xml deleted file mode 100644 index a2263638..00000000 --- a/examples/run-example.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/run.cmd b/examples/run.cmd new file mode 100644 index 00000000..c989f8b6 --- /dev/null +++ b/examples/run.cmd @@ -0,0 +1,38 @@ +@echo off + +:: Ensure we have at least one parameter (the class name) +IF "%~1"=="" ( + echo Usage: %~nx0 [--all ^| full.class.Name] [-jvm-option]... + echo --all run all examples. + echo full.class.Name fully qualified class name to run. + echo -jvm-option options and values passed to the java command. + exit /b +) + +:: Build the classpath +setlocal enabledelayedexpansion +for /r target\libs %%g in (*.jar) do ( + set CLASSPATH=!CLASSPATH!;%%g +) +set CLASSPATH=target\classes%CLASSPATH% + +:: Run the java processes +if /I "%~1"=="--all" ( + for /r target\classes %%g in (*Job.class) do ( + set "file=%%~g" + setlocal enabledelayedexpansion + set "class=!file:target\classes\=!" + set "class=!class:\=.!" + set "class=!class:.class=!" + echo ======================================================================= + echo Running !class! + echo ======================================================================= + java %*:~2 -cp "!CLASSPATH!" "!class!" + endlocal + ) +) else ( + echo ======================================================================= + echo Running %~1 + echo ======================================================================= + java %*:~2 -cp "%CLASSPATH%" "%~1" +) diff --git a/examples/run.sh b/examples/run.sh new file mode 100755 index 00000000..fb6fb218 --- /dev/null +++ b/examples/run.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +function ctrl_c() { + echo 'Script interrupted by user' + trap - SIGINT SIGTERM ## Clear the trap + kill -- -$$ ## Sends SIGTERM to child/sub processes +} + +print_line() { + echo -e "\e[1m=======================================================================\e[0m" + echo -e "\e[1mRunning $1 \e[0m" + echo -e "\e[1m=======================================================================\e[0m" +} + +if [ $# -eq 0 ]; then + echo "Usage: $0 [--all | full.class.Name] [-jvm-option]..." + echo " --all run all examples." + echo " full.class.Name fully qualified class name to run." + echo " -jvm-option options and values passed to the java command." + exit 1 +fi + +trap ctrl_c SIGINT SIGTERM + +CLASSPATH=target/classes:$(echo target/libs/*.jar | tr ' ' ':') + +if [ "$1" = "--all" ]; then + while IFS= read -r -d '' file; do + class=$(echo "${file#target/classes/}" | sed 's/\//./g' | sed 's/\.class$//') + print_line "$class" + java "${@:2}" -cp "$CLASSPATH" "$class" + done < <(find target/classes -type f -name "*Job.class" -print0 | sort -z) +else + print_line "$1" + java "${@:2}" -cp "$CLASSPATH" "$1" +fi