@@ -102,9 +102,18 @@ download_gapic_generator_pom_parent() {
102102 download_generator_artifact " ${gapic_generator_version} " " gapic-generator-java-pom-parent-${gapic_generator_version} .pom" " gapic-generator-java-pom-parent"
103103}
104104
105+ # This function returns the version of the grpc plugin to generate the libraries. If
106+ # DOCKER_GRPC_VERSION is set, this will be the version. Otherwise, it will be
107+ # computed from the gapic-generator-pom-parent artifact at the specified
108+ # gapic_generator_version.
105109get_grpc_version () {
106110 local gapic_generator_version=$1
107111 local grpc_version
112+ if [[ -n " ${DOCKER_GRPC_VERSION} " ]]; then
113+ >&2 echo " Using grpc version baked into the container: ${DOCKER_GRPC_VERSION} "
114+ echo " ${DOCKER_GRPC_VERSION} "
115+ return
116+ fi
108117 pushd " ${output_folder} " > /dev/null
109118 # get grpc version from gapic-generator-java-pom-parent/pom.xml
110119 download_gapic_generator_pom_parent " ${gapic_generator_version} "
@@ -113,6 +122,10 @@ get_grpc_version() {
113122 echo " ${grpc_version} "
114123}
115124
125+ # This function returns the version of protoc to generate the libraries. If
126+ # DOCKER_PROTOC_VERSION is set, this will be the version. Otherwise, it will be
127+ # computed from the gapic-generator-pom-parent artifact at the specified
128+ # gapic_generator_version.
116129get_protoc_version () {
117130 local gapic_generator_version=$1
118131 local protoc_version
@@ -129,6 +142,16 @@ get_protoc_version() {
129142 echo " ${protoc_version} "
130143}
131144
145+ # Given the versions of the gapic generator, protoc and the protoc-grpc plugin,
146+ # this function will download each one of the tools and create the environment
147+ # variables "protoc_path" and "grpc_path" which are expected upstream. Note that
148+ # if the specified versions of protoc and grpc match DOCKER_PROTOC_VERSION and
149+ # DOCKER_GRPC_VERSION respectively, this function will instead set "protoc_path"
150+ # and "grpc_path" to DOCKER_PROTOC_PATH and DOCKER_GRPC_PATH respectively (no
151+ # download), since the docker image will have downloaded these tools beforehand.
152+ # For the case of gapic-generator-java, no env var will be exported for the
153+ # upstream flow, but instead it will be assigned a default filename that will be
154+ # referenced by the file `library_generation/gapic-generator-java-wrapper`.
132155download_tools () {
133156 local gapic_generator_version=$1
134157 local protoc_version=$2
@@ -147,7 +170,15 @@ download_tools() {
147170 export protoc_path=$( download_protoc " ${protoc_version} " " ${os_architecture} " )
148171 fi
149172
150- download_grpc_plugin " ${grpc_version} " " ${os_architecture} "
173+ # similar case with grpc
174+ if [[ " ${DOCKER_GRPC_VERSION} " == " ${grpc_version} " ]]; then
175+ # if the specified grpc_version matches the one baked in the docker
176+ # container, we just point grpc_path to its location.
177+ export grpc_path=" ${DOCKER_GRPC_LOCATION} "
178+ else
179+ export grpc_path=$( download_grpc_plugin " ${grpc_version} " " ${os_architecture} " )
180+ fi
181+
151182 popd
152183}
153184
@@ -198,13 +229,15 @@ download_protoc() {
198229download_grpc_plugin () {
199230 local grpc_version=$1
200231 local os_architecture=$2
201- if [ ! -f " protoc-gen-grpc-java-${grpc_version} -${os_architecture} .exe" ]; then
232+ grpc_filename=" protoc-gen-grpc-java-${grpc_version} -${os_architecture} .exe"
233+ if [ ! -f " ${grpc_filename} " ]; then
202234 # download protoc-gen-grpc-java plugin from Google maven central mirror.
203235 download_from \
204- " https://maven-central.storage-download.googleapis.com/maven2/io/grpc/protoc-gen-grpc-java/${grpc_version} /protoc-gen-grpc-java- ${grpc_version} - ${os_architecture} .exe " \
205- " protoc-gen-grpc-java- ${grpc_version} - ${os_architecture} .exe "
206- chmod +x " protoc-gen-grpc-java- ${grpc_version} - ${os_architecture} .exe "
236+ " https://maven-central.storage-download.googleapis.com/maven2/io/grpc/protoc-gen-grpc-java/${grpc_version} /${grpc_filename} " \
237+ " ${grpc_filename} "
238+ chmod +x " ${grpc_filename} "
207239 fi
240+ echo " $( pwd) /${grpc_filename} "
208241}
209242
210243download_from () {
@@ -282,7 +315,7 @@ get_proto_path_from_preprocessed_sources() {
282315 pushd " ${sources} " > /dev/null
283316 local proto_library=$( find . -maxdepth 1 -type d -name ' proto-*' | sed ' s/\.\///' )
284317 local found_libraries=$( echo " ${proto_library} " | wc -l)
285- if [ -z ${proto_library} ]; then
318+ if [[ -z ${proto_library} ] ]; then
286319 echo " no proto libraries found in the supplied sources path"
287320 exit 1
288321 elif [ ${found_libraries} -gt 1 ]; then
0 commit comments