From 6d673f39dc10b072ba6012fecc17deb22136650e Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 22 Apr 2024 13:04:17 -0700 Subject: [PATCH 01/25] fix: replace `cfg = "host"` with `cfg = "exec"` (#2637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a no-op cleanup, 'host' is being renamed to 'exec', see: https://togithub.com/bazelbuild/bazel/issues/17032 Fixes #2514 β˜•οΈ --- gax-java/gax_java.bzl | 2 +- rules_java_gapic/java_gapic.bzl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gax-java/gax_java.bzl b/gax-java/gax_java.bzl index 83e11815c0..8276ab68bd 100644 --- a/gax-java/gax_java.bzl +++ b/gax-java/gax_java.bzl @@ -77,7 +77,7 @@ google_java_format_verification = rule( "srcs": attr.label_list(allow_files = True), "formatter": attr.label( executable = True, - cfg = "host", + cfg = "exec", ), }, outputs = {"output_file": "%{name}.txt"}, diff --git a/rules_java_gapic/java_gapic.bzl b/rules_java_gapic/java_gapic.bzl index f484c474d3..fdab81e7af 100644 --- a/rules_java_gapic/java_gapic.bzl +++ b/rules_java_gapic/java_gapic.bzl @@ -94,7 +94,7 @@ _java_gapic_postprocess_srcjar = rule( "formatter": attr.label( default = Label("//:google_java_format_binary"), executable = True, - cfg = "host", + cfg = "exec", ), }, outputs = { @@ -152,7 +152,7 @@ _java_gapic_samples_srcjar = rule( "formatter": attr.label( default = Label("//:google_java_format_binary"), executable = True, - cfg = "host", + cfg = "exec", ), }, outputs = { From 0a71cbf7092279c50f9f5114b79d8c674cdef997 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Mon, 22 Apr 2024 16:08:51 -0400 Subject: [PATCH 02/25] deps: update gapic-showcase to v0.33.0 (#2653) update gapic-showcase so that we can pickup changes in https://github.com/googleapis/gapic-showcase/pull/1484 Steps: 1) Updated the gapic-showcase version in `gapic-showcase/pom.xml` to 0.33.0 2) Ran `mvn compile -P update` --- WORKSPACE | 11 - showcase/gapic-showcase/pom.xml | 2 +- .../google/showcase/v1beta1/EchoClient.java | 5 + .../google/showcase/v1beta1/package-info.java | 1 + .../showcase/v1beta1/stub/GrpcEchoStub.java | 3 + .../v1beta1/stub/HttpJsonEchoStub.java | 3 + .../showcase/v1beta1/EchoOuterClass.java | 204 +++++------ .../google/showcase/v1beta1/EchoRequest.java | 210 ++++++++++- .../v1beta1/EchoRequestOrBuilder.java | 33 +- .../google/showcase/v1beta1/EchoResponse.java | 328 ++++++++++++++++++ .../v1beta1/EchoResponseOrBuilder.java | 40 +++ .../schema/google/showcase/v1beta1/echo.proto | 15 +- 12 files changed, 733 insertions(+), 122 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index b0704997f8..4612984c09 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -106,17 +106,6 @@ http_archive( urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/%s.zip" % _disco_to_proto3_converter_commit], ) -# Showcase -_showcase_version = "0.28.2" - -http_archive( - name = "com_google_gapic_showcase", - strip_prefix = "gapic-showcase-%s" % _showcase_version, - urls = [ - "https://github.com/googleapis/gapic-showcase/archive/refs/tags/v%s.zip" % _showcase_version, - ], -) - http_archive( name = "rules_pkg", sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2", diff --git a/showcase/gapic-showcase/pom.xml b/showcase/gapic-showcase/pom.xml index d049d1723d..5bdc31a945 100644 --- a/showcase/gapic-showcase/pom.xml +++ b/showcase/gapic-showcase/pom.xml @@ -19,7 +19,7 @@ - 0.30.0 + 0.33.0 diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java index 24749d8a0b..5cd400c2aa 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/EchoClient.java @@ -75,6 +75,7 @@ * .setHeader("header-1221270899") * .setOtherHeader("otherHeader-2026585667") * .setRequestId("requestId693933066") + * .setOtherRequestId("otherRequestId1248995034") * .build(); * EchoResponse response = echoClient.echo(request); * } @@ -440,6 +441,7 @@ public final OperationsClient getHttpJsonOperationsClient() { * .setHeader("header-1221270899") * .setOtherHeader("otherHeader-2026585667") * .setRequestId("requestId693933066") + * .setOtherRequestId("otherRequestId1248995034") * .build(); * EchoResponse response = echoClient.echo(request); * } @@ -471,6 +473,7 @@ public final EchoResponse echo(EchoRequest request) { * .setHeader("header-1221270899") * .setOtherHeader("otherHeader-2026585667") * .setRequestId("requestId693933066") + * .setOtherRequestId("otherRequestId1248995034") * .build(); * ApiFuture future = echoClient.echoCallable().futureCall(request); * // Do something. @@ -620,6 +623,7 @@ public final ServerStreamingCallable expandCallable * .setHeader("header-1221270899") * .setOtherHeader("otherHeader-2026585667") * .setRequestId("requestId693933066") + * .setOtherRequestId("otherRequestId1248995034") * .build(); * requestObserver.onNext(request); * } @@ -650,6 +654,7 @@ public final ClientStreamingCallable collectCallable( * .setHeader("header-1221270899") * .setOtherHeader("otherHeader-2026585667") * .setRequestId("requestId693933066") + * .setOtherRequestId("otherRequestId1248995034") * .build(); * bidiStream.send(request); * for (EchoResponse response : bidiStream) { diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java index ceb4779c4c..8b4ef84373 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java @@ -76,6 +76,7 @@ * .setHeader("header-1221270899") * .setOtherHeader("otherHeader-2026585667") * .setRequestId("requestId693933066") + * .setOtherRequestId("otherRequestId1248995034") * .build(); * EchoResponse response = echoClient.echo(request); * } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java index e7891eaa8b..0b7ac11084 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcEchoStub.java @@ -313,6 +313,9 @@ protected GrpcEchoStub( if (Strings.isNullOrEmpty(request.getRequestId())) { requestBuilder.setRequestId(UUID.randomUUID().toString()); } + if (Strings.isNullOrEmpty(request.getOtherRequestId())) { + requestBuilder.setOtherRequestId(UUID.randomUUID().toString()); + } return requestBuilder.build(); }) .build(); diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java index b41e0e6073..b2ffcfaf19 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonEchoStub.java @@ -668,6 +668,9 @@ protected HttpJsonEchoStub( if (Strings.isNullOrEmpty(request.getRequestId())) { requestBuilder.setRequestId(UUID.randomUUID().toString()); } + if (Strings.isNullOrEmpty(request.getOtherRequestId())) { + requestBuilder.setOtherRequestId(UUID.randomUUID().toString()); + } return requestBuilder.build(); }) .build(); diff --git a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoOuterClass.java b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoOuterClass.java index f6f2874138..d215dcb29a 100644 --- a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoOuterClass.java +++ b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoOuterClass.java @@ -133,107 +133,110 @@ public static void registerAllExtensions( "ns.proto\032\031google/protobuf/any.proto\032\036goo" + "gle/protobuf/duration.proto\032\037google/prot" + "obuf/timestamp.proto\032\027google/rpc/status." + - "proto\"\312\001\n\013EchoRequest\022\021\n\007content\030\001 \001(\tH\000" + + "proto\"\210\002\n\013EchoRequest\022\021\n\007content\030\001 \001(\tH\000" + "\022#\n\005error\030\002 \001(\0132\022.google.rpc.StatusH\000\0223\n" + "\010severity\030\003 \001(\0162!.google.showcase.v1beta" + "1.Severity\022\016\n\006header\030\004 \001(\t\022\024\n\014other_head" + - "er\030\005 \001(\t\022\034\n\nrequest_id\030\007 \001(\tB\010\342\214\317\327\010\002\010\001B\n" + - "\n\010response\"T\n\014EchoResponse\022\017\n\007content\030\001 " + - "\001(\t\0223\n\010severity\030\002 \001(\0162!.google.showcase." + - "v1beta1.Severity\"P\n\027EchoErrorDetailsRequ" + - "est\022\032\n\022single_detail_text\030\001 \001(\t\022\031\n\021multi" + - "_detail_text\030\002 \003(\t\"\362\002\n\030EchoErrorDetailsR" + - "esponse\022U\n\rsingle_detail\030\001 \001(\0132>.google." + - "showcase.v1beta1.EchoErrorDetailsRespons" + - "e.SingleDetail\022[\n\020multiple_details\030\002 \001(\013" + - "2A.google.showcase.v1beta1.EchoErrorDeta" + - "ilsResponse.MultipleDetails\032M\n\014SingleDet" + - "ail\022=\n\005error\030\001 \001(\0132..google.showcase.v1b" + - "eta1.ErrorWithSingleDetail\032S\n\017MultipleDe" + - "tails\022@\n\005error\030\001 \001(\01321.google.showcase.v" + - "1beta1.ErrorWithMultipleDetails\">\n\025Error" + - "WithSingleDetail\022%\n\007details\030\001 \001(\0132\024.goog" + - "le.protobuf.Any\"A\n\030ErrorWithMultipleDeta" + - "ils\022%\n\007details\030\001 \003(\0132\024.google.protobuf.A" + - "ny\"x\n\rExpandRequest\022\017\n\007content\030\001 \001(\t\022!\n\005" + - "error\030\002 \001(\0132\022.google.rpc.Status\0223\n\020strea" + - "m_wait_time\030\003 \001(\0132\031.google.protobuf.Dura" + - "tion\"Q\n\022PagedExpandRequest\022\024\n\007content\030\001 " + - "\001(\tB\003\340A\002\022\021\n\tpage_size\030\002 \001(\005\022\022\n\npage_toke" + - "n\030\003 \001(\t\"Y\n\030PagedExpandLegacyRequest\022\024\n\007c" + - "ontent\030\001 \001(\tB\003\340A\002\022\023\n\013max_results\030\002 \001(\005\022\022" + - "\n\npage_token\030\003 \001(\t\"h\n\023PagedExpandRespons" + - "e\0228\n\tresponses\030\001 \003(\0132%.google.showcase.v" + - "1beta1.EchoResponse\022\027\n\017next_page_token\030\002" + - " \001(\t\"(\n\027PagedExpandResponseList\022\r\n\005words" + - "\030\001 \003(\t\"\203\002\n\037PagedExpandLegacyMappedRespon" + - "se\022`\n\014alphabetized\030\001 \003(\0132J.google.showca" + - "se.v1beta1.PagedExpandLegacyMappedRespon" + - "se.AlphabetizedEntry\022\027\n\017next_page_token\030" + - "\002 \001(\t\032e\n\021AlphabetizedEntry\022\013\n\003key\030\001 \001(\t\022" + - "?\n\005value\030\002 \001(\01320.google.showcase.v1beta1" + - ".PagedExpandResponseList:\0028\001\"\331\001\n\013WaitReq" + - "uest\022.\n\010end_time\030\001 \001(\0132\032.google.protobuf" + - ".TimestampH\000\022(\n\003ttl\030\004 \001(\0132\031.google.proto" + - "buf.DurationH\000\022#\n\005error\030\002 \001(\0132\022.google.r" + - "pc.StatusH\001\0228\n\007success\030\003 \001(\0132%.google.sh" + - "owcase.v1beta1.WaitResponseH\001B\005\n\003endB\n\n\010" + - "response\"\037\n\014WaitResponse\022\017\n\007content\030\001 \001(" + - "\t\"<\n\014WaitMetadata\022,\n\010end_time\030\001 \001(\0132\032.go" + - "ogle.protobuf.Timestamp\"\255\001\n\014BlockRequest" + - "\0221\n\016response_delay\030\001 \001(\0132\031.google.protob" + - "uf.Duration\022#\n\005error\030\002 \001(\0132\022.google.rpc." + - "StatusH\000\0229\n\007success\030\003 \001(\0132&.google.showc" + - "ase.v1beta1.BlockResponseH\000B\n\n\010response\"" + - " \n\rBlockResponse\022\017\n\007content\030\001 \001(\t*D\n\010Sev" + - "erity\022\017\n\013UNNECESSARY\020\000\022\r\n\tNECESSARY\020\001\022\n\n" + - "\006URGENT\020\002\022\014\n\010CRITICAL\020\0032\241\r\n\004Echo\022\224\003\n\004Ech" + - "o\022$.google.showcase.v1beta1.EchoRequest\032" + - "%.google.showcase.v1beta1.EchoResponse\"\276" + - "\002\202\323\344\223\002\027\"\022/v1beta1/echo:echo:\001*\212\323\344\223\002\232\002\022\010\n" + - "\006header\022\031\n\006header\022\017{routing_id=**}\022+\n\006he" + - "ader\022!{table_name=regions/*/zones/*/**}\022" + - "\"\n\006header\022\030{super_id=projects/*}/**\0220\n\006h" + - "eader\022&{table_name=projects/*/instances/" + - "*/**}\0221\n\006header\022\'projects/*/{instance_id" + - "=instances/*}/**\022\030\n\014other_header\022\010{baz=*" + - "*}\022#\n\014other_header\022\023{qux=projects/*}/**\022" + - "\237\001\n\020EchoErrorDetails\0220.google.showcase.v" + - "1beta1.EchoErrorDetailsRequest\0321.google." + - "showcase.v1beta1.EchoErrorDetailsRespons" + - "e\"&\202\323\344\223\002 \"\033/v1beta1/echo:error-details:\001" + - "*\022\212\001\n\006Expand\022&.google.showcase.v1beta1.E" + - "xpandRequest\032%.google.showcase.v1beta1.E" + - "choResponse\"/\332A\rcontent,error\202\323\344\223\002\031\"\024/v1" + - "beta1/echo:expand:\001*0\001\022z\n\007Collect\022$.goog" + - "le.showcase.v1beta1.EchoRequest\032%.google" + - ".showcase.v1beta1.EchoResponse\" \202\323\344\223\002\032\"\025" + - "/v1beta1/echo:collect:\001*(\001\022W\n\004Chat\022$.goo" + - "gle.showcase.v1beta1.EchoRequest\032%.googl" + - "e.showcase.v1beta1.EchoResponse(\0010\001\022\216\001\n\013" + - "PagedExpand\022+.google.showcase.v1beta1.Pa" + - "gedExpandRequest\032,.google.showcase.v1bet" + - "a1.PagedExpandResponse\"$\202\323\344\223\002\036\"\031/v1beta1" + - "/echo:pagedExpand:\001*\022\240\001\n\021PagedExpandLega" + - "cy\0221.google.showcase.v1beta1.PagedExpand" + - "LegacyRequest\032,.google.showcase.v1beta1." + - "PagedExpandResponse\"*\202\323\344\223\002$\"\037/v1beta1/ec" + - "ho:pagedExpandLegacy:\001*\022\262\001\n\027PagedExpandL" + - "egacyMapped\022+.google.showcase.v1beta1.Pa" + - "gedExpandRequest\0328.google.showcase.v1bet" + - "a1.PagedExpandLegacyMappedResponse\"0\202\323\344\223" + - "\002*\"%/v1beta1/echo:pagedExpandLegacyMappe" + - "d:\001*\022\211\001\n\004Wait\022$.google.showcase.v1beta1." + - "WaitRequest\032\035.google.longrunning.Operati" + - "on\"<\312A\034\n\014WaitResponse\022\014WaitMetadata\202\323\344\223\002" + - "\027\"\022/v1beta1/echo:wait:\001*\022v\n\005Block\022%.goog" + - "le.showcase.v1beta1.BlockRequest\032&.googl" + - "e.showcase.v1beta1.BlockResponse\"\036\202\323\344\223\002\030" + - "\"\023/v1beta1/echo:block:\001*\032\021\312A\016localhost:7" + - "469Bq\n\033com.google.showcase.v1beta1P\001Z4gi" + - "thub.com/googleapis/gapic-showcase/serve" + - "r/genproto\352\002\031Google::Showcase::V1beta1b\006" + - "proto3" + "er\030\005 \001(\t\022\034\n\nrequest_id\030\007 \001(\tB\010\342\214\317\327\010\002\010\001\022\'" + + "\n\020other_request_id\030\010 \001(\tB\010\342\214\317\327\010\002\010\001H\001\210\001\001B" + + "\n\n\010responseB\023\n\021_other_request_id\"\202\001\n\014Ech" + + "oResponse\022\017\n\007content\030\001 \001(\t\0223\n\010severity\030\002" + + " \001(\0162!.google.showcase.v1beta1.Severity\022" + + "\022\n\nrequest_id\030\003 \001(\t\022\030\n\020other_request_id\030" + + "\004 \001(\t\"P\n\027EchoErrorDetailsRequest\022\032\n\022sing" + + "le_detail_text\030\001 \001(\t\022\031\n\021multi_detail_tex" + + "t\030\002 \003(\t\"\362\002\n\030EchoErrorDetailsResponse\022U\n\r" + + "single_detail\030\001 \001(\0132>.google.showcase.v1" + + "beta1.EchoErrorDetailsResponse.SingleDet" + + "ail\022[\n\020multiple_details\030\002 \001(\0132A.google.s" + + "howcase.v1beta1.EchoErrorDetailsResponse" + + ".MultipleDetails\032M\n\014SingleDetail\022=\n\005erro" + + "r\030\001 \001(\0132..google.showcase.v1beta1.ErrorW" + + "ithSingleDetail\032S\n\017MultipleDetails\022@\n\005er" + + "ror\030\001 \001(\01321.google.showcase.v1beta1.Erro" + + "rWithMultipleDetails\">\n\025ErrorWithSingleD" + + "etail\022%\n\007details\030\001 \001(\0132\024.google.protobuf" + + ".Any\"A\n\030ErrorWithMultipleDetails\022%\n\007deta" + + "ils\030\001 \003(\0132\024.google.protobuf.Any\"x\n\rExpan" + + "dRequest\022\017\n\007content\030\001 \001(\t\022!\n\005error\030\002 \001(\013" + + "2\022.google.rpc.Status\0223\n\020stream_wait_time" + + "\030\003 \001(\0132\031.google.protobuf.Duration\"Q\n\022Pag" + + "edExpandRequest\022\024\n\007content\030\001 \001(\tB\003\340A\002\022\021\n" + + "\tpage_size\030\002 \001(\005\022\022\n\npage_token\030\003 \001(\t\"Y\n\030" + + "PagedExpandLegacyRequest\022\024\n\007content\030\001 \001(" + + "\tB\003\340A\002\022\023\n\013max_results\030\002 \001(\005\022\022\n\npage_toke" + + "n\030\003 \001(\t\"h\n\023PagedExpandResponse\0228\n\trespon" + + "ses\030\001 \003(\0132%.google.showcase.v1beta1.Echo" + + "Response\022\027\n\017next_page_token\030\002 \001(\t\"(\n\027Pag" + + "edExpandResponseList\022\r\n\005words\030\001 \003(\t\"\203\002\n\037" + + "PagedExpandLegacyMappedResponse\022`\n\014alpha" + + "betized\030\001 \003(\0132J.google.showcase.v1beta1." + + "PagedExpandLegacyMappedResponse.Alphabet" + + "izedEntry\022\027\n\017next_page_token\030\002 \001(\t\032e\n\021Al" + + "phabetizedEntry\022\013\n\003key\030\001 \001(\t\022?\n\005value\030\002 " + + "\001(\01320.google.showcase.v1beta1.PagedExpan" + + "dResponseList:\0028\001\"\331\001\n\013WaitRequest\022.\n\010end" + + "_time\030\001 \001(\0132\032.google.protobuf.TimestampH" + + "\000\022(\n\003ttl\030\004 \001(\0132\031.google.protobuf.Duratio" + + "nH\000\022#\n\005error\030\002 \001(\0132\022.google.rpc.StatusH\001" + + "\0228\n\007success\030\003 \001(\0132%.google.showcase.v1be" + + "ta1.WaitResponseH\001B\005\n\003endB\n\n\010response\"\037\n" + + "\014WaitResponse\022\017\n\007content\030\001 \001(\t\"<\n\014WaitMe" + + "tadata\022,\n\010end_time\030\001 \001(\0132\032.google.protob" + + "uf.Timestamp\"\255\001\n\014BlockRequest\0221\n\016respons" + + "e_delay\030\001 \001(\0132\031.google.protobuf.Duration" + + "\022#\n\005error\030\002 \001(\0132\022.google.rpc.StatusH\000\0229\n" + + "\007success\030\003 \001(\0132&.google.showcase.v1beta1" + + ".BlockResponseH\000B\n\n\010response\" \n\rBlockRes" + + "ponse\022\017\n\007content\030\001 \001(\t*D\n\010Severity\022\017\n\013UN" + + "NECESSARY\020\000\022\r\n\tNECESSARY\020\001\022\n\n\006URGENT\020\002\022\014" + + "\n\010CRITICAL\020\0032\262\r\n\004Echo\022\224\003\n\004Echo\022$.google." + + "showcase.v1beta1.EchoRequest\032%.google.sh" + + "owcase.v1beta1.EchoResponse\"\276\002\202\323\344\223\002\027\"\022/v" + + "1beta1/echo:echo:\001*\212\323\344\223\002\232\002\022\010\n\006header\022\031\n\006" + + "header\022\017{routing_id=**}\022+\n\006header\022!{tabl" + + "e_name=regions/*/zones/*/**}\022\"\n\006header\022\030" + + "{super_id=projects/*}/**\0220\n\006header\022&{tab" + + "le_name=projects/*/instances/*/**}\0221\n\006he" + + "ader\022\'projects/*/{instance_id=instances/" + + "*}/**\022\030\n\014other_header\022\010{baz=**}\022#\n\014other" + + "_header\022\023{qux=projects/*}/**\022\237\001\n\020EchoErr" + + "orDetails\0220.google.showcase.v1beta1.Echo" + + "ErrorDetailsRequest\0321.google.showcase.v1" + + "beta1.EchoErrorDetailsResponse\"&\202\323\344\223\002 \"\033" + + "/v1beta1/echo:error-details:\001*\022\212\001\n\006Expan" + + "d\022&.google.showcase.v1beta1.ExpandReques" + + "t\032%.google.showcase.v1beta1.EchoResponse" + + "\"/\332A\rcontent,error\202\323\344\223\002\031\"\024/v1beta1/echo:" + + "expand:\001*0\001\022z\n\007Collect\022$.google.showcase" + + ".v1beta1.EchoRequest\032%.google.showcase.v" + + "1beta1.EchoResponse\" \202\323\344\223\002\032\"\025/v1beta1/ec" + + "ho:collect:\001*(\001\022W\n\004Chat\022$.google.showcas" + + "e.v1beta1.EchoRequest\032%.google.showcase." + + "v1beta1.EchoResponse(\0010\001\022\216\001\n\013PagedExpand" + + "\022+.google.showcase.v1beta1.PagedExpandRe" + + "quest\032,.google.showcase.v1beta1.PagedExp" + + "andResponse\"$\202\323\344\223\002\036\"\031/v1beta1/echo:paged" + + "Expand:\001*\022\240\001\n\021PagedExpandLegacy\0221.google" + + ".showcase.v1beta1.PagedExpandLegacyReque" + + "st\032,.google.showcase.v1beta1.PagedExpand" + + "Response\"*\202\323\344\223\002$\"\037/v1beta1/echo:pagedExp" + + "andLegacy:\001*\022\262\001\n\027PagedExpandLegacyMapped" + + "\022+.google.showcase.v1beta1.PagedExpandRe" + + "quest\0328.google.showcase.v1beta1.PagedExp" + + "andLegacyMappedResponse\"0\202\323\344\223\002*\"%/v1beta" + + "1/echo:pagedExpandLegacyMapped:\001*\022\211\001\n\004Wa" + + "it\022$.google.showcase.v1beta1.WaitRequest" + + "\032\035.google.longrunning.Operation\"<\312A\034\n\014Wa" + + "itResponse\022\014WaitMetadata\202\323\344\223\002\027\"\022/v1beta1" + + "/echo:wait:\001*\022v\n\005Block\022%.google.showcase" + + ".v1beta1.BlockRequest\032&.google.showcase." + + "v1beta1.BlockResponse\"\036\202\323\344\223\002\030\"\023/v1beta1/" + + "echo:block:\001*\032\"\312A\016localhost:7469\212\324\333\322\017\013v1" + + "_20240408Bq\n\033com.google.showcase.v1beta1" + + "P\001Z4github.com/googleapis/gapic-showcase" + + "/server/genproto\352\002\031Google::Showcase::V1b" + + "eta1b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, @@ -254,13 +257,13 @@ public static void registerAllExtensions( internal_static_google_showcase_v1beta1_EchoRequest_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_showcase_v1beta1_EchoRequest_descriptor, - new java.lang.String[] { "Content", "Error", "Severity", "Header", "OtherHeader", "RequestId", "Response", }); + new java.lang.String[] { "Content", "Error", "Severity", "Header", "OtherHeader", "RequestId", "OtherRequestId", "Response", }); internal_static_google_showcase_v1beta1_EchoResponse_descriptor = getDescriptor().getMessageTypes().get(1); internal_static_google_showcase_v1beta1_EchoResponse_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_google_showcase_v1beta1_EchoResponse_descriptor, - new java.lang.String[] { "Content", "Severity", }); + new java.lang.String[] { "Content", "Severity", "RequestId", "OtherRequestId", }); internal_static_google_showcase_v1beta1_EchoErrorDetailsRequest_descriptor = getDescriptor().getMessageTypes().get(2); internal_static_google_showcase_v1beta1_EchoErrorDetailsRequest_fieldAccessorTable = new @@ -371,6 +374,7 @@ public static void registerAllExtensions( new java.lang.String[] { "Content", }); com.google.protobuf.ExtensionRegistry registry = com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(com.google.api.ClientProto.apiVersion); registry.add(com.google.api.ClientProto.defaultHost); registry.add(com.google.api.FieldBehaviorProto.fieldBehavior); registry.add(com.google.api.FieldInfoProto.fieldInfo); diff --git a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequest.java b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequest.java index e5965aa907..76efd48438 100644 --- a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequest.java +++ b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequest.java @@ -28,6 +28,7 @@ private EchoRequest() { header_ = ""; otherHeader_ = ""; requestId_ = ""; + otherRequestId_ = ""; } @java.lang.Override @@ -50,6 +51,7 @@ protected java.lang.Object newInstance( com.google.showcase.v1beta1.EchoRequest.class, com.google.showcase.v1beta1.EchoRequest.Builder.class); } + private int bitField0_; private int responseCase_ = 0; @SuppressWarnings("serial") private java.lang.Object response_; @@ -324,7 +326,7 @@ public java.lang.String getOtherHeader() { private volatile java.lang.Object requestId_ = ""; /** *
-   * Based on go/client-populate-request-id-design; subject to change
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
    * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -345,7 +347,7 @@ public java.lang.String getRequestId() { } /** *
-   * Based on go/client-populate-request-id-design; subject to change
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
    * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -366,6 +368,65 @@ public java.lang.String getRequestId() { } } + public static final int OTHER_REQUEST_ID_FIELD_NUMBER = 8; + @SuppressWarnings("serial") + private volatile java.lang.Object otherRequestId_ = ""; + /** + *
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
+   * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return Whether the otherRequestId field is set. + */ + @java.lang.Override + public boolean hasOtherRequestId() { + return ((bitField0_ & 0x00000001) != 0); + } + /** + *
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
+   * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return The otherRequestId. + */ + @java.lang.Override + public java.lang.String getOtherRequestId() { + java.lang.Object ref = otherRequestId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + otherRequestId_ = s; + return s; + } + } + /** + *
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
+   * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return The bytes for otherRequestId. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getOtherRequestIdBytes() { + java.lang.Object ref = otherRequestId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + otherRequestId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + private byte memoizedIsInitialized = -1; @java.lang.Override public final boolean isInitialized() { @@ -398,6 +459,9 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestId_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 7, requestId_); } + if (((bitField0_ & 0x00000001) != 0)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 8, otherRequestId_); + } getUnknownFields().writeTo(output); } @@ -427,6 +491,9 @@ public int getSerializedSize() { if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestId_)) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, requestId_); } + if (((bitField0_ & 0x00000001) != 0)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, otherRequestId_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -449,6 +516,11 @@ public boolean equals(final java.lang.Object obj) { .equals(other.getOtherHeader())) return false; if (!getRequestId() .equals(other.getRequestId())) return false; + if (hasOtherRequestId() != other.hasOtherRequestId()) return false; + if (hasOtherRequestId()) { + if (!getOtherRequestId() + .equals(other.getOtherRequestId())) return false; + } if (!getResponseCase().equals(other.getResponseCase())) return false; switch (responseCase_) { case 1: @@ -481,6 +553,10 @@ public int hashCode() { hash = (53 * hash) + getOtherHeader().hashCode(); hash = (37 * hash) + REQUEST_ID_FIELD_NUMBER; hash = (53 * hash) + getRequestId().hashCode(); + if (hasOtherRequestId()) { + hash = (37 * hash) + OTHER_REQUEST_ID_FIELD_NUMBER; + hash = (53 * hash) + getOtherRequestId().hashCode(); + } switch (responseCase_) { case 1: hash = (37 * hash) + CONTENT_FIELD_NUMBER; @@ -638,6 +714,7 @@ public Builder clear() { header_ = ""; otherHeader_ = ""; requestId_ = ""; + otherRequestId_ = ""; responseCase_ = 0; response_ = null; return this; @@ -686,6 +763,12 @@ private void buildPartial0(com.google.showcase.v1beta1.EchoRequest result) { if (((from_bitField0_ & 0x00000020) != 0)) { result.requestId_ = requestId_; } + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000040) != 0)) { + result.otherRequestId_ = otherRequestId_; + to_bitField0_ |= 0x00000001; + } + result.bitField0_ |= to_bitField0_; } private void buildPartialOneofs(com.google.showcase.v1beta1.EchoRequest result) { @@ -759,6 +842,11 @@ public Builder mergeFrom(com.google.showcase.v1beta1.EchoRequest other) { bitField0_ |= 0x00000020; onChanged(); } + if (other.hasOtherRequestId()) { + otherRequestId_ = other.otherRequestId_; + bitField0_ |= 0x00000040; + onChanged(); + } switch (other.getResponseCase()) { case CONTENT: { responseCase_ = 1; @@ -833,6 +921,11 @@ public Builder mergeFrom( bitField0_ |= 0x00000020; break; } // case 58 + case 66: { + otherRequestId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000040; + break; + } // case 66 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { done = true; // was an endgroup tag @@ -1420,7 +1513,7 @@ public Builder setOtherHeaderBytes( private java.lang.Object requestId_ = ""; /** *
-     * Based on go/client-populate-request-id-design; subject to change
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
      * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -1440,7 +1533,7 @@ public java.lang.String getRequestId() { } /** *
-     * Based on go/client-populate-request-id-design; subject to change
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
      * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -1461,7 +1554,7 @@ public java.lang.String getRequestId() { } /** *
-     * Based on go/client-populate-request-id-design; subject to change
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
      * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -1478,7 +1571,7 @@ public Builder setRequestId( } /** *
-     * Based on go/client-populate-request-id-design; subject to change
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
      * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -1492,7 +1585,7 @@ public Builder clearRequestId() { } /** *
-     * Based on go/client-populate-request-id-design; subject to change
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
      * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -1508,6 +1601,109 @@ public Builder setRequestIdBytes( onChanged(); return this; } + + private java.lang.Object otherRequestId_ = ""; + /** + *
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
+     * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return Whether the otherRequestId field is set. + */ + public boolean hasOtherRequestId() { + return ((bitField0_ & 0x00000040) != 0); + } + /** + *
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
+     * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return The otherRequestId. + */ + public java.lang.String getOtherRequestId() { + java.lang.Object ref = otherRequestId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + otherRequestId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + *
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
+     * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return The bytes for otherRequestId. + */ + public com.google.protobuf.ByteString + getOtherRequestIdBytes() { + java.lang.Object ref = otherRequestId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + otherRequestId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + *
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
+     * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @param value The otherRequestId to set. + * @return This builder for chaining. + */ + public Builder setOtherRequestId( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + otherRequestId_ = value; + bitField0_ |= 0x00000040; + onChanged(); + return this; + } + /** + *
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
+     * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return This builder for chaining. + */ + public Builder clearOtherRequestId() { + otherRequestId_ = getDefaultInstance().getOtherRequestId(); + bitField0_ = (bitField0_ & ~0x00000040); + onChanged(); + return this; + } + /** + *
+     * To facilitate testing of https://google.aip.dev/client-libraries/4235
+     * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @param value The bytes for otherRequestId to set. + * @return This builder for chaining. + */ + public Builder setOtherRequestIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + otherRequestId_ = value; + bitField0_ |= 0x00000040; + onChanged(); + return this; + } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { diff --git a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequestOrBuilder.java b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequestOrBuilder.java index b95df17ab5..ab12471d39 100644 --- a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequestOrBuilder.java +++ b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoRequestOrBuilder.java @@ -125,7 +125,7 @@ public interface EchoRequestOrBuilder extends /** *
-   * Based on go/client-populate-request-id-design; subject to change
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
    * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -134,7 +134,7 @@ public interface EchoRequestOrBuilder extends java.lang.String getRequestId(); /** *
-   * Based on go/client-populate-request-id-design; subject to change
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
    * 
* * string request_id = 7 [(.google.api.field_info) = { ... } @@ -143,5 +143,34 @@ public interface EchoRequestOrBuilder extends com.google.protobuf.ByteString getRequestIdBytes(); + /** + *
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
+   * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return Whether the otherRequestId field is set. + */ + boolean hasOtherRequestId(); + /** + *
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
+   * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return The otherRequestId. + */ + java.lang.String getOtherRequestId(); + /** + *
+   * To facilitate testing of https://google.aip.dev/client-libraries/4235
+   * 
+ * + * optional string other_request_id = 8 [(.google.api.field_info) = { ... } + * @return The bytes for otherRequestId. + */ + com.google.protobuf.ByteString + getOtherRequestIdBytes(); + com.google.showcase.v1beta1.EchoRequest.ResponseCase getResponseCase(); } diff --git a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponse.java b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponse.java index 5c3fb4461e..4c14bbce86 100644 --- a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponse.java +++ b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponse.java @@ -23,6 +23,8 @@ private EchoResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) private EchoResponse() { content_ = ""; severity_ = 0; + requestId_ = ""; + otherRequestId_ = ""; } @java.lang.Override @@ -118,6 +120,100 @@ public java.lang.String getContent() { return result == null ? com.google.showcase.v1beta1.Severity.UNRECOGNIZED : result; } + public static final int REQUEST_ID_FIELD_NUMBER = 3; + @SuppressWarnings("serial") + private volatile java.lang.Object requestId_ = ""; + /** + *
+   * The request ID specified or autopopulated in the request.
+   * 
+ * + * string request_id = 3; + * @return The requestId. + */ + @java.lang.Override + public java.lang.String getRequestId() { + java.lang.Object ref = requestId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + requestId_ = s; + return s; + } + } + /** + *
+   * The request ID specified or autopopulated in the request.
+   * 
+ * + * string request_id = 3; + * @return The bytes for requestId. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getRequestIdBytes() { + java.lang.Object ref = requestId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + requestId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int OTHER_REQUEST_ID_FIELD_NUMBER = 4; + @SuppressWarnings("serial") + private volatile java.lang.Object otherRequestId_ = ""; + /** + *
+   * The other request ID specified or autopopulated in the request.
+   * 
+ * + * string other_request_id = 4; + * @return The otherRequestId. + */ + @java.lang.Override + public java.lang.String getOtherRequestId() { + java.lang.Object ref = otherRequestId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + otherRequestId_ = s; + return s; + } + } + /** + *
+   * The other request ID specified or autopopulated in the request.
+   * 
+ * + * string other_request_id = 4; + * @return The bytes for otherRequestId. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getOtherRequestIdBytes() { + java.lang.Object ref = otherRequestId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + otherRequestId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + private byte memoizedIsInitialized = -1; @java.lang.Override public final boolean isInitialized() { @@ -138,6 +234,12 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (severity_ != com.google.showcase.v1beta1.Severity.UNNECESSARY.getNumber()) { output.writeEnum(2, severity_); } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestId_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, requestId_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(otherRequestId_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, otherRequestId_); + } getUnknownFields().writeTo(output); } @@ -154,6 +256,12 @@ public int getSerializedSize() { size += com.google.protobuf.CodedOutputStream .computeEnumSize(2, severity_); } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(requestId_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, requestId_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(otherRequestId_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, otherRequestId_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -172,6 +280,10 @@ public boolean equals(final java.lang.Object obj) { if (!getContent() .equals(other.getContent())) return false; if (severity_ != other.severity_) return false; + if (!getRequestId() + .equals(other.getRequestId())) return false; + if (!getOtherRequestId() + .equals(other.getOtherRequestId())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -187,6 +299,10 @@ public int hashCode() { hash = (53 * hash) + getContent().hashCode(); hash = (37 * hash) + SEVERITY_FIELD_NUMBER; hash = (53 * hash) + severity_; + hash = (37 * hash) + REQUEST_ID_FIELD_NUMBER; + hash = (53 * hash) + getRequestId().hashCode(); + hash = (37 * hash) + OTHER_REQUEST_ID_FIELD_NUMBER; + hash = (53 * hash) + getOtherRequestId().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -324,6 +440,8 @@ public Builder clear() { bitField0_ = 0; content_ = ""; severity_ = 0; + requestId_ = ""; + otherRequestId_ = ""; return this; } @@ -363,6 +481,12 @@ private void buildPartial0(com.google.showcase.v1beta1.EchoResponse result) { if (((from_bitField0_ & 0x00000002) != 0)) { result.severity_ = severity_; } + if (((from_bitField0_ & 0x00000004) != 0)) { + result.requestId_ = requestId_; + } + if (((from_bitField0_ & 0x00000008) != 0)) { + result.otherRequestId_ = otherRequestId_; + } } @java.lang.Override @@ -417,6 +541,16 @@ public Builder mergeFrom(com.google.showcase.v1beta1.EchoResponse other) { if (other.severity_ != 0) { setSeverityValue(other.getSeverityValue()); } + if (!other.getRequestId().isEmpty()) { + requestId_ = other.requestId_; + bitField0_ |= 0x00000004; + onChanged(); + } + if (!other.getOtherRequestId().isEmpty()) { + otherRequestId_ = other.otherRequestId_; + bitField0_ |= 0x00000008; + onChanged(); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -453,6 +587,16 @@ public Builder mergeFrom( bitField0_ |= 0x00000002; break; } // case 16 + case 26: { + requestId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000004; + break; + } // case 26 + case 34: { + otherRequestId_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000008; + break; + } // case 34 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { done = true; // was an endgroup tag @@ -634,6 +778,190 @@ public Builder clearSeverity() { onChanged(); return this; } + + private java.lang.Object requestId_ = ""; + /** + *
+     * The request ID specified or autopopulated in the request.
+     * 
+ * + * string request_id = 3; + * @return The requestId. + */ + public java.lang.String getRequestId() { + java.lang.Object ref = requestId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + requestId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + *
+     * The request ID specified or autopopulated in the request.
+     * 
+ * + * string request_id = 3; + * @return The bytes for requestId. + */ + public com.google.protobuf.ByteString + getRequestIdBytes() { + java.lang.Object ref = requestId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + requestId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + *
+     * The request ID specified or autopopulated in the request.
+     * 
+ * + * string request_id = 3; + * @param value The requestId to set. + * @return This builder for chaining. + */ + public Builder setRequestId( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + requestId_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + /** + *
+     * The request ID specified or autopopulated in the request.
+     * 
+ * + * string request_id = 3; + * @return This builder for chaining. + */ + public Builder clearRequestId() { + requestId_ = getDefaultInstance().getRequestId(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + /** + *
+     * The request ID specified or autopopulated in the request.
+     * 
+ * + * string request_id = 3; + * @param value The bytes for requestId to set. + * @return This builder for chaining. + */ + public Builder setRequestIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + requestId_ = value; + bitField0_ |= 0x00000004; + onChanged(); + return this; + } + + private java.lang.Object otherRequestId_ = ""; + /** + *
+     * The other request ID specified or autopopulated in the request.
+     * 
+ * + * string other_request_id = 4; + * @return The otherRequestId. + */ + public java.lang.String getOtherRequestId() { + java.lang.Object ref = otherRequestId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + otherRequestId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + *
+     * The other request ID specified or autopopulated in the request.
+     * 
+ * + * string other_request_id = 4; + * @return The bytes for otherRequestId. + */ + public com.google.protobuf.ByteString + getOtherRequestIdBytes() { + java.lang.Object ref = otherRequestId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + otherRequestId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + *
+     * The other request ID specified or autopopulated in the request.
+     * 
+ * + * string other_request_id = 4; + * @param value The otherRequestId to set. + * @return This builder for chaining. + */ + public Builder setOtherRequestId( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + otherRequestId_ = value; + bitField0_ |= 0x00000008; + onChanged(); + return this; + } + /** + *
+     * The other request ID specified or autopopulated in the request.
+     * 
+ * + * string other_request_id = 4; + * @return This builder for chaining. + */ + public Builder clearOtherRequestId() { + otherRequestId_ = getDefaultInstance().getOtherRequestId(); + bitField0_ = (bitField0_ & ~0x00000008); + onChanged(); + return this; + } + /** + *
+     * The other request ID specified or autopopulated in the request.
+     * 
+ * + * string other_request_id = 4; + * @param value The bytes for otherRequestId to set. + * @return This builder for chaining. + */ + public Builder setOtherRequestIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + otherRequestId_ = value; + bitField0_ |= 0x00000008; + onChanged(); + return this; + } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { diff --git a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponseOrBuilder.java b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponseOrBuilder.java index da43484b72..e2c2bdd395 100644 --- a/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponseOrBuilder.java +++ b/showcase/proto-gapic-showcase-v1beta1/src/main/java/com/google/showcase/v1beta1/EchoResponseOrBuilder.java @@ -46,4 +46,44 @@ public interface EchoResponseOrBuilder extends * @return The severity. */ com.google.showcase.v1beta1.Severity getSeverity(); + + /** + *
+   * The request ID specified or autopopulated in the request.
+   * 
+ * + * string request_id = 3; + * @return The requestId. + */ + java.lang.String getRequestId(); + /** + *
+   * The request ID specified or autopopulated in the request.
+   * 
+ * + * string request_id = 3; + * @return The bytes for requestId. + */ + com.google.protobuf.ByteString + getRequestIdBytes(); + + /** + *
+   * The other request ID specified or autopopulated in the request.
+   * 
+ * + * string other_request_id = 4; + * @return The otherRequestId. + */ + java.lang.String getOtherRequestId(); + /** + *
+   * The other request ID specified or autopopulated in the request.
+   * 
+ * + * string other_request_id = 4; + * @return The bytes for otherRequestId. + */ + com.google.protobuf.ByteString + getOtherRequestIdBytes(); } diff --git a/showcase/proto-gapic-showcase-v1beta1/src/main/proto/schema/google/showcase/v1beta1/echo.proto b/showcase/proto-gapic-showcase-v1beta1/src/main/proto/schema/google/showcase/v1beta1/echo.proto index 3e797adfc3..eda1861a2d 100644 --- a/showcase/proto-gapic-showcase-v1beta1/src/main/proto/schema/google/showcase/v1beta1/echo.proto +++ b/showcase/proto-gapic-showcase-v1beta1/src/main/proto/schema/google/showcase/v1beta1/echo.proto @@ -43,6 +43,8 @@ service Echo { // This service is meant to only run locally on the port 7469 (keypad digits // for "show"). option (google.api.default_host) = "localhost:7469"; + // See https://github.com/aip-dev/google.aip.dev/pull/1331 + option (google.api.api_version) = "v1_20240408"; // This method simply echoes the request. This method showcases unary RPCs. rpc Echo(EchoRequest) returns (EchoResponse) { @@ -211,10 +213,15 @@ message EchoRequest { // Optional. This field can be set to test the routing annotation on the Echo method. string other_header = 5; - // Based on go/client-populate-request-id-design; subject to change + // To facilitate testing of https://google.aip.dev/client-libraries/4235 string request_id = 7 [ (google.api.field_info).format = UUID4 ]; + + // To facilitate testing of https://google.aip.dev/client-libraries/4235 + optional string other_request_id = 8 [ + (google.api.field_info).format = UUID4 + ]; } // The response message for the Echo methods. @@ -224,6 +231,12 @@ message EchoResponse { // The severity specified in the request. Severity severity = 2; + + // The request ID specified or autopopulated in the request. + string request_id = 3; + + // The other request ID specified or autopopulated in the request. + string other_request_id = 4; } // The request message used for the EchoErrorDetails method. From 3967a19e8b68c3a95cf1ced737f3a1aa73b02e93 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Tue, 23 Apr 2024 11:48:51 -0400 Subject: [PATCH 03/25] deps: Make opentelemetry-api an optional dependency. (#2681) Mark opentelemetry-api as an optional dependency per [internal discussion](https://docs.google.com/document/d/1mhuUD6yZfMJHdOvmHwYM-pYnjMO_t7DwCGKJmSPYE5k/edit?resourcekey=0-fLgYpys-qO89rF_kwOejug&tab=t.0#heading=h.9y4fw0m64snt). Both [java-bigtable](https://github.com/googleapis/java-bigtable/blob/3f37d8da8b51a3fea56d1c462b9500ee2c244973/google-cloud-bigtable/pom.xml#L222) and [java-spanner ](https://github.com/googleapis/java-spanner/blob/6f522dd73123b3de8399902e28d755a5496829c3/google-cloud-spanner/pom.xml#L253)already declare this dependency in their poms, so this is not a breaking change. --- gax-java/gax/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/gax-java/gax/pom.xml b/gax-java/gax/pom.xml index 2bf4bf1cea..ffcd2b3070 100644 --- a/gax-java/gax/pom.xml +++ b/gax-java/gax/pom.xml @@ -60,6 +60,7 @@ io.opentelemetry opentelemetry-api + true From 42526dc03e00a2e01e8f7a075817560089f378ee Mon Sep 17 00:00:00 2001 From: Blake Li Date: Tue, 23 Apr 2024 11:49:16 -0400 Subject: [PATCH 04/25] docs: Add contributing guidelines to PR and issue templates (#2682) --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 3 ++- .github/PULL_REQUEST_TEMPLATE.md | 5 ++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c36cc0354f..3daff23532 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -6,7 +6,7 @@ about: Create a report to help us improve Thanks for stopping by to let us know something could be better! -**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. +**PLEASE READ**: Before creating a new issue, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md). If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. Please run down the following list and make sure you've tried the usual "quick fixes": diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 63c28769c1..a71b0715c1 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -6,7 +6,8 @@ about: Suggest an idea for this library Thanks for stopping by to let us know something could be better! -**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. +**PLEASE READ**: Before creating a new issue, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md). + If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. **Is your feature request related to a problem? Please describe.** What the problem is. Example: I'm always frustrated when [...] diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5f3f055bdf..876946070b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,7 +1,6 @@ -Thank you for opening a Pull Request! For general contributing guidelines, please refer to [contributing guide](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md) - -Before submitting your PR, there are a few things you can do to make sure it goes smoothly: +Thank you for opening a Pull Request! Before submitting your PR, please read our [contributing guidelines](https://github.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md). +There are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/gapic-generator-java/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) From 971e4a37514d58e80986dd058925e616180e59f2 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:41:10 -0400 Subject: [PATCH 05/25] chore: show difference in integration test (#2684) In this PR: - Show file diff in integration tests. I manually edited a line in test branch and this is the test result: ``` Difference in google-cloud-alloydb/src/main/java/com/google/cloud/alloydb/v1/AlloyDBAdminClient.java: --- +++ @@ -774,7 +774,7 @@ /** * Constructs an instance of AlloyDBAdminClient, using the given stub for making calls. This is - * for advanced usage - prefer using create(AlloyDBAdminSettings) - manually added. + * for advanced usage - prefer using create(AlloyDBAdminSettings). */ public static final AlloyDBAdminClient create(AlloyDBAdminStub stub) { return new AlloyDBAdminClient(stub); Error: Process completed with exit code 1. ``` --- library_generation/test/integration_tests.py | 24 ++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 9c4663e373..356bdec447 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import difflib import json from filecmp import cmp from filecmp import dircmp @@ -102,12 +103,9 @@ def test_entry_point_running_in_container(self): print(f"Checking for differences in '{library_name}'.") print(f" The expected library is in {golden_dir}/{library_name}.") print(f" The actual library is in {actual_library}. ") - target_repo_dest = ( - f"{repo_dest}/{library_name}" if config.is_monorepo() else repo_dest - ) compare_result = dircmp( f"{golden_dir}/{library_name}", - target_repo_dest, + actual_library, ignore=[".repo-metadata.json"], ) diff_files = [] @@ -122,12 +120,24 @@ def test_entry_point_running_in_container(self): print_file = lambda f: print(f" - {f}") if len(diff_files) > 0: print(" Some files (found in both folders) are differing:") - [print_file(f) for f in diff_files] + for diff_file in diff_files: + print(f"Difference in {diff_file}:") + with open( + f"{golden_dir}/{library_name}/{diff_file}" + ) as expected_file: + with open(f"{actual_library}/{diff_file}") as actual_file: + [ + print(line) + for line in difflib.unified_diff( + expected_file.readlines(), + actual_file.readlines(), + ) + ] if len(golden_only) > 0: print(" There were files found only in the golden dir:") [print_file(f) for f in golden_only] if len(generated_only) > 0: - print(" Some files were found to have differences:") + print(" There were files found only in the generated dir:") [print_file(f) for f in generated_only] self.assertTrue(len(golden_only) == 0) @@ -139,7 +149,7 @@ def test_entry_point_running_in_container(self): self.assertTrue( self.__compare_json_files( f"{golden_dir}/{library_name}/.repo-metadata.json", - f"{target_repo_dest}/.repo-metadata.json", + f"{actual_library}/.repo-metadata.json", ), msg=f" The generated {library_name}/.repo-metadata.json is different from golden.", ) From 463801cea5f73b2ff00d78e3bd53ddcd81f23ed0 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Tue, 23 Apr 2024 18:15:23 -0400 Subject: [PATCH 06/25] chore: update package information report (#2674) In this PR: - Generate package information report for package that has no non-compliant licenses and security vulnerabilities. - Encode version using `URLEncoder`. The version may contain special characters that needs to be encoded before sending to deps.dev, e.g., [9+181-r4173-1](https://deps.dev/maven/com.google.errorprone%3Ajavac-shaded/9%2B181-r4173-1). An example of the report: ``` ## Package information of io.opentelemetry:opentelemetry-api:1.37.0 Licenses: [Apache-2.0] Vulnerabilities: None. Checked in [deps.dev query](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=io.opentelemetry:opentelemetry-api&versionKey.version=1.37.0) ## Dependencies: ## Package information of io.opentelemetry:opentelemetry-context:1.37.0 Licenses: [Apache-2.0] Vulnerabilities: None. Checked in [deps.dev query](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=io.opentelemetry:opentelemetry-context&versionKey.version=1.37.0) ``` --- .../com/google/cloud/DependencyAnalyzer.java | 10 +-- .../google/cloud/external/DepsDevClient.java | 31 +++++--- .../google/cloud/model/AnalysisResult.java | 72 +++++++++++++++++-- .../java/com/google/cloud/model/License.java | 27 +++++-- .../google/cloud/model/LicenseCategory.java | 9 ++- .../com/google/cloud/model/VersionKey.java | 12 ++++ .../cloud/external/DepsDevClientTest.java | 21 +++++- .../cloud/model/AnalysisResultTest.java | 43 +++++++++++ .../com/google/cloud/model/LicenseTest.java | 12 ++++ 9 files changed, 208 insertions(+), 29 deletions(-) diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java index 7b73f73e35..710d2ee9d4 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java @@ -86,10 +86,12 @@ public AnalysisResult analyze(String system, String packageName, String packageV */ public static void main(String[] args) throws IllegalArgumentException { checkArgument(args.length == 3, - "The length of the inputs should be 3.\n" + - "The 1st input should be the package management system.\n" + - "The 2nd input should be the package name.\n" + - "The 3rd input should be the package version.\n" + """ + The length of the inputs should be 3. + The 1st input should be the package management system. + The 2nd input should be the package name. + The 3rd input should be the package version. + """ ); String system = args[0]; diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/external/DepsDevClient.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/external/DepsDevClient.java index fe61edccd8..a42c46a64a 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/external/DepsDevClient.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/external/DepsDevClient.java @@ -6,6 +6,7 @@ import com.google.cloud.model.QueryResult; import com.google.cloud.model.Relation; import com.google.cloud.model.VersionKey; +import com.google.errorprone.annotations.RestrictedApi; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -16,10 +17,12 @@ import java.lang.reflect.Type; import java.net.URI; import java.net.URISyntaxException; +import java.net.URLEncoder; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.stream.Collectors; @@ -27,9 +30,11 @@ public class DepsDevClient { private final HttpClient client; public final Gson gson; - private final static String advisoryUrlBase = "https://api.deps.dev/v3/advisories/%s"; - private final static String queryUrlBase = "https://api.deps.dev/v3/query?versionKey.system=%s&versionKey.name=%s&versionKey.version=%s"; - private final static String dependencyUrlBase = "https://api.deps.dev/v3/systems/%s/packages/%s/versions/%s:dependencies"; + private final static String ADVISORY_URL_BASE = "https://api.deps.dev/v3/advisories/%s"; + + private final static String DEPENDENCY_URLBASE = "https://api.deps.dev/v3/systems/%s/packages/%s/versions/%s:dependencies"; + + public final static String QUERY_URL_BASE = "https://api.deps.dev/v3/query?versionKey.system=%s&versionKey.name=%s&versionKey.version=%s"; public DepsDevClient(HttpClient client) { this.client = client; @@ -76,15 +81,25 @@ public Advisory getAdvisory(String advisoryId) } private String getAdvisoryUrl(String advisoryId) { - return String.format(advisoryUrlBase, advisoryId); + return String.format(ADVISORY_URL_BASE, advisoryId); + } + + @RestrictedApi( + explanation = "This method is for internal use only.", + allowedOnPath = "test/java/com/google/cloud/external") + public String getQueryUrl(String system, String name, String version) { + return String.format(QUERY_URL_BASE, system, name, encode(version)); } - private String getQueryUrl(String system, String name, String version) { - return String.format(queryUrlBase, system, name, version); + @RestrictedApi( + explanation = "This method is for internal use only.", + allowedOnPath = "test/java/com/google/cloud/external") + public String getDependencyUrl(String system, String name, String version) { + return String.format(DEPENDENCY_URLBASE, system, name, encode(version)); } - private String getDependencyUrl(String system, String name, String version) { - return String.format(dependencyUrlBase, system, name, version); + private String encode(String str) { + return URLEncoder.encode(str, StandardCharsets.UTF_8); } private HttpResponse getResponse(String endpoint) diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java index 5ae1907bb6..d675679bbc 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java @@ -1,27 +1,29 @@ package com.google.cloud.model; -import com.google.common.collect.ImmutableSet; +import static com.google.cloud.external.DepsDevClient.QUERY_URL_BASE; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; public class AnalysisResult { private final VersionKey root; + private final List packageInfos; private final Map> advisories; private final Map> nonCompliantLicenses; - private final ImmutableSet compliantCategories = ImmutableSet.of( - LicenseCategory.NOTICE); private final static Logger LOGGER = Logger.getLogger(AnalysisResult.class.getName()); private AnalysisResult(VersionKey root, List result) { this.root = root; - advisories = getAdvisories(result); - nonCompliantLicenses = getNonCompliantLicenses(result); + this.packageInfos = result; + this.advisories = getAdvisories(result); + this.nonCompliantLicenses = getNonCompliantLicenses(result); } public static AnalysisResult of(VersionKey root, List result) { @@ -44,6 +46,9 @@ public ReportResult generateReport() { LOGGER.log(Level.INFO, String.format("%s have no known vulnerabilities and non compliant licenses", root)); + LOGGER.log(Level.INFO, "Generate package information report..."); + System.out.println(packageInfoReport()); + return ReportResult.PASS; } @@ -60,6 +65,7 @@ private Map> getAdvisories(List result) private Map> getNonCompliantLicenses(List result) { Map> licenses = new HashMap<>(); + Set compliantCategories = LicenseCategory.compliantCategories(); result.forEach(packageInfo -> { List nonCompliantLicenses = new ArrayList<>(); @@ -92,11 +98,63 @@ private void formatLog(VersionKey root, Map> map, String } private String beginSeparator(VersionKey versionKey, VersionKey root) { - return String.format("====================== %s, dependency of %s ======================", - versionKey.toString(), root.toString()); + String relation = versionKey.equals(root) ? "self" : "dependency"; + return String.format("====================== %s, %s of %s ======================", + versionKey, relation, root); } private String endSeparator() { return "==========================================================="; } + + public String packageInfoReport() { + StringBuilder builder = new StringBuilder(); + PackageInfo root = packageInfos.get(0); + String title = String.format(""" + Please copy and paste the package information below to your ticket. + + ## Package information of %s + %s + """, root.versionKey(), packageInfoSection(root)); + builder.append(title); + + builder.append("## Dependencies:\n"); + if (packageInfos.size() == 1) { + builder.append("None"); + } else { + for (int i = 1; i < packageInfos.size(); i++) { + PackageInfo info = packageInfos.get(i); + String dependencyInfo = String.format(""" + ### Package information of %s + %s + """, info.versionKey(), packageInfoSection(info)); + builder.append(dependencyInfo); + } + } + builder.append("\n"); + + return builder.toString(); + } + + private String packageInfoSection(PackageInfo packageInfo) { + VersionKey versionKey = packageInfo.versionKey(); + // generate the report using Markdown format. + String packageInfoReport = """ + Licenses: %s + Vulnerabilities: None. + Checked in [%s (%s)](%s) + """; + return String.format(packageInfoReport, + packageInfo.licenses(), + versionKey.name(), + versionKey.version(), + getQueryUrl( + versionKey.pkgManagement().toString(), + versionKey.name(), + versionKey.version())); + } + + private String getQueryUrl(String system, String name, String version) { + return String.format(QUERY_URL_BASE, system, name, version); + } } diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java index 1394afdd16..83ed971e7b 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java @@ -14,17 +14,21 @@ * For more information, please refer to go/thirdpartylicenses. */ public enum License { - APACHE_2_0(Set.of(NOTICE)), - BCL(Set.of(RESTRICTED, NOTICE)), - GL2PS(Set.of(RESTRICTED, NOTICE)), - MIT(Set.of(NOTICE)), - NOT_RECOGNIZED(Set.of()); + APACHE_2_0("Apache-2.0", Set.of(NOTICE)), + BCL("BCL", Set.of(RESTRICTED, NOTICE)), + BSD_3_CLAUSE("BSD-3-Clause", Set.of(NOTICE)), + GL2PS("GL2PS", Set.of(RESTRICTED, NOTICE)), + MIT("MIT", Set.of(NOTICE)), + NOT_RECOGNIZED("Not-Recognized", Set.of()); private final static Logger LOGGER = Logger.getLogger(License.class.getName()); + private final String licenseStr; + private final Set categories; - License(Set categories) { + License(String licenseStr, Set categories) { + this.licenseStr = licenseStr; this.categories = categories; } @@ -44,4 +48,15 @@ public static License toLicense(String licenseStr) { public Set getCategories() { return ImmutableSet.copyOf(categories); } + + @Override + public String toString() { + Set compliantCategories = LicenseCategory.compliantCategories(); + for (LicenseCategory category : this.categories) { + if (!compliantCategories.contains(category)) { + return this.licenseStr; + } + } + return String.format("%s (Google-compliant)", this.licenseStr); + } } diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/LicenseCategory.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/LicenseCategory.java index cf98a35bfa..642d51b00a 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/LicenseCategory.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/LicenseCategory.java @@ -1,5 +1,8 @@ package com.google.cloud.model; +import com.google.common.collect.ImmutableSet; +import java.util.Set; + /** * The type of license associated with open-source software. *

@@ -8,5 +11,9 @@ public enum LicenseCategory { PERMISSIVE, RESTRICTED, - NOTICE + NOTICE; + + public static Set compliantCategories() { + return ImmutableSet.of(LicenseCategory.NOTICE); + } } diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/VersionKey.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/VersionKey.java index 7a145d3677..589ae7190a 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/VersionKey.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/VersionKey.java @@ -20,4 +20,16 @@ public static VersionKey from(String system, String name, String version) return new VersionKey(pkg, name, version); } + @Override + public String toString() { + if (pkgManagement == PkgManagement.MAVEN) { + return String.format("%s:%s", name, version); + } + + return "VersionKey{" + + "pkgManagement=" + pkgManagement + + ", name='" + name + '\'' + + ", version='" + version + '\'' + + '}'; + } } diff --git a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/external/DepsDevClientTest.java b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/external/DepsDevClientTest.java index 9d58e339a2..4ac683d4ef 100644 --- a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/external/DepsDevClientTest.java +++ b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/external/DepsDevClientTest.java @@ -1,6 +1,7 @@ package com.google.cloud.external; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -21,19 +22,32 @@ public class DepsDevClientTest { - private HttpClient httpClient; private HttpResponse response; private DepsDevClient client; @Before public void setUp() throws IOException, InterruptedException { - httpClient = mock(HttpClient.class); + HttpClient httpClient = mock(HttpClient.class); client = new DepsDevClient(httpClient); response = mock(HttpResponse.class); when(httpClient.send(any(HttpRequest.class), any(BodyHandler.class))) .thenReturn(response); } + @Test + public void testGetQueryUrlReturnsEncodedUrl() { + assertEquals( + "https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.google.errorprone:javac-shaded&versionKey.version=9%2B181-r4173-1", + client.getQueryUrl("MAVEN", "com.google.errorprone:javac-shaded", "9+181-r4173-1")); + } + + @Test + public void testGetDependenciesReturnsEncodedUrl() { + assertEquals( + "https://api.deps.dev/v3/systems/MAVEN/packages/com.google.errorprone:javac-shaded/versions/9%2B181-r4173-1:dependencies", + client.getDependencyUrl("MAVEN", "com.google.errorprone:javac-shaded", "9+181-r4173-1")); + } + @Test public void testGetDirectDependenciesOnlyReturnsDirectDeps() throws IOException, InterruptedException, URISyntaxException, IllegalArgumentException { @@ -50,7 +64,8 @@ public void testGetQueryResultSucceed() throws URISyntaxException, IOException, InterruptedException, IllegalArgumentException { String responseBody = "{\"results\":[{\"version\":{\"versionKey\":{\"system\":\"MAVEN\",\"name\":\"org.apache.logging.log4j:log4j-core\",\"version\":\"2.17.0\"},\"publishedAt\":\"2021-12-18T01:58:10Z\",\"isDefault\":false,\"licenses\":[\"Apache-2.0\"],\"advisoryKeys\":[{\"id\":\"GHSA-8489-44mv-ggj8\"}],\"links\":[{\"label\":\"SOURCE_REPO\",\"url\":\"https://gitbox.apache.org/repos/asf?p=logging-log4j2.git\"},{\"label\":\"ISSUE_TRACKER\",\"url\":\"https://issues.apache.org/jira/browse/LOG4J2\"},{\"label\":\"HOMEPAGE\",\"url\":\"https://logging.apache.org/log4j/2.x/\"}],\"slsaProvenances\":[],\"registries\":[\"https://repo.maven.apache.org/maven2/\"],\"relatedProjects\":[{\"projectKey\":{\"id\":\"\"},\"relationProvenance\":\"UNVERIFIED_METADATA\",\"relationType\":\"ISSUE_TRACKER\"}]}}]}"; when(response.body()).thenReturn(responseBody); - VersionKey log4jCore = VersionKey.from("maven", "org.apache.logging.log4j:log4j-core", "2.17.0"); + VersionKey log4jCore = + VersionKey.from("maven", "org.apache.logging.log4j:log4j-core", "2.17.0"); QueryResult queryResult = client.getQueryResult(log4jCore); assertThat(queryResult.results()).hasSize(1); Version version = queryResult.results().get(0).version(); diff --git a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java index a074bc17be..3dc7986966 100644 --- a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java +++ b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java @@ -59,4 +59,47 @@ public void testGenerateReportWithoutRiskSucceeds() ReportResult result = AnalysisResult.of(root, results).generateReport(); assertEquals(ReportResult.PASS, result); } + + @Test + public void testPackageInfoReportReturnsCorrectContents() { + VersionKey root = VersionKey.from("maven", "com.example:artifact", "1.2.3"); + List results = List.of( + new PackageInfo( + root, + List.of("Apache-2.0"), + List.of() + ), + new PackageInfo( + VersionKey.from("maven", "com.example:dependency", "4.5.6"), + List.of("Apache-2.0", "MIT"), + List.of() + ), + new PackageInfo( + VersionKey.from("maven", "com.example:nested-dependency", "2.3.1"), + List.of("Apache-2.0", "MIT"), + List.of() + ) + ); + assertEquals(""" + Please copy and paste the package information below to your ticket. + + ## Package information of com.example:artifact:1.2.3 + Licenses: [Apache-2.0] + Vulnerabilities: None. + Checked in [com.example:artifact (1.2.3)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:artifact&versionKey.version=1.2.3) + + ## Dependencies: + ### Package information of com.example:dependency:4.5.6 + Licenses: [Apache-2.0, MIT] + Vulnerabilities: None. + Checked in [com.example:dependency (4.5.6)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:dependency&versionKey.version=4.5.6) + + ### Package information of com.example:nested-dependency:2.3.1 + Licenses: [Apache-2.0, MIT] + Vulnerabilities: None. + Checked in [com.example:nested-dependency (2.3.1)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:nested-dependency&versionKey.version=2.3.1) + + + """, AnalysisResult.of(root, results).packageInfoReport()); + } } diff --git a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java index aa6ea2a45d..1637462297 100644 --- a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java +++ b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java @@ -16,4 +16,16 @@ public void testToLicenseReturnsNonRecognizedLicense() { String license = "Non-existent-license"; assertEquals(License.NOT_RECOGNIZED, License.toLicense(license)); } + + @Test + public void testToStringOfACompliantLicense() { + String license = "Apache-2.0"; + assertEquals("Apache-2.0 (Google-compliant)", License.toLicense(license).toString()); + } + + @Test + public void testToStringOfANonCompliantLicense() { + String license = "BCL"; + assertEquals("BCL", License.toLicense(license).toString()); + } } From 40711fd69468a2021108bb5fba00bb02ac4bb19f Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Wed, 24 Apr 2024 10:06:26 -0400 Subject: [PATCH 07/25] feat: Parser to consume the api-versioning value from proto (#2630) This is part one to resolve b/330980553, this pr allows read and parse api versioning from proto to service model. Changes included in this pr: - rename current apiVersion to packageVersion. This packageVersion is parsed from package name and exposed in #1075. It was intended to be used in Spring codegen, but not actually used. It is used in generating sample region tags (see details [9ec3531](https://github.com/googleapis/sdk-platform-java/pull/2630/commits/9ec3531ea267c641ed265d685d4d4fecbe2285f3)) - exposing apiVersion from Service model. - Parser.java to parse apiVersion from `ClientProto.apiVersion` to service. --- .../generator/gapic/composer/Composer.java | 2 +- .../AbstractServiceClientClassComposer.java | 2 +- .../AbstractServiceSettingsClassComposer.java | 2 +- ...tractServiceStubSettingsClassComposer.java | 2 +- .../api/generator/gapic/model/GapicClass.java | 10 +- .../api/generator/gapic/model/Service.java | 25 +- .../generator/gapic/protoparser/Parser.java | 5 + .../gapic/composer/ComposerTest.java | 4 +- .../grpc/ServiceClientClassComposerTest.java | 4 +- .../ServiceSettingsClassComposerTest.java | 4 +- .../grpc/ServiceStubClassComposerTest.java | 4 +- .../ServiceStubSettingsClassComposerTest.java | 4 +- .../generator/gapic/model/ServiceTest.java | 56 +++- .../gapic/protoparser/ParserTest.java | 72 +++++ .../src/test/proto/api_version_testing.proto | 264 ++++++++++++++++++ 15 files changed, 421 insertions(+), 39 deletions(-) create mode 100644 gapic-generator-java/src/test/proto/api_version_testing.proto diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/Composer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/Composer.java index e92fd9b0c4..f2ffa56016 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/Composer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/Composer.java @@ -207,7 +207,7 @@ static List prepareExecutableSamples(List clazzes) { sample -> samples.add( addRegionTagAndHeaderToSample( - sample, gapicClass.apiShortName(), gapicClass.apiVersion()))); + sample, gapicClass.apiShortName(), gapicClass.packageVersion()))); clazzesWithSamples.add(gapicClass.withSamples(samples)); }); return clazzesWithSamples; diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java index 5f8456aa97..e8bd6fe081 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceClientClassComposer.java @@ -173,7 +173,7 @@ public GapicClass generate(GapicContext context, Service service) { updateGapicMetadata(context, service, className, grpcRpcsToJavaMethodNames); return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples)) .withApiShortName(service.apiShortName()) - .withApiVersion(service.apiVersion()); + .withPackageVersion(service.packageVersion()); } private static List createClassAnnotations(Service service, TypeStore typeStore) { diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java index c83bd54deb..60e3fcd38a 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceSettingsClassComposer.java @@ -128,7 +128,7 @@ public GapicClass generate(GapicContext context, Service service) { .build(); return GapicClass.create(kind, classDef, SampleComposerUtil.handleDuplicateSamples(samples)) .withApiShortName(service.apiShortName()) - .withApiVersion(service.apiVersion()); + .withPackageVersion(service.packageVersion()); } private static List createClassHeaderComments( diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java index f8c00131be..88a3cc6ecd 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java @@ -204,7 +204,7 @@ public GapicClass generate(GapicContext context, Service service) { return GapicClass.create( GapicClass.Kind.STUB, classDef, SampleComposerUtil.handleDuplicateSamples(samples)) .withApiShortName(service.apiShortName()) - .withApiVersion(service.apiVersion()); + .withPackageVersion(service.packageVersion()); } protected MethodDefinition createDefaultCredentialsProviderBuilderMethod() { diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicClass.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicClass.java index 11d6598e7e..1fd06a8dfe 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicClass.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicClass.java @@ -43,7 +43,7 @@ public enum Kind { public abstract String apiShortName(); // Only used for generating the region tag for samples; therefore only used in select Composers. - public abstract String apiVersion(); + public abstract String packageVersion(); /** * Create a GapicClass with minimal information. This is intended to be used for GapicClasses that @@ -76,7 +76,7 @@ static Builder builder() { return new AutoValue_GapicClass.Builder() .setSamples(Collections.emptyList()) .setApiShortName("") - .setApiVersion(""); + .setPackageVersion(""); } abstract Builder toBuilder(); @@ -89,8 +89,8 @@ public final GapicClass withApiShortName(String apiShortName) { return toBuilder().setApiShortName(apiShortName).build(); } - public final GapicClass withApiVersion(String apiVersion) { - return toBuilder().setApiVersion(apiVersion).build(); + public final GapicClass withPackageVersion(String packageVersion) { + return toBuilder().setPackageVersion(packageVersion).build(); } @AutoValue.Builder @@ -103,7 +103,7 @@ abstract static class Builder { abstract Builder setApiShortName(String apiShortName); - abstract Builder setApiVersion(String apiVersion); + abstract Builder setPackageVersion(String packageVersion); abstract GapicClass build(); } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Service.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Service.java index b89d42b4d2..656bf6bbd3 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Service.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Service.java @@ -27,6 +27,9 @@ public abstract class Service { public abstract String name(); + @Nullable + public abstract String apiVersion(); + public abstract String defaultHost(); public abstract ImmutableList oauthScopes(); @@ -52,6 +55,10 @@ public boolean hasDescription() { return !Strings.isNullOrEmpty(description()); } + public boolean hasApiVersion() { + return !Strings.isNullOrEmpty(apiVersion()); + } + public String hostServiceName() { // Host Service Name is guaranteed to exist and be non-null and non-empty // Parser will fail if the default host is not supplied @@ -65,9 +72,9 @@ public String apiShortName() { return ""; } - public String apiVersion() { + public String packageVersion() { if (!Strings.isNullOrEmpty(protoPakkage())) { - return parseApiVersion(protoPakkage()); + return parsePackageVersion(protoPakkage()); } return ""; } @@ -158,6 +165,8 @@ public abstract static class Builder { public abstract Builder setOverriddenName(String overriddenName); + public abstract Builder setApiVersion(String apiVersion); + public abstract Builder setDefaultHost(String defaultHost); public abstract Builder setOauthScopes(List oauthScopes); @@ -177,17 +186,17 @@ public abstract static class Builder { public abstract Service build(); } - private static String parseApiVersion(String protoPackage) { - // parse protoPackage for apiVersion + private static String parsePackageVersion(String protoPackage) { + // parse protoPackage for packageVersion String[] pakkage = protoPackage.split("\\."); - String apiVersion; + String packageVersion; // e.g. v1, v2, v1beta1 if (pakkage[pakkage.length - 1].matches("v[0-9].*")) { - apiVersion = pakkage[pakkage.length - 1]; + packageVersion = pakkage[pakkage.length - 1]; } else { - apiVersion = ""; + packageVersion = ""; } - return apiVersion; + return packageVersion; } // Parse the service name from the default host configured in the protos diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index e960ad3f6d..c7d0b95a3d 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -470,6 +470,11 @@ public static List parseService( } } + if (serviceOptions.hasExtension(ClientProto.apiVersion)) { + String apiVersion = serviceOptions.getExtension(ClientProto.apiVersion); + serviceBuilder.setApiVersion(apiVersion); + } + String serviceName = s.getName(); String overriddenServiceName = serviceName; String pakkage = TypeParser.getPackage(fileDescriptor); diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java index bc99864bdd..66ad0584be 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java @@ -45,7 +45,7 @@ public class ComposerTest { GrpcServiceCallableFactoryClassComposer.instance() .generate(context, echoProtoService) .withApiShortName(echoProtoService.apiShortName()) - .withApiVersion(echoProtoService.apiVersion())); + .withPackageVersion(echoProtoService.packageVersion())); private final Sample sample = Sample.builder() .setRegionTag( @@ -160,7 +160,7 @@ private List getTestClassListFromService(Service testService) { .generate(context, testService) .withSamples(ListofSamples) .withApiShortName(testService.apiShortName()) - .withApiVersion(testService.apiVersion()); + .withPackageVersion(testService.packageVersion()); List testClassList = Arrays.asList(new GapicClass[] {testClass}); return testClassList; } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java index 8da1e5015c..151ccb578d 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java @@ -72,7 +72,7 @@ public static Collection data() { public String apiShortNameExpected; @Parameterized.Parameter(3) - public String apiVersionExpected; + public String packageVersionExpected; @Test public void generateServiceClientClasses() { @@ -83,6 +83,6 @@ public void generateServiceClientClasses() { Assert.assertGoldenSamples( this.getClass(), name, clazz.classDefinition().packageString(), clazz.samples()); Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected); - Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected); + Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected); } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java index 9a9f4fb2e1..7a955fecd3 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java @@ -55,7 +55,7 @@ public static Collection data() { public String apiShortNameExpected; @Parameterized.Parameter(3) - public String apiVersionExpected; + public String packageVersionExpected; @Test public void generateServiceSettingsClasses() { @@ -69,6 +69,6 @@ public void generateServiceSettingsClasses() { clazz.classDefinition().packageString(), clazz.samples()); Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected); - Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected); + Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected); } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java index 387dba166f..8984c3550c 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java @@ -45,7 +45,7 @@ public static Collection data() { public String apiShortNameExpected; @Parameterized.Parameter(3) - public String apiVersionExpected; + public String packageVersionExpected; @Test public void generateServiceStubClasses() { @@ -55,6 +55,6 @@ public void generateServiceStubClasses() { Assert.assertGoldenClass(this.getClass(), clazz, name + ".golden"); Assert.assertEmptySamples(clazz.samples()); Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected); - Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected); + Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected); } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java index d552342d67..ff4f35bff7 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java @@ -67,7 +67,7 @@ public static Collection data() { public String apiShortNameExpected; @Parameterized.Parameter(3) - public String apiVersionExpected; + public String packageVersionExpected; @Test public void generateServiceStubSettingsClasses() { @@ -81,6 +81,6 @@ public void generateServiceStubSettingsClasses() { clazz.classDefinition().packageString(), clazz.samples()); Assert.assertCodeEquals(clazz.apiShortName(), apiShortNameExpected); - Assert.assertCodeEquals(clazz.apiVersion(), apiVersionExpected); + Assert.assertCodeEquals(clazz.packageVersion(), packageVersionExpected); } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/ServiceTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/ServiceTest.java index 82a3a7f2b9..10b82ec585 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/ServiceTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/ServiceTest.java @@ -16,24 +16,20 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import com.google.api.generator.engine.ast.TypeNode; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.Arrays; +import org.junit.Before; import org.junit.Test; public class ServiceTest { private static final String SHOWCASE_PACKAGE_NAME = "com.google.showcase.v1beta1"; - private static final Service.Builder testServiceBuilder = - Service.builder() - .setName("Echo") - .setDefaultHost("localhost:7469") - .setOauthScopes(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")) - .setPakkage(SHOWCASE_PACKAGE_NAME) - .setProtoPakkage(SHOWCASE_PACKAGE_NAME) - .setOriginalJavaPackage(SHOWCASE_PACKAGE_NAME) - .setOverriddenName("Echo"); + private Service.Builder testServiceBuilder; private static final Method.Builder testMethodBuilder = Method.builder() @@ -50,6 +46,19 @@ public class ServiceTest { .setIsAsteriskBody(false) .setHttpVerb(HttpBindings.HttpVerb.GET); + @Before + public void init() { + testServiceBuilder = + Service.builder() + .setName("Echo") + .setDefaultHost("localhost:7469") + .setOauthScopes(Arrays.asList("https://www.googleapis.com/auth/cloud-platform")) + .setPakkage(SHOWCASE_PACKAGE_NAME) + .setProtoPakkage(SHOWCASE_PACKAGE_NAME) + .setOriginalJavaPackage(SHOWCASE_PACKAGE_NAME) + .setOverriddenName("Echo"); + } + @Test public void apiShortName_shouldReturnApiShortNameIfHostContainsRegionalEndpoint() { String defaultHost = "us-east1-pubsub.googleapis.com"; @@ -79,17 +88,40 @@ public void apiShortName_shouldReturnHostIfNoPeriods() { } @Test - public void apiVersion_shouldReturnVersionIfMatch() { + public void packageVersion_shouldReturnVersionIfMatch() { String protoPackage = "com.google.showcase.v1"; Service testService = testServiceBuilder.setProtoPakkage(protoPackage).build(); - assertEquals("v1", testService.apiVersion()); + assertEquals("v1", testService.packageVersion()); } @Test - public void apiVersion_shouldReturnEmptyIfNoMatch() { + public void packageVersion_shouldReturnEmptyIfNoMatch() { String protoPackage = "com.google.showcase"; Service testService = testServiceBuilder.setProtoPakkage(protoPackage).build(); + assertEquals("", testService.packageVersion()); + } + + @Test + public void apiVersion_shouldReturnApiVersion() { + String apiVersion = "v1_20230601"; + Service testService = testServiceBuilder.setApiVersion(apiVersion).build(); + assertTrue(testService.hasApiVersion()); + assertEquals(apiVersion, testService.apiVersion()); + } + + @Test + public void apiVersion_shouldReturnNoApiVersionWhenNull() { + Service testService = testServiceBuilder.build(); + assertNull(testService.apiVersion()); + assertFalse(testService.hasApiVersion()); + } + + @Test + public void apiVersion_shouldReturnNoApiVersionWhenEmpty() { + String apiVersion = ""; + Service testService = testServiceBuilder.setApiVersion(apiVersion).build(); assertEquals("", testService.apiVersion()); + assertFalse(testService.hasApiVersion()); } @Test diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java index b4379fdf66..42462dd1c8 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -35,6 +36,7 @@ import com.google.api.generator.gapic.model.ResourceName; import com.google.api.generator.gapic.model.ResourceReference; import com.google.api.generator.gapic.model.Transport; +import com.google.api.version.test.ApiVersionTestingOuterClass; import com.google.auto.populate.field.AutoPopulateFieldTestingOuterClass; import com.google.bookshop.v1beta1.BookshopProto; import com.google.common.collect.ImmutableList; @@ -607,6 +609,76 @@ public void parseNestedProtoTypeName() { "google.ads.googleads.v3.resources.MutateJob.MutateJobMetadata")); } + @Test + public void parseServiceApiVersionTest() { + FileDescriptor apiVersionFileDescriptor = ApiVersionTestingOuterClass.getDescriptor(); + Map messageTypes = Parser.parseMessages(apiVersionFileDescriptor); + Map resourceNames = Parser.parseResourceNames(apiVersionFileDescriptor); + List services = + Parser.parseService( + apiVersionFileDescriptor, + messageTypes, + resourceNames, + Optional.empty(), + new HashSet<>()); + com.google.api.generator.gapic.model.Service parsedEchoService = services.get(0); + + assertEquals("Echo", parsedEchoService.overriddenName()); + assertTrue(parsedEchoService.hasApiVersion()); + assertEquals("fake_version", parsedEchoService.apiVersion()); + } + + @Test + public void parseServiceWithoutApiVersionTest() { + FileDescriptor apiVersionFileDescriptor = ApiVersionTestingOuterClass.getDescriptor(); + Map messageTypes = Parser.parseMessages(apiVersionFileDescriptor); + Map resourceNames = Parser.parseResourceNames(apiVersionFileDescriptor); + List services = + Parser.parseService( + apiVersionFileDescriptor, + messageTypes, + resourceNames, + Optional.empty(), + new HashSet<>()); + com.google.api.generator.gapic.model.Service parsedEchoWithoutVersionService = services.get(1); + + assertNull(parsedEchoWithoutVersionService.apiVersion()); + assertFalse(parsedEchoWithoutVersionService.hasApiVersion()); + assertEquals("EchoWithoutVersion", parsedEchoWithoutVersionService.overriddenName()); + } + + @Test + public void parseServiceWithEmptyApiVersionTest() { + FileDescriptor apiVersionFileDescriptor = ApiVersionTestingOuterClass.getDescriptor(); + Map messageTypes = Parser.parseMessages(apiVersionFileDescriptor); + Map resourceNames = Parser.parseResourceNames(apiVersionFileDescriptor); + List services = + Parser.parseService( + apiVersionFileDescriptor, + messageTypes, + resourceNames, + Optional.empty(), + new HashSet<>()); + com.google.api.generator.gapic.model.Service parsedEchoWithEmptyVersionService = + services.get(2); + + assertEquals("EchoWithEmptyVersion", parsedEchoWithEmptyVersionService.overriddenName()); + assertEquals("", parsedEchoWithEmptyVersionService.apiVersion()); + assertFalse(parsedEchoWithEmptyVersionService.hasApiVersion()); + } + + @Test + public void testServiceWithoutApiVersionParsed() { + FileDescriptor bookshopFileDescriptor = BookshopProto.getDescriptor(); + Map messageTypes = Parser.parseMessages(bookshopFileDescriptor); + Map resourceNames = Parser.parseResourceNames(bookshopFileDescriptor); + List services = + Parser.parseService( + bookshopFileDescriptor, messageTypes, resourceNames, Optional.empty(), new HashSet<>()); + com.google.api.generator.gapic.model.Service parsedBookshopService = services.get(0); + assertNull(parsedBookshopService.apiVersion()); + } + private void assertMethodArgumentEquals( String name, TypeNode type, List nestedFields, MethodArgument argument) { assertEquals(name, argument.name()); diff --git a/gapic-generator-java/src/test/proto/api_version_testing.proto b/gapic-generator-java/src/test/proto/api_version_testing.proto new file mode 100644 index 0000000000..52c7b6bdd9 --- /dev/null +++ b/gapic-generator-java/src/test/proto/api_version_testing.proto @@ -0,0 +1,264 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/field_info.proto"; +import "google/api/resource.proto"; +import "google/longrunning/operations.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/rpc/status.proto"; + +package google.api.version.test; + +option java_package = "com.google.api.version.test"; +option java_multiple_files = true; +option java_outer_classname = "ApiVersionTestingOuterClass"; + +option (google.api.resource_definition) = { + type: "showcase.googleapis.com/AnythingGoes" + pattern: "*" +}; +// This proto is used to test scenarios related to api_version feature. +// api_version is set on service level, so this proto includes various services +// to test different scenarios. + +// This service is used to test when api_version string is provided. +service Echo { + // This service is meant to only run locally on the port 7469 (keypad digits + // for "show"). + option (google.api.default_host) = "localhost:7469"; + option (google.api.api_version) = "fake_version"; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform"; + + // This method simply echos the request. This method is showcases unary rpcs. + rpc Echo(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1beta1/echo:echo" + body: "*" + }; + option (google.api.method_signature) = "content"; + option (google.api.method_signature) = "error"; + option (google.api.method_signature) = "content,severity"; + option (google.api.method_signature) = "name"; + option (google.api.method_signature) = "parent"; + option (google.api.method_signature) = ""; + } +} + +// This service is used to test when api_version is not provided. +service EchoWithoutVersion { + // This service is meant to only run locally on the port 7469 (keypad digits + // for "show"). + option (google.api.default_host) = "localhost:7469"; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform"; + + // This method simply echos the request. This method is showcases unary rpcs. + rpc Echo(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1beta1/echo:echo" + body: "*" + }; + option (google.api.method_signature) = "content"; + option (google.api.method_signature) = "error"; + option (google.api.method_signature) = "content,severity"; + option (google.api.method_signature) = "name"; + option (google.api.method_signature) = "parent"; + option (google.api.method_signature) = ""; + } +} + +// This service is to test api_version is empty. +service EchoWithEmptyVersion { + // This service is meant to only run locally on the port 7469 (keypad digits + // for "show"). + option (google.api.default_host) = "localhost:7469"; + option (google.api.api_version) = ""; + option (google.api.oauth_scopes) = + "https://www.googleapis.com/auth/cloud-platform"; + + // This method simply echos the request. This method is showcases unary rpcs. + rpc Echo(EchoRequest) returns (EchoResponse) { + option (google.api.http) = { + post: "/v1beta1/echo:echo" + body: "*" + }; + option (google.api.method_signature) = "content"; + option (google.api.method_signature) = "error"; + option (google.api.method_signature) = "content,severity"; + option (google.api.method_signature) = "name"; + option (google.api.method_signature) = "parent"; + option (google.api.method_signature) = ""; + } +} + +// A severity enum used to test enum capabilities in GAPIC surfaces +enum Severity { + UNNECESSARY = 0; + NECESSARY = 1; + URGENT = 2; + CRITICAL = 3; +} + +message Foobar { + option (google.api.resource) = { + type: "showcase.googleapis.com/Foobar" + pattern: "projects/{project}/foobars/{foobar}" + pattern: "projects/{project}/chocolate/variants/{variant}/foobars/{foobar}" + pattern: "foobars/{foobar}" + pattern: "bar_foos/{bar_foo}/foobars/{foobar}" + pattern: "*" + }; + + string name = 1; + string info = 2; +} + +// The request message used for the Echo, Collect and Chat methods. +// If content or opt are set in this message then the request will succeed. +// If status is set in this message +// then the status will be returned as an error. +message EchoRequest { + string name = 5 [ + (google.api.resource_reference).type = "showcase.googleapis.com/Foobar", + (google.api.field_behavior) = REQUIRED + ]; + + string parent = 6 [ + (google.api.resource_reference).child_type = + "showcase.googleapis.com/AnythingGoes", + (google.api.field_behavior) = REQUIRED + ]; + + oneof response { + // The content to be echoed by the server. + string content = 1; + + // The error to be thrown by the server. + google.rpc.Status error = 2; + } + + // The severity to be echoed by the server. + Severity severity = 3; + + Foobar foobar = 4; +} + +// The response message for the Echo methods. +message EchoResponse { + // The content specified in the request. + string content = 1; + + // The severity specified in the request. + Severity severity = 2; +} + +// Tests name collisions with java.lang.Object. +message Object { + // The content specified in the request. + string content = 1; +} + +// The request message for the Expand method. +message ExpandRequest { + // The content that will be split into words and returned on the stream. + string content = 1; + + // The error that is thrown after all words are sent on the stream. + google.rpc.Status error = 2; + + string info = 3; + +} + +// The request for the PagedExpand method. +message PagedExpandRequest { + // The string to expand. + string content = 1 [(google.api.field_behavior) = REQUIRED]; + + // The amount of words to returned in each page. + int32 page_size = 2; + + // The position of the page to be returned. + string page_token = 3; +} + +// The response for the PagedExpand method. +message PagedExpandResponse { + // The words that were expanded. + repeated EchoResponse responses = 1; + + // The next page token. + string next_page_token = 2; +} + +// The request for Wait method. +message WaitRequest { + oneof end { + // The time that this operation will complete. + google.protobuf.Timestamp end_time = 1; + + // The duration of this operation. + google.protobuf.Duration ttl = 4; + } + + oneof response { + // The error that will be returned by the server. If this code is specified + // to be the OK rpc code, an empty response will be returned. + google.rpc.Status error = 2; + + // The response to be returned on operation completion. + WaitResponse success = 3; + } +} + +// The result of the Wait operation. +message WaitResponse { + // This content of the result. + string content = 1; +} + +// The metadata for Wait operation. +message WaitMetadata { + // The time that this operation will complete. + google.protobuf.Timestamp end_time = 1; +} + +// The request for Block method. +message BlockRequest { + // The amount of time to block before returning a response. + google.protobuf.Duration response_delay = 1; + + oneof response { + // The error that will be returned by the server. If this code is specified + // to be the OK rpc code, an empty response will be returned. + google.rpc.Status error = 2; + + // The response to be returned that will signify successful method call. + BlockResponse success = 3; + } +} + +// The response for Block method. +message BlockResponse { + // This content can contain anything, the server will not depend on a value + // here. + string content = 1; +} From fe0481ec599f26f6cfe4df48b404da20ee447f57 Mon Sep 17 00:00:00 2001 From: hvadehra Date: Wed, 24 Apr 2024 17:16:19 +0200 Subject: [PATCH 08/25] chore: Add `load()`s for the Bazel builtin java rules (#2678) `load()` statements are being added to prepare for moving the rules out of Bazel and into `rules_java` Thank you for opening a Pull Request! For general contributing guidelines, please refer to [contributing guide](https://togithub.com/googleapis/gapic-generator-java/blob/main/CONTRIBUTING.md) Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/gapic-generator-java/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes https://togithub.com/googleapis/sdk-platform-java/issues/2683 --- gax-java/gax_java.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gax-java/gax_java.bzl b/gax-java/gax_java.bzl index 8276ab68bd..c9974575f4 100644 --- a/gax-java/gax_java.bzl +++ b/gax-java/gax_java.bzl @@ -26,13 +26,15 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +load("@rules_java//java:defs.bzl", "java_test") + def java_tests(name, srcs, runtime_deps, size): classNames = [] for src in srcs: # convert .java file path to fully qualified class name className = src[(src.index("/com/") + 1):-5].replace("/", ".") classNames.append(className) - native.java_test( + java_test( name = className, test_class = className, runtime_deps = runtime_deps, From e2680e1acf94fba0a86b3364a9a5888934edc3e9 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:15:29 -0400 Subject: [PATCH 09/25] chore: change report logic (#2689) In this PR: - Show the package information report regardless of the analysis result. - Change report format (verified in unit tests). --- .../com/google/cloud/DependencyAnalyzer.java | 13 ++- .../java/com/google/cloud/model/Advisory.java | 4 + .../google/cloud/model/AnalysisResult.java | 80 +++++------------ .../java/com/google/cloud/model/License.java | 9 +- .../com/google/cloud/model/PackageInfo.java | 4 +- .../cloud/model/AnalysisResultTest.java | 86 ++++++++++++++----- .../com/google/cloud/model/LicenseTest.java | 9 +- 7 files changed, 118 insertions(+), 87 deletions(-) diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java index 710d2ee9d4..7423af8f11 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/DependencyAnalyzer.java @@ -6,6 +6,7 @@ import com.google.cloud.model.Advisory; import com.google.cloud.model.AdvisoryKey; import com.google.cloud.model.AnalysisResult; +import com.google.cloud.model.License; import com.google.cloud.model.ReportResult; import com.google.cloud.model.PackageInfo; import com.google.cloud.model.QueryResult; @@ -52,11 +53,13 @@ public AnalysisResult analyze(String system, String packageName, String packageV List result = new ArrayList<>(); for (VersionKey versionKey : dependencies) { QueryResult packageInfo = depsDevClient.getQueryResult(versionKey); - List licenses = new ArrayList<>(); + List licenses = new ArrayList<>(); List advisories = new ArrayList<>(); for (Result res : packageInfo.results()) { Version version = res.version(); - licenses.addAll(version.licenses()); + for (String license : version.licenses()) { + licenses.add(License.toLicense(license)); + } for (AdvisoryKey advisoryKey : version.advisoryKeys()) { advisories.add(depsDevClient.getAdvisory(advisoryKey.id())); } @@ -65,7 +68,7 @@ public AnalysisResult analyze(String system, String packageName, String packageV result.add(new PackageInfo(versionKey, licenses, advisories)); } - return AnalysisResult.of(root, result); + return AnalysisResult.of(result); } /** @@ -109,7 +112,9 @@ public static void main(String[] args) throws IllegalArgumentException { System.exit(1); } - ReportResult result = analyzeReport.generateReport(); + System.out.println("Please copy and paste the package information below to your ticket.\n"); + System.out.println(analyzeReport.toString()); + ReportResult result = analyzeReport.getAnalysisResult(); System.out.println(result); if (result.equals(ReportResult.FAIL)) { System.out.println( diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/Advisory.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/Advisory.java index 542033dedd..dc08fda614 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/Advisory.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/Advisory.java @@ -22,5 +22,9 @@ public record Advisory( double cvss3Score, String cvss3Vector) { + @Override + public String toString() { + return String.format("Advisory (id: %s, more info: [%s](%s))", advisoryKey.id(), title, url); + } } diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java index d675679bbc..006764055d 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/AnalysisResult.java @@ -7,49 +7,34 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; public class AnalysisResult { - private final VersionKey root; private final List packageInfos; private final Map> advisories; - private final Map> nonCompliantLicenses; + private final Map> nonCompliantLicenses; - private final static Logger LOGGER = Logger.getLogger(AnalysisResult.class.getName()); - - private AnalysisResult(VersionKey root, List result) { - this.root = root; + private AnalysisResult(List result) { this.packageInfos = result; this.advisories = getAdvisories(result); this.nonCompliantLicenses = getNonCompliantLicenses(result); } - public static AnalysisResult of(VersionKey root, List result) { - return new AnalysisResult(root, result); + public static AnalysisResult of(List result) { + return new AnalysisResult(result); } - public ReportResult generateReport() { - if (!advisories.isEmpty()) { - formatLog(root, advisories, "New security vulnerability found in dependencies:"); - } - - if (!nonCompliantLicenses.isEmpty()) { - formatLog(root, nonCompliantLicenses, "Non-compliant license found in dependencies:"); + public ReportResult getAnalysisResult() { + if (advisories.isEmpty() && nonCompliantLicenses.isEmpty()) { + return ReportResult.PASS; } - if (!advisories.isEmpty() || !nonCompliantLicenses.isEmpty()) { - LOGGER.log(Level.SEVERE, String.format("Found dependency risk in %s", root)); - return ReportResult.FAIL; - } - - LOGGER.log(Level.INFO, - String.format("%s have no known vulnerabilities and non compliant licenses", root)); - LOGGER.log(Level.INFO, "Generate package information report..."); - System.out.println(packageInfoReport()); + return ReportResult.FAIL; + } - return ReportResult.PASS; + @Override + public String toString() { + return packageInfoReport(); } private Map> getAdvisories(List result) { @@ -63,14 +48,13 @@ private Map> getAdvisories(List result) return advisories; } - private Map> getNonCompliantLicenses(List result) { - Map> licenses = new HashMap<>(); + private Map> getNonCompliantLicenses(List result) { + Map> licenses = new HashMap<>(); Set compliantCategories = LicenseCategory.compliantCategories(); result.forEach(packageInfo -> { - List nonCompliantLicenses = new ArrayList<>(); - for (String licenseStr : packageInfo.licenses()) { - License license = License.toLicense(licenseStr); + List nonCompliantLicenses = new ArrayList<>(); + for (License license : packageInfo.licenses()) { // fiter out all compliant categories, the remaining ones are non-compliant. List nonCompliantCategories = license .getCategories() @@ -78,7 +62,7 @@ private Map> getNonCompliantLicenses(List .filter(category -> !compliantCategories.contains(category)) .toList(); if (!nonCompliantCategories.isEmpty()) { - nonCompliantLicenses.add(licenseStr); + nonCompliantLicenses.add(license); } } if (!nonCompliantLicenses.isEmpty()) { @@ -88,39 +72,18 @@ private Map> getNonCompliantLicenses(List return licenses; } - private void formatLog(VersionKey root, Map> map, String message) { - LOGGER.log(Level.SEVERE, message); - map.forEach((versionKey, list) -> { - LOGGER.log(Level.SEVERE, beginSeparator(versionKey, root)); - list.forEach(item -> LOGGER.log(Level.SEVERE, item.toString())); - LOGGER.log(Level.SEVERE, endSeparator()); - }); - } - - private String beginSeparator(VersionKey versionKey, VersionKey root) { - String relation = versionKey.equals(root) ? "self" : "dependency"; - return String.format("====================== %s, %s of %s ======================", - versionKey, relation, root); - } - - private String endSeparator() { - return "==========================================================="; - } - - public String packageInfoReport() { + private String packageInfoReport() { StringBuilder builder = new StringBuilder(); PackageInfo root = packageInfos.get(0); String title = String.format(""" - Please copy and paste the package information below to your ticket. - ## Package information of %s %s """, root.versionKey(), packageInfoSection(root)); builder.append(title); - builder.append("## Dependencies:\n"); + builder.append("## Dependencies\n"); if (packageInfos.size() == 1) { - builder.append("None"); + builder.append(String.format("%s has no dependency.", root.versionKey())); } else { for (int i = 1; i < packageInfos.size(); i++) { PackageInfo info = packageInfos.get(i); @@ -141,11 +104,12 @@ private String packageInfoSection(PackageInfo packageInfo) { // generate the report using Markdown format. String packageInfoReport = """ Licenses: %s - Vulnerabilities: None. + Vulnerabilities: %s. Checked in [%s (%s)](%s) """; return String.format(packageInfoReport, packageInfo.licenses(), + packageInfo.advisories(), versionKey.name(), versionKey.version(), getQueryUrl( diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java index 83ed971e7b..246cff06b1 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/License.java @@ -51,12 +51,17 @@ public Set getCategories() { @Override public String toString() { + String nonCompliantPrefix = "%s (Not Google-compliant!)"; + String compliantPrefix = "%s (Google-compliant)"; Set compliantCategories = LicenseCategory.compliantCategories(); + if (this.categories.isEmpty()) { + return String.format(nonCompliantPrefix, this.licenseStr); + } for (LicenseCategory category : this.categories) { if (!compliantCategories.contains(category)) { - return this.licenseStr; + return String.format(nonCompliantPrefix, this.licenseStr); } } - return String.format("%s (Google-compliant)", this.licenseStr); + return String.format(compliantPrefix, this.licenseStr); } } diff --git a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/PackageInfo.java b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/PackageInfo.java index 046fcf80aa..7aa1f12768 100644 --- a/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/PackageInfo.java +++ b/java-shared-dependencies/dependency-analyzer/src/main/java/com/google/cloud/model/PackageInfo.java @@ -9,10 +9,10 @@ */ public record PackageInfo( VersionKey versionKey, - List licenses, + List licenses, List advisories) { - public List licenses() { + public List licenses() { return ImmutableList.copyOf(licenses); } diff --git a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java index 3dc7986966..ab3bd50b0e 100644 --- a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java +++ b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/AnalysisResultTest.java @@ -9,7 +9,7 @@ public class AnalysisResultTest { @Test - public void testGenerateReportWithAdvisoriesThrowsException() + public void testGenerateReportWithAdvisoriesReturnsFailure() throws IllegalArgumentException { VersionKey root = VersionKey.from("maven", "com.example:artifact", "1.2.3"); List results = List.of( @@ -26,22 +26,22 @@ public void testGenerateReportWithAdvisoriesThrowsException() )) ) ); - ReportResult result = AnalysisResult.of(root, results).generateReport(); + ReportResult result = AnalysisResult.of(results).getAnalysisResult(); assertEquals(ReportResult.FAIL, result); } @Test - public void testGenerateReportWithNonCompliantLicenseThrowsException() + public void testGenerateReportWithNonCompliantLicenseReturnsFailure() throws IllegalArgumentException { VersionKey root = VersionKey.from("maven", "com.example:artifact", "1.2.3"); List results = List.of( new PackageInfo( root, - List.of("BCL"), + List.of(License.toLicense("BCL")), List.of() ) ); - ReportResult result = AnalysisResult.of(root, results).generateReport(); + ReportResult result = AnalysisResult.of(results).getAnalysisResult(); assertEquals(ReportResult.FAIL, result); } @@ -52,54 +52,100 @@ public void testGenerateReportWithoutRiskSucceeds() List results = List.of( new PackageInfo( root, - List.of("Apache-2.0"), + List.of(License.toLicense("Apache-2.0")), List.of() ) ); - ReportResult result = AnalysisResult.of(root, results).generateReport(); + ReportResult result = AnalysisResult.of(results).getAnalysisResult(); assertEquals(ReportResult.PASS, result); } @Test - public void testPackageInfoReportReturnsCorrectContents() { + public void testToStringReturnsNoRiskInformation() { VersionKey root = VersionKey.from("maven", "com.example:artifact", "1.2.3"); List results = List.of( new PackageInfo( root, - List.of("Apache-2.0"), + List.of(License.toLicense("Apache-2.0")), List.of() ), new PackageInfo( VersionKey.from("maven", "com.example:dependency", "4.5.6"), - List.of("Apache-2.0", "MIT"), + List.of(License.toLicense("Apache-2.0"), License.toLicense("MIT")), List.of() ), new PackageInfo( VersionKey.from("maven", "com.example:nested-dependency", "2.3.1"), - List.of("Apache-2.0", "MIT"), + List.of(License.toLicense("Apache-2.0"), License.toLicense("MIT")), List.of() ) ); assertEquals(""" - Please copy and paste the package information below to your ticket. + ## Package information of com.example:artifact:1.2.3 + Licenses: [Apache-2.0 (Google-compliant)] + Vulnerabilities: []. + Checked in [com.example:artifact (1.2.3)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:artifact&versionKey.version=1.2.3) + + ## Dependencies + ### Package information of com.example:dependency:4.5.6 + Licenses: [Apache-2.0 (Google-compliant), MIT (Google-compliant)] + Vulnerabilities: []. + Checked in [com.example:dependency (4.5.6)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:dependency&versionKey.version=4.5.6) + + ### Package information of com.example:nested-dependency:2.3.1 + Licenses: [Apache-2.0 (Google-compliant), MIT (Google-compliant)] + Vulnerabilities: []. + Checked in [com.example:nested-dependency (2.3.1)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:nested-dependency&versionKey.version=2.3.1) + + """, AnalysisResult.of(results).toString()); + } + + @Test + public void testToStringReturnsRiskInformation() { + VersionKey root = VersionKey.from("maven", "com.example:artifact", "1.2.3"); + List results = List.of( + new PackageInfo( + root, + List.of(License.APACHE_2_0, License.BCL), + List.of() + ), + new PackageInfo( + VersionKey.from("maven", "com.example:dependency", "4.5.6"), + List.of(License.MIT), + List.of(new Advisory( + new AdvisoryKey("GHSA-2qrg-x229-3v8q"), + "https://osv.dev/vulnerability/GHSA-2qrg-x229-3v8q", + "Deserialization of Untrusted Data in Log4j", + new String[]{"CVE-2019-17571"}, + 9.8, + "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H" + )) + ), + new PackageInfo( + VersionKey.from("maven", "com.example:nested-dependency", "2.3.1"), + List.of(License.MIT, License.GL2PS), + List.of() + ) + ); + assertEquals(""" ## Package information of com.example:artifact:1.2.3 - Licenses: [Apache-2.0] - Vulnerabilities: None. + Licenses: [Apache-2.0 (Google-compliant), BCL (Not Google-compliant!)] + Vulnerabilities: []. Checked in [com.example:artifact (1.2.3)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:artifact&versionKey.version=1.2.3) - ## Dependencies: + ## Dependencies ### Package information of com.example:dependency:4.5.6 - Licenses: [Apache-2.0, MIT] - Vulnerabilities: None. + Licenses: [MIT (Google-compliant)] + Vulnerabilities: [Advisory (id: GHSA-2qrg-x229-3v8q, more info: [Deserialization of Untrusted Data in Log4j](https://osv.dev/vulnerability/GHSA-2qrg-x229-3v8q))]. Checked in [com.example:dependency (4.5.6)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:dependency&versionKey.version=4.5.6) ### Package information of com.example:nested-dependency:2.3.1 - Licenses: [Apache-2.0, MIT] - Vulnerabilities: None. + Licenses: [MIT (Google-compliant), GL2PS (Not Google-compliant!)] + Vulnerabilities: []. Checked in [com.example:nested-dependency (2.3.1)](https://api.deps.dev/v3/query?versionKey.system=MAVEN&versionKey.name=com.example:nested-dependency&versionKey.version=2.3.1) - """, AnalysisResult.of(root, results).packageInfoReport()); + """, AnalysisResult.of(results).toString()); } } diff --git a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java index 1637462297..9973a50eb5 100644 --- a/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java +++ b/java-shared-dependencies/dependency-analyzer/src/test/java/com/google/cloud/model/LicenseTest.java @@ -5,6 +5,7 @@ import org.junit.Test; public class LicenseTest { + @Test public void testToLicenseSucceeds() { String license = "Apache-2.0"; @@ -26,6 +27,12 @@ public void testToStringOfACompliantLicense() { @Test public void testToStringOfANonCompliantLicense() { String license = "BCL"; - assertEquals("BCL", License.toLicense(license).toString()); + assertEquals("BCL (Not Google-compliant!)", License.toLicense(license).toString()); + } + + @Test + public void testToStringOfANotRecognizedLicense() { + String license = "Non-existent-license"; + assertEquals("Not-Recognized (Not Google-compliant!)", License.toLicense(license).toString()); } } From 4e92be8885af8633ea5b3371c43be9423a0f95ef Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:19:52 -0400 Subject: [PATCH 10/25] fix: change folder prefix for adding headers (#2688) In this PR: - Change post processor to add header when the folder name starts with `proto-` or `grpc-`. - Change post processor to add pom.xml when the folder name starts with `proto-` or `grpc-`. Context: we received a library generation request which the library name doesn't start with `google-` (b/329445405). The generated library has two issues: 1) pom.xml is not generated in `proto-` folder; 2) files in `proto-` folder have no header. This library uses REST so no `grpc-` folder was generated. --- library_generation/owlbot/src/fix-license-headers.py | 4 ++-- library_generation/owlbot/src/fix-poms.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library_generation/owlbot/src/fix-license-headers.py b/library_generation/owlbot/src/fix-license-headers.py index 50f9f7fce0..1c690b5d39 100644 --- a/library_generation/owlbot/src/fix-license-headers.py +++ b/library_generation/owlbot/src/fix-license-headers.py @@ -21,10 +21,10 @@ # Until the generator generates license headers on generated proto # classes, add the license headers in -for path in glob.glob("proto-google-*"): +for path in glob.glob("proto-*"): java.fix_proto_headers(root / path) # Until the generator generates license headers on generated grpc # classes, add the license headers in -for path in glob.glob("grpc-google-*"): +for path in glob.glob("grpc-*"): java.fix_grpc_headers(root / path, "unused") diff --git a/library_generation/owlbot/src/fix-poms.py b/library_generation/owlbot/src/fix-poms.py index 4bfbe05057..1de814e9ce 100644 --- a/library_generation/owlbot/src/fix-poms.py +++ b/library_generation/owlbot/src/fix-poms.py @@ -383,7 +383,7 @@ def main(versions_file, monorepo): # Missing Case 2: There's a new proto-XXX and grpc-XXX directory. It's a new # version in the proto file to a library. Both a new library and existing # library. - for path in glob.glob("proto-google-*"): + for path in glob.glob("proto-*"): if not path in existing_modules: existing_modules[path] = module.Module( group_id=__proto_group_id(group_id), @@ -422,7 +422,7 @@ def main(versions_file, monorepo): release_version=main_module.release_version, ) - for path in glob.glob("grpc-google-*"): + for path in glob.glob("grpc-*"): if not path in existing_modules: existing_modules[path] = module.Module( group_id=__proto_group_id(group_id), From 75352d197f1744435cca83ac788edea51de787f8 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:20:03 -0400 Subject: [PATCH 11/25] chore: change protobuf_version to protoc_version (#2686) In this PR: - Change `protobuf_version` to `protoc_version`. --- library_generation/README.md | 4 +- .../generate_composed_library.py | 2 +- library_generation/generate_library.sh | 10 ++-- library_generation/model/generation_config.py | 6 +-- .../test/generate_library_unit_tests.sh | 52 +++++++++---------- .../generate_pr_description_unit_tests.py | 2 +- .../test/model/config_change_unit_tests.py | 2 +- .../test/model/generation_config_unit_test.py | 2 +- .../baseline_generation_config.yaml | 2 +- .../current_generation_config.yaml | 2 +- .../java-bigtable/generation_config.yaml | 2 +- .../test-config/generation_config.yaml | 2 +- ...generation_config_comparator_unit_tests.py | 10 ++-- library_generation/utils/utilities.sh | 30 +++++------ 14 files changed, 64 insertions(+), 64 deletions(-) diff --git a/library_generation/README.md b/library_generation/README.md index 50ea1afe9c..4a51f665ef 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -94,7 +94,7 @@ They are shared by library level parameters. | Name | Required | Notes | |:------------------------|:--------:|:---------------------------------------------| | gapic_generator_version | Yes | | -| protobuf_version | No | inferred from the generator if not specified | +| protoc_version | No | inferred from the generator if not specified | | grpc_version | No | inferred from the generator if not specified | | googleapis-commitish | Yes | | | libraries_bom_version | Yes | | @@ -146,7 +146,7 @@ The GAPIC level parameters define how to generate a GAPIC library. ```yaml gapic_generator_version: 2.34.0 -protobuf_version: 25.2 +protoc_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 libraries_bom_version: 26.37.0 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index 12f21dec9c..a2f8d9f401 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -130,7 +130,7 @@ def __construct_tooling_arg(config: GenerationConfig) -> List[str]: arguments = [] arguments += util.create_argument("gapic_generator_version", config) arguments += util.create_argument("grpc_version", config) - arguments += util.create_argument("protobuf_version", config) + arguments += util.create_argument("protoc_version", config) return arguments diff --git a/library_generation/generate_library.sh b/library_generation/generate_library.sh index a5d73ebec4..88c2052b56 100755 --- a/library_generation/generate_library.sh +++ b/library_generation/generate_library.sh @@ -20,8 +20,8 @@ case $key in export gapic_generator_version shift ;; - --protobuf_version) - protobuf_version="$2" + --protoc_version) + protoc_version="$2" shift ;; --grpc_version) @@ -82,8 +82,8 @@ if [ -z "${gapic_generator_version}" ]; then exit 1 fi -if [ -z "${protobuf_version}" ]; then - protobuf_version=$(get_protobuf_version "${gapic_generator_version}") +if [ -z "${protoc_version}" ]; then + protoc_version=$(get_protoc_version "${gapic_generator_version}") fi if [ -z "${grpc_version}" ]; then @@ -177,7 +177,7 @@ case "${proto_path}" in ;; esac # download gapic-generator-java, protobuf and grpc plugin. -download_tools "${gapic_generator_version}" "${protobuf_version}" "${grpc_version}" "${os_architecture}" +download_tools "${gapic_generator_version}" "${protoc_version}" "${grpc_version}" "${os_architecture}" ##################### Section 1 ##################### # generate grpc-*/ ##################################################### diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 97eebe6788..650f4a45ba 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -35,7 +35,7 @@ def __init__( template_excludes: List[str], libraries: List[LibraryConfig], grpc_version: Optional[str] = None, - protobuf_version: Optional[str] = None, + protoc_version: Optional[str] = None, ): self.gapic_generator_version = gapic_generator_version self.googleapis_commitish = googleapis_commitish @@ -45,7 +45,7 @@ def __init__( self.template_excludes = template_excludes self.libraries = libraries self.grpc_version = grpc_version - self.protobuf_version = protobuf_version + self.protoc_version = protoc_version def get_proto_path_to_library_name(self) -> dict[str, str]: """ @@ -116,7 +116,7 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: parsed_config = GenerationConfig( gapic_generator_version=__required(config, "gapic_generator_version"), grpc_version=__optional(config, "grpc_version", None), - protobuf_version=__optional(config, "protobuf_version", None), + protoc_version=__optional(config, "protoc_version", None), googleapis_commitish=__required(config, "googleapis_commitish"), libraries_bom_version=__required(config, "libraries_bom_version"), owlbot_cli_image=__required(config, "owlbot_cli_image"), diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index ac499435c8..9b5f8bc456 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -28,16 +28,16 @@ get_grpc_version_failed_with_invalid_generator_version_test() { assertEquals 1 $((res)) } -get_protobuf_version_succeed_with_valid_generator_version_test() { +get_protoc_version_succeed_with_valid_generator_version_test() { local actual_version - actual_version=$(get_protobuf_version "2.24.0") + actual_version=$(get_protoc_version "2.24.0") assertEquals "23.2" "${actual_version}" rm "gapic-generator-java-pom-parent-2.24.0.pom" } -get_protobuf_version_failed_with_invalid_generator_version_test() { +get_protoc_version_failed_with_invalid_generator_version_test() { local res=0 - $(get_protobuf_version "1.99.0") || res=$? + $(get_protoc_version "1.99.0") || res=$? assertEquals 1 $((res)) } @@ -110,27 +110,27 @@ download_generator_failed_with_invalid_version_test() { assertEquals 1 $((res)) } -download_protobuf_succeed_with_valid_version_linux_test() { - download_protobuf "23.2" "linux-x86_64" - assertFileOrDirectoryExists "protobuf-23.2" - rm -rf "protobuf-23.2" +download_protoc_succeed_with_valid_version_linux_test() { + download_protoc "23.2" "linux-x86_64" + assertFileOrDirectoryExists "protoc-23.2" + rm -rf "protoc-23.2" } -download_protobuf_succeed_with_valid_version_macos_test() { - download_protobuf "23.2" "osx-x86_64" - assertFileOrDirectoryExists "protobuf-23.2" - rm -rf "protobuf-23.2" "google" +download_protoc_succeed_with_valid_version_macos_test() { + download_protoc "23.2" "osx-x86_64" + assertFileOrDirectoryExists "protoc-23.2" + rm -rf "protoc-23.2" "google" } -download_protobuf_failed_with_invalid_version_linux_test() { +download_protoc_failed_with_invalid_version_linux_test() { local res=0 - $(download_protobuf "22.99" "linux-x86_64") || res=$? + $(download_protoc "22.99" "linux-x86_64") || res=$? assertEquals 1 $((res)) } -download_protobuf_failed_with_invalid_arch_test() { +download_protoc_failed_with_invalid_arch_test() { local res=0 - $(download_protobuf "23.2" "customized-x86_64") || res=$? + $(download_protoc "23.2" "customized-x86_64") || res=$? assertEquals 1 $((res)) } @@ -166,7 +166,7 @@ generate_library_failed_with_invalid_generator_version() { -p google/cloud/alloydb/v1 \ -d ../"${destination}" \ --gapic_generator_version 1.99.0 \ - --protobuf_version 23.2 \ + --protoc_version 23.2 \ --grpc_version 1.55.1 \ --transport grpc+rest \ --rest_numeric_enums true || res=$? @@ -175,7 +175,7 @@ generate_library_failed_with_invalid_generator_version() { cleanup "${destination}" } -generate_library_failed_with_invalid_protobuf_version() { +generate_library_failed_with_invalid_protoc_version() { local destination="google-cloud-alloydb-v1-java" local res=0 cd "${script_dir}/resources" @@ -183,7 +183,7 @@ generate_library_failed_with_invalid_protobuf_version() { -p google/cloud/alloydb/v1 \ -d ../"${destination}" \ --gapic_generator_version 2.24.0 \ - --protobuf_version 22.99 \ + --protoc_version 22.99 \ --grpc_version 1.55.1 \ --transport grpc+rest \ --rest_numeric_enums true || res=$? @@ -256,24 +256,24 @@ test_list=( extract_folder_name_test get_grpc_version_succeed_with_valid_generator_version_test get_grpc_version_failed_with_invalid_generator_version_test - get_protobuf_version_succeed_with_valid_generator_version_test - get_protobuf_version_failed_with_invalid_generator_version_test + get_protoc_version_succeed_with_valid_generator_version_test + get_protoc_version_failed_with_invalid_generator_version_test get_gapic_opts_with_rest_test get_gapic_opts_without_rest_test get_gapic_opts_with_non_default_test remove_grpc_version_test download_generator_success_with_valid_version_test download_generator_failed_with_invalid_version_test - download_protobuf_succeed_with_valid_version_linux_test - download_protobuf_succeed_with_valid_version_macos_test - download_protobuf_failed_with_invalid_version_linux_test - download_protobuf_failed_with_invalid_arch_test + download_protoc_succeed_with_valid_version_linux_test + download_protoc_succeed_with_valid_version_macos_test + download_protoc_failed_with_invalid_version_linux_test + download_protoc_failed_with_invalid_arch_test download_grpc_plugin_succeed_with_valid_version_linux_test download_grpc_plugin_succeed_with_valid_version_macos_test download_grpc_plugin_failed_with_invalid_version_linux_test download_grpc_plugin_failed_with_invalid_arch_test generate_library_failed_with_invalid_generator_version - generate_library_failed_with_invalid_protobuf_version + generate_library_failed_with_invalid_protoc_version generate_library_failed_with_invalid_grpc_version copy_directory_if_exists_valid_folder_succeeds copy_directory_if_exists_invalid_folder_does_not_copy diff --git a/library_generation/test/generate_pr_description_unit_tests.py b/library_generation/test/generate_pr_description_unit_tests.py index c633268aa4..c977728859 100644 --- a/library_generation/test/generate_pr_description_unit_tests.py +++ b/library_generation/test/generate_pr_description_unit_tests.py @@ -65,7 +65,7 @@ def test_generate_pr_description_with_same_googleapis_commits(self): synthtool_commitish="", template_excludes=[], grpc_version="", - protobuf_version="", + protoc_version="", libraries=[], ), baseline_commit=commit_sha, diff --git a/library_generation/test/model/config_change_unit_tests.py b/library_generation/test/model/config_change_unit_tests.py index 388dd1f614..323edd3cc0 100644 --- a/library_generation/test/model/config_change_unit_tests.py +++ b/library_generation/test/model/config_change_unit_tests.py @@ -244,7 +244,7 @@ def __get_a_gen_config( synthtool_commitish="", template_excludes=[], grpc_version="", - protobuf_version="", + protoc_version="", libraries=libraries, ) diff --git a/library_generation/test/model/generation_config_unit_test.py b/library_generation/test/model/generation_config_unit_test.py index 08fea21523..fd7608bb4f 100644 --- a/library_generation/test/model/generation_config_unit_test.py +++ b/library_generation/test/model/generation_config_unit_test.py @@ -41,7 +41,7 @@ class GenerationConfigTest(unittest.TestCase): def test_from_yaml_succeeds(self): config = from_yaml(f"{test_config_dir}/generation_config.yaml") self.assertEqual("2.34.0", config.gapic_generator_version) - self.assertEqual(25.2, config.protobuf_version) + self.assertEqual(25.2, config.protoc_version) self.assertEqual( "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish ) diff --git a/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml index 9bfa47a7c5..6a100856b7 100644 --- a/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml @@ -1,5 +1,5 @@ gapic_generator_version: 2.38.1 -protobuf_version: 25.2 +protoc_version: 25.2 googleapis_commitish: a17d4caf184b050d50cacf2b0d579ce72c31ce74 libraries_bom_version: 26.37.0 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 diff --git a/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml index 447c525424..e34916a344 100644 --- a/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml @@ -1,5 +1,5 @@ gapic_generator_version: 2.38.1 -protobuf_version: 25.2 +protoc_version: 25.2 googleapis_commitish: 4ce0ff67a3d4509be641cbe47a35844ddc1268fc libraries_bom_version: 26.37.0 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 diff --git a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml index 48afd9eef7..f1eb4948d5 100644 --- a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml +++ b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml @@ -1,5 +1,5 @@ gapic_generator_version: 2.37.0 -protobuf_version: 25.2 +protoc_version: 25.2 googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 synthtool_commitish: a6fb7d5f072b75698af1cbf06c5b001565753cfb diff --git a/library_generation/test/resources/test-config/generation_config.yaml b/library_generation/test/resources/test-config/generation_config.yaml index a6deecfeeb..8930e982da 100644 --- a/library_generation/test/resources/test-config/generation_config.yaml +++ b/library_generation/test/resources/test-config/generation_config.yaml @@ -1,5 +1,5 @@ gapic_generator_version: 2.34.0 -protobuf_version: 25.2 +protoc_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 libraries_bom_version: 26.37.0 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 diff --git a/library_generation/test/utils/generation_config_comparator_unit_tests.py b/library_generation/test/utils/generation_config_comparator_unit_tests.py index a782cebe21..04d9661fcd 100644 --- a/library_generation/test/utils/generation_config_comparator_unit_tests.py +++ b/library_generation/test/utils/generation_config_comparator_unit_tests.py @@ -44,7 +44,7 @@ def setUp(self) -> None: synthtool_commitish="", template_excludes=[], grpc_version="", - protobuf_version="", + protoc_version="", libraries=[self.baseline_library], ) self.current_config = GenerationConfig( @@ -55,7 +55,7 @@ def setUp(self) -> None: synthtool_commitish="", template_excludes=[], grpc_version="", - protobuf_version="", + protoc_version="", libraries=[self.current_library], ) @@ -136,8 +136,8 @@ def test_compare_config_synthtool_update(self): self.assertEqual("commit456", config_change.current_value) def test_compare_protobuf_update(self): - self.baseline_config.protobuf_version = "3.25.2" - self.current_config.protobuf_version = "3.27.0" + self.baseline_config.protoc_version = "3.25.2" + self.current_config.protoc_version = "3.27.0" result = compare_config( baseline_config=self.baseline_config, current_config=self.current_config, @@ -146,7 +146,7 @@ def test_compare_protobuf_update(self): len(result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE]) == 1 ) config_change = result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE][0] - self.assertEqual("protobuf_version", config_change.changed_param) + self.assertEqual("protoc_version", config_change.changed_param) self.assertEqual("3.27.0", config_change.current_value) def test_compare_config_grpc_update(self): diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 1c3feb937b..16ad766ce5 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -108,25 +108,25 @@ get_grpc_version() { echo "${grpc_version}" } -get_protobuf_version() { +get_protoc_version() { local gapic_generator_version=$1 - local protobuf_version + local protoc_version pushd "${output_folder}" > /dev/null # get protobuf version from gapic-generator-java-pom-parent/pom.xml download_gapic_generator_pom_parent "${gapic_generator_version}" - protobuf_version=$(grep protobuf.version "gapic-generator-java-pom-parent-${gapic_generator_version}.pom" | sed 's/\(.*\)<\/protobuf\.version>/\1/' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | cut -d "." -f2-) + protoc_version=$(grep protobuf.version "gapic-generator-java-pom-parent-${gapic_generator_version}.pom" | sed 's/\(.*\)<\/protobuf\.version>/\1/' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | cut -d "." -f2-) popd > /dev/null - echo "${protobuf_version}" + echo "${protoc_version}" } download_tools() { local gapic_generator_version=$1 - local protobuf_version=$2 + local protoc_version=$2 local grpc_version=$3 local os_architecture=$4 pushd "${output_folder}" download_generator_artifact "${gapic_generator_version}" "gapic-generator-java-${gapic_generator_version}.jar" - download_protobuf "${protobuf_version}" "${os_architecture}" + download_protoc "${protoc_version}" "${os_architecture}" download_grpc_plugin "${grpc_version}" "${os_architecture}" popd } @@ -154,22 +154,22 @@ download_generator_artifact() { fi } -download_protobuf() { - local protobuf_version=$1 +download_protoc() { + local protoc_version=$1 local os_architecture=$2 - if [ ! -d "protobuf-${protobuf_version}" ]; then + if [ ! -d "protoc-${protoc_version}" ]; then # pull proto files and protoc from protobuf repository as maven central # doesn't have proto files download_from \ - "https://github.com/protocolbuffers/protobuf/releases/download/v${protobuf_version}/protoc-${protobuf_version}-${os_architecture}.zip" \ - "protobuf-${protobuf_version}.zip" \ + "https://github.com/protocolbuffers/protobuf/releases/download/v${protoc_version}/protoc-${protoc_version}-${os_architecture}.zip" \ + "protoc-${protoc_version}.zip" \ "GitHub" - unzip -o -q "protobuf-${protobuf_version}.zip" -d "protobuf-${protobuf_version}" - cp -r "protobuf-${protobuf_version}/include/google" . - rm "protobuf-${protobuf_version}.zip" + unzip -o -q "protoc-${protoc_version}.zip" -d "protoc-${protoc_version}" + cp -r "protoc-${protoc_version}/include/google" . + rm "protoc-${protoc_version}.zip" fi - protoc_path="${output_folder}/protobuf-${protobuf_version}/bin" + protoc_path="${output_folder}/protoc-${protoc_version}/bin" } download_grpc_plugin() { From 849bb503b9e09310e8225c2997a5ceeb866dab31 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Fri, 26 Apr 2024 12:31:04 -0400 Subject: [PATCH 12/25] chore: fix confusing step name (#2692) This is step does `mvn install` and is not only unit tests. --- .github/workflows/nightly.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index 355a651f55..12e239ae8c 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -23,7 +23,7 @@ jobs: distribution: temurin cache: maven - run: mvn -version - - name: Unit Tests + - name: Install run: mvn install --errors --batch-mode --no-transfer-progress -Dcheckstyle.skip -T 1C - name: Create issue if previous step fails if: ${{ failure() }} From e63d1b49159be07f0bb32bfe9d15c8445ac883c8 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Fri, 26 Apr 2024 17:30:49 -0400 Subject: [PATCH 13/25] feat: Update Gapic generator and Gax to emit api-versioning via header (#2671) This is part 2, following changes in https://github.com/googleapis/sdk-platform-java/pull/2630 Changes in this pr: - ApiClientHeaderProvider: add key and token setter for api version. - AbstractServiceStubSettingsClassComposer: add logic to set this header when api-version is present (not null or empty) - Unit and golden tests to reflect above changes. (This includeds a few new golden files created for tests based on the dedicated proto created in #2630) This pr does not include gapic-showcased testing for now. --- manual tested with [gapic-showcase](https://github.com/googleapis/gapic-showcase) v0.33.0 steps: - Use gapic-showcase v0.33.0 (which includes update in 1484) - use `gapic-showcase run -v` which prints the request header - From showcase folder, run `mvn verify -P enable-integration-tests -Dit.test=ITAutoPopulatedFields.java -pl=gapic-showcase` Printed header in manual testing Grpc ``` 2024/04/16 10:26:41 Received Unary Request for Method: /google.showcase.v1beta1.Echo/Echo 2024/04/16 10:26:41 Request headers: 2024/04/16 10:26:41 grpc-accept-encoding: gzip 2024/04/16 10:26:41 content-type: application/grpc 2024/04/16 10:26:41 x-goog-api-version: v1_20240408 2024/04/16 10:26:41 :authority: localhost:7469 2024/04/16 10:26:41 user-agent: grpc-java-netty/1.62.2 2024/04/16 10:26:41 x-goog-api-client: gl-java/17.0.7__Eclipse-Adoptium__Temurin-17.0.7-7 gapic/0.0.1-SNAPSHOT gax/2.46.2-SNAPSHOT grpc/1.62.2 2024/04/16 10:26:41 Request: error:{code:2} request_id:"1e26ee16-ed07-4eeb-be0e-49b769678779" other_request_id:"40883e5d-3b20-4add-854c-9808bd009260" 2024/04/16 10:26:41 Returning Error: rpc error: code = Unknown desc = ``` Httpjson ``` 2024/04/16 10:26:41 Received POST request matching '/v1beta1/echo:echo': "/v1beta1/echo:echo" 2024/04/16 10:26:41 urlPathParams (expect 0, have 0): map[] 2024/04/16 10:26:41 urlRequestHeaders: User-Agent: "Google-HTTP-Java-Client/1.44.1 (gzip)" Content-Type: "application/json; charset=utf-8" Connection: "keep-alive" Accept-Encoding: "gzip" X-Goog-Api-Client: "gl-java/17.0.7__Eclipse-Adoptium__Temurin-17.0.7-7 gapic/0.0.1-SNAPSHOT gax/2.46.2-SNAPSHOT rest/" X-Goog-Api-Version: "v1_20240408" Accept: "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" Content-Length: "129" 2024/04/16 10:26:41 request: { "error": { "code": 500, "message": "", "details": [] }, "severity": "UNNECESSARY", "header": "", "otherHeader": "", "requestId": "e690a84b-176d-421e-9e5d-ba752f68fec8", "otherRequestId": "47e0fbde-056a-43ae-bba6-8b6770d861f7" } ``` --- ...tractServiceStubSettingsClassComposer.java | 10 + .../ServiceStubSettingsClassComposerTest.java | 6 + .../ApiVersionTestingStubSettings.golden | 248 +++++++ .../stub/SyncEchoWithVersionMethod.golden | 49 ++ .../ServiceStubSettingsClassComposerTest.java | 41 +- .../grpcrest/goldens/EchoStubSettings.golden | 7 +- .../ServiceStubSettingsClassComposerTest.java | 35 +- ...tpJsonApiVersionTestingStubSettings.golden | 250 +++++++ .../goldens/HttpJsonEchoStubSettings.golden | 635 ++++++++++++++++++ .../gapic/protoparser/ParserTest.java | 2 +- .../test/protoloader/RestTestProtoLoader.java | 35 + .../test/protoloader/TestProtoLoader.java | 32 + .../src/test/proto/api_version_testing.proto | 6 +- .../src/test/proto/echo_grpcrest.proto | 1 + .../api/gax/rpc/ApiClientHeaderProvider.java | 18 + .../gax/rpc/ApiClientHeaderProviderTest.java | 14 + .../v1beta1/stub/EchoStubSettings.java | 7 +- 17 files changed, 1358 insertions(+), 38 deletions(-) create mode 100644 gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettings.golden create mode 100644 gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoWithVersionMethod.golden create mode 100644 gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonApiVersionTestingStubSettings.golden create mode 100644 gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonEchoStubSettings.golden diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java index 88a3cc6ecd..c13bc5f3f1 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubSettingsClassComposer.java @@ -370,6 +370,16 @@ protected MethodDefinition createApiClientHeaderProviderBuilderMethod( .setReturnType(returnType) .build(); + if (service.hasApiVersion()) { + + returnExpr = + MethodInvocationExpr.builder() + .setExprReferenceExpr(returnExpr) + .setMethodName("setApiVersionToken") + .setArguments(ValueExpr.withValue(StringObjectValue.withValue(service.apiVersion()))) + .setReturnType(returnType) + .build(); + } return MethodDefinition.builder() .setScope(ScopeNode.PUBLIC) .setIsStatic(true) diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java index ff4f35bff7..bfce68a45a 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java @@ -54,6 +54,12 @@ public static Collection data() { GrpcTestProtoLoader.instance().parseDeprecatedService(), "localhost:7469", "v1" + }, + { + "ApiVersionTestingStubSettings", + GrpcTestProtoLoader.instance().parseApiVersionTesting(), + "localhost:7469", + "v1" } }); } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettings.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettings.golden new file mode 100644 index 0000000000..c67187cf5e --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/ApiVersionTestingStubSettings.golden @@ -0,0 +1,248 @@ +package com.google.api.version.test.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.version.test.EchoRequest; +import com.google.api.version.test.EchoResponse; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoWithVersionStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of echoWithVersionMethod to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoWithVersionStubSettings.Builder echoWithVersionSettingsBuilder =
+ *     EchoWithVersionStubSettings.newBuilder();
+ * echoWithVersionSettingsBuilder
+ *     .echoWithVersionMethodSettings()
+ *     .setRetrySettings(
+ *         echoWithVersionSettingsBuilder
+ *             .echoWithVersionMethodSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * EchoWithVersionStubSettings echoWithVersionSettings = echoWithVersionSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class EchoWithVersionStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings echoWithVersionMethodSettings; + + /** Returns the object with the settings used for calls to echoWithVersionMethod. */ + public UnaryCallSettings echoWithVersionMethodSettings() { + return echoWithVersionMethodSettings; + } + + public EchoWithVersionStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcEchoWithVersionStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(EchoWithVersionStubSettings.class)) + .setTransportToken(GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()) + .setApiVersionToken("fake_version"); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoWithVersionStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + echoWithVersionMethodSettings = settingsBuilder.echoWithVersionMethodSettings().build(); + } + + /** Builder for EchoWithVersionStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder + echoWithVersionMethodSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + echoWithVersionMethodSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of(echoWithVersionMethodSettings); + initDefaults(this); + } + + protected Builder(EchoWithVersionStubSettings settings) { + super(settings); + + echoWithVersionMethodSettings = settings.echoWithVersionMethodSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of(echoWithVersionMethodSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .echoWithVersionMethodSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to echoWithVersionMethod. */ + public UnaryCallSettings.Builder echoWithVersionMethodSettings() { + return echoWithVersionMethodSettings; + } + + @Override + public EchoWithVersionStubSettings build() throws IOException { + return new EchoWithVersionStubSettings(this); + } + } +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoWithVersionMethod.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoWithVersionMethod.golden new file mode 100644 index 0000000000..fc298b28dc --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/samples/servicesettings/stub/SyncEchoWithVersionMethod.golden @@ -0,0 +1,49 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.api.version.test.stub.samples; + +// [START goldensample_generated_EchoWithVersionStubSettings_EchoWithVersionMethod_sync] +import com.google.api.version.test.stub.EchoWithVersionStubSettings; +import java.time.Duration; + +public class SyncEchoWithVersionMethod { + + public static void main(String[] args) throws Exception { + syncEchoWithVersionMethod(); + } + + public static void syncEchoWithVersionMethod() throws Exception { + // This snippet has been automatically generated and should be regarded as a code template only. + // It will require modifications to work: + // - It may require correct/in-range values for request initialization. + // - It may require specifying regional endpoints when creating the service client as shown in + // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library + EchoWithVersionStubSettings.Builder echoWithVersionSettingsBuilder = + EchoWithVersionStubSettings.newBuilder(); + echoWithVersionSettingsBuilder + .echoWithVersionMethodSettings() + .setRetrySettings( + echoWithVersionSettingsBuilder + .echoWithVersionMethodSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + EchoWithVersionStubSettings echoWithVersionSettings = echoWithVersionSettingsBuilder.build(); + } +} +// [END goldensample_generated_EchoWithVersionStubSettings_EchoWithVersionMethod_sync] diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/ServiceStubSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/ServiceStubSettingsClassComposerTest.java index 388fa54648..c9439d525f 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/ServiceStubSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/ServiceStubSettingsClassComposerTest.java @@ -23,37 +23,38 @@ import com.google.api.generator.test.protoloader.GrpcRestTestProtoLoader; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collection; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class ServiceStubSettingsClassComposerTest { + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList( + new Object[][] { + {"EchoStubSettings.golden", GrpcRestTestProtoLoader.instance().parseShowcaseEcho()}, + {"WickedStubSettings.golden", GrpcRestTestProtoLoader.instance().parseShowcaseWicked()} + }); + } + + @Parameterized.Parameter public String goldenFileName; + + @Parameterized.Parameter(1) + public GapicContext context; + @Test public void generateServiceClasses() { - GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho(); Service echoProtoService = context.services().get(0); GapicClass clazz = ServiceStubSettingsClassComposer.instance().generate(context, echoProtoService); JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); - GoldenFileWriter.saveCodegenToFile(this.getClass(), "EchoStubSettings.golden", visitor.write()); - Path goldenFilePath = - Paths.get(GoldenFileWriter.getGoldenDir(this.getClass()), "EchoStubSettings.golden"); - Assert.assertCodeEquals(goldenFilePath, visitor.write()); - } - - @Test - public void generateServiceClassesWicked() { - GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseWicked(); - Service wickedProtoService = context.services().get(0); - GapicClass clazz = - ServiceStubSettingsClassComposer.instance().generate(context, wickedProtoService); - - JavaWriterVisitor visitor = new JavaWriterVisitor(); - clazz.classDefinition().accept(visitor); - GoldenFileWriter.saveCodegenToFile( - this.getClass(), "WickedStubSettings.golden", visitor.write()); - Path goldenFilePath = - Paths.get(GoldenFileWriter.getGoldenDir(this.getClass()), "WickedStubSettings.golden"); + GoldenFileWriter.saveCodegenToFile(this.getClass(), goldenFileName, visitor.write()); + Path goldenFilePath = Paths.get(GoldenFileWriter.getGoldenDir(this.getClass()), goldenFileName); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoStubSettings.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoStubSettings.golden index fefa7643ba..565f38a483 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoStubSettings.golden +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpcrest/goldens/EchoStubSettings.golden @@ -348,8 +348,8 @@ public class EchoStubSettings extends StubSettings { public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) - .setTransportToken( - GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + .setTransportToken(GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()) + .setApiVersionToken("foo_version_for_tests"); } public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { @@ -357,7 +357,8 @@ public class EchoStubSettings extends StubSettings { .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) .setTransportToken( GaxHttpJsonProperties.getHttpJsonTokenName(), - GaxHttpJsonProperties.getHttpJsonVersion()); + GaxHttpJsonProperties.getHttpJsonVersion()) + .setApiVersionToken("foo_version_for_tests"); } public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposerTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposerTest.java index 1869a893fe..d2ac3b813a 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposerTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/ServiceStubSettingsClassComposerTest.java @@ -23,22 +23,41 @@ import com.google.api.generator.test.protoloader.RestTestProtoLoader; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collection; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +@RunWith(Parameterized.class) public class ServiceStubSettingsClassComposerTest { + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList( + new Object[][] { + {"ComplianceStubSettings.golden", RestTestProtoLoader.instance().parseCompliance()}, + { + "HttpJsonApiVersionTestingStubSettings.golden", + RestTestProtoLoader.instance().parseApiVersionTesting() + } + }); + } + + @Parameterized.Parameter public String goldenFileName; + + @Parameterized.Parameter(1) + public GapicContext context; + @Test public void generateServiceClasses() { - GapicContext context = RestTestProtoLoader.instance().parseCompliance(); - Service echoProtoService = context.services().get(0); - GapicClass clazz = - ServiceStubSettingsClassComposer.instance().generate(context, echoProtoService); + Service protoService = context.services().get(0); + GapicClass clazz = ServiceStubSettingsClassComposer.instance().generate(context, protoService); JavaWriterVisitor visitor = new JavaWriterVisitor(); clazz.classDefinition().accept(visitor); - GoldenFileWriter.saveCodegenToFile( - this.getClass(), "ComplianceStubSettings.golden", visitor.write()); - Path goldenFilePath = - Paths.get(GoldenFileWriter.getGoldenDir(this.getClass()), "ComplianceStubSettings.golden"); + GoldenFileWriter.saveCodegenToFile(this.getClass(), goldenFileName, visitor.write()); + Path goldenFilePath = Paths.get(GoldenFileWriter.getGoldenDir(this.getClass()), goldenFileName); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonApiVersionTestingStubSettings.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonApiVersionTestingStubSettings.golden new file mode 100644 index 0000000000..219800efd4 --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonApiVersionTestingStubSettings.golden @@ -0,0 +1,250 @@ +package com.google.api.version.test.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.version.test.EchoRequest; +import com.google.api.version.test.EchoResponse; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoWithVersionStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of echoWithVersionMethod to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoWithVersionStubSettings.Builder echoWithVersionSettingsBuilder =
+ *     EchoWithVersionStubSettings.newBuilder();
+ * echoWithVersionSettingsBuilder
+ *     .echoWithVersionMethodSettings()
+ *     .setRetrySettings(
+ *         echoWithVersionSettingsBuilder
+ *             .echoWithVersionMethodSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * EchoWithVersionStubSettings echoWithVersionSettings = echoWithVersionSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class EchoWithVersionStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings echoWithVersionMethodSettings; + + /** Returns the object with the settings used for calls to echoWithVersionMethod. */ + public UnaryCallSettings echoWithVersionMethodSettings() { + return echoWithVersionMethodSettings; + } + + public EchoWithVersionStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonEchoWithVersionStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultHttpJsonTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(EchoWithVersionStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()) + .setApiVersionToken("fake_version"); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoWithVersionStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + echoWithVersionMethodSettings = settingsBuilder.echoWithVersionMethodSettings().build(); + } + + /** Builder for EchoWithVersionStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder + echoWithVersionMethodSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); + definitions.put("no_retry_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + echoWithVersionMethodSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of(echoWithVersionMethodSettings); + initDefaults(this); + } + + protected Builder(EchoWithVersionStubSettings settings) { + super(settings); + + echoWithVersionMethodSettings = settings.echoWithVersionMethodSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of(echoWithVersionMethodSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .echoWithVersionMethodSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to echoWithVersionMethod. */ + public UnaryCallSettings.Builder echoWithVersionMethodSettings() { + return echoWithVersionMethodSettings; + } + + @Override + public EchoWithVersionStubSettings build() throws IOException { + return new EchoWithVersionStubSettings(this); + } + } +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonEchoStubSettings.golden b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonEchoStubSettings.golden new file mode 100644 index 0000000000..0c788d7ebd --- /dev/null +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonEchoStubSettings.golden @@ -0,0 +1,635 @@ +package com.google.showcase.v1beta1.stub; + +import static com.google.showcase.v1beta1.EchoClient.PagedExpandPagedResponse; +import static com.google.showcase.v1beta1.EchoClient.SimplePagedExpandPagedResponse; + +import com.google.api.core.ApiFunction; +import com.google.api.core.ApiFuture; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +import com.google.api.gax.httpjson.ProtoOperationTransformers; +import com.google.api.gax.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiCallContext; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.PageContext; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.PagedListDescriptor; +import com.google.api.gax.rpc.PagedListResponseFactory; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.showcase.v1beta1.BlockRequest; +import com.google.showcase.v1beta1.BlockResponse; +import com.google.showcase.v1beta1.EchoRequest; +import com.google.showcase.v1beta1.EchoResponse; +import com.google.showcase.v1beta1.ExpandRequest; +import com.google.showcase.v1beta1.Object; +import com.google.showcase.v1beta1.PagedExpandRequest; +import com.google.showcase.v1beta1.PagedExpandResponse; +import com.google.showcase.v1beta1.WaitMetadata; +import com.google.showcase.v1beta1.WaitRequest; +import com.google.showcase.v1beta1.WaitResponse; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link EchoStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (localhost) and default port (7469) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of echo to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * EchoStubSettings.Builder echoSettingsBuilder = EchoStubSettings.newBuilder();
+ * echoSettingsBuilder
+ *     .echoSettings()
+ *     .setRetrySettings(
+ *         echoSettingsBuilder
+ *             .echoSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * EchoStubSettings echoSettings = echoSettingsBuilder.build();
+ * }
+ */ +@BetaApi +@Generated("by gapic-generator-java") +public class EchoStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); + + private final UnaryCallSettings echoSettings; + private final ServerStreamingCallSettings expandSettings; + private final StreamingCallSettings collectSettings; + private final StreamingCallSettings chatSettings; + private final StreamingCallSettings chatAgainSettings; + private final PagedCallSettings + pagedExpandSettings; + private final PagedCallSettings< + PagedExpandRequest, PagedExpandResponse, SimplePagedExpandPagedResponse> + simplePagedExpandSettings; + private final UnaryCallSettings waitSettings; + private final OperationCallSettings + waitOperationSettings; + private final UnaryCallSettings blockSettings; + private final UnaryCallSettings collideNameSettings; + + private static final PagedListDescriptor + PAGED_EXPAND_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public PagedExpandRequest injectToken(PagedExpandRequest payload, String token) { + return PagedExpandRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public PagedExpandRequest injectPageSize(PagedExpandRequest payload, int pageSize) { + return PagedExpandRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(PagedExpandRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(PagedExpandResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(PagedExpandResponse payload) { + return payload.getResponsesList() == null + ? ImmutableList.of() + : payload.getResponsesList(); + } + }; + + private static final PagedListDescriptor + SIMPLE_PAGED_EXPAND_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public PagedExpandRequest injectToken(PagedExpandRequest payload, String token) { + return PagedExpandRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public PagedExpandRequest injectPageSize(PagedExpandRequest payload, int pageSize) { + return PagedExpandRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(PagedExpandRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(PagedExpandResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(PagedExpandResponse payload) { + return payload.getResponsesList() == null + ? ImmutableList.of() + : payload.getResponsesList(); + } + }; + + private static final PagedListResponseFactory< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + PAGED_EXPAND_PAGE_STR_FACT = + new PagedListResponseFactory< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + PagedExpandRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, PAGED_EXPAND_PAGE_STR_DESC, request, context); + return PagedExpandPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + private static final PagedListResponseFactory< + PagedExpandRequest, PagedExpandResponse, SimplePagedExpandPagedResponse> + SIMPLE_PAGED_EXPAND_PAGE_STR_FACT = + new PagedListResponseFactory< + PagedExpandRequest, PagedExpandResponse, SimplePagedExpandPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + PagedExpandRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, SIMPLE_PAGED_EXPAND_PAGE_STR_DESC, request, context); + return SimplePagedExpandPagedResponse.createAsync(pageContext, futureResponse); + } + }; + + /** Returns the object with the settings used for calls to echo. */ + public UnaryCallSettings echoSettings() { + return echoSettings; + } + + /** Returns the object with the settings used for calls to expand. */ + public ServerStreamingCallSettings expandSettings() { + return expandSettings; + } + + /** Returns the object with the settings used for calls to collect. */ + public StreamingCallSettings collectSettings() { + return collectSettings; + } + + /** Returns the object with the settings used for calls to chat. */ + public StreamingCallSettings chatSettings() { + return chatSettings; + } + + /** Returns the object with the settings used for calls to chatAgain. */ + public StreamingCallSettings chatAgainSettings() { + return chatAgainSettings; + } + + /** Returns the object with the settings used for calls to pagedExpand. */ + public PagedCallSettings + pagedExpandSettings() { + return pagedExpandSettings; + } + + /** Returns the object with the settings used for calls to simplePagedExpand. */ + public PagedCallSettings + simplePagedExpandSettings() { + return simplePagedExpandSettings; + } + + /** Returns the object with the settings used for calls to wait. */ + public UnaryCallSettings waitSettings() { + return waitSettings; + } + + /** Returns the object with the settings used for calls to wait. */ + public OperationCallSettings waitOperationSettings() { + return waitOperationSettings; + } + + /** Returns the object with the settings used for calls to block. */ + public UnaryCallSettings blockSettings() { + return blockSettings; + } + + /** Returns the object with the settings used for calls to collideName. */ + public UnaryCallSettings collideNameSettings() { + return collideNameSettings; + } + + public EchoStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonEchoStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "localhost:7469"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "localhost:7469"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultHttpJsonTransportProviderBuilder().build(); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected EchoStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + echoSettings = settingsBuilder.echoSettings().build(); + expandSettings = settingsBuilder.expandSettings().build(); + collectSettings = settingsBuilder.collectSettings().build(); + chatSettings = settingsBuilder.chatSettings().build(); + chatAgainSettings = settingsBuilder.chatAgainSettings().build(); + pagedExpandSettings = settingsBuilder.pagedExpandSettings().build(); + simplePagedExpandSettings = settingsBuilder.simplePagedExpandSettings().build(); + waitSettings = settingsBuilder.waitSettings().build(); + waitOperationSettings = settingsBuilder.waitOperationSettings().build(); + blockSettings = settingsBuilder.blockSettings().build(); + collideNameSettings = settingsBuilder.collideNameSettings().build(); + } + + /** Builder for EchoStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder echoSettings; + private final ServerStreamingCallSettings.Builder expandSettings; + private final StreamingCallSettings.Builder collectSettings; + private final StreamingCallSettings.Builder chatSettings; + private final StreamingCallSettings.Builder chatAgainSettings; + private final PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + pagedExpandSettings; + private final PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, SimplePagedExpandPagedResponse> + simplePagedExpandSettings; + private final UnaryCallSettings.Builder waitSettings; + private final OperationCallSettings.Builder + waitOperationSettings; + private final UnaryCallSettings.Builder blockSettings; + private final UnaryCallSettings.Builder collideNameSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "retry_policy_1_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNKNOWN))); + definitions.put( + "no_retry_0_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(2.0) + .setMaxRetryDelay(Duration.ofMillis(3000L)) + .setInitialRpcTimeout(Duration.ofMillis(10000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(10000L)) + .setTotalTimeout(Duration.ofMillis(10000L)) + .build(); + definitions.put("retry_policy_1_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(5000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(5000L)) + .setTotalTimeout(Duration.ofMillis(5000L)) + .build(); + definitions.put("no_retry_0_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + echoSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + expandSettings = ServerStreamingCallSettings.newBuilder(); + collectSettings = StreamingCallSettings.newBuilder(); + chatSettings = StreamingCallSettings.newBuilder(); + chatAgainSettings = StreamingCallSettings.newBuilder(); + pagedExpandSettings = PagedCallSettings.newBuilder(PAGED_EXPAND_PAGE_STR_FACT); + simplePagedExpandSettings = PagedCallSettings.newBuilder(SIMPLE_PAGED_EXPAND_PAGE_STR_FACT); + waitSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + waitOperationSettings = OperationCallSettings.newBuilder(); + blockSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + collideNameSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + echoSettings, + pagedExpandSettings, + simplePagedExpandSettings, + waitSettings, + blockSettings, + collideNameSettings); + initDefaults(this); + } + + protected Builder(EchoStubSettings settings) { + super(settings); + + echoSettings = settings.echoSettings.toBuilder(); + expandSettings = settings.expandSettings.toBuilder(); + collectSettings = settings.collectSettings.toBuilder(); + chatSettings = settings.chatSettings.toBuilder(); + chatAgainSettings = settings.chatAgainSettings.toBuilder(); + pagedExpandSettings = settings.pagedExpandSettings.toBuilder(); + simplePagedExpandSettings = settings.simplePagedExpandSettings.toBuilder(); + waitSettings = settings.waitSettings.toBuilder(); + waitOperationSettings = settings.waitOperationSettings.toBuilder(); + blockSettings = settings.blockSettings.toBuilder(); + collideNameSettings = settings.collideNameSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + echoSettings, + pagedExpandSettings, + simplePagedExpandSettings, + waitSettings, + blockSettings, + collideNameSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .echoSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .expandSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .pagedExpandSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + + builder + .simplePagedExpandSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .waitSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .blockSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .collideNameSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + + builder + .waitOperationSettings() + .setInitialCallSettings( + UnaryCallSettings.newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create(WaitResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(WaitMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(5000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ZERO) + .setTotalTimeout(Duration.ofMillis(300000L)) + .build())); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to echo. */ + public UnaryCallSettings.Builder echoSettings() { + return echoSettings; + } + + /** Returns the builder for the settings used for calls to expand. */ + public ServerStreamingCallSettings.Builder expandSettings() { + return expandSettings; + } + + /** Returns the builder for the settings used for calls to collect. */ + public StreamingCallSettings.Builder collectSettings() { + return collectSettings; + } + + /** Returns the builder for the settings used for calls to chat. */ + public StreamingCallSettings.Builder chatSettings() { + return chatSettings; + } + + /** Returns the builder for the settings used for calls to chatAgain. */ + public StreamingCallSettings.Builder chatAgainSettings() { + return chatAgainSettings; + } + + /** Returns the builder for the settings used for calls to pagedExpand. */ + public PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, PagedExpandPagedResponse> + pagedExpandSettings() { + return pagedExpandSettings; + } + + /** Returns the builder for the settings used for calls to simplePagedExpand. */ + public PagedCallSettings.Builder< + PagedExpandRequest, PagedExpandResponse, SimplePagedExpandPagedResponse> + simplePagedExpandSettings() { + return simplePagedExpandSettings; + } + + /** Returns the builder for the settings used for calls to wait. */ + public UnaryCallSettings.Builder waitSettings() { + return waitSettings; + } + + /** Returns the builder for the settings used for calls to wait. */ + public OperationCallSettings.Builder + waitOperationSettings() { + return waitOperationSettings; + } + + /** Returns the builder for the settings used for calls to block. */ + public UnaryCallSettings.Builder blockSettings() { + return blockSettings; + } + + /** Returns the builder for the settings used for calls to collideName. */ + public UnaryCallSettings.Builder collideNameSettings() { + return collideNameSettings; + } + + @Override + public EchoStubSettings build() throws IOException { + return new EchoStubSettings(this); + } + } +} diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java index 42462dd1c8..f06c464055 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java @@ -623,7 +623,7 @@ public void parseServiceApiVersionTest() { new HashSet<>()); com.google.api.generator.gapic.model.Service parsedEchoService = services.get(0); - assertEquals("Echo", parsedEchoService.overriddenName()); + assertEquals("EchoWithVersion", parsedEchoService.overriddenName()); assertTrue(parsedEchoService.hasApiVersion()); assertEquals("fake_version", parsedEchoService.apiVersion()); } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/RestTestProtoLoader.java b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/RestTestProtoLoader.java index 20d64c7b3a..63938fcaad 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/RestTestProtoLoader.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/RestTestProtoLoader.java @@ -15,6 +15,7 @@ package com.google.api.generator.test.protoloader; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertEquals; import com.google.api.generator.gapic.model.GapicContext; import com.google.api.generator.gapic.model.GapicServiceConfig; @@ -25,6 +26,7 @@ import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.gapic.protoparser.ServiceConfigParser; import com.google.api.generator.gapic.protoparser.ServiceYamlParser; +import com.google.api.version.test.ApiVersionTestingOuterClass; import com.google.longrunning.OperationsProto; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; @@ -121,4 +123,37 @@ public GapicContext parseEcho() { .setRestNumericEnumsEnabled(true) .build(); } + + public GapicContext parseApiVersionTesting() { + FileDescriptor testingFileDescriptor = ApiVersionTestingOuterClass.getDescriptor(); + ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0); + assertEquals(testingService.getName(), "EchoWithVersion"); + + Map messageTypes = Parser.parseMessages(testingFileDescriptor); + Map resourceNames = Parser.parseResourceNames(testingFileDescriptor); + Set outputResourceNames = new HashSet<>(); + List services = + Parser.parseService( + testingFileDescriptor, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); + + String jsonFilename = "showcase_grpc_service_config.json"; + Path jsonPath = Paths.get(getTestFilesDirectory(), jsonFilename); + Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); + assertThat(configOpt.isPresent()).isTrue(); + GapicServiceConfig config = configOpt.get(); + + return GapicContext.builder() + .setMessages(messageTypes) + .setResourceNames(resourceNames) + .setServices(services) + .setServiceConfig(config) + .setHelperResourceNames(outputResourceNames) + .setTransport(getTransport()) + .setRestNumericEnumsEnabled(true) + .build(); + } } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java index d5e62ddf70..db9efd06ca 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java @@ -28,6 +28,7 @@ import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.gapic.protoparser.ServiceConfigParser; import com.google.api.generator.gapic.protoparser.ServiceYamlParser; +import com.google.api.version.test.ApiVersionTestingOuterClass; import com.google.auto.populate.field.AutoPopulateFieldTestingOuterClass; import com.google.bookshop.v1beta1.BookshopProto; import com.google.explicit.dynamic.routing.header.ExplicitDynamicRoutingHeaderTestingOuterClass; @@ -293,6 +294,37 @@ public GapicContext parseExplicitDynamicRoutingHeaderTesting() { .build(); } + public GapicContext parseApiVersionTesting() { + FileDescriptor testingFileDescriptor = ApiVersionTestingOuterClass.getDescriptor(); + ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0); + assertEquals(testingService.getName(), "EchoWithVersion"); + + Map messageTypes = Parser.parseMessages(testingFileDescriptor); + Map resourceNames = Parser.parseResourceNames(testingFileDescriptor); + Set outputResourceNames = new HashSet<>(); + List services = + Parser.parseService( + testingFileDescriptor, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); + String jsonFilename = "showcase_grpc_service_config.json"; + Path jsonPath = Paths.get(testFilesDirectory, jsonFilename); + Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); + assertTrue(configOpt.isPresent()); + GapicServiceConfig config = configOpt.get(); + + return GapicContext.builder() + .setMessages(messageTypes) + .setResourceNames(resourceNames) + .setServices(services) + .setServiceConfig(config) + .setHelperResourceNames(outputResourceNames) + .setTransport(transport) + .build(); + } + public GapicContext parseAutoPopulateFieldTesting() { FileDescriptor autopopulationFileDescriptor = AutoPopulateFieldTestingOuterClass.getDescriptor(); diff --git a/gapic-generator-java/src/test/proto/api_version_testing.proto b/gapic-generator-java/src/test/proto/api_version_testing.proto index 52c7b6bdd9..f815a7633e 100644 --- a/gapic-generator-java/src/test/proto/api_version_testing.proto +++ b/gapic-generator-java/src/test/proto/api_version_testing.proto @@ -24,7 +24,7 @@ import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; import "google/rpc/status.proto"; -package google.api.version.test; +package google.api.version.test.v1; option java_package = "com.google.api.version.test"; option java_multiple_files = true; @@ -39,7 +39,7 @@ option (google.api.resource_definition) = { // to test different scenarios. // This service is used to test when api_version string is provided. -service Echo { +service EchoWithVersion { // This service is meant to only run locally on the port 7469 (keypad digits // for "show"). option (google.api.default_host) = "localhost:7469"; @@ -48,7 +48,7 @@ service Echo { "https://www.googleapis.com/auth/cloud-platform"; // This method simply echos the request. This method is showcases unary rpcs. - rpc Echo(EchoRequest) returns (EchoResponse) { + rpc EchoWithVersionMethod(EchoRequest) returns (EchoResponse) { option (google.api.http) = { post: "/v1beta1/echo:echo" body: "*" diff --git a/gapic-generator-java/src/test/proto/echo_grpcrest.proto b/gapic-generator-java/src/test/proto/echo_grpcrest.proto index fbab0c2553..ea4a9392f3 100644 --- a/gapic-generator-java/src/test/proto/echo_grpcrest.proto +++ b/gapic-generator-java/src/test/proto/echo_grpcrest.proto @@ -47,6 +47,7 @@ service Echo { option (google.api.default_host) = "localhost:7469"; option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; + option (google.api.api_version) = "foo_version_for_tests"; // This method simply echos the request. This method is showcases unary rpcs. rpc Echo(EchoRequest) returns (EchoResponse) { diff --git a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiClientHeaderProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiClientHeaderProvider.java index 34d00d0f3a..ae27404335 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiClientHeaderProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/rpc/ApiClientHeaderProvider.java @@ -42,6 +42,8 @@ public class ApiClientHeaderProvider implements HeaderProvider, Serializable { private static final long serialVersionUID = -8876627296793342119L; static final String QUOTA_PROJECT_ID_HEADER_KEY = "x-goog-user-project"; + static final String API_VERSION_HEADER_KEY = "x-goog-api-version"; + private final Map headers; protected ApiClientHeaderProvider(Builder builder) { @@ -68,6 +70,9 @@ protected ApiClientHeaderProvider(Builder builder) { headersBuilder.put(QUOTA_PROJECT_ID_HEADER_KEY, builder.getQuotaProjectIdToken()); } + if (builder.getApiVersionToken() != null) { + headersBuilder.put(API_VERSION_HEADER_KEY, builder.getApiVersionToken()); + } this.headers = headersBuilder.build(); } @@ -109,6 +114,8 @@ public static class Builder { private String resourceHeaderKey; private String resourceToken; + private String apiVersionToken; + protected Builder() { // Initialize with default values apiClientHeaderKey = getDefaultApiClientHeaderKey(); @@ -121,6 +128,8 @@ protected Builder() { resourceHeaderKey = getDefaultResourceHeaderKey(); resourceToken = null; + + apiVersionToken = null; } public String getApiClientHeaderKey() { @@ -206,6 +215,15 @@ public Builder setResourceToken(String resourceToken) { return this; } + public String getApiVersionToken() { + return apiVersionToken; + } + + public Builder setApiVersionToken(String apiVersionToken) { + this.apiVersionToken = apiVersionToken; + return this; + } + private String constructToken(String name, String version) { if (version == null) { return null; diff --git a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiClientHeaderProviderTest.java b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiClientHeaderProviderTest.java index f60c3c0760..bc524cb35d 100644 --- a/gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiClientHeaderProviderTest.java +++ b/gax-java/gax/src/test/java/com/google/api/gax/rpc/ApiClientHeaderProviderTest.java @@ -138,4 +138,18 @@ public void testQuotaProjectHeader() { assertThat(provider.getHeaders().get(ApiClientHeaderProvider.QUOTA_PROJECT_ID_HEADER_KEY)) .matches(quotaProjectHeaderValue); } + + @Test + public void testApiVersionHeader() { + ApiClientHeaderProvider provider = + ApiClientHeaderProvider.newBuilder().setApiVersionToken("fake-version-string").build(); + assertThat(provider.getHeaders().size()).isEqualTo(2); + assertThat(provider.getHeaders().get(ApiClientHeaderProvider.API_VERSION_HEADER_KEY)) + .matches("fake-version-string"); + + ApiClientHeaderProvider emptyProvider = + ApiClientHeaderProvider.newBuilder().setApiVersionToken("").build(); + assertThat( + emptyProvider.getHeaders().get(ApiClientHeaderProvider.API_VERSION_HEADER_KEY).isEmpty()); + } } diff --git a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java index 1e659ed8d7..a54d329a0e 100644 --- a/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java +++ b/showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/EchoStubSettings.java @@ -479,8 +479,8 @@ public static TransportChannelProvider defaultTransportChannelProvider() { public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) - .setTransportToken( - GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + .setTransportToken(GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()) + .setApiVersionToken("v1_20240408"); } public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { @@ -488,7 +488,8 @@ public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProv .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(EchoStubSettings.class)) .setTransportToken( GaxHttpJsonProperties.getHttpJsonTokenName(), - GaxHttpJsonProperties.getHttpJsonVersion()); + GaxHttpJsonProperties.getHttpJsonVersion()) + .setApiVersionToken("v1_20240408"); } public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { From f2ce52478a03048b9daffc3fc535f12cf2a9f856 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:46:23 -0400 Subject: [PATCH 14/25] feat: add a CLI tool to validate generation configuration (#2691) In this PR: - Add a CLI tool to validate generation config. Downstream libraries, e.g., google-cloud-java, can write a workflow job like: ``` docker run ... python /src/cli/entry_point.py \ validate-generation-config \ --generation-config-path=path/to/generation_config.yaml ``` --- library_generation/cli/entry_point.py | 24 +++ library_generation/model/generation_config.py | 65 ++++++-- .../test/cli/entry_point_unit_tests.py | 35 +++- .../test/model/generation_config_unit_test.py | 150 ++++++++++++++++++ .../config_without_gapics_key.yaml | 3 + .../config_without_gapics_value.yaml | 4 + ...yaml => config_without_library_value.yaml} | 1 - ...on_config_with_duplicate_library_name.yaml | 51 ++++++ .../test/utilities_unit_tests.py | 61 ------- library_generation/utils/utilities.py | 4 - 10 files changed, 315 insertions(+), 83 deletions(-) create mode 100644 library_generation/test/resources/test-config/config_without_gapics_key.yaml create mode 100644 library_generation/test/resources/test-config/config_without_gapics_value.yaml rename library_generation/test/resources/test-config/{config_without_gapics.yaml => config_without_library_value.yaml} (75%) create mode 100644 library_generation/test/resources/test-config/generation_config_with_duplicate_library_name.yaml diff --git a/library_generation/cli/entry_point.py b/library_generation/cli/entry_point.py index ccaf631e85..a8c9c3ee0d 100644 --- a/library_generation/cli/entry_point.py +++ b/library_generation/cli/entry_point.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import sys import click as click from library_generation.generate_pr_description import generate_pr_descriptions @@ -142,5 +143,28 @@ def generate( ) +@main.command() +@click.option( + "--generation-config-path", + required=False, + type=str, + help=""" + Absolute or relative path to a generation_config.yaml. + Default to generation_config.yaml in the current working directory. + """, +) +def validate_generation_config(generation_config_path: str) -> None: + """ + Validate the given generation configuration. + """ + if generation_config_path is None: + generation_config_path = "generation_config.yaml" + try: + from_yaml(os.path.abspath(generation_config_path)) + except ValueError as err: + print(err) + sys.exit(1) + + if __name__ == "__main__": main() diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 650f4a45ba..2a5d453981 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -12,13 +12,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - - import yaml -from typing import List, Optional, Dict +from typing import Optional from library_generation.model.library_config import LibraryConfig from library_generation.model.gapic_config import GapicConfig +REPO_LEVEL_PARAMETER = "Repo level parameter" +LIBRARY_LEVEL_PARAMETER = "Library level parameter" +GAPIC_LEVEL_PARAMETER = "GAPIC level parameter" + class GenerationConfig: """ @@ -32,8 +34,8 @@ def __init__( libraries_bom_version: str, owlbot_cli_image: str, synthtool_commitish: str, - template_excludes: List[str], - libraries: List[LibraryConfig], + template_excludes: list[str], + libraries: list[LibraryConfig], grpc_version: Optional[str] = None, protoc_version: Optional[str] = None, ): @@ -46,6 +48,7 @@ def __init__( self.libraries = libraries self.grpc_version = grpc_version self.protoc_version = protoc_version + self.__validate() def get_proto_path_to_library_name(self) -> dict[str, str]: """ @@ -62,6 +65,19 @@ def get_proto_path_to_library_name(self) -> dict[str, str]: def is_monorepo(self) -> bool: return len(self.libraries) > 1 + def __validate(self) -> None: + seen_library_names = dict() + for library in self.libraries: + library_name = library.get_library_name() + if library_name in seen_library_names: + raise ValueError( + f"Both {library.name_pretty} and " + f"{seen_library_names.get(library_name)} have the same " + f"library name: {library_name}, please update one of the " + f"library to have a different library name." + ) + seen_library_names[library_name] = library.name_pretty + def from_yaml(path_to_yaml: str) -> GenerationConfig: """ @@ -72,15 +88,19 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: with open(path_to_yaml, "r") as file_stream: config = yaml.safe_load(file_stream) - libraries = __required(config, "libraries") + libraries = __required(config, "libraries", REPO_LEVEL_PARAMETER) + if not libraries: + raise ValueError(f"Library is None in {path_to_yaml}.") parsed_libraries = list() for library in libraries: gapics = __required(library, "GAPICs") parsed_gapics = list() + if not gapics: + raise ValueError(f"GAPICs is None in {library}.") for gapic in gapics: - proto_path = __required(gapic, "proto_path") + proto_path = __required(gapic, "proto_path", GAPIC_LEVEL_PARAMETER) new_gapic = GapicConfig(proto_path) parsed_gapics.append(new_gapic) @@ -114,27 +134,40 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: parsed_libraries.append(new_library) parsed_config = GenerationConfig( - gapic_generator_version=__required(config, "gapic_generator_version"), + gapic_generator_version=__required( + config, "gapic_generator_version", REPO_LEVEL_PARAMETER + ), grpc_version=__optional(config, "grpc_version", None), protoc_version=__optional(config, "protoc_version", None), - googleapis_commitish=__required(config, "googleapis_commitish"), - libraries_bom_version=__required(config, "libraries_bom_version"), - owlbot_cli_image=__required(config, "owlbot_cli_image"), - synthtool_commitish=__required(config, "synthtool_commitish"), - template_excludes=__required(config, "template_excludes"), + googleapis_commitish=__required( + config, "googleapis_commitish", REPO_LEVEL_PARAMETER + ), + libraries_bom_version=__required( + config, "libraries_bom_version", REPO_LEVEL_PARAMETER + ), + owlbot_cli_image=__required(config, "owlbot_cli_image", REPO_LEVEL_PARAMETER), + synthtool_commitish=__required( + config, "synthtool_commitish", REPO_LEVEL_PARAMETER + ), + template_excludes=__required(config, "template_excludes", REPO_LEVEL_PARAMETER), libraries=parsed_libraries, ) return parsed_config -def __required(config: Dict, key: str): +def __required(config: dict, key: str, level: str = LIBRARY_LEVEL_PARAMETER): if key not in config: - raise ValueError(f"required key {key} not found in yaml") + message = ( + f"{level}, {key}, is not found in {config} in yaml." + if level != REPO_LEVEL_PARAMETER + else f"{level}, {key}, is not found in yaml." + ) + raise ValueError(message) return config[key] -def __optional(config: Dict, key: str, default: any): +def __optional(config: dict, key: str, default: any): if key not in config: return default return config[key] diff --git a/library_generation/test/cli/entry_point_unit_tests.py b/library_generation/test/cli/entry_point_unit_tests.py index ae168e9671..ace2794684 100644 --- a/library_generation/test/cli/entry_point_unit_tests.py +++ b/library_generation/test/cli/entry_point_unit_tests.py @@ -11,9 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import unittest from click.testing import CliRunner -from library_generation.cli.entry_point import generate +from library_generation.cli.entry_point import generate, validate_generation_config + +script_dir = os.path.dirname(os.path.realpath(__file__)) +test_resource_dir = os.path.join(script_dir, "..", "resources", "test-config") class EntryPointTest(unittest.TestCase): @@ -44,3 +48,32 @@ def test_entry_point_with_baseline_without_current_raise_file_exception(self): "current_generation_config is not specified when " "baseline_generation_config is specified.", ) + + def test_validate_generation_config_succeeds( + self, + ): + runner = CliRunner() + # noinspection PyTypeChecker + result = runner.invoke( + validate_generation_config, + [f"--generation-config-path={test_resource_dir}/generation_config.yaml"], + ) + self.assertEqual(0, result.exit_code) + + def test_validate_generation_config_with_duplicate_library_name_raise_file_exception( + self, + ): + runner = CliRunner() + # noinspection PyTypeChecker + result = runner.invoke( + validate_generation_config, + [ + f"--generation-config-path={test_resource_dir}/generation_config_with_duplicate_library_name.yaml" + ], + ) + self.assertEqual(1, result.exit_code) + self.assertEqual(SystemExit, result.exc_info[0]) + self.assertRegex( + result.output, + "have the same library name", + ) diff --git a/library_generation/test/model/generation_config_unit_test.py b/library_generation/test/model/generation_config_unit_test.py index fd7608bb4f..2c8b3fc93d 100644 --- a/library_generation/test/model/generation_config_unit_test.py +++ b/library_generation/test/model/generation_config_unit_test.py @@ -133,3 +133,153 @@ def test_is_monorepo_with_two_libraries_returns_true(self): libraries=[library_1, library_2], ) self.assertTrue(config.is_monorepo()) + + def test_validate_with_duplicate_library_name_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "the same library name", + GenerationConfig, + gapic_generator_version="", + googleapis_commitish="", + libraries_bom_version="", + owlbot_cli_image="", + synthtool_commitish="", + template_excludes=[], + libraries=[ + LibraryConfig( + api_shortname="secretmanager", + name_pretty="Secret API", + product_documentation="", + api_description="", + gapic_configs=list(), + ), + LibraryConfig( + api_shortname="another-secret", + name_pretty="Another Secret API", + product_documentation="", + api_description="", + gapic_configs=list(), + library_name="secretmanager", + ), + ], + ) + + def test_from_yaml_without_gapic_generator_version_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, gapic_generator_version", + from_yaml, + f"{test_config_dir}/config_without_generator.yaml", + ) + + def test_from_yaml_without_googleapis_commitish_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, googleapis_commitish", + from_yaml, + f"{test_config_dir}/config_without_googleapis.yaml", + ) + + def test_from_yaml_without_libraries_bom_version_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, libraries_bom_version", + from_yaml, + f"{test_config_dir}/config_without_libraries_bom_version.yaml", + ) + + def test_from_yaml_without_owlbot_cli_image_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, owlbot_cli_image", + from_yaml, + f"{test_config_dir}/config_without_owlbot.yaml", + ) + + def test_from_yaml_without_synthtool_commitish_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, synthtool_commitish", + from_yaml, + f"{test_config_dir}/config_without_synthtool.yaml", + ) + + def test_from_yaml_without_template_excludes_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, template_excludes", + from_yaml, + f"{test_config_dir}/config_without_temp_excludes.yaml", + ) + + def test_from_yaml_without_libraries_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Repo level parameter, libraries", + from_yaml, + f"{test_config_dir}/config_without_libraries.yaml", + ) + + def test_from_yaml_without_api_shortname_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Library level parameter, api_shortname", + from_yaml, + f"{test_config_dir}/config_without_api_shortname.yaml", + ) + + def test_from_yaml_without_api_description_raise_exception(self): + self.assertRaisesRegex( + ValueError, + r"Library level parameter, api_description.*'api_shortname': 'apigeeconnect'.*", + from_yaml, + f"{test_config_dir}/config_without_api_description.yaml", + ) + + def test_from_yaml_without_name_pretty_raise_exception(self): + self.assertRaisesRegex( + ValueError, + r"Library level parameter, name_pretty.*'api_shortname': 'apigeeconnect'.*", + from_yaml, + f"{test_config_dir}/config_without_name_pretty.yaml", + ) + + def test_from_yaml_without_product_documentation_raise_exception(self): + self.assertRaisesRegex( + ValueError, + r"Library level parameter, product_documentation.*'api_shortname': 'apigeeconnect'.*", + from_yaml, + f"{test_config_dir}/config_without_product_docs.yaml", + ) + + def test_from_yaml_without_gapics_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Library level parameter, GAPICs.*'api_shortname': 'apigeeconnect'.*", + from_yaml, + f"{test_config_dir}/config_without_gapics_key.yaml", + ) + + def test_from_yaml_without_proto_path_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "GAPIC level parameter, proto_path", + from_yaml, + f"{test_config_dir}/config_without_proto_path.yaml", + ) + + def test_from_yaml_with_zero_library_raise_exception(self): + self.assertRaisesRegex( + ValueError, + "Library is None", + from_yaml, + f"{test_config_dir}/config_without_library_value.yaml", + ) + + def test_from_yaml_with_zero_proto_path_raise_exception(self): + self.assertRaisesRegex( + ValueError, + r"GAPICs is None in.*'api_shortname': 'apigeeconnect'.*", + from_yaml, + f"{test_config_dir}/config_without_gapics_value.yaml", + ) diff --git a/library_generation/test/resources/test-config/config_without_gapics_key.yaml b/library_generation/test/resources/test-config/config_without_gapics_key.yaml new file mode 100644 index 0000000000..739a4d9239 --- /dev/null +++ b/library_generation/test/resources/test-config/config_without_gapics_key.yaml @@ -0,0 +1,3 @@ +gapic_generator_version: 2.34.0 +libraries: + - api_shortname: apigeeconnect diff --git a/library_generation/test/resources/test-config/config_without_gapics_value.yaml b/library_generation/test/resources/test-config/config_without_gapics_value.yaml new file mode 100644 index 0000000000..ec49e4a669 --- /dev/null +++ b/library_generation/test/resources/test-config/config_without_gapics_value.yaml @@ -0,0 +1,4 @@ +gapic_generator_version: 2.34.0 +libraries: + - api_shortname: apigeeconnect + GAPICs: diff --git a/library_generation/test/resources/test-config/config_without_gapics.yaml b/library_generation/test/resources/test-config/config_without_library_value.yaml similarity index 75% rename from library_generation/test/resources/test-config/config_without_gapics.yaml rename to library_generation/test/resources/test-config/config_without_library_value.yaml index 0f0c49fc48..174a293000 100644 --- a/library_generation/test/resources/test-config/config_without_gapics.yaml +++ b/library_generation/test/resources/test-config/config_without_library_value.yaml @@ -1,3 +1,2 @@ gapic_generator_version: 2.34.0 libraries: - random_key: diff --git a/library_generation/test/resources/test-config/generation_config_with_duplicate_library_name.yaml b/library_generation/test/resources/test-config/generation_config_with_duplicate_library_name.yaml new file mode 100644 index 0000000000..c5613f4308 --- /dev/null +++ b/library_generation/test/resources/test-config/generation_config_with_duplicate_library_name.yaml @@ -0,0 +1,51 @@ +gapic_generator_version: 2.34.0 +protoc_version: 25.2 +googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 +libraries_bom_version: 26.37.0 +owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 +synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +template_excludes: + - ".github/*" + - ".kokoro/*" + - "samples/*" + - "CODE_OF_CONDUCT.md" + - "CONTRIBUTING.md" + - "LICENSE" + - "SECURITY.md" + - "java.header" + - "license-checks.xml" + - "renovate.json" + - ".gitignore" +libraries: + - api_shortname: cloudasset + name_pretty: Cloud Asset + product_documentation: "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview" + api_description: "provides inventory services based on a time series database." + library_name: "asset" + client_documentation: "https://cloud.google.com/java/docs/reference/google-cloud-asset/latest/overview" + distribution_name: "com.google.cloud:google-cloud-asset" + release_level: "stable" + issue_tracker: "https://issuetracker.google.com/issues/new?component=187210&template=0" + api_reference: "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview" + codeowner_team: "@googleapis/analytics-dpe" + excluded_poms: proto-google-iam-v1-bom,google-iam-policy,proto-google-iam-v1 + excluded_dependencies: google-iam-policy + GAPICs: + - proto_path: google/cloud/asset/v1 + - proto_path: google/cloud/asset/v1p1beta1 + - proto_path: google/cloud/asset/v1p2beta1 + - proto_path: google/cloud/asset/v1p5beta1 + - proto_path: google/cloud/asset/v1p7beta1 + + - api_shortname: another-cloudasset + name_pretty: Cloud Asset Inventory + product_documentation: "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview" + api_description: "provides inventory services based on a time series database." + library_name: "asset" + client_documentation: "https://cloud.google.com/java/docs/reference/google-cloud-asset/latest/overview" + distribution_name: "com.google.cloud:google-cloud-asset" + release_level: "stable" + issue_tracker: "https://issuetracker.google.com/issues/new?component=187210&template=0" + api_reference: "https://cloud.google.com/resource-manager/docs/cloud-asset-inventory/overview" + GAPICs: + - proto_path: google/cloud/asset/v1 diff --git a/library_generation/test/utilities_unit_tests.py b/library_generation/test/utilities_unit_tests.py index 5e5869d0c1..7e8eccbcf8 100644 --- a/library_generation/test/utilities_unit_tests.py +++ b/library_generation/test/utilities_unit_tests.py @@ -26,7 +26,6 @@ from library_generation.model.gapic_config import GapicConfig from library_generation.model.generation_config import GenerationConfig from library_generation.model.gapic_inputs import parse as parse_build_file -from library_generation.model.generation_config import from_yaml from library_generation.model.library_config import LibraryConfig from library_generation.test.test_utils import FileComparator from library_generation.test.test_utils import cleanup @@ -114,55 +113,6 @@ def test_eprint_valid_input_succeeds(self): # print() appends a `\n` each time it's called self.assertEqual(test_input + "\n", result) - # parameterized tests need to run from the class, see - # https://github.com/wolever/parameterized/issues/37 for more info. - # This test confirms that a ValueError with an error message about a - # missing key (specified in the first parameter of each `parameterized` - # tuple) when parsing a test configuration yaml (second parameter) will - # be raised. - @parameterized.expand( - [ - ("libraries", f"{test_config_dir}/config_without_libraries.yaml"), - ("GAPICs", f"{test_config_dir}/config_without_gapics.yaml"), - ("proto_path", f"{test_config_dir}/config_without_proto_path.yaml"), - ("api_shortname", f"{test_config_dir}/config_without_api_shortname.yaml"), - ( - "api_description", - f"{test_config_dir}/config_without_api_description.yaml", - ), - ("name_pretty", f"{test_config_dir}/config_without_name_pretty.yaml"), - ( - "product_documentation", - f"{test_config_dir}/config_without_product_docs.yaml", - ), - ( - "gapic_generator_version", - f"{test_config_dir}/config_without_generator.yaml", - ), - ( - "googleapis_commitish", - f"{test_config_dir}/config_without_googleapis.yaml", - ), - ( - "libraries_bom_version", - f"{test_config_dir}/config_without_libraries_bom_version.yaml", - ), - ("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"), - ("synthtool_commitish", f"{test_config_dir}/config_without_synthtool.yaml"), - ( - "template_excludes", - f"{test_config_dir}/config_without_temp_excludes.yaml", - ), - ] - ) - def test_from_yaml_without_key_fails(self, error_message_contains, path_to_yaml): - self.assertRaisesRegex( - ValueError, - error_message_contains, - from_yaml, - path_to_yaml, - ) - @parameterized.expand( [ ("BUILD_no_additional_protos.bazel", " "), @@ -344,17 +294,6 @@ def test_prepare_repo_monorepo_success(self): ["java-bare-metal-solution", "java-secretmanager"], library_path ) - def test_prepare_repo_monorepo_duplicated_library_name_failed(self): - gen_config = self.__get_a_gen_config(3) - self.assertRaisesRegex( - ValueError, - "secretmanager", - util.prepare_repo, - gen_config, - gen_config.libraries, - f"{resources_dir}/misc", - ) - def test_prepare_repo_monorepo_failed(self): gen_config = self.__get_a_gen_config(2) self.assertRaises( diff --git a/library_generation/utils/utilities.py b/library_generation/utils/utilities.py index 1456ede48f..71c58f0455 100755 --- a/library_generation/utils/utilities.py +++ b/library_generation/utils/utilities.py @@ -130,10 +130,6 @@ def prepare_repo( # use absolute path because docker requires absolute path # in volume name. absolute_library_path = str(Path(library_path).resolve()) - if absolute_library_path in libraries: - # check whether the java_library is unique among all libraries - # because two libraries should not go to the same destination. - raise ValueError(f"{absolute_library_path} already exists.") libraries[absolute_library_path] = library # remove existing .repo-metadata.json json_name = ".repo-metadata.json" From 9fb85049fe55fd63f0db157cd123d3e0401e551d Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Mon, 29 Apr 2024 17:44:21 -0400 Subject: [PATCH 15/25] chore: add a log in config checker (#2696) In this PR: - Add a log when the config validation succeeds. Context: I tested the checker in [here](https://github.com/googleapis/google-cloud-java/actions/runs/8884272073/job/24392990025?pr=10761). It will be good if the checker emit a log when the check passed. --- library_generation/cli/entry_point.py | 1 + 1 file changed, 1 insertion(+) diff --git a/library_generation/cli/entry_point.py b/library_generation/cli/entry_point.py index a8c9c3ee0d..960fae8693 100644 --- a/library_generation/cli/entry_point.py +++ b/library_generation/cli/entry_point.py @@ -161,6 +161,7 @@ def validate_generation_config(generation_config_path: str) -> None: generation_config_path = "generation_config.yaml" try: from_yaml(os.path.abspath(generation_config_path)) + print(f"{generation_config_path} is validated without any errors.") except ValueError as err: print(err) sys.exit(1) From cae6d79ed29fd9e64abe4e9390a46b1f9f1d305f Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 17:30:18 +0200 Subject: [PATCH 16/25] deps: update dependency absl-py to v2.1.0 (#2659) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [absl-py](https://togithub.com/abseil/abseil-py) | `==2.0.0` -> `==2.1.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/absl-py/2.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/absl-py/2.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/absl-py/2.0.0/2.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/absl-py/2.0.0/2.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes

abseil/abseil-py (absl-py) ### [`v2.1.0`](https://togithub.com/abseil/abseil-py/blob/HEAD/CHANGELOG.md#210-2024-01-16) [Compare Source](https://togithub.com/abseil/abseil-py/compare/v2.0.0...v2.1.0) ##### Added - (flags) Added `absl.flags.override_value` function to provide `FlagHolder` with a construct to modify values. The new interface parallels `absl.flags.FlagValues.__setattr__` but checks that the provided value conforms to the flag's expected type. - (testing) Added a new method `absltest.TestCase.assertDataclassEqual` that tests equality of `dataclass.dataclass` objects with better error messages when the assert fails. ##### Changed - (flags) `absl.flags.argparse_flags.ArgumentParser` now correctly inherits an empty instance of `FlagValues` to ensure that absl flags, such as `--flagfile`, `--undefok` are supported. - (testing) Do not exit 5 if tests were skipped on Python 3.12. This follows the CPython change[https://togithub.com/python/cpython/pull/113856](https://togithub.com/python/cpython/pull/113856)3856. ##### Fixed - (flags) The flag `foo` no longer retains the value `bar` after `FLAGS.foo = bar` fails due to a validation error. - (testing) Fixed an issue caused by [this Python 3.12.1 change](https://togithub.com/python/cpython/pull/109725) where the test reporter crashes when all tests are skipped.
--- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- library_generation/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/requirements.txt b/library_generation/requirements.txt index daece50322..42a99bd110 100644 --- a/library_generation/requirements.txt +++ b/library_generation/requirements.txt @@ -1,4 +1,4 @@ -absl-py==2.0.0 +absl-py==2.1.0 attr==0.3.2 attrs==23.2.0 black==24.3.0 From 7fb565324427a98948c6d253066b734a4b5832bc Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 17:30:28 +0200 Subject: [PATCH 17/25] deps: update dependency typing to v3.10.0.0 (#2663) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [typing](https://docs.python.org/3/library/typing.html) ([source](https://togithub.com/python/typing)) | `==3.7.4.3` -> `==3.10.0.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/typing/3.10.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/typing/3.10.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/typing/3.7.4.3/3.10.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/typing/3.7.4.3/3.10.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
python/typing (typing) ### [`v3.10.0.0`](https://togithub.com/python/typing/compare/3.7.4.3...3.10.0.0) [Compare Source](https://togithub.com/python/typing/compare/3.7.4.3...3.10.0.0)
--- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- library_generation/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/requirements.txt b/library_generation/requirements.txt index 42a99bd110..d0edf9e413 100644 --- a/library_generation/requirements.txt +++ b/library_generation/requirements.txt @@ -14,7 +14,7 @@ pathspec==0.12.1 platformdirs==4.1.0 PyYAML==6.0.1 smmap==5.0.1 -typing==3.7.4.3 +typing==3.10.0.0 parameterized==0.9.0 # used in parameterized test colorlog==6.8.2 watchdog==4.0.0 From b95ad49834e0422e79f884b42cf5c81c89bb25fb Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 17:30:32 +0200 Subject: [PATCH 18/25] deps: update dependency lxml to v5.2.1 (#2661) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [lxml](https://lxml.de/) ([source](https://togithub.com/lxml/lxml), [changelog](https://git.launchpad.net/lxml/plain/CHANGES.txt)) | `==5.0.0` -> `==5.2.1` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/lxml/5.2.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/lxml/5.2.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/lxml/5.0.0/5.2.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/lxml/5.0.0/5.2.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
lxml/lxml (lxml) ### [`v5.2.1`](https://togithub.com/lxml/lxml/blob/HEAD/CHANGES.txt#521-2024-04-02) [Compare Source](https://togithub.com/lxml/lxml/compare/lxml-5.2.0...lxml-5.2.1) \================== ## Bugs fixed - [LP#2059910](https://togithub.com/LP/lxml/issues/2059910): The minimum CPU architecture for the Linux x86 binary wheels was set back to "core2", but with SSE 4.2 enabled. - [LP#2059977](https://togithub.com/LP/lxml/issues/2059977): `Element.iterfind("//absolute_path")` failed with a `SyntaxError` where it should have issued a warning. - [GH#416](https://togithub.com/GH/lxml/issues/416): The documentation build was using the non-standard `which` command. Patch by MichaΕ‚ GΓ³rny. ### [`v5.2.0`](https://togithub.com/lxml/lxml/blob/HEAD/CHANGES.txt#520-2024-03-30) [Compare Source](https://togithub.com/lxml/lxml/compare/lxml-5.1.1...lxml-5.2.0) \================== ## Other changes - [LP#1958539](https://togithub.com/LP/lxml/issues/1958539): The `lxml.html.clean` implementation suffered from several (only if used) security issues in the past and was now extracted into a separate library: https://togithub.com/fedora-python/lxml_html_clean Projects that use lxml without "lxml.html.clean" will not notice any difference, except that they won't have potentially vulnerable code installed. The module is available as an "extra" setuptools dependency "lxml\[html_clean]", so that Projects that need "lxml.html.clean" will need to switch their requirements from "lxml" to "lxml\[html_clean]", or install the new library themselves. - The minimum CPU architecture for the Linux x86 binary wheels was upgraded to "sandybridge" (launched 2011), and glibc 2.28 / gcc 12 (manylinux\_2\_28) wheels were added. - Built with Cython 3.0.10. ### [`v5.1.1`](https://togithub.com/lxml/lxml/blob/HEAD/CHANGES.txt#511-2024-03-28) [Compare Source](https://togithub.com/lxml/lxml/compare/lxml-5.1.0...lxml-5.1.1) \================== ## Bugs fixed - [LP#2048920](https://togithub.com/LP/lxml/issues/2048920): `iterlinks()` in `lxml.html` rejected `bytes` input in 5.1.0. - High source line numbers from the parser are no longer truncated (up to a C `long`) when using libxml2 2.11 or later. ## Other changes - [GH#407](https://togithub.com/GH/lxml/issues/407): A compatibility test was adapted to recent expat versions. Patch by Miro Hrončok. - Binary wheels use the library versions libxml2 2.12.6 and libxslt 1.1.39. - Windows binary wheels use the library versions libxml2 2.11.7 and libxslt 1.1.39. - Built with Cython 3.0.9. ### [`v5.1.0`](https://togithub.com/lxml/lxml/blob/HEAD/CHANGES.txt#510-2024-01-05) [Compare Source](https://togithub.com/lxml/lxml/compare/lxml-5.0.2...lxml-5.1.0) \================== ## Features added - Parsing ASCII strings is slightly faster. ## Bugs fixed - [GH#349](https://togithub.com/GH/lxml/issues/349): The HTML `Cleaner()` interpreted an accidentally provided string parameter for the `host_whitelist` as list of characters and silently failed to reject any hosts. Passing a non-collection is now rejected. ## Other changes - Support for Python 2.7 and Python versions < 3.6 was removed. - The wheel build was migrated to use `cibuildwheel`. Patch by PrimoΕΎ Godec. ### [`v5.0.2`](https://togithub.com/lxml/lxml/blob/HEAD/CHANGES.txt#502-2024-03-28) [Compare Source](https://togithub.com/lxml/lxml/compare/lxml-5.0.1...lxml-5.0.2) \================== ## Other changes - [GH#407](https://togithub.com/GH/lxml/issues/407): A compatibility test was adapted to recent expat versions. Patch by Miro Hrončok. - Binary wheels use the library versions libxml2 2.12.6 and libxslt 1.1.39. - Built with Cython 3.0.9. ### [`v5.0.1`](https://togithub.com/lxml/lxml/blob/HEAD/CHANGES.txt#501-2024-01-05) [Compare Source](https://togithub.com/lxml/lxml/compare/lxml-5.0.0...lxml-5.0.1) \================== ## Bugs fixed - [LP#2046208](https://togithub.com/LP/lxml/issues/2046208): Parsing non-BMP Python Unicode strings could fail on macOS. - [LP#2044225](https://togithub.com/LP/lxml/issues/2044225): When incrementally parsing broken HTML, reporting start events on missing structural tags failed and could lead to subsequent exceptions. - [LP#2045435](https://togithub.com/LP/lxml/issues/2045435): Some (not all) issues with stricter C compilers were resolved. - The binary wheels in the 5.0.0 release did not validate cleanly (but installed ok). .. \_latest_release:
--- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- library_generation/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/requirements.txt b/library_generation/requirements.txt index d0edf9e413..3d3ddd503e 100644 --- a/library_generation/requirements.txt +++ b/library_generation/requirements.txt @@ -6,7 +6,7 @@ click==8.1.7 gitdb==4.0.11 GitPython==3.1.41 Jinja2==3.1.3 -lxml==5.0.0 +lxml==5.2.1 MarkupSafe==2.1.3 mypy-extensions==1.0.0 packaging==23.2 From 208bef468b11d49e85d4df4008d99c7a2de9233c Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 17:32:22 +0200 Subject: [PATCH 19/25] deps: update dependency gitpython to v3.1.43 (#2656) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [GitPython](https://togithub.com/gitpython-developers/GitPython) | `==3.1.41` -> `==3.1.43` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/GitPython/3.1.43?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/GitPython/3.1.43?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/GitPython/3.1.41/3.1.43?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/GitPython/3.1.41/3.1.43?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
gitpython-developers/GitPython (GitPython) ### [`v3.1.43`](https://togithub.com/gitpython-developers/GitPython/releases/tag/3.1.43) [Compare Source](https://togithub.com/gitpython-developers/GitPython/compare/3.1.42...3.1.43) ##### Particularly Important Changes These are likely to affect you, please do take a careful look. - Issue and test deprecation warnings by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1886](https://togithub.com/gitpython-developers/GitPython/pull/1886) - Fix version_info cache invalidation, typing, parsing, and serialization by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1838](https://togithub.com/gitpython-developers/GitPython/pull/1838) - Document manual refresh path treatment by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1839](https://togithub.com/gitpython-developers/GitPython/pull/1839) - Improve static typing and docstrings related to git object types by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1859](https://togithub.com/gitpython-developers/GitPython/pull/1859) ##### Other Changes - Test in Docker with Alpine Linux on CI by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1826](https://togithub.com/gitpython-developers/GitPython/pull/1826) - Build online docs (RTD) with -W and dependencies by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1843](https://togithub.com/gitpython-developers/GitPython/pull/1843) - Suggest full-path refresh() in failure message by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1844](https://togithub.com/gitpython-developers/GitPython/pull/1844) - `repo.blame` and `repo.blame_incremental` now accept `None` as the `rev` parameter. by [@​Gaubbe](https://togithub.com/Gaubbe) in [https://togithub.com/gitpython-developers/GitPython/pull/1846](https://togithub.com/gitpython-developers/GitPython/pull/1846) - Make sure diff always uses the default diff driver when `create_patch=True` by [@​can-taslicukur](https://togithub.com/can-taslicukur) in [https://togithub.com/gitpython-developers/GitPython/pull/1832](https://togithub.com/gitpython-developers/GitPython/pull/1832) - Revise docstrings, comments, and a few messages by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1850](https://togithub.com/gitpython-developers/GitPython/pull/1850) - Expand what is included in the API Reference by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1855](https://togithub.com/gitpython-developers/GitPython/pull/1855) - Restore building of documentation downloads by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1856](https://togithub.com/gitpython-developers/GitPython/pull/1856) - Revise type annotations slightly by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1860](https://togithub.com/gitpython-developers/GitPython/pull/1860) - Updating regex pattern to handle unicode whitespaces. by [@​jcole-crowdstrike](https://togithub.com/jcole-crowdstrike) in [https://togithub.com/gitpython-developers/GitPython/pull/1853](https://togithub.com/gitpython-developers/GitPython/pull/1853) - Use upgraded pip in test fixture virtual environment by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1864](https://togithub.com/gitpython-developers/GitPython/pull/1864) - lint: replace `flake8` with `ruff` check by [@​Borda](https://togithub.com/Borda) in [https://togithub.com/gitpython-developers/GitPython/pull/1862](https://togithub.com/gitpython-developers/GitPython/pull/1862) - lint: switch Black with `ruff-format` by [@​Borda](https://togithub.com/Borda) in [https://togithub.com/gitpython-developers/GitPython/pull/1865](https://togithub.com/gitpython-developers/GitPython/pull/1865) - Update readme and tox.ini for recent tooling changes by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1868](https://togithub.com/gitpython-developers/GitPython/pull/1868) - Split tox lint env into three envs, all safe by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1870](https://togithub.com/gitpython-developers/GitPython/pull/1870) - Slightly broaden Ruff, and update and clarify tool configuration by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1871](https://togithub.com/gitpython-developers/GitPython/pull/1871) - Add a "doc" extra for documentation build dependencies by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1872](https://togithub.com/gitpython-developers/GitPython/pull/1872) - Describe `Submodule.__init__` parent_commit parameter by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1877](https://togithub.com/gitpython-developers/GitPython/pull/1877) - Include TagObject in git.types.Tree_ish by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1878](https://togithub.com/gitpython-developers/GitPython/pull/1878) - Improve Sphinx role usage, including linking Git manpages by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1879](https://togithub.com/gitpython-developers/GitPython/pull/1879) - Replace all wildcard imports with explicit imports by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1880](https://togithub.com/gitpython-developers/GitPython/pull/1880) - Clarify how tag objects are usually tree-ish and commit-ish by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1881](https://togithub.com/gitpython-developers/GitPython/pull/1881) ##### New Contributors - [@​Gaubbe](https://togithub.com/Gaubbe) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1846](https://togithub.com/gitpython-developers/GitPython/pull/1846) - [@​can-taslicukur](https://togithub.com/can-taslicukur) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1832](https://togithub.com/gitpython-developers/GitPython/pull/1832) - [@​jcole-crowdstrike](https://togithub.com/jcole-crowdstrike) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1853](https://togithub.com/gitpython-developers/GitPython/pull/1853) - [@​Borda](https://togithub.com/Borda) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1862](https://togithub.com/gitpython-developers/GitPython/pull/1862) **Full Changelog**: https://togithub.com/gitpython-developers/GitPython/compare/3.1.42...3.1.43 ### [`v3.1.42`](https://togithub.com/gitpython-developers/GitPython/releases/tag/3.1.42) [Compare Source](https://togithub.com/gitpython-developers/GitPython/compare/3.1.41...3.1.42) #### What's Changed - Fix release link in changelog by [@​PeterJCLaw](https://togithub.com/PeterJCLaw) in [https://togithub.com/gitpython-developers/GitPython/pull/1795](https://togithub.com/gitpython-developers/GitPython/pull/1795) - Remove test dependency on sumtypes library by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1798](https://togithub.com/gitpython-developers/GitPython/pull/1798) - Pin Sphinx plugins to compatible versions by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1803](https://togithub.com/gitpython-developers/GitPython/pull/1803) - fix: treeNotSorted issue by [@​et-repositories](https://togithub.com/et-repositories) in [https://togithub.com/gitpython-developers/GitPython/pull/1799](https://togithub.com/gitpython-developers/GitPython/pull/1799) - Remove git.util.NullHandler by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1807](https://togithub.com/gitpython-developers/GitPython/pull/1807) - Clarify why GIT_PYTHON_GIT_EXECUTABLE may be set on failure by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1810](https://togithub.com/gitpython-developers/GitPython/pull/1810) - Report actual attempted Git command when Git.refresh fails by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1812](https://togithub.com/gitpython-developers/GitPython/pull/1812) - Don't suppress messages when logging is not configured by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1813](https://togithub.com/gitpython-developers/GitPython/pull/1813) - Pin Python 3.9.16 on Cygwin CI by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1814](https://togithub.com/gitpython-developers/GitPython/pull/1814) - Have initial refresh use a logger to warn by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1815](https://togithub.com/gitpython-developers/GitPython/pull/1815) - Omit warning prefix in "Bad git executable" message by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1816](https://togithub.com/gitpython-developers/GitPython/pull/1816) - Test with M1 macOS CI runner by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1817](https://togithub.com/gitpython-developers/GitPython/pull/1817) - Bump pre-commit/action from 3.0.0 to 3.0.1 by [@​dependabot](https://togithub.com/dependabot) in [https://togithub.com/gitpython-developers/GitPython/pull/1818](https://togithub.com/gitpython-developers/GitPython/pull/1818) - Bump Vampire/setup-wsl from 2.0.2 to 3.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://togithub.com/gitpython-developers/GitPython/pull/1819](https://togithub.com/gitpython-developers/GitPython/pull/1819) - Remove deprecated section in README.md by [@​marcm-ml](https://togithub.com/marcm-ml) in [https://togithub.com/gitpython-developers/GitPython/pull/1823](https://togithub.com/gitpython-developers/GitPython/pull/1823) - Keep temp files out of project dir and improve cleanup by [@​EliahKagan](https://togithub.com/EliahKagan) in [https://togithub.com/gitpython-developers/GitPython/pull/1825](https://togithub.com/gitpython-developers/GitPython/pull/1825) #### New Contributors - [@​PeterJCLaw](https://togithub.com/PeterJCLaw) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1795](https://togithub.com/gitpython-developers/GitPython/pull/1795) - [@​et-repositories](https://togithub.com/et-repositories) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1799](https://togithub.com/gitpython-developers/GitPython/pull/1799) - [@​marcm-ml](https://togithub.com/marcm-ml) made their first contribution in [https://togithub.com/gitpython-developers/GitPython/pull/1823](https://togithub.com/gitpython-developers/GitPython/pull/1823) **Full Changelog**: https://togithub.com/gitpython-developers/GitPython/compare/3.1.41...3.1.42
--- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- library_generation/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/requirements.txt b/library_generation/requirements.txt index 3d3ddd503e..e194b4813b 100644 --- a/library_generation/requirements.txt +++ b/library_generation/requirements.txt @@ -4,7 +4,7 @@ attrs==23.2.0 black==24.3.0 click==8.1.7 gitdb==4.0.11 -GitPython==3.1.41 +GitPython==3.1.43 Jinja2==3.1.3 lxml==5.2.1 MarkupSafe==2.1.3 From 34b4bc3362f3c30bd77f5a59c3cb3aea36358eee Mon Sep 17 00:00:00 2001 From: Lawrence Qiu Date: Tue, 30 Apr 2024 16:38:29 +0000 Subject: [PATCH 20/25] fix: Log HttpJson's async thread pool core size (#2697) Fixes https://github.com/googleapis/sdk-platform-java/issues/2680 --- .../google/api/gax/core/InstantiatingExecutorProvider.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gax-java/gax/src/main/java/com/google/api/gax/core/InstantiatingExecutorProvider.java b/gax-java/gax/src/main/java/com/google/api/gax/core/InstantiatingExecutorProvider.java index 1faee91a4a..25c8213f02 100644 --- a/gax-java/gax/src/main/java/com/google/api/gax/core/InstantiatingExecutorProvider.java +++ b/gax-java/gax/src/main/java/com/google/api/gax/core/InstantiatingExecutorProvider.java @@ -34,6 +34,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; +import java.util.logging.Logger; /** * InstantiatingChannelProvider is an ExecutorProvider which constructs a new @@ -41,6 +43,9 @@ */ @AutoValue public abstract class InstantiatingExecutorProvider implements ExecutorProvider { + private static final Logger LOGGER = + Logger.getLogger(InstantiatingExecutorProvider.class.getName()); + // Thread factory to use to create our worker threads private static final ThreadFactory DEFAULT_THREAD_FACTORY = new ThreadFactory() { @@ -95,6 +100,8 @@ public static Builder newBuilder() { public static Builder newIOBuilder() { int numCpus = Runtime.getRuntime().availableProcessors(); int numThreads = IO_THREAD_MULTIPLIER * Math.max(MIN_THREAD_AMOUNT, numCpus); + LOGGER.log( + Level.CONFIG, String.format("Thread Pool for requests has Core Pool Size: %d", numThreads)); return new AutoValue_InstantiatingExecutorProvider.Builder() .setExecutorThreadCount(numThreads) From 712af4b51352d4fc42026af0e58a6a525a7d9201 Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:49:58 -0400 Subject: [PATCH 21/25] chore: update plugin version pom template (#2704) In this PR: - The `maven-deploy-plugin` in google-cloud-java is updated to `3.1.2`, update the version in template. - Restore `typing` version to `3.7.4.3` because this is the highest version supported by python 3.11.x --- library_generation/requirements.txt | 2 +- library_generation/templates/root-pom.xml.j2 | 2 +- .../test/resources/test_monorepo_postprocessing/pom-golden.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library_generation/requirements.txt b/library_generation/requirements.txt index e194b4813b..bd8fc35915 100644 --- a/library_generation/requirements.txt +++ b/library_generation/requirements.txt @@ -14,7 +14,7 @@ pathspec==0.12.1 platformdirs==4.1.0 PyYAML==6.0.1 smmap==5.0.1 -typing==3.10.0.0 +typing==3.7.4.3 parameterized==0.9.0 # used in parameterized test colorlog==6.8.2 watchdog==4.0.0 diff --git a/library_generation/templates/root-pom.xml.j2 b/library_generation/templates/root-pom.xml.j2 index c48e8b71ef..a713cefa2c 100644 --- a/library_generation/templates/root-pom.xml.j2 +++ b/library_generation/templates/root-pom.xml.j2 @@ -25,7 +25,7 @@ org.apache.maven.plugins maven-deploy-plugin - 3.1.1 + 3.1.2 true diff --git a/library_generation/test/resources/test_monorepo_postprocessing/pom-golden.xml b/library_generation/test/resources/test_monorepo_postprocessing/pom-golden.xml index 8347287bc3..44a1df9409 100644 --- a/library_generation/test/resources/test_monorepo_postprocessing/pom-golden.xml +++ b/library_generation/test/resources/test_monorepo_postprocessing/pom-golden.xml @@ -25,7 +25,7 @@ org.apache.maven.plugins maven-deploy-plugin - 3.1.1 + 3.1.2 true From b45eb847b91e1c65404f75f42cd4e9a900222d4b Mon Sep 17 00:00:00 2001 From: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:50:03 -0400 Subject: [PATCH 22/25] chore: run library generation jobs conditionally (#2698) In this PR: - Add a job to get changed directories in pull request. - Run library generation tests only if the changed directories contains `library_generation`. Verified in - [Run tests](https://github.com/googleapis/sdk-platform-java/actions/runs/8887270660/job/24402267953) - [Don't run tests](https://github.com/googleapis/sdk-platform-java/actions/runs/8887279933/job/24402294618) The goal is to make library generation tests as a required check. Moreover, we don't want these tests run against every pull requests because only pull requests change library_generation directory should be tested. Currently, the workflow can only run if the files changed are within `paths`. Therefore, we can't set this workflow as required because it will get stuck and prevent merging for pull requests that don't change files within paths. Using this approach, this workflow runs on every pull request and only run actual tests when the condition is met (determined by the first job). Official docs: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks We can make the workflow required after merging this PR and the tests in the workflow will only run if the changed directories contains `library_generation`. --- .../workflows/verify_library_generation.yaml | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/verify_library_generation.yaml b/.github/workflows/verify_library_generation.yaml index c51f8ed7b0..8feec8a9d6 100644 --- a/.github/workflows/verify_library_generation.yaml +++ b/.github/workflows/verify_library_generation.yaml @@ -3,14 +3,38 @@ on: branches: - main pull_request: - paths: - - library_generation/** workflow_dispatch: name: verify_library_generation jobs: - integration_tests: + should-run-library-generation-tests: runs-on: ubuntu-22.04 + outputs: + should_run: ${{ steps.get_changed_directories.outputs.should_run }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: get changed directories in the pull request + id: get_changed_directories + shell: bash + run: | + set -ex + git checkout "${base_ref}" + git checkout "${head_ref}" + changed_directories="$(git diff --name-only ${base_ref} ${head_ref})" + if [[ ${changed_directories} =~ "library_generation/" ]]; then + echo "should_run=true" >> $GITHUB_OUTPUT + else + echo "should_run=false" >> $GITHUB_OUTPUT + fi + env: + base_ref: ${{ github.event.pull_request.base.ref }} + head_ref: ${{ github.event.pull_request.head.ref }} + library-generation-integration-tests: + runs-on: ubuntu-22.04 + needs: should-run-library-generation-tests + if: needs.should-run-library-generation-tests.outputs.should_run == 'true' steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -41,12 +65,14 @@ jobs: run: | set -x python -m unittest library_generation/test/integration_tests.py - unit_tests: + library-generation-unit-tests: + runs-on: ${{ matrix.os }} + needs: should-run-library-generation-tests + if: needs.should-run-library-generation-tests.outputs.should_run == 'true' strategy: matrix: java: [ 8 ] os: [ ubuntu-22.04, macos-12 ] - runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: install utils (macos) @@ -88,8 +114,10 @@ jobs: run: | set -x python -m unittest discover -s library_generation/test/ -p "*unit_tests.py" - lint-shell: + library-generation-lint-shell: runs-on: ubuntu-22.04 + needs: should-run-library-generation-tests + if: needs.should-run-library-generation-tests.outputs.should_run == 'true' steps: - uses: actions/checkout@v4 - name: Run ShellCheck @@ -98,8 +126,10 @@ jobs: scandir: 'library_generation' format: tty severity: error - lint-python: + library-generation-lint-python: runs-on: ubuntu-22.04 + needs: should-run-library-generation-tests + if: needs.should-run-library-generation-tests.outputs.should_run == 'true' steps: - uses: actions/checkout@v4 - name: install python dependencies From aab99687e9a63cf78face29102361bf797fd700f Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 22:04:17 +0200 Subject: [PATCH 23/25] build(deps): update dependency org.apache.maven.plugins:maven-shade-plugin to v3.5.3 (#2701) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [org.apache.maven.plugins:maven-shade-plugin](https://maven.apache.org/plugins/) | `3.5.2` -> `3.5.3` | [![age](https://developer.mend.io/api/mc/badges/age/maven/org.apache.maven.plugins:maven-shade-plugin/3.5.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/org.apache.maven.plugins:maven-shade-plugin/3.5.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/org.apache.maven.plugins:maven-shade-plugin/3.5.2/3.5.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/org.apache.maven.plugins:maven-shade-plugin/3.5.2/3.5.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- gapic-generator-java/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gapic-generator-java/pom.xml b/gapic-generator-java/pom.xml index 923191445c..5b1145d0bd 100644 --- a/gapic-generator-java/pom.xml +++ b/gapic-generator-java/pom.xml @@ -351,7 +351,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.2 + 3.5.3 package From eb365760726342f3fe7aa9badf08ef0a8077de36 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 22:04:21 +0200 Subject: [PATCH 24/25] build(deps): update dependency org.apache.maven.plugins:maven-deploy-plugin to v3.1.2 (#2702) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [org.apache.maven.plugins:maven-deploy-plugin](https://maven.apache.org/plugins/) | `3.1.1` -> `3.1.2` | [![age](https://developer.mend.io/api/mc/badges/age/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.1/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/org.apache.maven.plugins:maven-deploy-plugin/3.1.1/3.1.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- .../owlbot/templates/java_library/samples/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library_generation/owlbot/templates/java_library/samples/pom.xml b/library_generation/owlbot/templates/java_library/samples/pom.xml index add08dc502..e653958eb4 100644 --- a/library_generation/owlbot/templates/java_library/samples/pom.xml +++ b/library_generation/owlbot/templates/java_library/samples/pom.xml @@ -38,7 +38,7 @@ org.apache.maven.plugins maven-deploy-plugin - 3.1.1 + 3.1.2 true diff --git a/pom.xml b/pom.xml index bb18ea81cd..a26c57a42a 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ org.apache.maven.plugins maven-deploy-plugin - 3.1.1 + 3.1.2 true From 87069bc9618704e2607aeae486d8481e4454dc17 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 30 Apr 2024 22:06:23 +0200 Subject: [PATCH 25/25] deps: update dependency net.bytebuddy:byte-buddy to v1.14.14 (#2703) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [net.bytebuddy:byte-buddy](https://bytebuddy.net) | `1.14.13` -> `1.14.14` | [![age](https://developer.mend.io/api/mc/badges/age/maven/net.bytebuddy:byte-buddy/1.14.14?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/net.bytebuddy:byte-buddy/1.14.14?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/net.bytebuddy:byte-buddy/1.14.13/1.14.14?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/net.bytebuddy:byte-buddy/1.14.13/1.14.14?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Configuration πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/sdk-platform-java). --- gax-java/dependencies.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gax-java/dependencies.properties b/gax-java/dependencies.properties index 6519fdfe96..e76c827179 100644 --- a/gax-java/dependencies.properties +++ b/gax-java/dependencies.properties @@ -83,5 +83,5 @@ maven.org_mockito_mockito_core=org.mockito:mockito-core:2.28.2 maven.org_hamcrest_hamcrest_core=org.hamcrest:hamcrest-core:1.3 maven.com_google_truth_truth=com.google.truth:truth:1.4.2 maven.com_googlecode_java_diff_utils_diffutils=com.googlecode.java-diff-utils:diffutils:1.3.0 -maven.net_bytebuddy_byte_buddy=net.bytebuddy:byte-buddy:1.14.13 +maven.net_bytebuddy_byte_buddy=net.bytebuddy:byte-buddy:1.14.14 maven.org_objenesis_objenesis=org.objenesis:objenesis:2.6