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 6f84847349..94f5418132 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 @@ -44,7 +44,9 @@ public class ClientLibraryPackageInfoComposer { private static final String SERVICE_DESCRIPTION_HEADER_PATTERN = "Service Description: %s"; public static GapicPackageInfo generatePackageInfo(GapicContext context) { - Preconditions.checkState(!context.services().isEmpty(), "No services found to generate"); + if (context.services().isEmpty()) { + return GapicPackageInfo.empty(); + } // 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/model/GapicPackageInfo.java b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicPackageInfo.java index 5c6ac6c3a7..bf1129bf45 100644 --- a/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicPackageInfo.java +++ b/gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicPackageInfo.java @@ -26,6 +26,10 @@ public static GapicPackageInfo with(PackageInfoDefinition packageInfo) { return builder().setPackageInfo(packageInfo).build(); } + public static GapicPackageInfo empty() { + return builder().setPackageInfo(PackageInfoDefinition.builder().build()).build(); + } + static Builder builder() { return new AutoValue_GapicPackageInfo.Builder(); } 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 81ffdfd628..76c647a0fd 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 @@ -176,13 +176,13 @@ public static GapicContext parse(CodeGeneratorRequest request) { transport); if (services.isEmpty()) { - //throw new NoServicesFoundException(); + System.err.println("No services found. Will not generate Gapic clients"); } // TODO(vam-google): Figure out whether we should keep this allowlist or bring // back the unused resource names for all APIs. // Temporary workaround for Ads, who still need these resource names. - if (services.get(0).protoPakkage().startsWith("google.ads.googleads.v")) { + if (!services.isEmpty() && services.get(0).protoPakkage().startsWith("google.ads.googleads.v")) { Function typeNameFn = r -> r.resourceTypeString().substring(r.resourceTypeString().indexOf("/") + 1); Function, Set> typeStringSetFn =