version: 0.2

phases:
  install:
    runtime-versions:
      java: "$JAVA_RUNTIME"

  build:
    commands:
      - |
        if [ ! -z "$INTEGRATION_TEST_ROLE_ARN" ]; then
          ASSUME_ROLE_OUTPUT=`aws sts assume-role --role-arn "$INTEGRATION_TEST_ROLE_ARN" --role-session-name "integration-tests" --duration-seconds 7200 --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' --output text`
          AWS_ACCESS_KEY_ID=`echo $ASSUME_ROLE_OUTPUT | awk '{ print $1 }'`
          AWS_SECRET_ACCESS_KEY=`echo $ASSUME_ROLE_OUTPUT | awk '{ print $2 }'`
          AWS_SESSION_TOKEN=`echo $ASSUME_ROLE_OUTPUT | awk '{ print $3 }'`
          echo "Using role $INTEGRATION_TEST_ROLE_ARN with access key $AWS_ACCESS_KEY_ID."
        fi
      - mvn clean install -Dskip.unit.tests -P integration-tests -Dfindbugs.skip -Dcheckstyle.skip -T1C $MAVEN_OPTIONS
      - JAVA_VERSION=$(java -version 2>&1 | grep -i version | cut -d'"' -f2 | cut -d'.' -f1-1)
      - echo $JAVA_VERSION
      - echo $MAVEN_OPTIONS
      - |
        if [ "$JAVA_VERSION" -ge "9" ]; then
          cd test/module-path-tests
          mvn package
          mvn exec:exec -P integ-tests
        fi
    finally:
      - mkdir -p codebuild-test-reports
      - find ./ -name 'TEST-*.xml' -type f -exec cp {} codebuild-test-reports/ \;
reports:
  IntegTests:
    files:
      - 'codebuild-test-reports/**/*'
