From cf14f15d46d499fdfce2976e33af917724e303a0 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Tue, 5 Nov 2024 14:26:58 -0500 Subject: [PATCH] removed unused method. address sonar issue. --- .../generator/gapic/protoparser/Parser.java | 23 +++++----- .../test/protoloader/TestProtoLoader.java | 44 ------------------- 2 files changed, 13 insertions(+), 54 deletions(-) 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 b89327d4ce..2e17b9026b 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 @@ -85,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; @@ -442,12 +443,14 @@ static boolean shouldIncludeMethodInGeneration( // Give warnings and disregard this config. default to include all. if (!librarySettingsList.get(0).getVersion().isEmpty() && !protoPackage.equals(librarySettingsList.get(0).getVersion())) { - 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)); + 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 @@ -481,10 +484,10 @@ private static boolean isEmptyService( shouldIncludeMethodInGeneration(method, serviceYamlProtoOpt, protoPackage)) .collect(Collectors.toList()); if (methodListSelected.isEmpty()) { - LOGGER.warning( - String.format( - "Service %s has no RPC methods and will not be generated", - serviceDescriptor.getName())); + LOGGER.log( + Level.WARNING, + "Service {0} has no RPC methods and will not be generated", + serviceDescriptor.getName()); } return methodListSelected.isEmpty(); } diff --git a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java index 032cc17edf..4172581d06 100644 --- a/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java +++ b/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java @@ -39,7 +39,6 @@ import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.pubsub.v1.PubsubProto; -import com.google.selective.generate.v1beta1.SelectiveApiGenerationOuterClass; import com.google.showcase.v1beta1.EchoOuterClass; import com.google.showcase.v1beta1.IdentityOuterClass; import com.google.showcase.v1beta1.MessagingOuterClass; @@ -362,49 +361,6 @@ public GapicContext parseAutoPopulateFieldTesting() { .build(); } - public GapicContext parseSelectiveGenerationTesting() { - FileDescriptor selectiveGenerationFileDescriptor = - SelectiveApiGenerationOuterClass.getDescriptor(); - ServiceDescriptor selectiveGenerationServiceDescriptor = - selectiveGenerationFileDescriptor.getServices().get(0); - assertEquals( - selectiveGenerationServiceDescriptor.getName(), "EchoServiceShouldGeneratePartial"); - - String serviceYamlFilename = "selective_api_generation_v1beta1.yaml"; - Path serviceYamlPath = Paths.get(testFilesDirectory, serviceYamlFilename); - Optional serviceYamlOpt = - ServiceYamlParser.parse(serviceYamlPath.toString()); - assertTrue(serviceYamlOpt.isPresent()); - - Map messageTypes = Parser.parseMessages(selectiveGenerationFileDescriptor); - Map resourceNames = - Parser.parseResourceNames(selectiveGenerationFileDescriptor); - Set outputResourceNames = new HashSet<>(); - List services = - Parser.parseService( - selectiveGenerationFileDescriptor, - messageTypes, - resourceNames, - serviceYamlOpt, - outputResourceNames); - - String jsonFilename = "selective_api_generation_grpc_service_config.json"; - Path jsonPath = Paths.get(testFilesDirectory, jsonFilename); - Optional configOpt = ServiceConfigParser.parse(jsonPath.toString()); - assertTrue(configOpt.isPresent()); - GapicServiceConfig config = configOpt.get(); - return GapicContext.builder() - .setMessages(messageTypes) - .setResourceNames(resourceNames) - .setServices(services) - .setHelperResourceNames(outputResourceNames) - .setServiceYamlProto(serviceYamlOpt.orElse(null)) - .setGapicMetadataEnabled(true) - .setServiceConfig(config) - .setTransport(transport) - .build(); - } - public GapicContext parsePubSubPublisher() { FileDescriptor serviceFileDescriptor = PubsubProto.getDescriptor(); FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor();