gbsteps: &gbsteps
  steps:
    - run:
        name: Report on build environment
        command: |
          java -version
          javac -version

    - checkout
    - run: ant

    - run: ant test
    - run:
        name: Collect test results
        command: |
          mkdir -p test_reports/junit/
          cp -a build/tests/TEST-*.xml test_reports/junit/
    - store_test_results:
        path: test_reports
    - store_artifacts:
        path:  build/target/reports


version: 2.1


jobs:
  buildJ8:
    docker:
      - image: circleci/openjdk:8-jdk

    <<: *gbsteps

  buildJ9:
    docker:
      - image: circleci/openjdk:9-jdk

    <<: *gbsteps

  buildJ11:
    docker:
      - image: circleci/openjdk:11-jdk

    <<: *gbsteps

workflows:
  version: 2
  build:
    jobs:
      - buildJ8:
          post-steps:
            - run:
                name: Upload coverage to Codecov
                command: bash <(curl -s https://codecov.io/bash)
            - run:
                name: Prepare Code Climate coverage reporter
                command: |
                  curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
                  chmod +x ./cc-test-reporter
                  ./cc-test-reporter before-build
            - run:
                name: Upload coverage to Code Climate
                command: |
                  JACOCO_SOURCE_PATH=src/main/java ./cc-test-reporter format-coverage ./build/target/reports/coverage/jacoco.xml --input-type jacoco
                  ./cc-test-reporter upload-coverage
                when: on_success
            - run:
                name: Upload coverage to Codacy
                command: bash <(curl -Ls https://coverage.codacy.com/get.sh) report
      - "buildJ9"
      - "buildJ11"