forked from airlift/airline
-
Notifications
You must be signed in to change notification settings - Fork 20
/
runExample
executable file
·48 lines (40 loc) · 1.39 KB
/
runExample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
SCRIPT_DIR=$(cd `dirname $0` && pwd)
JAR_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout=true 2>/dev/null)
if [ -z "${JAR_VERSION}" ]; then
# Try just grepping it out of the pom.xml instead
JAR_VERSION=$(grep "<version>" pom.xml | head -n 1 | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
if [ -z "${JAR_VERSION}" ]; then
echo "Failed to detect examples version from pom.xml"
exit 1
fi
fi
JAR_FILE="${SCRIPT_DIR}/target/airline-examples-${JAR_VERSION}.jar"
EXAMPLE=$1
shift
if [ -z "${EXAMPLE}" ]; then
echo "No example specified to run"
echo "Usage is ./runExample ExampleClass [Command [Options]]"
exit 1
fi
# Strip .class/.java if specified
EXAMPLE="${EXAMPLE%.class}"
EXAMPLE="${EXAMPLE%.java}"
# Locate the example class name
CLASS=$(find ${SCRIPT_DIR}/src/main/java/com/github/rvesse/airline/examples -name ${EXAMPLE}.java)
if [ -z "${CLASS}" ]; then
echo "${EXAMPLE} does not appear to be an example that can be run"
exit 1
fi
# Convert filename to Java class name
# Remove leading src/main/java
# Replace / with .
# Remove trailing .java
CLASS="${CLASS#${SCRIPT_DIR}/src/main/java/}"
CLASS="${CLASS//\//.}"
CLASS="${CLASS%.java}"
if [ ! -f "${JAR_FILE}" ]; then
echo "Examples JAR ${JAR_FILE} does not yet exist, please run mvn package to build"
exit 1
fi
java -cp "${SCRIPT_DIR}/target/modules/*:${JAR_FILE}" ${CLASS} "$@"