-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: gapic-generator-java to perform a no-op when no services are detected #2460
base: main
Are you sure you want to change the base?
Conversation
Throwing an exception and catch it just to perform no-op and/or logging is not a good practice. It would be better if we can do the same thing gracefully. For example, can we remove this check, log the scenario, and return an empty |
… into gapic-generator-no-service-noop
From https://github.com/googleapis/sdk-platform-java/actions/runs/8150253915/job/22276206879?pr=2460
I confirmed they pass locally. Not sure how to prove it in a PR that updates both the generator and the hermetic build scripts Reason: the hermetic build IT uses a published GGJ instead of compiling its own EDIT: I decided to move all |
...-generator-java/src/main/java/com/google/api/generator/engine/ast/PackageInfoDefinition.java
Outdated
Show resolved
Hide resolved
...c-generator-java/src/main/java/com/google/api/generator/engine/writer/JavaWriterVisitor.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/google/api/generator/gapic/composer/ClientLibraryPackageInfoComposer.java
Outdated
Show resolved
Hide resolved
gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/GapicPackageInfo.java
Outdated
Show resolved
Hide resolved
@@ -154,6 +168,22 @@ public void composeSamples_parseProtoPackage() { | |||
} | |||
} | |||
|
|||
@Test | |||
public void testEmptyGapicContext_succeeds() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I read from the test, you want to verify no exception is thrown in Composer.composeServiceClasses(GapicContext.EMPTY)
How about write tests verifying the result, rather assert the exception is null? The test will fail if an exception is thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this simplifies the test. Done.
} | ||
|
||
@Test | ||
public void productionWrite_emptyGapicContext_succeeds() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment on testEmptyGapicContext_succeeds
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
What creates the |
…rvice-noop # Conflicts: # gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/ComposerTest.java # gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java # gapic-generator-java/src/test/java/com/google/api/generator/gapic/protowriter/WriterTest.java
That sounds good. I modified |
Quality Gate passed for 'gapic-generator-java-root'Issues Measures |
Quality Gate passed for 'java_showcase_integration_tests'Issues Measures |
@@ -53,8 +56,13 @@ class ComposerTest { | |||
.build(); | |||
private List<Sample> ListofSamples = Arrays.asList(new Sample[] {sample}); | |||
|
|||
@Before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this tag to @BeforeEach
?
@Test | ||
void gapicClass_addApacheLicense() { | ||
public void gapicClass_addApacheLicense_validInput_succeeds() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the public
in the signature?
@@ -175,7 +179,10 @@ public static GapicContext parse(CodeGeneratorRequest request) { | |||
mixinServices, | |||
transport); | |||
|
|||
Preconditions.checkState(!services.isEmpty(), "No services found to generate"); | |||
if (services.isEmpty()) { | |||
LOGGER.warning("No services found to generate. This will produce an empty zip file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq, is this still correct? If
if (response != EMPTY_RESPONSE) {
response.writeTo(System.out);
}
doesn't write anything to System.out does it generate a zip file?
// package info may come as null if we have no services, but we will exit | ||
// this function early if so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq, is this also still true? I don't see writePackageInfo()
exiting early.
@@ -154,6 +162,16 @@ void composeSamples_parseProtoPackage() { | |||
} | |||
} | |||
|
|||
@Test | |||
public void testEmptyGapicContext_doesNotThrow() { | |||
Composer.composeServiceClasses(GapicContext.EMPTY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can this be something like assert empty list or assert null instead?
GapicContext result = Parser.parse(CodeGeneratorRequest.newBuilder().build()); | ||
assertFalse(result.containsServices()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: to match the test method, can this be assert that the result == GapicContext.Empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a few nits regarding the comments and tests
Fixes #2050
Adds behavior to gracefully perform a NOOP if no services are contained in the generation request.
Confimation in hermetic build scripts
From
generate_library.sh
againstgoogle/cloud/alloydb/connectors/v1
I made some changes to library_generation but I moved them to a follow up PR (#2599) so the checks can pass here.