# For some special functionality you'll need to set some environment variables in Travis (https://docs.travis-ci.com/user/environment-variables#Defining-Variables-in-Repository-Settings).
#
# If you want to deploy to GitHub releases (when a git-tag is built):
# - set `DEPLOY_GITHUB_RELEASES` to true
# - set `GH_TOKEN` to one of your personal access tokens from GitHub (https://help.github.com/articles/creating-an-access-token-for-command-line-use/), disable displaying the value in the build log!
#
# If you want to send build information to sonarqube.com (when on master):
# - set `SUBMIT_TO_SONARQUBE` to true
# - set `SONAR_TOKEN` to one of your user tokens from sonarqube.com (http://docs.sonarqube.org/display/SONAR/User+Token), disable displaying the value in the build log!
#
# If you want to publish the build results onto the gh-pages branch (when on master):
# - set `PUBLISH_GH_PAGES` to true
# - set `GH_TOKEN` to one of your personal access tokens from GitHub (https://help.github.com/articles/creating-an-access-token-for-command-line-use/), disable displaying the value in the build log!
# - set `GH_USERNAME` to the GitHub username to which the personal access token belongs

sudo: false
dist: trusty

cache:
  directories:
  - $HOME/.gradle/caches

language: java
jdk:
  - openjdk8
  - oraclejdk8
  - oraclejdk9

install: ./gradlew --build-cache assemble
before_script: # init GUI for tests that can't run headless (https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI)
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3
script: ./.travis/script
# Deploy to GitHub pages
after_script: ./.travis/after_script
# Upload code coverage data
after_success: ./.travis/after_success
# Release the plugin via GitHub releases when pushing a tag

deploy:
  provider: releases
  file_glob: true
  api_key: "${GH_TOKEN}"
  file:
    - "build/dist/Mapillary.jar"
    - "build/tmp/jar/MANIFEST.MF"
  skip_cleanup: true
  on:
    condition: "$DEPLOY_GITHUB_RELEASES = true"
    tags: true
    jdk: openjdk8

jobs:
  include:
    - stage: i18n
      language: python
      python: "3.6"
      install: pip install git+https://github.com/transifex/transifex-client.git@08deb1255de7217d2574e3c49dcb578f03b195e0#egg=transifex-client
      script: ./gradlew generatePot
      after_success: |
        if [ ! -z "$TRANSIFEX_TOKEN" ]; then
          tx --token="$TRANSIFEX_TOKEN" --force-save --no-interactive init
          git checkout HEAD .tx/config
          tx push -s --no-interactive
        fi

stages:
  - test
  - name: i18n
    if: branch = master

matrix:
  fast_finish: true
  allow_failures:
  - jdk: oraclejdk9
  - language: python

