forked from LMAX-Exchange/disruptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·112 lines (97 loc) · 2.82 KB
/
build.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
set -euo pipefail
BUILD_DIR=build_tmp
BUILD_LIB_DIR=${BUILD_DIR}/lib
BUILD_MAIN_CLASSES=${BUILD_DIR}/main/classes
BUILD_TEST_CLASSES=${BUILD_DIR}/test/classes
BUILD_PERF_CLASSES=${BUILD_DIR}/perf/classes
if [ -z ${JAVA_HOME+x} ]; then
echo "JAVA_HOME is not set"
exit -1
else
JC=${JAVA_HOME}/bin/javac
fi
function create_dir()
{
if [ ! -d $1 ]; then
mkdir -p $1
fi
}
function create_build()
{
create_dir ${BUILD_LIB_DIR}
create_dir ${BUILD_MAIN_CLASSES}
create_dir ${BUILD_TEST_CLASSES}
create_dir ${BUILD_PERF_CLASSES}
}
function clean_classes()
{
rm -rf ${BUILD_MAIN_CLASSES}/*
rm -rf ${BUILD_TEST_CLASSES}/*
rm -rf ${BUILD_PERF_CLASSES}/*
}
function download()
{
if [ ! -e $BUILD_LIB_DIR/$1 ]; then
cd ${BUILD_LIB_DIR} &&
{
curl -o $1 $2
if [ $? -eq 1 ]; then
echo "curl download failed for $2"
exit $?
fi
cd -
}
fi
}
function do_javac()
{
$JC -Xlint:deprecation -g -d $2 @$1
}
function download_dependencies()
{
download 'junit-4.12.jar' 'http://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar'
download 'hamcrest-core-1.3.jar' 'http://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar'
download 'HdrHistogram-2.1.8.jar' 'http://repo1.maven.org/maven2/org/hdrhistogram/HdrHistogram/2.1.8/HdrHistogram-2.1.8.jar'
}
function compile()
{
COMPILE_FILE=$2
find $1 -name '*.java' >> ${COMPILE_FILE}
do_javac ${COMPILE_FILE} $3
}
function main_compile()
{
local compile_file=${BUILD_DIR}/src.main.java.txt
rm -f ${compile_file}
compile 'src/main/java' ${compile_file} ${BUILD_MAIN_CLASSES}
}
function test_compile()
{
local compile_file=${BUILD_DIR}/src.test.java.txt
rm -f ${compile_file}
JARS=$(find ${BUILD_LIB_DIR} -name "*.jar" | paste -sd ':')
echo "-cp ${BUILD_MAIN_CLASSES}:$JARS" >> ${compile_file}
compile 'src/test/java' ${compile_file} ${BUILD_TEST_CLASSES}
}
function perf_compile()
{
local compile_file=${BUILD_DIR}/src.pef.java.txt
rm -f ${compile_file}
JARS=$(find ${BUILD_LIB_DIR} -name "*.jar" | paste -sd ':')
echo "-cp ${BUILD_MAIN_CLASSES}:${BUILD_TEST_CLASSES}:$JARS" >> ${compile_file}
compile 'src/perftest/java' ${compile_file} ${BUILD_PERF_CLASSES}
}
function run_tests()
{
JARS=$(find ${BUILD_LIB_DIR} -name "*.jar" | paste -sd ':')
TESTS=$(for i in $(find build_tmp/test/classes -name '*Test.class') ; do l=${i#build_tmp/test/classes/} ; j=${l%.class} ; echo ${j////.} ; done | paste -sd ' ')
$JAVA_HOME/bin/java -cp ${JARS}:${BUILD_MAIN_CLASSES}:${BUILD_TEST_CLASSES} org.junit.runner.JUnitCore $TESTS 2> /dev/null
}
create_build &&
download_dependencies &&
clean_classes &&
main_compile &&
test_compile &&
perf_compile &&
run_tests