blob: 1c9b8d331ce7f29581c651c34a06c8489bc60d3c [file] [log] [blame]
Gary Wud04e4402017-07-28 12:26:54 -07001#!/bin/bash
2##############################################################################
3# Copyright (c) 2015, 2016 The Linux Foundation. All rights reserved.
4##############################################################################
5
6# autorelease root dir
7ROOT=`git rev-parse --show-toplevel`/autorelease
8
9BUILD_DIR=$ROOT/build
10
11mkdir -p $BUILD_DIR
12cd $BUILD_DIR
13
14# MAP of path to a parent pom from the perspective of hosting directory
15# starting from the autorelease repo root.
16#
17# Format: <groupId>:<artifactId>:<path>
18
19fix_relative_paths() {
20 PARENT_MAP=(
21 "org.openo.oparent:oparent:oparent"
22 "org.openo.nfvo:nfvo-root:nfvo"
23 )
24
25 pom=$1
26 echo "Scanning $pom"
27 pomPath=`dirname $pom`
28
29 # Find and replace parent poms
30 for parent in "${PARENT_MAP[@]}"; do
31 map=${parent#*:} #
32
33 groupId=${parent%%:*} # Maven groupId
34 artifactId=${map%%:*} # Maven artifactId
35 projectPath=${map#*:} # Path to pom file from the perspective of hosting repo
36
37 # Compute relative path to parent pom
38 relativePath=`python -c "import os.path; print os.path.relpath('$projectPath','$pomPath')"`
39
40 # Standardize POM XML formatting
41 xmlstarlet fo "$pom" > "${pom}.old"
42
43 # Update any existing relativePath values
44 xmlstarlet ed -P -N x=http://maven.apache.org/POM/4.0.0 \
45 -u "//x:parent[x:artifactId=\"$artifactId\" and x:groupId=\"$groupId\"]/x:relativePath" \
46 -v "$relativePath" "${pom}" > "${pom}.new1"
47
48 # Add missing ones
49 xmlstarlet ed -P -N x=http://maven.apache.org/POM/4.0.0 \
50 -s "//x:parent[x:artifactId=\"$artifactId\" and x:groupId=\"$groupId\" and count(x:relativePath)=0]" \
51 -t elem -n relativePath -v "$relativePath" "${pom}.new1" > "${pom}.new2"
52
53 # Standardize POM XML formatting again
54 xmlstarlet fo "${pom}.new2" > "${pom}.new"
55
56 diff -u "${pom}.old" "${pom}.new"
57 cp "${pom}.new" "${pom}"
58 done
59}
60
61# Find all project poms ignoring the /src/ paths (We don't want to scan code)
62find . -name pom.xml -not -path "*/src/*" | sort | xargs -I^ bash -c "$(declare -f fix_relative_paths); fix_relative_paths ^"