- job:
    name: jdk8-jtreg-test-persist-results
    project-type: matrix
    defaults: global
    description: |
        * Writes the results to $HOME/srv/openjdk8u/openjdk-jtreg-nightly-tests.
    properties:
        - authorization:
            everyone-flat:
                - job-read
            openjdk-members:
                - job-extended-read
                - job-build
                - job-cancel
                - job-workspace
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 10
            artifact-num-to-keep: 5
    parameters:
        - string:
            name: YEAR
            default: 'default'
        - string:
            name: DAY_OF_YEAR
            default: 'default'
    disabled: true
    node: j12-qrep-01
    display-name: 'DELETE ME'
    axes:
        - axis:
            type: user-defined
            name: BUILD_TYPE
            values:
                - release
        - axis:
            type: user-defined
            name: JTREG_CATEGORY
            values:
                - jdk
                - hotspot
                - langtools
        - axis:
            type: slave
            name: label
            values:
                - j12-qrep-01
    execution-strategy:
        sequential: true
    wrappers:
        - workspace-cleanup:
            dirmatch: false
        - timestamps
        - matrix-tie-parent:
            node: j12-qrep-01
    builders:
        - copyartifact:
            project: jdk8-jtreg-test
            filter: 'out/jtreg-results-${JTREG_CATEGORY}-${BUILD_TYPE}.tar.gz'
            target: incoming
            flatten: true
        - copyartifact:
            project: jdk8-build-image
            filter: 'out/jdk8u-${BUILD_TYPE}.tar.gz'
            target: incoming
            flatten: true
        - shell: |
            #!/bin/bash

            set -exu

            tree -f .

            PERSIST=$HOME/srv/openjdk8u
            export JDK_VERSION=8u

            result_tarball=${WORKSPACE}/incoming/BUILD_TYPE=${BUILD_TYPE},JTREG_CATEGORY=${JTREG_CATEGORY},label=${label}/jtreg-results-${JTREG_CATEGORY}-${BUILD_TYPE}.tar.gz

            image_tarball=${WORKSPACE}/incoming/BUILD_TYPE=${BUILD_TYPE},label=${label}/jdk8u-${BUILD_TYPE}.tar.gz

            : ${YEAR:=$(date +%Y)}
            : ${DAY_OF_YEAR:=$(date +%j)}

            basedir=$PERSIST/openjdk-jtreg-nightly-tests
            src_dir=${basedir}/src/${YEAR}/${DAY_OF_YEAR}
            work_dir=${basedir}/builds/${BUILD_TYPE}/${YEAR}/${DAY_OF_YEAR}/JTwork-${JTREG_CATEGORY}
            report_dir=${basedir}/reports/${BUILD_TYPE}/${JTREG_CATEGORY}/$(uname -m)/${YEAR}/${DAY_OF_YEAR}/JTreport
            image_dir=${basedir}/builds/${BUILD_TYPE},label=${label}/${YEAR}/${DAY_OF_YEAR}/images/j2sdk-image

            rm -rf  ${image_dir}
            mkdir -p ${image_dir}

            tar -C ${basedir} \
              --transform="s/YYY__DAY_OF_YEAR__YYY/$DAY_OF_YEAR/;s/XXX__YEAR__XXX/$YEAR/" \
              --show-transformed-names \
              --overwrite \
              -xvf ${result_tarball}

            tar -C ${image_dir} \
              --strip-components=1 \
              --show-transformed-names \
              --overwrite \
              -xvf ${image_tarball}

            # Change location.
            # Match the exact output of the cron-based scripts.
            sed_expr1=$(echo s!XXX__YEAR__XXX!$YEAR!g)
            sed_expr2=$(echo s!YYY__DAY_OF_YEAR__YYY!$DAY_OF_YEAR!g)

            find ${work_dir} -type f -exec perl -p -i -e "$sed_expr1" {} \;
            find ${work_dir} -type f -exec perl -p -i -e "$sed_expr2" {} \;

            find ${report_dir} -type f -exec perl -p -i -e "$sed_expr1" {} \;
            find ${report_dir} -type f -exec perl -p -i -e "$sed_expr2" {} \;
