11
11
12
12
set -ex
13
13
14
- # Check if a filename was provided as an argument
15
- if [ -z " $1 " ]; then
16
- echo " Usage: $0 <dependency_file>"
17
- exit 1
18
- fi
14
+ file=' '
15
+ dependency_list=' '
19
16
20
- UPPER_BOUND_DEPENDENCY_FILE=" $1 "
17
+ function print_help() {
18
+ echo " Unexpected input argument for this script."
19
+ echo " Use -f for the directory of the upper-bound dependencies file."
20
+ echo " Use -l for a comma-separate list of dependencies to test (Format: dep1=1.0,dep2=2.0)"
21
+ }
21
22
22
- if [ ! -e " ${UPPER_BOUND_DEPENDENCY_FILE} " ]; then
23
- echo " The inputted upper-bound dependency file '$FILE ' does not exist"
24
- exit 1
23
+ while getopts ' f:l:' flag; do
24
+ case " ${flag} " in
25
+ f) file=" ${OPTARG} " ;;
26
+ l) dependency_list=" ${OPTARG} " ;;
27
+ * ) print_help && exit 1
28
+ esac
29
+ done
30
+
31
+ if [[ -z " ${file} " && -z " ${dependency_list} " ]]; then
32
+ print_help && exit 1
25
33
fi
26
34
27
35
MAVEN_COMMAND=" mvn verify -Penable-integration-tests -Dclirr.skip -Dcheckstyle.skip -Dfmt.skip "
28
36
29
- # Read the file line by line
30
- while IFS= read -r line; do
31
- # Ignore comments and blank lines
32
- if [[ " ${line} " =~ ^[[:space:]]* # ]] || [[ -z "${line}" ]]; then
33
- continue
37
+ # Check if a list of dependencies was provided as an argument. If the list of dependency inputted
38
+ # is empty, then run with the upper-bound dependencies file
39
+ if [ -z " ${dependency_list} " ]; then
40
+ UPPER_BOUND_DEPENDENCY_FILE=$file
41
+
42
+ if [ ! -e " ${UPPER_BOUND_DEPENDENCY_FILE} " ]; then
43
+ echo " The inputted upper-bound dependency file '${UPPER_BOUND_DEPENDENCY_FILE} ' does not exist"
44
+ exit 1
34
45
fi
35
46
36
- # Extract the dependency name and version
37
- # We use 'cut' to split the line by '=' and trim whitespace
38
- # The sed command is used to remove potential trailing whitespace from the version number
39
- dependency= $( echo " ${line} " | cut -d' =' -f1 | tr -d ' [:space:]' )
40
- version= $( echo " ${line} " | cut -d' =' -f2 | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
47
+ # Read the file line by line
48
+ while IFS= read -r line; do
49
+ # Ignore comments and blank lines
50
+ if [[ " ${line} " =~ ^[[:space:]]* # ]] || [[ -z "${line}" ]]; then
51
+ continue
52
+ fi
41
53
42
- # Append the formatted property to the Maven command
43
- MAVEN_COMMAND+= " -D${dependency} =${version} "
44
- done < " ${UPPER_BOUND_DEPENDENCY_FILE} "
54
+ # Extract the dependency name and version
55
+ # We use 'cut' to split the line by '=' and trim whitespace
56
+ # The sed command is used to remove potential trailing whitespace from the version number
57
+ dependency= $( echo " ${line} " | cut -d' =' -f1 | tr -d ' [:space:]' )
58
+ version= $( echo " ${line} " | cut -d' =' -f2 | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
59
+
60
+ # Append the formatted property to the Maven command
61
+ MAVEN_COMMAND+= " -D${dependency} =${version} "
62
+ done < " ${UPPER_BOUND_DEPENDENCY_FILE} "
63
+ else # List of dependencies was inputted
64
+ # Set the Internal Field Separator (IFS) to a comma.
65
+ # This tells 'read' to split the string by commas into an array named DEPS.
66
+ # The 'read -ra' command reads the input into an array.
67
+ IFS= ' ,' read -r a DEPS <<< " ${dependency_list} "
68
+
69
+ # Loop through each item in the DEPS array.
70
+ for DEP_PAIR in " ${DEPS[@]} " ; do
71
+ # Skip any empty items that might result from trailing commas.
72
+ if [ -z " $DEP_PAIR " ]; then
73
+ continue
74
+ fi
75
+
76
+ # Extract the dependency name and version
77
+ # We use 'cut' to split the line by '=' and trim whitespace
78
+ # The sed command is used to remove potential trailing whitespace from the version number
79
+ dependency=$( echo " ${DEP_PAIR} " | cut -d' =' -f1 | tr -d ' [:space:]' )
80
+ version=$( echo " ${DEP_PAIR} " | cut -d' =' -f2 | sed ' s/^[[:space:]]*//;s/[[:space:]]*$//' )
81
+
82
+ # Append the formatted property to the PROPERTIES string.
83
+ MAVEN_COMMAND+=" -D${dependency} .version=${version} "
84
+ done
85
+ fi
45
86
46
87
# Run the generated maven command to test with the dependency versions
47
88
$MAVEN_COMMAND
0 commit comments