4 # ============LICENSE_START================================================
6 # =========================================================================
7 # Copyright (C) 2021-2022 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==================================================
25 SCRIPT_NAME=$(basename "$0")
27 # Use the bash internal OSTYPE variable to check for MacOS
28 if [[ "$OSTYPE" == "darwin"* ]]
38 echo "$SCRIPT_NAME - update the parent reference in a POM file"
40 echo " usage: $SCRIPT_NAME [-options]"
43 echo " -h - this help message"
44 echo " -f pom_file - the POM file to update"
45 echo " -g group_id - the parent group ID"
46 echo " -a artifact_id - the parent artifact ID"
47 echo " -v version - the parent version"
51 while getopts "hf:g:a:v:" opt
74 echo "Option -$OPTARG requires an argument." >&2
82 echo "no arguments were specified"
86 if [ ! -f "$pom_file" ]
88 echo "POM file '$pom_file' specified on '-f' flag not found"
94 echo "group ID not specified on '-g' flag"
98 if [ -z "$artifact_id" ]
100 echo "artifact ID not specified on '-a' flag"
106 echo "version not specified on '-v' flag"
110 pom_lines=$(wc -l "$pom_file" | $SED 's/^[ \t]*//' | cut -f1 -d' ')
111 parent_start_line=$(grep -n '^[\t ]*<parent>[\t ]*$' "$pom_file" | cut -f1 -d':')
112 parent_end_line=$(grep -n '^[\t ]*</parent>[\t ]*$' "$pom_file" | cut -f1 -d':')
114 pom_head_lines=$((parent_start_line-1))
115 pom_tail_lines=$((pom_lines-parent_end_line))
117 pom_temp_file=$(mktemp)
120 head -$pom_head_lines "$pom_file"
122 echo " <groupId>$group_id</groupId>"
123 echo " <artifactId>$artifact_id</artifactId>"
124 echo " <version>$version</version>"
125 echo " <relativePath />"
127 tail -$pom_tail_lines "$pom_file"
130 mv "$pom_temp_file" "$pom_file"