1 |
#!/bin/bash |
2 |
# Builds jar files to run jtreg for jsr166 CVS. |
3 |
# |
4 |
# Leverages the hard work done by Ubuntu and Maven packagers |
5 |
|
6 |
set -eux |
7 |
|
8 |
declare -a MAKE_FLAGS=() DOWNLOADED_MAVEN_JARS=() |
9 |
|
10 |
die() { printf "%s: $1\n" "$0" "${@:2}" >&2; exit 2; } |
11 |
|
12 |
def_make_var() { |
13 |
typeset -n varref="$1" |
14 |
varref="$2" |
15 |
MAKE_FLAGS+=("$1=$2") |
16 |
} |
17 |
|
18 |
def_make_file() { |
19 |
[[ -f "$2" ]] || die "%s: no such file" "$2" |
20 |
def_make_var "$@" |
21 |
} |
22 |
|
23 |
def_make_dir() { |
24 |
[[ -d "$2" ]] || die "%s: no such directory" "$2" |
25 |
def_make_var "$@" |
26 |
} |
27 |
|
28 |
download_ubuntu() { |
29 |
local -r pkg="$1" |
30 |
wget -q "http://us.archive.ubuntu.com/ubuntu/pool/universe/${pkg:0:1}/${pkg}" |
31 |
} |
32 |
|
33 |
download_maven_jar() { |
34 |
local -r groupId="$1" artifactId="$2" version="$3" |
35 |
local -r jarfile="${artifactId}-${version}.jar" |
36 |
wget -qO"/tmp/$jarfile" \ |
37 |
"http://search.maven.org/remotecontent?filepath=${groupId}/${artifactId}/${version}/${jarfile}" |
38 |
def_make_file "${artifactId^^}_JAR" "/tmp/$jarfile" |
39 |
DOWNLOADED_MAVEN_JARS+=("/tmp/$jarfile") |
40 |
} |
41 |
|
42 |
main() { |
43 |
[[ "$PWD" =~ /lib-src$ ]] || { echo Always run as ./build-jtreg; exit 1; } |
44 |
TESTNG_VERSION="6.9.9" |
45 |
rm -rf "/tmp/testng-$TESTNG_VERSION"*; mkdir "/tmp/testng-$TESTNG_VERSION" |
46 |
def_make_dir TESTNG_HOME "/tmp/testng-$TESTNG_VERSION" |
47 |
|
48 |
# Download a mostly unused testng distribution, because jtreg's |
49 |
# makefiles want both TESTNG_JAR and TESTNG_HOME. |
50 |
# https://github.com/cbeust/testng/releases |
51 |
rm -rf "/tmp/${TESTNG_VERSION}.tar.gz" "/tmp/${TESTNG_VERSION}" |
52 |
wget -qO"/tmp/testng-${TESTNG_VERSION}.tar.gz" \ |
53 |
"https://github.com/cbeust/testng/archive/${TESTNG_VERSION}.tar.gz" |
54 |
( |
55 |
cd /tmp |
56 |
tar xzf "/tmp/testng-${TESTNG_VERSION}.tar.gz" |
57 |
rm -f "/tmp/testng-${TESTNG_VERSION}.tar.gz" |
58 |
) |
59 |
|
60 |
download_maven_jar "junit" "junit" "4.10" |
61 |
download_maven_jar "org/testng" "testng" "$TESTNG_VERSION" |
62 |
download_maven_jar "com/beust" "jcommander" "1.72" |
63 |
|
64 |
# TODO: Upgrade to jtharness 5.x |
65 |
rm -rf jtharness-4.6; rm -f ./*jtharness*4.6* |
66 |
download_ubuntu "jtharness/jtharness_4.6-1.debian.tar.xz" |
67 |
download_ubuntu "jtharness/jtharness_4.6-1.dsc" |
68 |
download_ubuntu "jtharness/jtharness_4.6.orig.tar.xz" |
69 |
download_ubuntu "jtharness/libjtharness-java_4.6-1_all.deb" |
70 |
tar xJf "jtharness_4.6.orig.tar.xz" |
71 |
def_make_dir JTHARNESS_HOME "$PWD/jtharness-4.6" |
72 |
|
73 |
rm -f ./javahelp2*2.0.05* |
74 |
download_ubuntu "javahelp2/javahelp2_2.0.05.ds1-9.debian.tar.xz" |
75 |
download_ubuntu "javahelp2/javahelp2_2.0.05.ds1-9.dsc" |
76 |
download_ubuntu "javahelp2/javahelp2_2.0.05.ds1-9_all.deb" |
77 |
download_ubuntu "javahelp2/javahelp2_2.0.05.ds1.orig.tar.gz" |
78 |
|
79 |
|
80 |
## Currently we build jtreg from source, but get its dependencies |
81 |
## from Ubuntu or Maven Central. Below are past approaches. |
82 |
|
83 |
# rm -f ./jtreg_4.2-b03* |
84 |
# download_ubuntu "jtreg/jtreg_4.2-b03-1~16.04.debian.tar.xz" |
85 |
# download_ubuntu "jtreg/jtreg_4.2-b03-1~16.04_all.deb" |
86 |
# download_ubuntu "jtreg/jtreg_4.2-b03-1~16.04.dsc" |
87 |
# download_ubuntu "jtreg/jtreg_4.2-b03.orig.tar.gz" |
88 |
|
89 |
# rm -f ./testng*6.9* |
90 |
# download_ubuntu "testng/testng_6.9.5-1.debian.tar.xz" |
91 |
# download_ubuntu "testng/testng_6.9.5-1.dsc" |
92 |
# download_ubuntu "testng/testng_6.9.5-1_all.deb" |
93 |
# download_ubuntu "testng/testng_6.9.5.orig.tar.gz" |
94 |
|
95 |
# rm -f ./*jcommander*1.48* |
96 |
# download_ubuntu "jcommander/jcommander_1.48-1.debian.tar.xz" |
97 |
# download_ubuntu "jcommander/jcommander_1.48-1.dsc" |
98 |
# download_ubuntu "jcommander/jcommander_1.48.orig.tar.gz" |
99 |
# download_ubuntu "jcommander/libjcommander-java_1.48-1_all.deb" |
100 |
|
101 |
# rm -f ./*junit4* |
102 |
# download_ubuntu "junit4/junit4_4.12-4ubuntu1.debian.tar.xz" |
103 |
# download_ubuntu "junit4/junit4_4.12-4ubuntu1.dsc" |
104 |
# download_ubuntu "junit4/junit4_4.12-4ubuntu1_all.deb" |
105 |
# download_ubuntu "junit4/junit4_4.12.orig.tar.xz" |
106 |
|
107 |
rm -rf ./extract |
108 |
mkdir extract |
109 |
for deb in *.deb; do dpkg -x $deb extract; done |
110 |
EXTRACT="$PWD/extract" |
111 |
def_make_file JAVATEST_JAR "$(find $EXTRACT/ -name javatest.jar)" |
112 |
def_make_file JAVAHELP_JAR "$(find $EXTRACT/ -name jh.jar)" |
113 |
|
114 |
hg_clone_codetools() { |
115 |
local -r repo="$1" rev="$2" |
116 |
rm -rf "$repo" |
117 |
hg clone -r "$rev" "http://hg.openjdk.java.net/code-tools/${repo}" |
118 |
rm -rf "${repo}/.hg" |
119 |
tar cJf "${repo}.tar.xz" "$repo" |
120 |
} |
121 |
|
122 |
# asmtools is optional, but let's build it for completeness. |
123 |
hg_clone_codetools asmtools 7.0-b02 |
124 |
rm -rf "asmtools-"*"-build" |
125 |
(cd "asmtools/build" && ant build) |
126 |
def_make_dir ASMTOOLS_HOME "$PWD/asmtools-"*"-build/release" |
127 |
|
128 |
def_make_var BUILD_NUMBER "b14" |
129 |
JTREG_REV="jtreg4.2-${BUILD_NUMBER}" |
130 |
hg_clone_codetools jtreg "$JTREG_REV" |
131 |
|
132 |
def_make_dir JDK17HOME "$HOME/jdk/jdk7" |
133 |
def_make_dir JDK18HOME "$HOME/jdk/jdk8" |
134 |
def_make_dir JDK19HOME "$HOME/jdk/jdk9" |
135 |
|
136 |
def_make_dir ANTHOME "/usr/share/ant" |
137 |
|
138 |
make "${MAKE_FLAGS[@]}" -C "jtreg/make" clean images |
139 |
|
140 |
cp jtreg/build/images/jtreg/lib/*.jar ../jsr166/lib/. |
141 |
|
142 |
# As a side effect, save a general purpose jtreg "distribution". |
143 |
rsync -a jtreg/build/images/jtreg/ "${JTREG_REV#jtreg}/" |
144 |
|
145 |
# Clean up intermediate artifacts. |
146 |
# asmtools creates a bogus index.html |
147 |
rm -rf asmtools asmtools-*-build index.html \ |
148 |
jtreg extract "${DOWNLOADED_MAVEN_JARS[@]}" \ |
149 |
"$JTHARNESS_HOME" "$TESTNG_HOME" |
150 |
|
151 |
exit 0 |
152 |
} |
153 |
|
154 |
main "$@" |