Skip to content

Commit

Permalink
Merge branch 'main' into renovate/checker-qual.version
Browse files Browse the repository at this point in the history
  • Loading branch information
jinseopkim0 authored Nov 13, 2024
2 parents 9d8693a + a31c682 commit fab1b38
Show file tree
Hide file tree
Showing 30 changed files with 889 additions and 306 deletions.
1 change: 1 addition & 0 deletions .cloudbuild/graalvm/cloudbuild-test-a-downstream-kms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ substitutions:
_JAVA_SHARED_CONFIG_VERSION: '1.11.3'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ substitutions:
_JAVA_SHARED_CONFIG_VERSION: '1.11.3'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: [
Expand Down
4 changes: 3 additions & 1 deletion .cloudbuild/graalvm/cloudbuild-test-a.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ substitutions:
_JAVA_SHARED_CONFIG_VERSION: '1.11.3'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: [
Expand All @@ -41,4 +42,5 @@ steps:
entrypoint: bash
args: [ './.kokoro/presubmit/showcase-native.sh' ]
waitFor: [ "graalvm-a-build" ]
id: native-showcase
id: native-showcase

1 change: 1 addition & 0 deletions .cloudbuild/graalvm/cloudbuild-test-b-downstream-kms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ substitutions:
_JAVA_SHARED_CONFIG_VERSION: '1.11.3'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ substitutions:
_JAVA_SHARED_CONFIG_VERSION: '1.11.3'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: [
Expand Down
1 change: 1 addition & 0 deletions .cloudbuild/graalvm/cloudbuild-test-b.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ substitutions:
_JAVA_SHARED_CONFIG_VERSION: '1.11.3'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
steps:
- name: gcr.io/cloud-builders/docker
args: [
Expand Down
2 changes: 2 additions & 0 deletions .cloudbuild/graalvm/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ steps:
id: graalvm-b-build
waitFor: [ "-" ]

options:
logging: CLOUD_LOGGING_ONLY

images:
- gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:${_SHARED_DEPENDENCIES_VERSION}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
timeout: 7200s # 2 hours
substitutions:
_IMAGE_NAME: "us-docker.pkg.dev/java-hermetic-build-prod/private-resources/java-library-generation"
_GAPIC_GENERATOR_JAVA_VERSION: '2.46.2-SNAPSHOT' # {x-version-update:gapic-generator-java:current}
_GAPIC_GENERATOR_JAVA_VERSION: '2.49.1-SNAPSHOT' # {x-version-update:gapic-generator-java:current}
_SHA_IMAGE_ID: "${_IMAGE_NAME}:${COMMIT_SHA}"
_LATEST_IMAGE_ID: "${_IMAGE_NAME}:latest"
_VERSIONED_IMAGE_ID: "${_IMAGE_NAME}:${_GAPIC_GENERATOR_JAVA_VERSION}"
Expand All @@ -30,6 +30,8 @@ steps:
"--file", ".cloudbuild/library_generation/library_generation.Dockerfile", "."]
id: library-generation-build
waitFor: ["-"]
env:
- 'DOCKER_BUILDKIT=1'

options:
logging: CLOUD_LOGGING_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ steps:
"--file", ".cloudbuild/library_generation/library_generation.Dockerfile", "."]
id: library-generation-build
waitFor: ["-"]
env:
- 'DOCKER_BUILDKIT=1'

options:
logging: CLOUD_LOGGING_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ FROM docker.io/library/python@sha256:38e179a0f0436c97ecc76bcd378d7293ab3ee79e4b8

ARG OWLBOT_CLI_COMMITTISH=38fe6f89a2339ee75c77739b31b371f601b01bb3
ARG PROTOC_VERSION=25.5
ARG GRPC_VERSION=1.67.1
ARG GRPC_VERSION=1.68.1
ARG JAVA_FORMAT_VERSION=1.7
ENV HOME=/home
ENV OS_ARCHITECTURE="linux-x86_64"
Expand Down
3 changes: 0 additions & 3 deletions .github/scripts/hermetic_library_generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ git checkout "${current_branch}"
# copy generation configuration from target branch to current branch.
git show "${target_branch}":"${generation_config}" > "${baseline_generation_config}"

# get .m2 folder so it's mapped into the docker container
m2_folder=$(dirname "$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)")

# download api definitions from googleapis repository
googleapis_commitish=$(grep googleapis_commitish "${generation_config}" | cut -d ":" -f 2 | xargs)
api_def_dir=$(mktemp -d)
Expand Down
4 changes: 2 additions & 2 deletions gapic-generator-java-pom-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<!-- External dependencies, especially gRPC and Protobuf version, should be
consistent across modules in this repository -->
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<grpc.version>1.67.1</grpc.version>
<google.auth.version>1.29.0</google.auth.version>
<grpc.version>1.68.1</grpc.version>
<google.auth.version>1.30.0</google.auth.version>
<google.http-client.version>1.45.0</google.http-client.version>
<gson.version>2.11.0</gson.version>
<guava.version>33.3.1-jre</guava.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.api.generator.gapic.protoparser;

import com.google.api.ClientLibrarySettings;
import com.google.api.ClientProto;
import com.google.api.DocumentationRule;
import com.google.api.FieldBehavior;
Expand Down Expand Up @@ -84,6 +85,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -160,11 +162,11 @@ public static GapicContext parse(CodeGeneratorRequest request) {
messages = updateResourceNamesInMessages(messages, resourceNames.values());

// Contains only resource names that are actually used. Usage refers to the presence of a
// request message's field in an RPC's method_signature annotation. That is, resource name
// definitions
// or references that are simply defined, but not used in such a manner, will not have
// corresponding Java helper
// classes generated.
// request message's field in an RPC's method_signature annotation. That is, resource name
// definitions or references that are simply defined, but not used in such a manner,
// will not have corresponding Java helper classes generated.
// If selective api generation is configured via service yaml, Java helper classes are only
// generated if resource names are actually used by methods selected to generate.
Set<ResourceName> outputArgResourceNames = new HashSet<>();
List<Service> mixinServices = new ArrayList<>();
Transport transport = Transport.parse(transportOpt.orElse(Transport.GRPC.toString()));
Expand Down Expand Up @@ -425,6 +427,71 @@ public static List<Service> parseService(
Transport.GRPC);
}

static boolean shouldIncludeMethodInGeneration(
MethodDescriptor method,
Optional<com.google.api.Service> serviceYamlProtoOpt,
String protoPackage) {
// default to include all when no service yaml or no library setting section.
if (!serviceYamlProtoOpt.isPresent()
|| serviceYamlProtoOpt.get().getPublishing().getLibrarySettingsCount() == 0) {
return true;
}
List<ClientLibrarySettings> librarySettingsList =
serviceYamlProtoOpt.get().getPublishing().getLibrarySettingsList();
// Validate for logging purpose, this should be validated upstream.
// If library_settings.version does not match with proto package name
// Give warnings and disregard this config. default to include all.
if (!librarySettingsList.get(0).getVersion().isEmpty()
&& !protoPackage.equals(librarySettingsList.get(0).getVersion())) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(
String.format(
"Service yaml config is misconfigured. Version in "
+ "publishing.library_settings (%s) does not match proto package (%s)."
+ "Disregarding selective generation settings.",
librarySettingsList.get(0).getVersion(), protoPackage));
}
return true;
}
// librarySettingsList is technically a list, but is processed upstream and
// only leave with 1 element. Otherwise, it is a misconfiguration and
// should be caught upstream.
List<String> includeMethodsList =
librarySettingsList
.get(0)
.getJavaSettings()
.getCommon()
.getSelectiveGapicGeneration()
.getMethodsList();
// default to include all when nothing specified, this could be no java section
// specified in library setting, or the method list is empty
if (includeMethodsList.isEmpty()) {
return true;
}

return includeMethodsList.contains(method.getFullName());
}

