@@ -19,8 +19,11 @@ output_filename="../../libraries-release-data/artifacts_to_services_apiary.txt"
1919sudo apt-get update
2020sudo apt-get install -q -y jq
2121
22+ total_files_processed=0
23+ successful_outputs=0
2224# loop through dicovery json files
2325for file in * .json; do
26+ (( total_files_processed++ ))
2427 # Use jq to extract the "name" field
2528
2629 # group_id logic: https://github.com/googleapis/google-api-java-client-services/blob/421c5d6ed56d5eb1257d3fc057d7d6b4fd2f9bb7/generator/src/googleapis/codegen/utilities/maven_utils.py#L50
@@ -30,21 +33,37 @@ for file in *.json; do
3033 default_host=$( jq -r ' .rootUrl' " $file " )
3134 owner_domain=$( jq -r ' .ownerDomain' " $file " )
3235
33- if [[ " $default_host " =~ ^https:// ]] && [ -n " $artifact_id_suffix " ] && [ -n " $owner_domain " ]; then
34- if [[ " $owner_domain " != ' google.com' ]]; then
35- echo " $owner_domain =============="
36+ # Check if jq failed to extract essential fields
37+ if [ -z " $artifact_id_suffix " ] || [ -z " $default_host " ] || [ -z " $owner_domain " ]; then
38+ echo " Error: Could not extract 'name', 'rootUrl', or 'ownerDomain' from $file . Skipping."
39+ continue
40+ fi
41+ if [[ " $owner_domain " != ' google.com' ]]; then
42+ echo " Info: '$owner_domain ' in $file is not 'google.com'. Skipping."
43+ continue
44+ fi
45+ group_id=" com.google.apis"
46+ if [[ " $default_host " == " https://www.googleapis.com/" ]]; then
47+ echo " rootUrl is https://www.googleapis.com/, use name ${service_name} as service_name"
48+ service_name=" $artifact_id_suffix "
49+ else
50+ service_name_parts=$( echo " $default_host " | cut -d' /' -f3 | cut -d' .' -f1 2> /dev/null)
51+ if [ -z " $service_name_parts " ]; then
52+ echo " Error: Could not extract 'service_name' from 'rootUrl' ('$default_host ') in $file . Skipping."
3653 continue
3754 fi
38- group_id=" com.google.apis"
39- service_name=$( echo " $default_host " | cut -d' /' -f3 | cut -d' .' -f1)
40- artifact_id=" google-api-services-${artifact_id_suffix} "
41- echo " ${group_id} ,${artifact_id} ,${service_name} " >> " $output_filename "
42- else
43- echo " $default_host : Not a valid URL or No 'name' field found in $file "
55+ service_name=" $service_name_parts "
4456 fi
57+ artifact_id=" google-api-services-${artifact_id_suffix} "
58+ echo " ${group_id} ,${artifact_id} ,${service_name} " >> " $output_filename "
59+ (( successful_outputs++ ))
4560
4661done
4762
63+ echo " Processing complete."
64+ echo " Total files processed: $total_files_processed "
65+ echo " Successful outputs recorded: $successful_outputs "
66+
4867cd ../..
4968
5069rm -rf discovery-artifact-manager/
0 commit comments