# This task produces the coverage reports and publishes them to codecov.
steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.8'

- template: jdk.yml
  parameters:
    version: 11

- script: |
    python setup.py test_java
    pip install gcovr pytest-cov -r test-requirements.txt
    pip install numpy setuptools
  displayName: 'Install requirements'

- script: |
    python setup.py develop --enable-coverage --enable-build-jar
  displayName: 'Build'

- script: |
    python -m pytest -v -s test/jpypetest --cov=jpype --cov-report=xml:coverage_py.xml --classpath="build/classes" --jacoco --checkjni
  displayName: 'Test'

- script: |
    gcovr -r . --xml -o coverage.xml --exclude-unreachable-branches --exclude-throw-branches
    java -jar lib/org.jacoco.cli-0.8.5-nodeps.jar report build/coverage/jacoco.exec --classfiles build/classes/ --xml coverage_java.xml --sourcefiles native/java
    bash <(curl -s https://codecov.io/bash) -f coverage.xml -f coverage_py.xml -f coverage_java.xml -X gcov
  displayName: 'Report'

- task: PublishCodeCoverageResults@2
  inputs:
    codeCoverageTool: 'JaCoCo'
    summaryFileLocation: coverage_java.xml
    pathToSources: native/java

- task: PublishCodeCoverageResults@2
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: coverage.xml

- task: PublishCodeCoverageResults@2
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: coverage_py.xml

