33set -eo pipefail
44
55# parse input parameters
6- while [[ $# -gt 0 ]]
7- do
6+ while [[ $# -gt 0 ]]; do
87key=" $1 "
98case $key in
10- -p|--proto_path)
9+ -p|--proto_path)
1110 proto_path=" $2 "
1211 shift
1312 ;;
14- -d|--destination_path)
13+ -d|--destination_path)
1514 destination_path=" $2 "
1615 shift
1716 ;;
18- --gapic_generator_version)
17+ --gapic_generator_version)
1918 gapic_generator_version=" $2 "
2019 # export this variable so that it can be used in gapic-generator-java-wrapper.sh
2120 export gapic_generator_version
2221 shift
2322 ;;
24- --protobuf_version)
23+ --protobuf_version)
2524 protobuf_version=" $2 "
2625 shift
2726 ;;
28- --grpc_version)
27+ --grpc_version)
2928 grpc_version=" $2 "
3029 shift
3130 ;;
32- --transport)
31+ --transport)
3332 transport=" $2 "
3433 shift
3534 ;;
36- --rest_numeric_enums)
35+ --rest_numeric_enums)
3736 rest_numeric_enums=" $2 "
3837 shift
3938 ;;
40- --include_samples)
39+ --include_samples)
4140 include_samples=" $2 "
4241 shift
4342 ;;
44- --os_architecture)
43+ --os_architecture)
4544 os_architecture=" $2 "
4645 shift
4746 ;;
48- * )
47+ * )
4948 echo " Invalid option: [$1 ]"
5049 exit 1
5150 ;;
5554
5655script_dir=$( dirname " $( readlink -f " $0 " ) " )
5756# source utility functions
58- source " $script_dir " /utilities.sh
57+ source " ${ script_dir} " /utilities.sh
5958
60- if [ -z " $protobuf_version " ]; then
61- protobuf_version=$( get_protobuf_version " $gapic_generator_version " )
59+ if [ -z " ${ protobuf_version} " ]; then
60+ protobuf_version=$( get_protobuf_version " ${ gapic_generator_version} " )
6261fi
6362
64- if [ -z " $grpc_version " ]; then
65- grpc_version=$( get_grpc_version " $gapic_generator_version " )
63+ if [ -z " ${ grpc_version} " ]; then
64+ grpc_version=$( get_grpc_version " ${ gapic_generator_version} " )
6665fi
6766
68- if [ -z " $transport " ]; then
67+ if [ -z " ${ transport} " ]; then
6968 transport=" grpc"
7069fi
7170
72- if [ -z " $rest_numeric_enums " ]; then
71+ if [ -z " ${ rest_numeric_enums} " ]; then
7372 rest_numeric_enums=" true"
7473fi
7574
76- if [ -z " $include_samples " ]; then
75+ if [ -z " ${ include_samples} " ]; then
7776 include_samples=" true"
7877fi
7978
80- if [ -z " $os_architecture " ]; then
79+ if [ -z " ${ os_architecture} " ]; then
8180 os_architecture=" linux-x86_64"
8281fi
8382
84- mkdir -p " $destination_path "
83+ mkdir -p " ${ destination_path} "
8584# #################### Section 0 #####################
8685# prepare tooling
8786# ####################################################
8887# the order of services entries in gapic_metadata.json is relevant to the
8988# order of proto file, sort the proto files with respect to their name to
9089# get a fixed order.
91- proto_files=$( find " $proto_path " -type f -name " *.proto" | sort)
92- folder_name=$( extract_folder_name " $destination_path " )
90+ proto_files=$( find " ${ proto_path} " -type f -name " *.proto" | sort)
91+ folder_name=$( extract_folder_name " ${ destination_path} " )
9392# download gapic-generator-java, protobuf and grpc plugin.
94- download_tools " $gapic_generator_version " " $protobuf_version " " $grpc_version " " $os_architecture "
93+ download_tools " ${ gapic_generator_version} " " ${ protobuf_version} " " ${ grpc_version} " " ${ os_architecture} "
9594# #################### Section 1 #####################
9695# generate grpc-*/
9796# ####################################################
98- " $protoc_path " /protoc " --plugin=protoc-gen-rpc-plugin=protoc-gen-grpc-java-$grpc_version -${os_architecture} .exe" \
99- " --rpc-plugin_out=:$destination_path /java_grpc.jar" \
100- $proto_files
97+ " ${ protoc_path} " /protoc " --plugin=protoc-gen-rpc-plugin=protoc-gen-grpc-java-${ grpc_version} -${os_architecture} .exe" \
98+ " --rpc-plugin_out=:${ destination_path} /java_grpc.jar" \
99+ ${ proto_files} # Do not quote because this variable should not be treated as one long string.
101100# unzip java_grpc.jar to grpc-*/src/main/java
102101unzip_src_files " grpc"
103102# remove empty files in grpc-*/src/main/java
@@ -108,23 +107,23 @@ remove_grpc_version
108107# # generate gapic-*/, part of proto-*/, samples/
109108# #####################################################
110109" $protoc_path " /protoc --experimental_allow_proto3_optional \
111- " --plugin=protoc-gen-java_gapic=$script_dir /gapic-generator-java-wrapper" \
112- " --java_gapic_out=metadata:$destination_path /java_gapic_srcjar_raw.srcjar.zip" \
110+ " --plugin=protoc-gen-java_gapic=${ script_dir} /gapic-generator-java-wrapper" \
111+ " --java_gapic_out=metadata:${ destination_path} /java_gapic_srcjar_raw.srcjar.zip" \
113112" --java_gapic_opt=$( get_gapic_opts) " \
114113${proto_files} $( search_additional_protos)
115114
116- unzip -o -q " $destination_path /java_gapic_srcjar_raw.srcjar.zip" -d " $destination_path "
115+ unzip -o -q " ${ destination_path} /java_gapic_srcjar_raw.srcjar.zip" -d " ${ destination_path} "
117116# Sync'\''d to the output file name in Writer.java.
118- unzip -o -q " $destination_path /temp-codegen.srcjar" -d " $destination_path /java_gapic_srcjar"
117+ unzip -o -q " ${ destination_path} /temp-codegen.srcjar" -d " ${ destination_path} /java_gapic_srcjar"
119118# Resource name source files.
120- proto_dir=$destination_path /java_gapic_srcjar/proto/src/main/java
121- if [ ! -d " $proto_dir " ]; then
119+ proto_dir=${ destination_path} /java_gapic_srcjar/proto/src/main/java
120+ if [ ! -d " ${ proto_dir} " ]; then
122121 # Some APIs don'\''t have resource name helpers, like BigQuery v2.
123122 # Create an empty file so we can finish building. Gating the resource name rule definition
124123 # on file existences go against Bazel'\''s design patterns, so we'\''ll simply delete all empty
125124 # files during the final packaging process (see java_gapic_pkg.bzl)
126- mkdir -p " $proto_dir "
127- touch " $proto_dir " /PlaceholderFile.java
125+ mkdir -p " ${ proto_dir} "
126+ touch " ${ proto_dir} " /PlaceholderFile.java
128127fi
129128
130129# move java_gapic_srcjar/src/main to gapic-*/src.
@@ -133,14 +132,14 @@ mv_src_files "gapic" "main"
133132remove_empty_files " gapic"
134133# move java_gapic_srcjar/src/test to gapic-*/src
135134mv_src_files " gapic" " test"
136- if [ " $include_samples " == " true" ]; then
135+ if [ " ${ include_samples} " == " true" ]; then
137136 # move java_gapic_srcjar/samples/snippets to samples/snippets
138137 mv_src_files " samples" " main"
139138fi
140139# #################### Section 3 #####################
141140# generate proto-*/
142141# ####################################################
143- " $protoc_path " /protoc " --java_out=$destination_path /java_proto.jar" $proto_files
142+ " $protoc_path " /protoc " --java_out=${ destination_path} /java_proto.jar" ${ proto_files}
144143# move java_gapic_srcjar/proto/src/main/java (generated resource name helper class)
145144# to proto-*/src/main
146145mv_src_files " proto" " main"
@@ -149,12 +148,12 @@ unzip_src_files "proto"
149148# remove empty files in proto-*/src/main/java
150149remove_empty_files " proto"
151150# copy proto files to proto-*/src/main/proto
152- for proto_src in $proto_files ; do
153- mkdir -p " $destination_path /proto-$folder_name /src/main/proto"
154- rsync -R " $proto_src " " $destination_path /proto-$folder_name /src/main/proto"
151+ for proto_src in ${ proto_files} ; do
152+ mkdir -p " ${ destination_path} /proto-${ folder_name} /src/main/proto"
153+ rsync -R " ${ proto_src} " " ${ destination_path} /proto-${ folder_name} /src/main/proto"
155154done
156155# #################### Section 4 #####################
157156# rm tar files
158157# ####################################################
159- cd " $destination_path "
158+ cd " ${ destination_path} "
160159rm -rf java_gapic_srcjar java_gapic_srcjar_raw.srcjar.zip java_grpc.jar java_proto.jar temp-codegen.srcjar
0 commit comments