blob: 3aa91ff8f19cdd9288df76322da8568fbe14ec39 (
plain)
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
|
#!/bin/sh
. ../../lib/sh-test-lib
OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE
VERSION="8"
usage() {
echo "Usage: $0 [-v <8|9>] [-s <true|false>]" 1>&2
exit 1
}
while getopts "v:s:" o; do
case "$o" in
v) VERSION="${OPTARG}" ;;
s) SKIP_INSTALL="${OPTARG}" ;;
*) usage ;;
esac
done
! check_root && error_msg "You need to be root to run this script."
create_out_dir "${OUTPUT}"
if [ "${SKIP_INSTALL}" = "True" ] || [ "${SKIP_INSTALL}" = "true" ]; then
info_msg "JDK package installation skipped"
else
dist_name
# shellcheck disable=SC2154
case "${dist}" in
debian|ubuntu) pkg="openjdk-${VERSION}-jdk" ;;
centos|fedora) pkg="java-1.${VERSION}.0-openjdk-devel" ;;
*) error_msg "Unsupported distribution" ;;
esac
install_deps "${pkg}"
exit_on_fail "jdk${VERSION}-installation"
fi
# Set the specific version as default in case more than one jdk installed.
for link in java javac; do
path="$(update-alternatives --display "${link}" \
| egrep "^/usr/lib/jvm/java-(${VERSION}|1.${VERSION}.0)" \
| awk '{print $1}')"
update-alternatives --set "${link}" "${path}"
done
java -version 2>&1 | grep "version \"1.${VERSION}"
exit_on_fail "check-java-version"
javac -version 2>&1 | grep "javac 1.${VERSION}"
exit_on_fail "check-javac-version"
# shellcheck disable=SC2164
cd "${OUTPUT}"
cat > "HelloWorld.java" << EOL
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
EOL
javac HelloWorld.java
check_return "compile-HelloWorld"
java HelloWorld | grep "Hello, World"
check_return "execute-HelloWorld"
|