sudo: required
dist: trusty
group: edge

language: java
cache:
  directories: $HOME/.gradle
jdk:
  - oraclejdk9
  - oraclejdk8
  - openjdk8
before_install: pip install --user codecov
before_script: # init GUI for tests that can't run headless
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3
script: ./gradlew build javadoc

# Release the plugin via GitHub releases when pushing a tag
before_deploy: 'cp -T build/libs/josm-mapillary-plugin.jar build/libs/Mapillary.jar'
deploy:
  provider: releases
  api_key: "${GH_TOKEN}"
  file: "build/libs/Mapillary.jar"
  skip_cleanup: true
  on:
    tags: true

# Deploy to GitHub pages
after_script: |
  if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_JDK_VERSION" == "openjdk8" ]; then
    git config --global user.email "deploy@travis"
    git config --global user.name "Travis CI"

    # Prevent printout of credentials
    git config --global credential.helper store
    echo "https://${GH_USERNAME}:${GH_TOKEN}@github.com" > $HOME/.git-credentials

    git remote add deploy "https://github.com/floscher/josm-mapillary-plugin.git"
    git fetch --depth=1 origin gh-pages:gh-pages
    git checkout gh-pages
    git rm -r reports/ docs/
    mkdir -p reports/ docs/
    cp -R build/docs/javadoc/ docs/javadoc/
    cp -R build/reports/tests/ reports/junit/
    cp -R build/reports/jacoco/ reports/jacoco/
    cp -R build/reports/findbugs/ reports/findbugs/
    git stage docs/ reports/
    masterCommit=`git rev-parse master`
    git commit -m "Publish developer resources to GitHub pages

  These resources are generated by Travis CI for commit $masterCommit using Gradle."
    git push deploy gh-pages
  else
    echo "This is branch $TRAVIS_BRANCH with JDK $TRAVIS_JDK_VERSION, developer resources are only published with openjdk8 on branch master."
  fi

after_success: codecov