private static boolean isEmptyService(
ServiceDescriptor serviceDescriptor,
Optional<com.google.api.Service> serviceYamlProtoOpt,
String protoPackage) {
List<MethodDescriptor> methodsList = serviceDescriptor.getMethods();
List<MethodDescriptor> methodListSelected =
methodsList.stream()
.filter(
method ->
shouldIncludeMethodInGeneration(method, serviceYamlProtoOpt, protoPackage))
.collect(Collectors.toList());
if (methodListSelected.isEmpty()) {
LOGGER.log(
Level.WARNING,
"Service {0} has no RPC methods and will not be generated",
serviceDescriptor.getName());
}
return methodListSelected.isEmpty();
}

public static List<Service> parseService(
FileDescriptor fileDescriptor,
Map<String, Message> messageTypes,
Expand All @@ -433,19 +500,11 @@ public static List<Service> parseService(
Optional<GapicServiceConfig> serviceConfigOpt,
Set<ResourceName> outputArgResourceNames,
Transport transport) {

String protoPackage = fileDescriptor.getPackage();
return fileDescriptor.getServices().stream()
.filter(
serviceDescriptor -> {
List<MethodDescriptor> methodsList = serviceDescriptor.getMethods();
if (methodsList.isEmpty()) {
LOGGER.warning(
String.format(
"Service %s has no RPC methods and will not be generated",
serviceDescriptor.getName()));
}
return !methodsList.isEmpty();
})
serviceDescriptor ->
!isEmptyService(serviceDescriptor, serviceYamlProtoOpt, protoPackage))
.map(
s -> {
// Workaround for a missing default_host and oauth_scopes annotation from a service
Expand Down Expand Up @@ -498,6 +557,8 @@ public static List<Service> parseService(
String pakkage = TypeParser.getPackage(fileDescriptor);
String originalJavaPackage = pakkage;
// Override Java package with that specified in gapic.yaml.
// this override is deprecated and legacy support only
// see go/client-user-guide#configure-long-running-operation-polling-timeouts-optional
if (serviceConfigOpt.isPresent()
&& serviceConfigOpt.get().getLanguageSettingsOpt().isPresent()) {
GapicLanguageSettings languageSettings =
Expand All @@ -518,6 +579,7 @@ public static List<Service> parseService(
.setMethods(
parseMethods(
s,
protoPackage,
pakkage,
messageTypes,
resourceNames,
Expand Down Expand Up @@ -709,6 +771,7 @@ public static Map<String, ResourceName> parseResourceNames(
@VisibleForTesting
static List<Method> parseMethods(
ServiceDescriptor serviceDescriptor,
String protoPackage,
String servicePackage,
Map<String, Message> messageTypes,
Map<String, ResourceName> resourceNames,
Expand All @@ -721,8 +784,10 @@ static List<Method> parseMethods(
// Parse the serviceYaml for autopopulated methods and fields once and put into a map
Map<String, List<String>> autoPopulatedMethodsWithFields =
parseAutoPopulatedMethodsAndFields(serviceYamlProtoOpt);

for (MethodDescriptor protoMethod : serviceDescriptor.getMethods()) {
if (!shouldIncludeMethodInGeneration(protoMethod, serviceYamlProtoOpt, protoPackage)) {
continue;
}
// Parse the method.
TypeNode inputType = TypeParser.parseType(protoMethod.getInputType());
Method.Builder methodBuilder = Method.builder();
Expand Down
Loading

0 comments on commit fab1b38

Please sign in to comment.