1#!/bin/bash
2#
3# Travis build script, cf.
4# https://docs.travis-ci.com/user/customizing-the-build/#Implementing-Complex-Build-Steps.
5
6set -o errexit
7set -o xtrace
8
9case "$TASK" in
10  "CHECK_GIT_HISTORY")
11    python "$(dirname "$0")"/check-git-history.py
12    ;;
13  "BUILD")
14    case "$TRAVIS_OS_NAME" in
15      "linux")
16        source /opt/jdk_switcher/jdk_switcher.sh
17        export JAVA8_HOME="$(jdk_switcher home oraclejdk8)"
18        case "$TRAVIS_JDK_VERSION" in
19          "oraclejdk9")
20            ./gradlew clean assemble check --stacktrace
21            ;;
22          "oraclejdk8")
23            export JAVA_HOMES="$(jdk_switcher home openjdk6)/jre:$(jdk_switcher home openjdk7)/jre:$(jdk_switcher home oraclejdk8)/jre:$(jdk_switcher home oraclejdk9)"
24            ./gradlew clean assemble --stacktrace
25            ./gradlew check :opencensus-all:jacocoTestReport
26            ./gradlew verGJF
27            ;;
28          "openjdk7")
29            # "./gradlew classes testClasses" is a workaround for
30            # https://github.com/gradle/gradle/issues/2421.
31            # See https://github.com/gradle/gradle/issues/2421#issuecomment-319916874.
32            JAVA_HOME="$(jdk_switcher home openjdk8)" ./gradlew classes testClasses
33            ./gradlew clean assemble --stacktrace
34            ./gradlew check
35            ;;
36          *)
37            echo "Unknown JDK version $TRAVIS_JDK_VERSION"
38            exit 1
39            ;;
40        esac
41        ;;
42      "osx")
43        # OS X is a separate case, because the JDK version is determined by the OS X image:
44        # https://docs.travis-ci.com/user/reference/osx/#JDK-and-OS-X
45        ./gradlew clean assemble --stacktrace
46        ./gradlew check
47        ;;
48      *)
49        echo "Unknown OS name $TRAVIS_OS_NAME"
50        exit 1
51        ;;
52    esac
53    ;;
54  "CHECKER_FRAMEWORK")
55    ./gradlew clean assemble -PcheckerFramework=true
56    ;;
57  "CHECK_EXAMPLES_LICENSE")
58    curl -L -o checkstyle-8.12-all.jar https://github.com/checkstyle/checkstyle/releases/download/checkstyle-8.12/checkstyle-8.12-all.jar
59    java -DrootDir=. -jar checkstyle-8.12-all.jar -c buildscripts/checkstyle.xml examples/src/
60    ;;
61  "CHECK_EXAMPLES_FORMAT")
62    curl -L -o google-java-format-1.5-all-deps.jar https://github.com/google/google-java-format/releases/download/google-java-format-1.5/google-java-format-1.5-all-deps.jar
63    java -jar google-java-format-1.5-all-deps.jar --set-exit-if-changed --dry-run `find examples/src/ -name '*.java'`
64    ;;
65  "BUILD_EXAMPLES_GRADLE")
66    pushd examples && ./gradlew clean assemble --stacktrace && popd
67    ;;
68  "BUILD_EXAMPLES_MAVEN")
69    pushd examples && mvn clean package appassembler:assemble -e && popd
70    ;;
71  "BUILD_EXAMPLES_BAZEL")
72    pushd examples && bazel clean && bazel build :all && popd
73    ;;
74  *)
75    echo "Unknown task $TASK"
76    exit 1
77    ;;
78esac
79