Skip to content

Commit

Permalink
issue #726 New scripts to run examples - greatly simplified, no Maven…
Browse files Browse the repository at this point in the history
… or Ant dependency.
  • Loading branch information
wajda committed Jul 29, 2023
1 parent ea93541 commit 72c80bd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 145 deletions.
60 changes: 17 additions & 43 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,53 +94,27 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>examples</id>
<properties>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="classpath" refid="maven.runtime.classpath" />
<ant antfile="${basedir}/run-example.xml">
<target name="main" />
</ant>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<artifactId>ant</artifactId>
<groupId>ant</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>google</id>
<!-- the profile is required to run `BigQueryExample` -->
Expand Down
102 changes: 0 additions & 102 deletions examples/run-example.xml

This file was deleted.

38 changes: 38 additions & 0 deletions examples/run.cmd
Original file line number Diff line number Diff line change
@@ -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"
)
36 changes: 36 additions & 0 deletions examples/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 72c80bd

Please sign in to comment.