From 50a869394aa1cc005172933cfa07c872dc9a0374 Mon Sep 17 00:00:00 2001 From: Chanseok Oh Date: Thu, 27 Jan 2022 13:55:20 -0500 Subject: [PATCH] chore: rework build infrastructure (#913) --- PROPERTIES.bzl | 33 +++++++++++++ WORKSPACE | 8 --- dependencies.properties | 40 --------------- repositories.bzl | 2 +- repository_rules.bzl | 49 ------------------- .../BatchingDescriptorComposerTest.java | 10 ++-- 6 files changed, 38 insertions(+), 104 deletions(-) create mode 100644 PROPERTIES.bzl delete mode 100644 dependencies.properties delete mode 100644 repository_rules.bzl diff --git a/PROPERTIES.bzl b/PROPERTIES.bzl new file mode 100644 index 0000000000..1adc9b2fd0 --- /dev/null +++ b/PROPERTIES.bzl @@ -0,0 +1,33 @@ +PROPERTIES = { + "version.com_google_protobuf": "3.19.1", + # Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8. + "version.google_java_format": "1.7", + "version.com_google_api_common_java": "1.9.3", + "version.io_grpc_java": "1.42.1", + + # Common deps. + "maven.com_google_guava_guava": "com.google.guava:guava:30.1-android", + "maven.com_google_code_findbugs_jsr305": "com.google.code.findbugs:jsr305:3.0.0", + "maven.com_google_auto_value_auto_value": "com.google.auto.value:auto-value:1.7.2", + "maven.com_google_auto_value_auto_value_annotations": "com.google.auto.value:auto-value-annotations:1.7.2", + "maven.com_google_code_gson": "com.google.code.gson:gson:2.8.6", + "maven.com_google_protobuf_protobuf_java": "com.google.protobuf:protobuf-java:3.19.1", + "maven.io_github_java_diff_utils": "io.github.java-diff-utils:java-diff-utils:4.0", + "maven.javax_annotation_javax_annotation_api": "javax.annotation:javax.annotation-api:1.3.2", + "maven.javax_validation_javax_validation_api": "javax.validation:validation-api:2.0.1.Final", + + # Gapic YAML parsing for batching settings. + "maven.org_yaml_snakeyaml": "org.yaml:snakeyaml:1.26", + + # ServiceStubSettings class. Used only in generated code. + "maven.org_threeten_threetenbp": "org.threeten:threetenbp:1.3.3", + + # Testing. + "maven.junit_junit": "junit:junit:4.13.1", + # This hamcrest-core dependency is for running JUnit test manually, before JUnit 4.11 it's wrapped along with JUnit package. + # But now it has to be explicitly added. + "maven.org_hamcrest_hamcrest_core": "org.hamcrest:hamcrest-core:1.3", + "maven.org_mockito_mockito_core": "org.mockito:mockito-core:2.21.0", + # Keep in sync with gax-java. + "maven.com_google_truth_truth": "com.google.truth:truth:1.1.2", +} diff --git a/WORKSPACE b/WORKSPACE index 767c6560b6..87f44eeca7 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -52,14 +52,6 @@ load("@com_google_api_gax_java//:repositories.bzl", "com_google_api_gax_java_rep com_google_api_gax_java_repositories() -load("//:repository_rules.bzl", "gapic_generator_java_properties") - -gapic_generator_java_properties( - name = "gapic_generator_java_properties", - file = "//:dependencies.properties", -) - -load("@gapic_generator_java_properties//:dependencies.properties.bzl", "PROPERTIES") load("//:repositories.bzl", "gapic_generator_java_repositories") gapic_generator_java_repositories() diff --git a/dependencies.properties b/dependencies.properties deleted file mode 100644 index fb33bd94ea..0000000000 --- a/dependencies.properties +++ /dev/null @@ -1,40 +0,0 @@ -# This file is shared between gradle and bazel build scripts and exists to keep the dependencies -# configuration between the two build systems in sync. - -# The properties format is the following: -# [.]= - -# Target workspace name: gapic_generator_java - -# Versions only, for dependencies which actual artifacts differ between Bazel and Gradle -version.com_google_protobuf=3.19.1 -# Version of google-java-format is downgraded from 1.8 to 1.7, because 1.8 supports java 11 minimum, while our JRE is java 8. -version.google_java_format=1.7 -version.com_google_api_common_java=1.9.3 -version.io_grpc_java=1.42.1 - -# Common deps. -maven.com_google_guava_guava=com.google.guava:guava:30.1-android -maven.com_google_code_findbugs_jsr305=com.google.code.findbugs:jsr305:3.0.0 -maven.com_google_auto_value_auto_value=com.google.auto.value:auto-value:1.7.2 -maven.com_google_auto_value_auto_value_annotations=com.google.auto.value:auto-value-annotations:1.7.2 -maven.com_google_code_gson=com.google.code.gson:gson:2.8.6 -maven.com_google_protobuf_protobuf_java=com.google.protobuf:protobuf-java:3.19.1 -maven.io_github_java_diff_utils=io.github.java-diff-utils:java-diff-utils:4.0 -maven.javax_annotation_javax_annotation_api=javax.annotation:javax.annotation-api:1.3.2 -maven.javax_validation_javax_validation_api=javax.validation:validation-api:2.0.1.Final - -# Gapic YAML parsing for batching settings. -maven.org_yaml_snakeyaml=org.yaml:snakeyaml:1.26 - -# ServiceStubSettings class. Used only in generated code. -maven.org_threeten_threetenbp=org.threeten:threetenbp:1.3.3 - -# Testing. -maven.junit_junit=junit:junit:4.13.1 -# This hamcrest-core dependency is for running JUnit test manually, before JUnit 4.11 it's wrapped along with JUnit package. -# But now it has to be explicitly added. -maven.org_hamcrest_hamcrest_core=org.hamcrest:hamcrest-core:1.3 -maven.org_mockito_mockito_core=org.mockito:mockito-core:2.21.0 -# Keep in sync with gax-java. -maven.com_google_truth_truth=com.google.truth:truth:1.1.2 diff --git a/repositories.bzl b/repositories.bzl index 85dbf7e334..fc241af91c 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -15,7 +15,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") -load("@gapic_generator_java_properties//:dependencies.properties.bzl", "PROPERTIES") +load("//:PROPERTIES.bzl", "PROPERTIES") def gapic_generator_java_repositories(): # Import dependencies shared between Gradle and Bazel (i.e. maven dependencies) diff --git a/repository_rules.bzl b/repository_rules.bzl deleted file mode 100644 index dff7ef57b1..0000000000 --- a/repository_rules.bzl +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2019 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. - -def _gapic_generator_java_properties_impl(ctx): - props_path = ctx.path(ctx.attr.file) - result = ctx.execute(["cat", props_path]) - - if result.return_code != 0: - fail("Could not load dependencies from properties file, error_code %s" + result.return_code) - - props = result.stdout.splitlines() - props_as_map = {} - - for prop in props: - p = prop.strip() - if len(p) <= 0 or p.startswith("#"): - continue - key_value = p.split("=", 1) - props_as_map[key_value[0]] = key_value[1] - - props_name = ctx.attr.file.name - dependencies_bzl = """ -# DO NOT EDIT. This file was generated from {properties_file}. -PROPERTIES = {props_as_map} - """.format( - properties_file = props_name, - props_as_map = str(props_as_map), - ) - ctx.file("BUILD.bazel", "") - ctx.file("%s.bzl" % props_name, dependencies_bzl) - -gapic_generator_java_properties = repository_rule( - implementation = _gapic_generator_java_properties_impl, - attrs = { - "file": attr.label(), - }, - local = True, -) diff --git a/src/test/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposerTest.java index 50fdf0fac3..a3cae5106c 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/common/BatchingDescriptorComposerTest.java @@ -178,11 +178,9 @@ public void batchingDescriptor_noSubresponseField() { } private static Method findMethod(Service service, String methodName) { - for (Method m : service.methods()) { - if (m.name().equals(methodName)) { - return m; - } - } - return null; + return service.methods().stream() + .filter(m -> m.name().equals(methodName)) + .findFirst() + .orElse(null); } }