-
Notifications
You must be signed in to change notification settings - Fork 72
fix: make gapic-generator-java output zip timestamps deterministic #4097
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
base: main
Are you sure you want to change the base?
Conversation
Set a fixed timestamp on all output Jar entries. This follows the approach of [Bazel's Jar creation logic](https://github.com/bazelbuild/bazel/blob/0327100c98a126b9fc83223ba41303fe8b37d331/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java#L43-L55). Fixes googleapis#4096
Summary of ChangesHello @benjaminp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses the problem of non-deterministic JAR file generation in Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request makes the output of gapic-generator-java deterministic by setting a fixed timestamp on all entries in the generated JAR file. This is a good practice for reproducible builds. The implementation introduces a helper method to create JarEntry objects with a constant timestamp, and this is applied consistently. I have one suggestion to improve the code's readability and maintainability by extracting the hardcoded date into a named constant.
|
|
||
| private static JarEntry jarEntry(String name) { | ||
| JarEntry entry = new JarEntry(name); | ||
| entry.setTimeLocal(LocalDateTime.of(2010, 1, 1, 0, 0, 0)); | ||
| return entry; | ||
| } |
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.
For better readability and maintainability, consider extracting the magic date LocalDateTime.of(2010, 1, 1, 0, 0, 0) into a private static final constant with a descriptive name. Adding a comment explaining the choice of this date, similar to the Bazel implementation you linked, would also be beneficial. This makes the code more self-documenting.
/**
* The default timestamp for Jar entries. This is 2010-01-01 00:00:00 UTC.
*
* <p>Using a constant timestamp helps ensure that Jar files are deterministic.
*/
private static final LocalDateTime DETERMINISTIC_JAR_TIMESTAMP =
LocalDateTime.of(2010, 1, 1, 0, 0, 0);
private static JarEntry jarEntry(String name) {
JarEntry entry = new JarEntry(name);
entry.setTimeLocal(DETERMINISTIC_JAR_TIMESTAMP);
return entry;
}
Set a fixed timestamp on all output Jar entries. This follows the approach of Bazel's Jar creation logic.
Fixes #4096