aboutsummaryrefslogtreecommitdiffstats
path: root/autorelease/scripts/fix-relativepaths.sh
diff options
context:
space:
mode:
authorGary Wu <gary.i.wu@huawei.com>2017-07-28 12:26:54 -0700
committerGary Wu <gary.i.wu@huawei.com>2017-07-28 12:26:54 -0700
commitd04e4407a6a5888b8f6d924e0c9706378c3d285a (patch)
treea1847dab1f8bbf784747166eaf623df958aa9e30 /autorelease/scripts/fix-relativepaths.sh
parent14387356f435a416f1f180d0d670d5760888c6b3 (diff)
Add integration scripts from OPEN-O
Change-Id: Ife6951ed9ea8c5b9dcea68e7a095b6bd5180e7d1 Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
Diffstat (limited to 'autorelease/scripts/fix-relativepaths.sh')
-rwxr-xr-xautorelease/scripts/fix-relativepaths.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/autorelease/scripts/fix-relativepaths.sh b/autorelease/scripts/fix-relativepaths.sh
new file mode 100755
index 000000000..1c9b8d331
--- /dev/null
+++ b/autorelease/scripts/fix-relativepaths.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+##############################################################################
+# Copyright (c) 2015, 2016 The Linux Foundation. All rights reserved.
+##############################################################################
+
+# autorelease root dir
+ROOT=`git rev-parse --show-toplevel`/autorelease
+
+BUILD_DIR=$ROOT/build
+
+mkdir -p $BUILD_DIR
+cd $BUILD_DIR
+
+# MAP of path to a parent pom from the perspective of hosting directory
+# starting from the autorelease repo root.
+#
+# Format: <groupId>:<artifactId>:<path>
+
+fix_relative_paths() {
+ PARENT_MAP=(
+ "org.openo.oparent:oparent:oparent"
+ "org.openo.nfvo:nfvo-root:nfvo"
+ )
+
+ pom=$1
+ echo "Scanning $pom"
+ pomPath=`dirname $pom`
+
+ # Find and replace parent poms
+ for parent in "${PARENT_MAP[@]}"; do
+ map=${parent#*:} #
+
+ groupId=${parent%%:*} # Maven groupId
+ artifactId=${map%%:*} # Maven artifactId
+ projectPath=${map#*:} # Path to pom file from the perspective of hosting repo
+
+ # Compute relative path to parent pom
+ relativePath=`python -c "import os.path; print os.path.relpath('$projectPath','$pomPath')"`
+
+ # Standardize POM XML formatting
+ xmlstarlet fo "$pom" > "${pom}.old"
+
+ # Update any existing relativePath values
+ xmlstarlet ed -P -N x=http://maven.apache.org/POM/4.0.0 \
+ -u "//x:parent[x:artifactId=\"$artifactId\" and x:groupId=\"$groupId\"]/x:relativePath" \
+ -v "$relativePath" "${pom}" > "${pom}.new1"
+
+ # Add missing ones
+ xmlstarlet ed -P -N x=http://maven.apache.org/POM/4.0.0 \
+ -s "//x:parent[x:artifactId=\"$artifactId\" and x:groupId=\"$groupId\" and count(x:relativePath)=0]" \
+ -t elem -n relativePath -v "$relativePath" "${pom}.new1" > "${pom}.new2"
+
+ # Standardize POM XML formatting again
+ xmlstarlet fo "${pom}.new2" > "${pom}.new"
+
+ diff -u "${pom}.old" "${pom}.new"
+ cp "${pom}.new" "${pom}"
+ done
+}
+
+# Find all project poms ignoring the /src/ paths (We don't want to scan code)
+find . -name pom.xml -not -path "*/src/*" | sort | xargs -I^ bash -c "$(declare -f fix_relative_paths); fix_relative_paths ^"