@@ -29,6 +29,18 @@ function print_help() {
2929 echo " Use -l {deps_list} for a comma-separated list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
3030}
3131
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+
3244# Default to the upper bounds file in the root of the repo
3345file=' dependencies.txt'
3446dependency_list=' '
@@ -65,15 +77,7 @@ if [ -z "${dependency_list}" ]; then
6577 if [[ " ${line} " =~ ^[[:space:]]* # ]] || [[ -z "${line}" ]]; then
6678 continue
6779 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} "
7781 done < " ${UPPER_BOUND_DEPENDENCY_FILE} "
7882else # This else block means that a list of dependencies was inputted
7983 # 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
8791 if [ -z " ${DEP_PAIR} " ]; then
8892 continue
8993 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} "
9995 done
10096fi
10197
0 commit comments