From d896e6e1b052a9da5ef1304220ec88017a24991d Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Mon, 27 Jun 2022 09:14:31 -0700 Subject: [PATCH] fix: Fix mixin mock service and gradle build generation (#1010) 1) The generated mixin mock service classes must be in the same package as the service itself (not of the mixed-in service) - this is a regression of migrating to microgenerator. For example the PR when this happened for KMS: https://github.com/googleapis/java-kms/pull/502/files#diff-59a3127359a0458dedfaa9b6bdfc658e88a2491a6d907f32e17fac462b1a3c27L16 2) In case there is a location mixin, we also need to include grpc-google-common-protos dependency for output to compile --- rules_java_gapic/java_gapic_pkg.bzl | 1 + .../com/google/api/generator/gapic/protoparser/Parser.java | 7 ++++++- .../cloud/kms/v1/KeyManagementServiceClientTest.java | 2 -- .../com/google/{iam => cloud/kms}/v1/MockIAMPolicy.java | 2 +- .../google/{iam => cloud/kms}/v1/MockIAMPolicyImpl.java | 6 +++++- .../google/cloud/{location => kms/v1}/MockLocations.java | 2 +- .../cloud/{location => kms/v1}/MockLocationsImpl.java | 6 +++++- 7 files changed, 19 insertions(+), 7 deletions(-) rename test/integration/goldens/kms/src/com/google/{iam => cloud/kms}/v1/MockIAMPolicy.java (97%) rename test/integration/goldens/kms/src/com/google/{iam => cloud/kms}/v1/MockIAMPolicyImpl.java (93%) rename test/integration/goldens/kms/src/com/google/cloud/{location => kms/v1}/MockLocations.java (97%) rename test/integration/goldens/kms/src/com/google/cloud/{location => kms/v1}/MockLocationsImpl.java (93%) diff --git a/rules_java_gapic/java_gapic_pkg.bzl b/rules_java_gapic/java_gapic_pkg.bzl index 66ba5476c5..37088297fa 100644 --- a/rules_java_gapic/java_gapic_pkg.bzl +++ b/rules_java_gapic/java_gapic_pkg.bzl @@ -131,6 +131,7 @@ def _construct_extra_deps(scope_to_deps, versions_map): "iam_java_proto": "maven.com_google_api_grpc_proto_google_iam_v1", "iam_java_grpc": "maven.com_google_api_grpc_grpc_google_iam_v1", "iam_policy_java_grpc": "maven.com_google_api_grpc_grpc_google_iam_v1", + "location_java_grpc": "maven.com_google_api_grpc_grpc_google_common_protos", } extra_deps = {} for scope, deps in scope_to_deps.items(): diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java index df45446229..30cdc6a690 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java @@ -203,7 +203,12 @@ public static GapicContext parse(CodeGeneratorRequest request) { return GapicContext.builder() .setServices(services) - .setMixinServices(mixinServices) + .setMixinServices( + // Mixin classes must share the package with the service they are mixed in, instead of + // their original package + mixinServices.stream() + .map(s -> s.toBuilder().setPakkage(services.get(0).pakkage()).build()) + .collect(Collectors.toList())) .setMessages(messages) .setResourceNames(resourceNames) .setHelperResourceNames(outputArgResourceNames) diff --git a/test/integration/goldens/kms/src/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java index dab97c7f08..52969cf34d 100644 --- a/test/integration/goldens/kms/src/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java +++ b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/KeyManagementServiceClientTest.java @@ -34,12 +34,10 @@ import com.google.cloud.location.ListLocationsRequest; import com.google.cloud.location.ListLocationsResponse; import com.google.cloud.location.Location; -import com.google.cloud.location.MockLocations; import com.google.common.collect.Lists; import com.google.iam.v1.Binding; import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.GetPolicyOptions; -import com.google.iam.v1.MockIAMPolicy; import com.google.iam.v1.Policy; import com.google.iam.v1.TestIamPermissionsRequest; import com.google.iam.v1.TestIamPermissionsResponse; diff --git a/test/integration/goldens/kms/src/com/google/iam/v1/MockIAMPolicy.java b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockIAMPolicy.java similarity index 97% rename from test/integration/goldens/kms/src/com/google/iam/v1/MockIAMPolicy.java rename to test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockIAMPolicy.java index 3d7859824b..829e78d2d3 100644 --- a/test/integration/goldens/kms/src/com/google/iam/v1/MockIAMPolicy.java +++ b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockIAMPolicy.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.iam.v1; +package com.google.cloud.kms.v1; import com.google.api.core.BetaApi; import com.google.api.gax.grpc.testing.MockGrpcService; diff --git a/test/integration/goldens/kms/src/com/google/iam/v1/MockIAMPolicyImpl.java b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockIAMPolicyImpl.java similarity index 93% rename from test/integration/goldens/kms/src/com/google/iam/v1/MockIAMPolicyImpl.java rename to test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockIAMPolicyImpl.java index f6e73437ac..a944265e4c 100644 --- a/test/integration/goldens/kms/src/com/google/iam/v1/MockIAMPolicyImpl.java +++ b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockIAMPolicyImpl.java @@ -14,10 +14,14 @@ * limitations under the License. */ -package com.google.iam.v1; +package com.google.cloud.kms.v1; import com.google.api.core.BetaApi; +import com.google.iam.v1.GetIamPolicyRequest; import com.google.iam.v1.IAMPolicyGrpc.IAMPolicyImplBase; +import com.google.iam.v1.Policy; +import com.google.iam.v1.TestIamPermissionsRequest; +import com.google.iam.v1.TestIamPermissionsResponse; import com.google.protobuf.AbstractMessage; import io.grpc.stub.StreamObserver; import java.util.ArrayList; diff --git a/test/integration/goldens/kms/src/com/google/cloud/location/MockLocations.java b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockLocations.java similarity index 97% rename from test/integration/goldens/kms/src/com/google/cloud/location/MockLocations.java rename to test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockLocations.java index 8ce43edf9b..d025927eab 100644 --- a/test/integration/goldens/kms/src/com/google/cloud/location/MockLocations.java +++ b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockLocations.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.location; +package com.google.cloud.kms.v1; import com.google.api.core.BetaApi; import com.google.api.gax.grpc.testing.MockGrpcService; diff --git a/test/integration/goldens/kms/src/com/google/cloud/location/MockLocationsImpl.java b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockLocationsImpl.java similarity index 93% rename from test/integration/goldens/kms/src/com/google/cloud/location/MockLocationsImpl.java rename to test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockLocationsImpl.java index d6b51f13d1..340e0a3df3 100644 --- a/test/integration/goldens/kms/src/com/google/cloud/location/MockLocationsImpl.java +++ b/test/integration/goldens/kms/src/com/google/cloud/kms/v1/MockLocationsImpl.java @@ -14,9 +14,13 @@ * limitations under the License. */ -package com.google.cloud.location; +package com.google.cloud.kms.v1; import com.google.api.core.BetaApi; +import com.google.cloud.location.GetLocationRequest; +import com.google.cloud.location.ListLocationsRequest; +import com.google.cloud.location.ListLocationsResponse; +import com.google.cloud.location.Location; import com.google.cloud.location.LocationsGrpc.LocationsImplBase; import com.google.protobuf.AbstractMessage; import io.grpc.stub.StreamObserver;