# SPDX-FileCopyrightText: 2021 Paul Schaub <info@pgpainless.org>
#
# SPDX-License-Identifier: Apache-2.0

language: java
dist: bionic
jdk:
  - openjdk8
  - openjdk11

services:
  - docker

before_cache:
  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
  directories:
    - $HOME/.gradle/caches/
    - $HOME/.m2

before_install:
  - export GRADLE_VERSION=6.2
  - wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
  - unzip -q gradle-${GRADLE_VERSION}-all.zip
  - rm gradle-${GRADLE_VERSION}-all.zip
  - sudo mv gradle-${GRADLE_VERSION} /usr/local/bin/
  - export PATH="/usr/local/bin/gradle-${GRADLE_VERSION}/bin:$PATH"
  - docker pull fsfe/reuse:latest
  - docker run -v ${TRAVIS_BUILD_DIR}:/data fsfe/reuse:latest lint

install: gradle assemble --stacktrace

# Run the test suite and also install the artifacts in the local maven
# archive to additionaly test if artifact creation is
# functional. Which hasn't always be the case in the past, see
# 90cbcaebc7a89f4f771f733a33ac9f389df85be2
# Also run javadocAll to ensure it works.
script:
  - |
    JAVAC_MAJOR_VERSION=$(javac -version | sed -E 's/javac ([[:digit:]]+).*/\1/')
    GRADLE_TASKS=()
    GRADLE_TASKS+=(check)
    if [[ ${JAVAC_MAJOR_VERSION} -ge 11 ]]; then
      GRADLE_TASKS+=(javadocAll)
    fi
    gradle ${GRADLE_TASKS[@]} --stacktrace

after_success:
  - JAVAC_VERSION=$((javac -version) 2>&1)
  # Only run jacocoRootReport in the Java 8 build
  - if [[ "$JAVAC_VERSION" = javac\ 1.8.* ]]; then gradle jacocoRootReport coveralls; fi
