Make sure that jjb-cleanup.sh allows unbound vars
[releng/global-jjb.git] / shell / maven-fetch-metadata.sh
1 #!/bin/bash -l
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 # Uses wget to fetch a project's maven-metadata.xml files from a Maven repository.
13
14 # Ensure we fail the job if any steps fail.
15 set -xeu -o pipefail
16
17 project=$(xmlstarlet sel \
18     -N "x=http://maven.apache.org/POM/4.0.0" -t \
19     --if "/x:project/x:groupId" \
20       -v "/x:project/x:groupId" \
21     --elif "/x:project/x:parent/x:groupId" \
22       -v "/x:project/x:parent/x:groupId" \
23     --else -o "" pom.xml)
24 project_path="${project//.//}"
25
26 mkdir -p "$WORKSPACE/m2repo/$project_path"
27 pushd "$WORKSPACE/m2repo/$project_path"
28     # Temporarily disable failing for wget
29     # If 404 happens we don't care because it might be a new project.
30     set +e
31     wget -nv --recursive \
32          --accept maven-metadata.xml \
33          -R "index.html*" \
34          --execute robots=off \
35          --no-parent \
36          --no-host-directories \
37          --cut-dirs="$NEXUS_CUT_DIRS" \
38          "$NEXUS_URL/content/repositories/$NEXUS_REPO/$project_path/"
39     set -e  # Re-enable.
40 popd
41
42 # Backup metadata - Used later to find metadata files that have not been modified
43 mkdir -p "$WORKSPACE/m2repo-backup"
44 cp -a "$WORKSPACE/m2repo/"* "$WORKSPACE/m2repo-backup"