4 # ============LICENSE_START================================================
6 # =========================================================================
7 # Copyright (C) 2021 Nordix Foundation.
8 # =========================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END==================================================
23 SCRIPT_NAME=`basename $0`
28 echo "$SCRIPT_NAME - update the parent reference in a POM file"
30 echo " usage: $SCRIPT_NAME [-options]"
33 echo " -h - this help message"
34 echo " -f pom_file - the POM file to update"
35 echo " -g group_id - the parent group ID"
36 echo " -a artifact_id - the parent artifact ID"
37 echo " -v version - the parent version"
41 while getopts "hf:g:a:v:" opt
64 echo "Option -$OPTARG requires an argument." >&2
72 echo "no arguments were specified"
76 if [ ! -f "$pom_file" ]
78 echo "POM file '$pom_file' specified on '-f' flag not found"
84 echo "group ID not specified on '-g' flag"
88 if [ -z "$artifact_id" ]
90 echo "artifact ID not specified on '-a' flag"
96 echo "version not specified on '-v' flag"
100 pom_lines=`wc -l $pom_file | sed 's/^[ \t]*//' | cut -f1 -d' '`
101 parent_start_line=`grep -n '^[\t ]*<parent>[\t*]*$' $pom_file | cut -f1 -d':'`
102 parent_end_line=`grep -n '^[\t ]*</parent>[\t*]*$' $pom_file | cut -f1 -d':'`
104 pom_head_lines=$((parent_start_line-1))
105 pom_tail_lines=$((pom_lines-parent_end_line))
107 pom_temp_file=$(mktemp)
109 head -$pom_head_lines $pom_file > $pom_temp_file
110 echo " <parent>" >> $pom_temp_file
111 echo " <groupId>$group_id</groupId>" >> $pom_temp_file
112 echo " <artifactId>$artifact_id</artifactId>" >> $pom_temp_file
113 echo " <version>$version</version>" >> $pom_temp_file
114 echo " <relativePath />" >> $pom_temp_file
115 echo " </parent>" >> $pom_temp_file
116 tail -$pom_tail_lines $pom_file >> $pom_temp_file
118 mv $pom_temp_file $pom_file