diff options
author | liamfallon <liam.fallon@est.tech> | 2021-12-13 16:41:52 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2021-12-13 16:41:57 +0000 |
commit | 5946bbfbefc9305961e72681f3bf161e16dfcd5d (patch) | |
tree | 91b55e0073cb7f3b0ab52985141c68d84fb1d64e | |
parent | a14dffcc6b97a6b8a11fceb2f781665346dcd2eb (diff) |
Script to update a POM parent reference
This script changes teh parent reference in a POM file to use the group
ID, artifact ID and version specified on flags that are input to the
script.
Issue-ID: POLICY-3835
Change-Id: I0970f94d3acfc2a3d8d01fdfcb923b8f38442bf4
Signed-off-by: liamfallon <liam.fallon@est.tech>
-rwxr-xr-x | integration/src/release_scripts/updateParentRef.sh | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/integration/src/release_scripts/updateParentRef.sh b/integration/src/release_scripts/updateParentRef.sh new file mode 100755 index 00000000..831d6c39 --- /dev/null +++ b/integration/src/release_scripts/updateParentRef.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# +# ============LICENSE_START================================================ +# ONAP +# ========================================================================= +# Copyright (C) 2021 Nordix Foundation. +# ========================================================================= +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================== +# + +SCRIPT_NAME=`basename $0` + +usage() +{ + echo "" + echo "$SCRIPT_NAME - update the parent reference in a POM file" + echo "" + echo " usage: $SCRIPT_NAME [-options]" + echo "" + echo " options" + echo " -h - this help message" + echo " -f pom_file - the POM file to update" + echo " -g group_id - the parent group ID" + echo " -a artifact_id - the parent artifact ID" + echo " -v version - the parent version" + exit 255; +} + +while getopts "hf:g:a:v:" opt +do + case $opt in + h) + usage + ;; + f) + pom_file=$OPTARG + ;; + g) + group_id=$OPTARG + ;; + a) + artifact_id=$OPTARG + ;; + v) + version=$OPTARG + ;; + \?) + usage + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +if [ $OPTIND -eq 1 ] +then + echo "no arguments were specified" + usage +fi + +if [ ! -f "$pom_file" ] +then + echo "POM file '$pom_file' specified on '-f' flag not found" + exit 1 +fi + +if [ -z "$group_id" ] +then + echo "group ID not specified on '-g' flag" + exit 1 +fi + +if [ -z "$artifact_id" ] +then + echo "artifact ID not specified on '-a' flag" + exit 1 +fi + +if [ -z "$version" ] +then + echo "version not specified on '-v' flag" + exit 1 +fi + +pom_lines=`wc -l $pom_file | sed 's/^[ \t]*//' | cut -f1 -d' '` +parent_start_line=`grep -n '^[\t ]*<parent>[\t*]*$' $pom_file | cut -f1 -d':'` +parent_end_line=`grep -n '^[\t ]*</parent>[\t*]*$' $pom_file | cut -f1 -d':'` + +pom_head_lines=$((parent_start_line-1)) +pom_tail_lines=$((pom_lines-parent_end_line)) + +pom_temp_file=$(mktemp) + +head -$pom_head_lines $pom_file > $pom_temp_file +echo " <parent>" >> $pom_temp_file +echo " <groupId>$group_id</groupId>" >> $pom_temp_file +echo " <artifactId>$artifact_id</artifactId>" >> $pom_temp_file +echo " <version>$version</version>" >> $pom_temp_file +echo " <relativePath />" >> $pom_temp_file +echo " </parent>" >> $pom_temp_file +tail -$pom_tail_lines $pom_file >> $pom_temp_file + +mv $pom_temp_file $pom_file |