Make rtd jobs verbose
[releng/global-jjb.git] / shell / common-variables.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # This file contains a list of variables that are generally useful in many
13 # scripts. It is meant to be sourced in other scripts so that the variables can
14 # be called.
15
16 MAVEN_OPTIONS="$(echo --show-version \
17     --batch-mode \
18     -Djenkins \
19     -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
20     -Dmaven.repo.local=/tmp/r \
21     -Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r)"
22 echo "$MAVEN_OPTIONS"
23
24 # Activates the lftools virtualenv
25 lftools_activate() {
26     virtualenv --quiet "/tmp/v/lftools"
27     set +u  # Ignore unbound variables in activate
28     # shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
29     source "/tmp/v/lftools/bin/activate"
30     set -u  # Restore unbound variable checking
31 }
32
33 # Check maven-metadata.xml for any unexpected timestamp mismatches
34 maven_metadata_validate() {
35     stage_dir="$1"
36
37     if [ -z "$1" ]; then
38         echo "Usage: maven_metadata_validate STAGE_REPO_DIR"
39         exit 1
40     fi
41
42     error_detected=0
43     mapfile -t files < <(find "$stage_dir" -name maven-metadata.xml | grep SNAPSHOT)
44
45     for f in "${files[@]}"; do
46         timestamp=$(xmlstarlet sel \
47             -t -v "/metadata/versioning/snapshot/timestamp" "$f")
48
49         # Scan all snapshot versions but ignore javadoc and source jars
50         mapfile -t ext_timestamps < <(xmlstarlet sel \
51             -t -m "/metadata/versioning/snapshotVersions/snapshotVersion" \
52             -n \
53             --if "classifier='javadoc'" \
54                -o "" \
55             --elif "classifier='sources'" \
56                -o "" \
57             --else \
58                -o "extension:" -v extension \
59                -o " value:" -v value \
60                -o " updated:" -v updated \
61             "$f")
62
63         for t in "${ext_timestamps[@]}"; do
64             # Ignore blank timestamps caused by xmlstarlet ignores
65             if [[ -z "$t" ]]; then
66                 continue
67             fi
68
69             timestamp_error=0
70             if [[ $t != *"$timestamp"* ]]; then
71                 echo "Metadata $f 'value:$timestamp' mismatch vs '$t'"
72                 timestamp_error=1
73             fi
74             # Updated is timestamp without the dot character
75             if [[ $t != *"${timestamp//\./}"* ]]; then
76                 echo "Metadata $f 'updated:${timestamp//\./}' mismatch vs '$t'"
77                 timestamp_error=1
78             fi
79
80             if [[ $timestamp_error != 0 ]]; then
81                 error_detected=1
82                 cat "$f"
83             fi
84         done
85     done
86
87     if [ $error_detected -ne 0 ]; then
88         echo "ERROR: Mismatches in maven-metadata discovered. Quitting..."
89         exit 1
90     fi
91 }