name: CI
on:
  - push
  - pull_request
jobs:
  Linux:
    strategy:
      fail-fast: false
      matrix:
        include:
          - jdk: 8
          - jdk: 11
          - jdk: 17
          - jdk: 21
    name: JDK ${{ matrix.jdk }}
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
        with:
          distribution: 'zulu'
          java-version: |
            ${{ matrix.jdk }}
            17
      - name: 'Generate toolchains.xml'
        env:
          JDK_VERSION: ${{ matrix.jdk }}
          JDK_HOME_VARIABLE_NAME: JAVA_HOME_${{ matrix.jdk }}_X64
        run: |
          echo "
          <toolchains>
            <toolchain>
              <type>jdk</type>
              <provides>
                <id>$JDK_VERSION</id>
                <version>$JDK_VERSION</version>
              </provides>
              <configuration>
                <jdkHome>${!JDK_HOME_VARIABLE_NAME}</jdkHome>
              </configuration>
            </toolchain>
          </toolchains>
          " > toolchains.xml
      - name: 'Build'
        run: |
          mvn -V -B -e --no-transfer-progress \
            verify -Djdk.version=${{ matrix.jdk }} -Dbytecode.version=${{ matrix.jdk }} \
            --toolchains=toolchains.xml
  Windows:
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
        with:
          distribution: 'zulu'
          java-version: |
            6
            17
      - name: 'Generate toolchains.xml'
        env:
          JDK_VERSION: 6
          JDK_HOME_VARIABLE_NAME: JAVA_HOME_6_X64
        shell: bash
        run: |
          echo "
          <toolchains>
            <toolchain>
              <type>jdk</type>
              <provides>
                <id>$JDK_VERSION</id>
                <version>$JDK_VERSION</version>
              </provides>
              <configuration>
                <jdkHome>${!JDK_HOME_VARIABLE_NAME}</jdkHome>
              </configuration>
            </toolchain>
          </toolchains>
          " > toolchains.xml
      - name: 'Build'
        shell: bash
        run: |
          mvn -V -B -e --no-transfer-progress \
            verify -Djdk.version=6 -Dbytecode.version=5 \
            --toolchains=toolchains.xml
      - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
        id: artifact-upload-step
        with:
          name: jacoco
          path: jacoco/target/*.zip
          if-no-files-found: error
