Merge "Refactor install_python function"
[integration.git] / autorelease / scripts / fix-names.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015, 2016 The Linux Foundation.  All rights reserved.
4 ##############################################################################
5
6 # autorelease root dir
7 ROOT=`git rev-parse --show-toplevel`/autorelease
8
9 BUILD_DIR=$ROOT/build
10
11 mkdir -p $BUILD_DIR
12 cd $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
19 fix_name() {
20     pom=$1
21     echo -e "\nScanning $pom"
22     pomPath=`dirname $pom`
23
24     projectPath=${pomPath#*/}  # Path to pom file from the perspective of hosting repo
25
26     relativePath="$projectPath"  # Calculated relative path to parent pom
27
28     # Update any existing project names
29     xmlstarlet ed -P -N x=http://maven.apache.org/POM/4.0.0 \
30                -u "/x:project/x:name" -v "$relativePath" \
31                "$pom" > "${pom}.new"
32     mv "${pom}.new" "${pom}"
33
34     # Add missing ones
35     xmlstarlet ed -P -N x=http://maven.apache.org/POM/4.0.0 \
36                -s "/x:project[count(x:name)=0]" -t elem -n name -v "$relativePath" \
37                "$pom" > "${pom}.new" 
38     mv "${pom}.new" "${pom}"
39 }
40
41 # Find all project poms ignoring the /src/ paths (We don't want to scan code)
42 find . -name pom.xml -not -path "*/src/*" | xargs -I^ -P8 bash -c "$(declare -f fix_name); fix_name ^"