-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-java.sh
executable file
·45 lines (33 loc) · 1.12 KB
/
run-java.sh
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
#!/bin/bash
# fail on compiler or fetch errors
set -o pipefail
set -e
JUNIT_VERSION="4.11"
HAMCREST_VERSION="1.3"
if [ ! -d libs ]
then
mkdir libs
fi
if [ ! -r "libs/junit-${JUNIT_VERSION}.jar" ]
then
wget -P libs "https://repository.sonatype.org/service/local/repositories/central-proxy/content/junit/junit/${JUNIT_VERSION}/junit-${JUNIT_VERSION}.jar"
fi
if [ ! -r "libs/hamcrest-all-${HAMCREST_VERSION}.jar" ]
then
wget -P libs "https://repository.sonatype.org/service/local/repositories/central-proxy/content/org/hamcrest/hamcrest-all/${HAMCREST_VERSION}/hamcrest-all-${HAMCREST_VERSION}.jar"
fi
# Strip .java extension if provided
file=$(echo $1 | sed -e "s/.java$//g")
if [[ $file == *Test ]]
then
main=$(echo $file | sed -e "s/Test//g")
if [ -f $main.java ]; then
echo "Compiling $main first..."
javac $main.java
#main code had better not need junit/hamcrest...
fi
fi
echo "Compiling $file..."
javac -cp ".:libs/hamcrest-all-${HAMCREST_VERSION}.jar:libs/junit-${JUNIT_VERSION}.jar" $file.java
echo "Running..."
time java -cp ".:libs/hamcrest-all-${HAMCREST_VERSION}.jar:libs/junit-${JUNIT_VERSION}.jar" $file