From d15074769db3e5552ad758bf6d06140a48d80fbe Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 12 Feb 2024 20:29:46 +0000 Subject: [PATCH] revert NoServicesFoundException --- .../src/main/java/com/google/api/generator/Main.java | 10 ++-------- .../java/com/google/api/generator/gapic/Generator.java | 5 +---- .../composer/ClientLibraryPackageInfoComposer.java | 7 +++---- .../gapic/protoparser/NoServicesFoundException.java | 9 --------- .../google/api/generator/gapic/protoparser/Parser.java | 4 ++-- .../api/generator/gapic/protoparser/ParserTest.java | 1 + 6 files changed, 9 insertions(+), 27 deletions(-) delete mode 100644 gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/NoServicesFoundException.java diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/Main.java b/gapic-generator-java/src/main/java/com/google/api/generator/Main.java index 35ba225bf8..2ad75c19ba 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/Main.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/Main.java @@ -15,7 +15,6 @@ package com.google.api.generator; import com.google.api.generator.gapic.Generator; -import com.google.api.generator.gapic.protoparser.NoServicesFoundException; import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; @@ -26,12 +25,7 @@ public static void main(String[] args) throws IOException { ExtensionRegistry registry = ExtensionRegistry.newInstance(); ProtoRegistry.registerAllExtensions(registry); CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry); - try { - CodeGeneratorResponse response = Generator.generateGapic(request); - response.writeTo(System.out); - } catch (NoServicesFoundException ex) { - // If no services are found in the protos we will no-op - System.err.println("No services found to generate"); - } + CodeGeneratorResponse response = Generator.generateGapic(request); + response.writeTo(System.out); } } diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/Generator.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/Generator.java index f8e5c8ed2b..b005a16ceb 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/Generator.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/Generator.java @@ -14,13 +14,11 @@ package com.google.api.generator.gapic; -import com.google.api.gax.rpc.StatusCode.Code; import com.google.api.generator.gapic.composer.Composer; import com.google.api.generator.gapic.model.GapicClass; import com.google.api.generator.gapic.model.GapicContext; import com.google.api.generator.gapic.model.GapicPackageInfo; import com.google.api.generator.gapic.model.ReflectConfig; -import com.google.api.generator.gapic.protoparser.NoServicesFoundException; import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.gapic.protowriter.Writer; import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; @@ -28,8 +26,7 @@ import java.util.List; public class Generator { - public static CodeGeneratorResponse generateGapic(CodeGeneratorRequest request) - throws NoServicesFoundException { + public static CodeGeneratorResponse generateGapic(CodeGeneratorRequest request) { GapicContext context = Parser.parse(request); List clazzes = Composer.composeServiceClasses(context); GapicPackageInfo packageInfo = Composer.composePackageInfo(context); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java index f5d509ba8f..6f84847349 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java @@ -29,7 +29,7 @@ import com.google.api.generator.gapic.model.GapicPackageInfo; import com.google.api.generator.gapic.model.Sample; import com.google.api.generator.gapic.model.Service; -import com.google.api.generator.gapic.protoparser.NoServicesFoundException; +import com.google.common.base.Preconditions; import com.google.common.base.Strings; import javax.annotation.Generated; @@ -44,9 +44,8 @@ public class ClientLibraryPackageInfoComposer { private static final String SERVICE_DESCRIPTION_HEADER_PATTERN = "Service Description: %s"; public static GapicPackageInfo generatePackageInfo(GapicContext context) { - if (context.services().isEmpty()) { - throw new NoServicesFoundException("No services found to generate"); - } + Preconditions.checkState(!context.services().isEmpty(), "No services found to generate"); + // Pick some service's package, as we assume they are all the same. String libraryPakkage = context.services().get(0).pakkage(); diff --git a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/NoServicesFoundException.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/NoServicesFoundException.java deleted file mode 100644 index e37101a32c..0000000000 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/NoServicesFoundException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.google.api.generator.gapic.protoparser; - -public class NoServicesFoundException extends IllegalStateException { - - public NoServicesFoundException() {} - public NoServicesFoundException(String message) { - super(message); - } -} 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 4afbfe4321..81ffdfd628 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 @@ -115,7 +115,7 @@ public GapicParserException(String errorMessage) { } } - public static GapicContext parse(CodeGeneratorRequest request) throws NoServicesFoundException { + public static GapicContext parse(CodeGeneratorRequest request) { Optional gapicYamlConfigPathOpt = PluginArgumentParser.parseGapicYamlConfigPath(request); Optional> batchingSettingsOpt = @@ -176,7 +176,7 @@ public static GapicContext parse(CodeGeneratorRequest request) throws NoServices transport); if (services.isEmpty()) { - throw new NoServicesFoundException(); + //throw new NoServicesFoundException(); } // TODO(vam-google): Figure out whether we should keep this allowlist or bring 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..70e95959b7 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 @@ -42,6 +42,7 @@ import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.MethodDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; +import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; import com.google.showcase.v1beta1.EchoOuterClass; import com.google.showcase.v1beta1.TestingOuterClass; import com.google.testgapic.v1beta1.LockerProto;