1#!/bin/bash
2
3set -euo pipefail
4
5# Prevent accidental execution outside of Travis:
6if [ -z "${TRAVIS+false}" ]
7then
8  echo "TRAVIS environment variable is not set"
9  exit 1
10fi
11
12function jdk_switcher {
13  DIR=$1
14  if [ ! -d "$DIR" ]; then
15    echo "Not found: $DIR"
16    exit 1
17  fi
18  export JAVA_HOME="$DIR"
19  export JDK_HOME="${JAVA_HOME}"
20  export JAVAC="${JAVA_HOME}/bin/javac"
21  export PATH="${JAVA_HOME}/bin:${PATH}"
22}
23
24# Switch to desired JDK, download if required:
25function install_jdk {
26  JDK_URL=$1
27
28  FILENAME="${JDK_URL##*/}"
29
30  rm -rf /tmp/jdk/$JDK
31  mkdir -p /tmp/jdk/$JDK
32
33  if [ ! -f "/tmp/jdk/$FILENAME" ]
34  then
35    curl -L $JDK_URL -o /tmp/jdk/$FILENAME
36  fi
37
38  tar -xzf /tmp/jdk/$FILENAME -C /tmp/jdk/$JDK --strip-components 1
39
40  if [ -z "${2+false}" ]
41  then
42    jdk_switcher "/tmp/jdk/$JDK"
43  fi
44}
45
46# Preinstalled JDKs:
47ls -lA /usr/lib/jvm/
48
49
50case "$JDK" in
515)
52  install_jdk $JDK5_URL false
53  ;;
546 | 7 | 8)
55  jdk_switcher /usr/lib/jvm/java-8-oracle
56  ;;
579)
58  jdk_switcher /usr/lib/jvm/java-9-oracle
59  ;;
6010)
61  install_jdk $JDK10_URL
62  ;;
6311)
64  install_jdk $JDK11_URL
65  ;;
6612)
67  install_jdk $JDK12_URL
68  ;;
6913-ea)
70  install_jdk $JDK13_EA_URL
71  ;;
72esac
73
74# Do not use "~/.mavenrc" set by Travis (https://github.com/travis-ci/travis-ci/issues/3893),
75# because it prevents execution of JaCoCo during integration tests for jacoco-maven-plugin,
76# and "-XMaxPermSize" not supported by JDK 9
77export MAVEN_SKIP_RC=true
78
79# Build:
80case "$JDK" in
815)
82  if [[ ${TRAVIS_PULL_REQUEST} == 'false' && ${TRAVIS_BRANCH} == 'master' ]]
83  then
84    # Travis does shallow clone, but SonarQube performs "git blame" and so requires full history
85    git fetch --unshallow
86
87    # goal "deploy:deploy" used directly instead of "deploy" phase to avoid pollution of Maven repository by "install" phase
88    mvn -V -B -e -f org.jacoco.build verify sonar:sonar deploy:deploy -DdeployAtEnd -Djdk.version=5 --toolchains=./.travis/toolchains.xml --settings=./.travis/settings.xml -Dsonar.host.url=${SONARQUBE_URL} -Dsonar.login=${SONARQUBE_TOKEN}
89    python ./.travis/trigger-site-deployment.py
90  else
91    mvn -V -B -e verify -Djdk.version=5 --toolchains=./.travis/toolchains.xml \
92      --settings=./.travis/settings.xml
93  fi
94  ;;
956 | 7 | 8 | 9)
96  mvn -V -B -e verify -Djdk.version=${JDK} -Dbytecode.version=${JDK} -Decj=${ECJ:-} --toolchains=./.travis/travis-toolchains.xml \
97    --settings=./.travis/settings.xml
98  ;;
9910 | 11 | 12)
100  mvn -V -B -e verify -Dbytecode.version=${JDK} \
101    --settings=./.travis/settings.xml
102  ;;
10313-ea)
104  mvn -V -B -e verify -Dbytecode.version=13 \
105    --projects \!org.jacoco.core.test.validation.groovy \
106    --settings=./.travis/settings.xml
107  ;;
108*)
109  echo "Incorrect JDK [$JDK]"
110  exit 1;
111  ;;
112esac
113