1
1
#! /usr/bin/env bash
2
2
3
3
readonly FETCH_BUILD_SCAN_DATA_JAR=" ${LIB_DIR} /export-api-clients/fetch-build-scan-data-cmdline-tool-${SCRIPT_VERSION} -all.jar"
4
- readonly MOCK_SCAN_DUMP_TO_CSV_JAR=" ${LIB_DIR} /export-api-clients/mock-scan-dump-to-csv-tool-${SCRIPT_VERSION} -all.jar"
4
+
5
+ # Arrays used by callers to access the fetched build scan data
6
+ project_names=()
7
+ base_urls=()
8
+ build_scan_urls=()
9
+ build_scan_ids=()
10
+ git_repos=()
11
+ git_branches=()
12
+ git_commit_ids=()
13
+ requested_tasks=()
14
+ build_outcomes=()
15
+ # shellcheck disable=SC2034 # not all scripts use this data
16
+ remote_build_cache_urls=()
17
+ # shellcheck disable=SC2034 # not all scripts use this data
18
+ remote_build_cache_shards=()
19
+
20
+ # Build caching performance metrics
21
+ avoided_up_to_date_num_tasks=()
22
+ avoided_up_to_date_avoidance_savings=()
23
+ avoided_from_cache_num_tasks=()
24
+ avoided_from_cache_avoidance_savings=()
25
+ executed_cacheable_num_tasks=()
26
+ executed_cacheable_duration=()
27
+ executed_not_cacheable_num_tasks=()
28
+ executed_not_cacheable_duration=()
5
29
6
30
read_build_scan_metadata () {
7
31
# This isn't the most robust way to read a CSV,
@@ -23,10 +47,114 @@ read_build_data_from_current_dir() {
23
47
requested_tasks+=(" ${tasks} " )
24
48
}
25
49
50
+ fetch_build_scan_data () {
51
+ # OS specific support (must be 'true' or 'false').
52
+ cygwin=false
53
+ msys=false
54
+ case " $( uname) " in
55
+ CYGWIN* )
56
+ cygwin=true
57
+ ;;
58
+ MINGW* )
59
+ msys=true
60
+ ;;
61
+ esac
62
+
63
+ # Determine the Java command to use to start the JVM.
64
+ if [ -n " $JAVA_HOME " ] ; then
65
+ if [ -x " $JAVA_HOME /jre/sh/java" ] ; then
66
+ # IBM's JDK on AIX uses strange locations for the executables
67
+ JAVACMD=" $JAVA_HOME /jre/sh/java"
68
+ else
69
+ JAVACMD=" $JAVA_HOME /bin/java"
70
+ fi
71
+ if [ ! -x " $JAVACMD " ] ; then
72
+ die " ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
73
+
74
+ Please set the JAVA_HOME variable in your environment to match the
75
+ location of your Java installation."
76
+ fi
77
+ else
78
+ JAVACMD=" java"
79
+ which java > /dev/null 2>&1 || die " ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
80
+
81
+ Please set the JAVA_HOME variable in your environment to match the
82
+ location of your Java installation."
83
+ fi
84
+
85
+ # For Cygwin or MSYS, switch paths to Windows format before running java
86
+ if [ " $cygwin " = " true" ] || [ " $msys " = " true" ] ; then
87
+ APP_HOME=$( cygpath --path --mixed " $APP_HOME " )
88
+ CLASSPATH=$( cygpath --path --mixed " $CLASSPATH " )
89
+ JAVACMD=$( cygpath --unix " $JAVACMD " )
90
+
91
+ # We build the pattern for arguments to be converted via cygpath
92
+ ROOTDIRSRAW=$( find -L / -maxdepth 1 -mindepth 1 -type d 2> /dev/null)
93
+ SEP=" "
94
+ for dir in $ROOTDIRSRAW ; do
95
+ ROOTDIRS=" $ROOTDIRS$SEP$dir "
96
+ SEP=" |"
97
+ done
98
+ OURCYGPATTERN=" (^($ROOTDIRS ))"
99
+ # Add a user-defined pattern to the cygpath arguments
100
+ if [ " $GRADLE_CYGPATTERN " != " " ] ; then
101
+ OURCYGPATTERN=" $OURCYGPATTERN |($GRADLE_CYGPATTERN )"
102
+ fi
103
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
104
+ i=0
105
+ for arg in " $@ " ; do
106
+ CHECK=$( echo " $arg " | grep -E -c " $OURCYGPATTERN " -)
107
+ CHECK2=$( echo " $arg " | grep -E -c " ^-" ) # ## Determine if an option
108
+
109
+ # shellcheck disable=SC2046 # we actually want word splitting
110
+ # shellcheck disable=SC2116 # using echo to expand globs
111
+ if [ " $CHECK " -ne 0 ] && [ " $CHECK2 " -eq 0 ] ; then # ## Added a condition
112
+ eval $( echo args$i ) =$( cygpath --path --ignore --mixed " $arg " )
113
+ else
114
+ eval $( echo args$i ) =" \" $arg \" "
115
+ fi
116
+ # shellcheck disable=SC2003
117
+ i=$( expr $i + 1)
118
+ done
119
+ # shellcheck disable=SC2154
120
+ case $i in
121
+ 0) set -- ;;
122
+ 1) set -- " $args0 " ;;
123
+ 2) set -- " $args0 " " $args1 " ;;
124
+ 3) set -- " $args0 " " $args1 " " $args2 " ;;
125
+ 4) set -- " $args0 " " $args1 " " $args2 " " $args3 " ;;
126
+ 5) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " ;;
127
+ 6) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " ;;
128
+ 7) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " " $args6 " ;;
129
+ 8) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " " $args6 " " $args7 " ;;
130
+ 9) set -- " $args0 " " $args1 " " $args2 " " $args3 " " $args4 " " $args5 " " $args6 " " $args7 " " $args8 " ;;
131
+ esac
132
+ fi
133
+
134
+ # Escape application args
135
+ save () {
136
+ for i do printf %s\\ n " $i " | sed " s/'/'\\\\ ''/g;1s/^/'/;\$ s/\$ /' \\\\ /" ; done
137
+ echo " "
138
+ }
139
+ APP_ARGS=$( save " $@ " )
140
+
141
+ CLASSPATH=" ${FETCH_BUILD_SCAN_DATA_JAR} "
142
+ # Collect all arguments for the java command, following the shell quoting and substitution rules
143
+ eval set -- -Dpicocli.ansi=true -jar " \" $CLASSPATH \" " " $APP_ARGS "
144
+
145
+ # shellcheck disable=SC2154
146
+ if [[ " $_arg_debug " == " on" ]]; then
147
+ debug " $JAVACMD $* " 1>&2
148
+ print_bl 1>&2
149
+ fi
150
+
151
+ exec " $JAVACMD " " $@ "
152
+ }
153
+
26
154
fetch_and_read_build_scan_data () {
27
155
# This isn't the most robust way to read a CSV,
28
156
# but we control the CSV so we don't have to worry about various CSV edge cases
29
- local args build_cache_metrics_only
157
+ local args build_cache_metrics_only fetched_data header_row_read idx
30
158
args=()
31
159
32
160
if [[ " $_arg_debug " == " on" ]]; then
@@ -51,14 +179,49 @@ fetch_and_read_build_scan_data() {
51
179
fi
52
180
shift
53
181
args+=( " $@ " )
182
+ fetched_data=" $( fetch_build_scan_data " ${args[@]} " ) "
54
183
55
- raw_build_scan_data=" $( invoke_java " $FETCH_BUILD_SCAN_DATA_JAR " " ${args[@]} " ) "
56
- parse_raw_build_scan_data " $raw_build_scan_data " " $build_cache_metrics_only "
57
- }
184
+ debug " Raw fetched build scan data"
185
+ debug " ---------------------------"
186
+ debug " ${fetched_data} "
187
+ debug " "
188
+
189
+ header_row_read=false
190
+ idx=0
191
+
192
+ # shellcheck disable=SC2034 # not all scripts use all of the fetched data
193
+ while IFS=, read -r field_1 field_2 field_3 field_4 field_5 field_6 field_7 field_8 field_9 field_10 field_11 field_12 field_13 field_14 field_15 field_16 field_17 field_18 field_19; do
194
+ if [[ " $header_row_read " == " false" ]]; then
195
+ header_row_read=true
196
+ continue ;
197
+ fi
198
+
199
+ if [[ " ${build_cache_metrics_only} " != " true" ]]; then
200
+ project_names[idx]=" $field_1 "
201
+ base_urls[idx]=" $field_2 "
202
+ build_scan_urls[idx]=" $field_3 "
203
+ build_scan_ids[idx]=" $field_4 "
204
+ git_repos[idx]=" $field_5 "
205
+ git_branches[idx]=" $field_6 "
206
+ git_commit_ids[idx]=" $field_7 "
207
+ requested_tasks[idx]=" $( remove_clean_task " ${field_8} " ) "
208
+ build_outcomes[idx]=" $field_9 "
209
+ remote_build_cache_urls[idx]=" ${field_10} "
210
+ remote_build_cache_shards[idx]=" ${field_11} "
211
+ fi
212
+
213
+ # Build caching performance metrics
214
+ avoided_up_to_date_num_tasks[idx]=" ${field_12} "
215
+ avoided_up_to_date_avoidance_savings[idx]=" ${field_13} "
216
+ avoided_from_cache_num_tasks[idx]=" ${field_14} "
217
+ avoided_from_cache_avoidance_savings[idx]=" ${field_15} "
218
+ executed_cacheable_num_tasks[idx]=" ${field_16} "
219
+ executed_cacheable_duration[idx]=" ${field_17} "
220
+ executed_not_cacheable_num_tasks[idx]=" ${field_18} "
221
+ executed_not_cacheable_duration[idx]=" ${field_19} "
58
222
59
- read_build_scan_from_scan_dump () {
60
- raw_build_scan_data=" $( invoke_java " $MOCK_SCAN_DUMP_TO_CSV_JAR " ) "
61
- parse_raw_build_scan_data " $raw_build_scan_data "
223
+ (( idx++ ))
224
+ done <<< " ${fetched_data}"
62
225
}
63
226
64
227
detect_warnings_from_build_scans () {
0 commit comments