trigger: none

pr:
  branches:
    include:
      - main
  paths:
    include:
      - eng/pipelines/latest-jdk.yml
      - eng/scrips/Install-Latest-JDK.ps1

variables:
  - template: /eng/pipelines/templates/variables/globals.yml

stages:
  - stage: LatestJdk
    displayName: Latest JDK

    jobs:
      - job: RunLatestJdk
        displayName: Run Latest JDK
        timeoutInMinutes: 180

        pool:
          name: 'azsdk-pool-mms-ubuntu-2004-general'
          vmImage: 'MMSUbuntu20.04'

        steps:
          # Skip sparse checkout for the `azure-sdk-for-<lang>-pr` private mirrored repositories
          # as we require the GitHub service connection to be loaded.
          - ${{ if not(contains(variables['Build.DefinitionName'], 'java-pr')) }}:
              - template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
                parameters:
                  Paths:
                    - '**/*.xml'

          - task: UsePythonVersion@0
            displayName: 'Use Python $(PythonVersion)'
            inputs:
              versionSpec: $(PythonVersion)

          - template: /eng/pipelines/templates/steps/generate-project-list-and-cache-maven-repository.yml
            parameters:
              JobType: 'LatestJdk'
              Artifacts:
                - name: latest-jdk # fake artifact name
                  groupId: run # fake group id

          - task: PythonScript@0
            displayName: 'Generate FromSource POM and directories for sparse checkout'
            inputs:
              scriptPath: 'eng/scripts/generate_from_source_pom.py'
              arguments: '--match-any-version --set-skip-linting-projects SkipLintingProjects --project-list com.azure:azure-core'
              workingDirectory: '$(System.DefaultWorkingDirectory)'

          - template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
            parameters:
              SkipCheckoutNone: true
              Paths: $(SparseCheckoutDirectories)

          - template: /eng/pipelines/templates/steps/install-reporting-tools.yml

          - template: /eng/pipelines/templates/steps/install-latest-jdk.yml
            parameters:
              LatestJdkFeatureVersion: '19'

          - task: Maven@3
            displayName: 'Run All Libraries Latest JDK'
            inputs:
              mavenPomFile: ClientFromSourcePom.xml
              options: '$(DefaultOptions) -T 1C -Dgpg.skip'
              mavenOptions: '$(MemoryOptions) $(LoggingOptions)'
              javaHomeOption: 'JDKVersion'
              jdkVersionOption: '1.19'
              jdkArchitectureOption: 'x64'
              publishJUnitResults: false
              goals: 'clean install'
            continueOnError: true

          - task: PublishTestResults@2
            condition: always()
            inputs:
              testResultsFormat: 'JUnit'
              testResultsFiles: '**/TEST-*.xml'
              searchFolder: '$(System.DefaultWorkingDirectory)/sdk'
              mergeTestResults: true
              testRunTitle: $(Agent.JobName)
