From 90cfe2fea3cafbbf604aa89658e24b94e1b77733 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Tue, 10 Nov 2020 16:52:40 -0800 Subject: [PATCH] feat!: remove service.yaml logic from codegen --- .../ClientLibraryPackageInfoComposer.java | 27 +++++-- .../generator/gapic/model/GapicContext.java | 9 --- .../generator/gapic/protoparser/Parser.java | 25 +----- .../protoparser/PluginArgumentParser.java | 24 +----- .../gapic/protoparser/ServiceYamlParser.java | 59 -------------- ...rviceCallableFactoryClassComposerTest.java | 4 +- .../GrpcServiceStubClassComposerTest.java | 16 +--- .../MockServiceClassComposerTest.java | 4 +- .../MockServiceImplClassComposerTest.java | 4 +- .../ResourceNameHelperClassComposerTest.java | 22 +----- .../composer/RetrySettingsComposerTest.java | 18 ++--- .../ServiceClientClassComposerTest.java | 7 +- .../ServiceClientTestClassComposerTest.java | 22 +----- .../ServiceSettingsClassComposerTest.java | 4 +- .../ServiceStubClassComposerTest.java | 4 +- .../ServiceStubSettingsClassComposerTest.java | 2 +- .../gapic/model/GapicServiceConfigTest.java | 3 +- .../generator/gapic/protoparser/BUILD.bazel | 1 - .../gapic/protoparser/ParserTest.java | 4 +- .../protoparser/PluginArgumentParserTest.java | 79 +------------------ .../goldens/asset/package-info.java | 4 +- .../goldens/logging/package-info.java | 4 +- .../goldens/redis/package-info.java | 4 +- 23 files changed, 61 insertions(+), 289 deletions(-) delete mode 100644 src/main/java/com/google/api/generator/gapic/protoparser/ServiceYamlParser.java diff --git a/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java index c4332baeb8..1be7f58de7 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java @@ -24,8 +24,8 @@ import com.google.api.generator.gapic.model.GapicPackageInfo; import com.google.api.generator.gapic.model.Service; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Generated; @@ -37,7 +37,7 @@ public class ClientLibraryPackageInfoComposer { "The interfaces provided are listed below, along with usage samples."; private static final String CLIENT_PATTERN = "%sClient"; - private static final String PACKAGE_INFO_TITLE_PATTERN = "A client to %s"; + private static final String PACKAGE_INFO_TITLE_PATTERN = "Clients for %s."; private static final String SAMPLE_CODE_HEADER_PATTERN = "Sample for %s:"; private static final String SERVICE_DESCRIPTION_HEADER_PATTERN = "Service Description: %s"; @@ -61,12 +61,14 @@ public static GapicPackageInfo generatePackageInfo(GapicContext context) { private static CommentStatement createPackageInfoJavadoc(GapicContext context) { JavaDocComment.Builder javaDocCommentBuilder = JavaDocComment.builder(); - if (context.hasServiceYamlProto() - && !Strings.isNullOrEmpty(context.serviceYamlProto().getTitle())) { - javaDocCommentBuilder = - javaDocCommentBuilder.addComment( - String.format(PACKAGE_INFO_TITLE_PATTERN, context.serviceYamlProto().getTitle())); - } + javaDocCommentBuilder = + javaDocCommentBuilder.addComment( + String.format( + PACKAGE_INFO_TITLE_PATTERN, + context.services().stream() + .map(s -> s.name()) + .collect( + Collectors.collectingAndThen(Collectors.toList(), joiningOxfordComma())))); javaDocCommentBuilder = javaDocCommentBuilder.addParagraph(PACKAGE_INFO_DESCRIPTION); @@ -117,4 +119,13 @@ private static CommentStatement createPackageInfoJavadoc(GapicContext context) { return CommentStatement.withComment(javaDocCommentBuilder.build()); } + + private static Function, String> joiningOxfordComma() { + return vals -> { + int last = vals.size() - 1; + if (last < 1) return String.join("", vals); + if (last == 1) return String.join(" and ", vals); + return String.join(", and ", String.join(", ", vals.subList(0, last)), vals.get(last)); + }; + } } diff --git a/src/main/java/com/google/api/generator/gapic/model/GapicContext.java b/src/main/java/com/google/api/generator/gapic/model/GapicContext.java index 1ed089c4b5..59dbc06806 100644 --- a/src/main/java/com/google/api/generator/gapic/model/GapicContext.java +++ b/src/main/java/com/google/api/generator/gapic/model/GapicContext.java @@ -38,13 +38,6 @@ public abstract class GapicContext { @Nullable public abstract GapicServiceConfig serviceConfig(); - @Nullable - public abstract com.google.api.Service serviceYamlProto(); - - public boolean hasServiceYamlProto() { - return serviceYamlProto() != null; - } - public static Builder builder() { return new AutoValue_GapicContext.Builder(); } @@ -61,8 +54,6 @@ public abstract static class Builder { public abstract Builder setServiceConfig(GapicServiceConfig serviceConfig); - public abstract Builder setServiceYamlProto(com.google.api.Service serviceYamlProto); - public abstract GapicContext build(); } } 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 db3aa08608..f0b2aea2a2 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 @@ -80,13 +80,6 @@ public static GapicContext parse(CodeGeneratorRequest request) { String serviceConfigPath = serviceConfigPathOpt.isPresent() ? serviceConfigPathOpt.get() : null; Optional serviceConfigOpt = ServiceConfigParser.parse(serviceConfigPath); - Optional serviceYamlConfigPathOpt = - PluginArgumentParser.parseServiceYamlConfigPath(request); - Optional serviceYamlProtoOpt = - serviceYamlConfigPathOpt.isPresent() - ? ServiceYamlParser.parse(serviceYamlConfigPathOpt.get()) - : Optional.empty(); - // Keep message and resource name parsing separate for cleaner logic. // While this takes an extra pass through the protobufs, the extra time is relatively trivial // and is worth the larger reduced maintenance cost. @@ -95,15 +88,13 @@ public static GapicContext parse(CodeGeneratorRequest request) { messages = updateResourceNamesInMessages(messages, resourceNames.values()); Set outputArgResourceNames = new HashSet<>(); List services = - parseServices( - request, messages, resourceNames, outputArgResourceNames, serviceYamlProtoOpt); + parseServices(request, messages, resourceNames, outputArgResourceNames); return GapicContext.builder() .setServices(services) .setMessages(messages) .setResourceNames(resourceNames) .setHelperResourceNames(outputArgResourceNames) .setServiceConfig(serviceConfigOpt.isPresent() ? serviceConfigOpt.get() : null) - .setServiceYamlProto(serviceYamlProtoOpt.isPresent() ? serviceYamlProtoOpt.get() : null) .build(); } @@ -111,8 +102,7 @@ public static List parseServices( CodeGeneratorRequest request, Map messageTypes, Map resourceNames, - Set outputArgResourceNames, - Optional serviceYamlProtoOpt) { + Set outputArgResourceNames) { Map fileDescriptors = getFilesToGenerate(request); List services = new ArrayList<>(); @@ -124,12 +114,7 @@ public static List parseServices( fileToGenerate); services.addAll( - parseService( - fileDescriptor, - messageTypes, - resourceNames, - serviceYamlProtoOpt, - outputArgResourceNames)); + parseService(fileDescriptor, messageTypes, resourceNames, outputArgResourceNames)); } return services; @@ -139,7 +124,6 @@ public static List parseService( FileDescriptor fileDescriptor, Map messageTypes, Map resourceNames, - Optional serviceYamlProtoOpt, Set outputArgResourceNames) { String pakkage = TypeParser.getPackage(fileDescriptor); @@ -154,9 +138,6 @@ public static List parseService( if (serviceOptions.hasExtension(ClientProto.defaultHost)) { defaultHost = sanitizeDefaultHost(serviceOptions.getExtension(ClientProto.defaultHost)); - } else if (serviceYamlProtoOpt.isPresent()) { - // Fall back to the DNS name supplied in the service .yaml config. - defaultHost = serviceYamlProtoOpt.get().getName(); } Preconditions.checkState( !Strings.isNullOrEmpty(defaultHost), diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/PluginArgumentParser.java b/src/main/java/com/google/api/generator/gapic/protoparser/PluginArgumentParser.java index 0cd4a17bc8..1096055d44 100644 --- a/src/main/java/com/google/api/generator/gapic/protoparser/PluginArgumentParser.java +++ b/src/main/java/com/google/api/generator/gapic/protoparser/PluginArgumentParser.java @@ -26,33 +26,16 @@ public class PluginArgumentParser { // Synced to rules_java_gapic/java_gapic.bzl. @VisibleForTesting static final String KEY_GRPC_SERVICE_CONFIG = "grpc-service-config"; - @VisibleForTesting static final String KEY_SERVICE_YAML_CONFIG = "gapic-service-config"; private static final String JSON_FILE_ENDING = "grpc_service_config.json"; - private static final String GAPIC_YAML_FILE_ENDING = "gapic.yaml"; - private static final String SERVICE_YAML_FILE_ENDING = ".yaml"; static Optional parseJsonConfigPath(CodeGeneratorRequest request) { return parseJsonConfigPath(request.getParameter()); } - static Optional parseServiceYamlConfigPath(CodeGeneratorRequest request) { - return parseServiceYamlConfigPath(request.getParameter()); - } - /** Expects a comma-separated list of file paths. */ @VisibleForTesting static Optional parseJsonConfigPath(String pluginProtocArgument) { - return parseArgument(pluginProtocArgument, KEY_GRPC_SERVICE_CONFIG, JSON_FILE_ENDING); - } - - @VisibleForTesting - static Optional parseServiceYamlConfigPath(String pluginProtocArgument) { - return parseArgument(pluginProtocArgument, KEY_SERVICE_YAML_CONFIG, SERVICE_YAML_FILE_ENDING); - } - - private static Optional parseArgument( - String pluginProtocArgument, String key, String fileEnding) { if (Strings.isNullOrEmpty(pluginProtocArgument)) { return Optional.empty(); } @@ -63,12 +46,7 @@ private static Optional parseArgument( } String keyVal = args[0]; String valueVal = args[1]; - boolean valueMeetsCriteria = keyVal.equals(key) && valueVal.endsWith(fileEnding); - if (fileEnding.equals(SERVICE_YAML_FILE_ENDING)) { - valueMeetsCriteria &= !valueVal.endsWith(GAPIC_YAML_FILE_ENDING); - } - - if (valueMeetsCriteria) { + if (keyVal.equals(KEY_GRPC_SERVICE_CONFIG) && valueVal.endsWith(JSON_FILE_ENDING)) { return Optional.of(valueVal); } } diff --git a/src/main/java/com/google/api/generator/gapic/protoparser/ServiceYamlParser.java b/src/main/java/com/google/api/generator/gapic/protoparser/ServiceYamlParser.java deleted file mode 100644 index 839903d460..0000000000 --- a/src/main/java/com/google/api/generator/gapic/protoparser/ServiceYamlParser.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2020 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 -// -// http://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.generator.gapic.protoparser; - -import com.google.common.base.Strings; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.util.JsonFormat; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.SafeConstructor; - -public class ServiceYamlParser { - public static Optional parse(String serviceYamlFilePath) { - if (Strings.isNullOrEmpty(serviceYamlFilePath) || !(new File(serviceYamlFilePath)).exists()) { - return Optional.empty(); - } - - String fileContents = null; - try { - fileContents = new String(Files.readAllBytes(Paths.get(serviceYamlFilePath))); - } catch (IOException e) { - return Optional.empty(); - } - - Yaml yaml = new Yaml(new SafeConstructor()); - Map yamlMap = yaml.load(fileContents); - Gson gson = new GsonBuilder().setPrettyPrinting().setLenient().create(); - String jsonString = gson.toJson(yamlMap, LinkedHashMap.class); - // Use the full name instead of an import, to avoid reader confusion with this and - // model.Service. - com.google.api.Service.Builder serviceBuilder = com.google.api.Service.newBuilder(); - try { - JsonFormat.parser().ignoringUnknownFields().merge(jsonString, serviceBuilder); - } catch (InvalidProtocolBufferException e) { - return Optional.empty(); - } - return Optional.of(serviceBuilder.build()); - } -} diff --git a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java index bc1f8d0c09..4437b3a166 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceCallableFactoryClassComposerTest.java @@ -32,7 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -54,8 +53,7 @@ public void generateServiceClasses() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = diff --git a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java index 47c7767d45..28f7bec18f 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/GrpcServiceStubClassComposerTest.java @@ -36,7 +36,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Test; @@ -51,8 +50,7 @@ public void generateGrpcServiceStubClass_simple() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(echoProtoService, messageTypes); @@ -75,11 +73,7 @@ public void generateGrpcServiceStubClass_httpBindings() { Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - testingFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + testingFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service testingProtoService = services.get(0); GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(testingProtoService, messageTypes); @@ -108,11 +102,7 @@ public void generateGrpcServiceStubClass_httpBindingsWithSubMessageFields() { Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - serviceFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + serviceFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service service = services.get(0); GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(service, messageTypes); diff --git a/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java index 61785acb7b..aa4e19b271 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/MockServiceClassComposerTest.java @@ -32,7 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -54,8 +53,7 @@ public void generateServiceClasses() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = MockServiceClassComposer.instance().generate(echoProtoService, messageTypes); diff --git a/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java index 624126bb96..6e0295adb2 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/MockServiceImplClassComposerTest.java @@ -32,7 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -54,8 +53,7 @@ public void generateServiceClasses() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = diff --git a/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java index 5532738d73..c0fad3badb 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java @@ -41,7 +41,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -95,8 +94,7 @@ public void generateResourceNameClass_echoFoobarMultiplePatterns() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); ResourceName foobarResname = resourceNames.get("showcase.googleapis.com/Foobar"); assertThat(outputResourceNames).contains(foobarResname); @@ -138,11 +136,7 @@ public void generateResourceNameClass_loggingOnePatternMultipleVariables() { Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - serviceFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + serviceFileDescriptor, messageTypes, resourceNames, outputResourceNames); ResourceName billingAccountLocationResname = resourceNames.get("logging.googleapis.com/BillingAccountLocation"); @@ -170,11 +164,7 @@ public void generateResourceNameClass_testingSessionOnePattern() { Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - testingFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + testingFileDescriptor, messageTypes, resourceNames, outputResourceNames); ResourceName sessionResname = resourceNames.get("showcase.googleapis.com/Session"); assertThat(outputResourceNames).contains(sessionResname); @@ -199,11 +189,7 @@ public void generateResourceNameClass_testingBlueprintPatternWithNonSlashSeparat Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - testingFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + testingFileDescriptor, messageTypes, resourceNames, outputResourceNames); ResourceName testResname = resourceNames.get("showcase.googleapis.com/Test"); assertThat(outputResourceNames).contains(testResname); diff --git a/src/test/java/com/google/api/generator/gapic/composer/RetrySettingsComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/RetrySettingsComposerTest.java index 6d6f69c29e..8c31bbccaa 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/RetrySettingsComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/RetrySettingsComposerTest.java @@ -72,8 +72,7 @@ public void paramDefinitionsBlock_noConfigsFound() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); Service service = services.get(0); @@ -109,8 +108,7 @@ public void paramDefinitionsBlock_basic() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); Service service = services.get(0); @@ -150,8 +148,7 @@ public void codesDefinitionsBlock_noConfigsFound() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); Service service = services.get(0); @@ -187,8 +184,7 @@ public void codesDefinitionsBlock_basic() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); Service service = services.get(0); @@ -227,8 +223,7 @@ public void simpleBuilderExpr_basic() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); Service service = services.get(0); @@ -309,8 +304,7 @@ public void lroBuilderExpr() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); Service service = services.get(0); diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java index 1a882a6a30..7e2f8d24d0 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientClassComposerTest.java @@ -33,7 +33,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Test; @@ -48,8 +47,7 @@ public void generateServiceClasses() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = @@ -72,8 +70,7 @@ public void generateServiceClasses_methodSignatureHasNestedFields() { Map resourceNames = Parser.parseResourceNames(fileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - fileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(fileDescriptor, messageTypes, resourceNames, outputResourceNames); Service protoService = services.get(0); GapicClass clazz = ServiceClientClassComposer.instance().generate(protoService, messageTypes); diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java index a2d576066f..6544e47f9e 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceClientTestClassComposerTest.java @@ -41,7 +41,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Test; @@ -56,8 +55,7 @@ public void generateClientTest_echoClient() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = @@ -83,11 +81,7 @@ public void generateClientTest_testingClientResnameWithOnePatternWithNonSlashSep Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - testingFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + testingFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service testingProtoService = services.get(0); GapicClass clazz = @@ -118,11 +112,7 @@ public void generateClientTest_pubSubPublisherClient() { Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - serviceFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + serviceFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service subscriptionService = services.get(1); assertEquals("Subscriber", subscriptionService.name()); @@ -165,11 +155,7 @@ public void generateClientTest_logging() { Set outputResourceNames = new HashSet<>(); List services = Parser.parseService( - serviceFileDescriptor, - messageTypes, - resourceNames, - Optional.empty(), - outputResourceNames); + serviceFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service loggingService = services.get(0); GapicClass clazz = diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java index bd7b41eb16..17aa47ed38 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceSettingsClassComposerTest.java @@ -32,7 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -54,8 +53,7 @@ public void generateServiceClasses() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java index 2e7a390b0b..87417b7c6e 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubClassComposerTest.java @@ -32,7 +32,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -54,8 +53,7 @@ public void generateServiceClasses() { Map resourceNames = Parser.parseResourceNames(echoFileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, outputResourceNames); Service echoProtoService = services.get(0); GapicClass clazz = ServiceStubClassComposer.instance().generate(echoProtoService, messageTypes); diff --git a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java index dfc35f44d5..5808c905b3 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ServiceStubSettingsClassComposerTest.java @@ -164,6 +164,6 @@ private static List parseServices( Map resourceNames) { Set outputResourceNames = new HashSet<>(); return Parser.parseService( - protoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + protoFileDescriptor, messageTypes, resourceNames, outputResourceNames); } } diff --git a/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java b/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java index 435b4e7402..dbeb6c8e92 100644 --- a/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java +++ b/src/test/java/com/google/api/generator/gapic/model/GapicServiceConfigTest.java @@ -129,8 +129,7 @@ private static Service parseService(FileDescriptor fileDescriptor) { Map resourceNames = Parser.parseResourceNames(fileDescriptor); Set outputResourceNames = new HashSet<>(); List services = - Parser.parseService( - fileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(fileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(1, services.size()); return services.get(0); diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel b/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel index eefb4b9789..30931c1380 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel +++ b/src/test/java/com/google/api/generator/gapic/protoparser/BUILD.bazel @@ -10,7 +10,6 @@ TESTS = [ "ResourceNameParserTest", "ResourceReferenceParserTest", "ServiceConfigParserTest", - "ServiceYamlParserTest", "SourceCodeInfoParserTest", "TypeParserTest", ] diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java index d092b7111b..5668d86445 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java @@ -41,7 +41,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -372,8 +371,7 @@ public void parseResourceNames_inputTypeHasReferenceNotInMethodSignature() { Map messageTypes = Parser.parseMessages(testingFileDescriptor); Map resourceNames = Parser.parseResourceNames(testingFileDescriptor); Set outputResourceNames = new HashSet<>(); - Parser.parseService( - testingFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames); + Parser.parseService(testingFileDescriptor, messageTypes, resourceNames, outputResourceNames); assertEquals(2, outputResourceNames.size()); diff --git a/src/test/java/com/google/api/generator/gapic/protoparser/PluginArgumentParserTest.java b/src/test/java/com/google/api/generator/gapic/protoparser/PluginArgumentParserTest.java index b843a734b7..573f71fcb0 100644 --- a/src/test/java/com/google/api/generator/gapic/protoparser/PluginArgumentParserTest.java +++ b/src/test/java/com/google/api/generator/gapic/protoparser/PluginArgumentParserTest.java @@ -53,11 +53,11 @@ public void parseJsonPath_similarFileAppearsFirst() { String.join( ",", Arrays.asList( - createServiceConfig(gapicPath), + createGrpcServiceConfig(gapicPath), createGrpcServiceConfig("/tmp/something.json"), createGrpcServiceConfig("/tmp/some_grpc_service_configjson"), createGrpcServiceConfig(jsonPath), - createServiceConfig(gapicPath))); + createGrpcServiceConfig(gapicPath))); assertEquals(jsonPath, PluginArgumentParser.parseJsonConfigPath(rawArgument).get()); } @@ -90,82 +90,7 @@ public void parseJsonPath_noneFound() { assertFalse(PluginArgumentParser.parseJsonConfigPath(rawArgument).isPresent()); } - @Test - public void parseServiceYamlPath_onlyOnePresent() { - String servicePath = "/tmp/something.yaml"; - assertEquals( - servicePath, - PluginArgumentParser.parseServiceYamlConfigPath(createServiceConfig(servicePath)).get()); - } - - @Test - public void parseServiceYamlPath_returnsFirstOneFound() { - String servicePathOne = "/tmp/something.yaml"; - String servicePathTwo = "/tmp/other.yaml"; - assertEquals( - servicePathOne, - PluginArgumentParser.parseServiceYamlConfigPath( - String.join( - ",", - Arrays.asList( - createServiceConfig(servicePathOne), createServiceConfig(servicePathTwo)))) - .get()); - } - - @Test - public void parseServiceYamlPath_gapicFilePresent() { - String gapicPath = "/tmp/something_gapic.yaml"; - String servicePath = "/tmp/something.yaml"; - // Both passed under the service yaml flag. - String rawArgument = - String.join( - ",", Arrays.asList(createServiceConfig(gapicPath), createServiceConfig(servicePath))); - assertEquals(servicePath, PluginArgumentParser.parseServiceYamlConfigPath(rawArgument).get()); - - // Passed under the right flags. - rawArgument = - String.join( - ",", Arrays.asList(createServiceConfig(gapicPath), createServiceConfig(servicePath))); - assertEquals(servicePath, PluginArgumentParser.parseServiceYamlConfigPath(rawArgument).get()); - - // Swapped flags. - rawArgument = - String.join( - ",", Arrays.asList(createServiceConfig(gapicPath), createServiceConfig(gapicPath))); - assertFalse(PluginArgumentParser.parseServiceYamlConfigPath(rawArgument).isPresent()); - } - - @Test - public void parseServiceYamlPath_similarFileAppearsFirst() { - String jsonPath = "/tmp/foo_grpc_service_config.json"; - String gapicPath = "/tmp/something_gapic.yaml"; - String servicePath = "/tmp/something.yaml"; - String rawArgument = - String.join( - ",", - Arrays.asList( - createGrpcServiceConfig(jsonPath), - createServiceConfig("/tmp/something.yaml"), - createServiceConfig("/tmp/some_gapicyaml"), - createServiceConfig(gapicPath), - createServiceConfig(servicePath))); - assertEquals(servicePath, PluginArgumentParser.parseServiceYamlConfigPath(rawArgument).get()); - } - - @Test - public void parseServiceYamlPath_noneFound() { - String jsonPath = "/tmp/foo_grpc_service_config.json"; - String gapicPath = ""; - String rawArgument = - String.join(",", Arrays.asList(createGrpcServiceConfig(jsonPath), gapicPath)); - assertFalse(PluginArgumentParser.parseServiceYamlConfigPath(rawArgument).isPresent()); - } - private static String createGrpcServiceConfig(String path) { return String.format("%s=%s", PluginArgumentParser.KEY_GRPC_SERVICE_CONFIG, path); } - - private static String createServiceConfig(String path) { - return String.format("%s=%s", PluginArgumentParser.KEY_SERVICE_YAML_CONFIG, path); - } } diff --git a/test/integration/goldens/asset/package-info.java b/test/integration/goldens/asset/package-info.java index e57f641808..7cbdb1c73d 100644 --- a/test/integration/goldens/asset/package-info.java +++ b/test/integration/goldens/asset/package-info.java @@ -15,7 +15,9 @@ */ /** - * The interfaces provided are listed below, along with usage samples. + * Clients for AssetService. + * + *

The interfaces provided are listed below, along with usage samples. * *

======================= AssetServiceClient ======================= * diff --git a/test/integration/goldens/logging/package-info.java b/test/integration/goldens/logging/package-info.java index 13c3b7b556..ed7528391e 100644 --- a/test/integration/goldens/logging/package-info.java +++ b/test/integration/goldens/logging/package-info.java @@ -15,7 +15,9 @@ */ /** - * The interfaces provided are listed below, along with usage samples. + * Clients for LoggingServiceV2, ConfigServiceV2, and MetricsServiceV2. + * + *

The interfaces provided are listed below, along with usage samples. * *

======================= LoggingServiceV2Client ======================= * diff --git a/test/integration/goldens/redis/package-info.java b/test/integration/goldens/redis/package-info.java index 3ed9ea15f2..685afa59d6 100644 --- a/test/integration/goldens/redis/package-info.java +++ b/test/integration/goldens/redis/package-info.java @@ -15,7 +15,9 @@ */ /** - * The interfaces provided are listed below, along with usage samples. + * Clients for CloudRedis. + * + *

The interfaces provided are listed below, along with usage samples. * *

======================= CloudRedisClient ======================= *