@@ -29,6 +29,18 @@ function print_help() {
29
29
echo " Use -l {deps_list} for a comma-separated list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
30
30
}
31
31
32
+ # Function to parse a dependency string and append it to the Maven command
33
+ function add_dependency_to_maven_command() {
34
+ local dep_pair=$1
35
+ if [[ ! " ${dep_pair} " =~ .* = .* ]]; then
36
+ echo " Malformed dependency string: ${dep_pair} . Expected format: dependency=version"
37
+ exit 1
38
+ fi
39
+ local dependency=$( echo " ${dep_pair} " | cut -d' =' -f1 | tr -d ' [:space:]' )
40
+ local version=$( echo " ${dep_pair} " | cut -d' =' -f2 | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
41
+ MAVEN_COMMAND+=" -D${dependency} .version=${version} "
42
+ }
43
+
32
44
# Default to the upper bounds file in the root of the repo
33
45
file=' dependencies.txt'
34
46
dependency_list=' '
@@ -65,15 +77,7 @@ if [ -z "${dependency_list}" ]; then
65
77
if [[ " ${line} " =~ ^[[:space:]]* # ]] || [[ -z "${line}" ]]; then
66
78
continue
67
79
fi
68
-
69
- # Extract the dependency name and version
70
- # We use 'cut' to split the line by '=' and trim whitespace
71
- # The sed command is used to remove potential trailing whitespace from the version number
72
- dependency= $( echo " ${line} " | cut -d' =' -f1 | tr -d ' [:space:]' )
73
- version= $( echo " ${line} " | cut -d' =' -f2 | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
74
-
75
- # Append the formatted property to the Maven command
76
- MAVEN_COMMAND+= " -D${dependency} .version=${version} "
80
+ add_dependency_to_maven_command " ${line} "
77
81
done < " ${UPPER_BOUND_DEPENDENCY_FILE} "
78
82
else # This else block means that a list of dependencies was inputted
79
83
# Set the Internal Field Separator (IFS) to a comma.
@@ -87,15 +91,7 @@ else # This else block means that a list of dependencies was inputted
87
91
if [ -z " ${DEP_PAIR} " ]; then
88
92
continue
89
93
fi
90
-
91
- # Extract the dependency name and version
92
- # We use 'cut' to split the line by '=' and trim whitespace
93
- # The sed command is used to remove potential trailing whitespace from the version number
94
- dependency=$( echo " ${DEP_PAIR} " | cut -d' =' -f1 | tr -d ' [:space:]' )
95
- version=$( echo " ${DEP_PAIR} " | cut -d' =' -f2 | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
96
-
97
- # Append the formatted property to the PROPERTIES string.
98
- MAVEN_COMMAND+=" -D${dependency} .version=${version} "
94
+ add_dependency_to_maven_command " ${DEP_PAIR} "
99
95
done
100
96
fi
101
97
0 commit comments