fix: make gapic-generator-java output zip timestamps deterministic#12200
fix: make gapic-generator-java output zip timestamps deterministic#12200benjaminp wants to merge 1 commit intogoogleapis:mainfrom
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/sdk-platform-java#4096.
Summary of ChangesHello, 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 enhances the Highlights
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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the Writer.java file by introducing a new helper method jarEntry to standardize the creation of JarEntry objects. This method sets a fixed timestamp for all JAR entries, which helps in generating deterministic JAR files. The review suggests extracting the magic number used for the timestamp into a named constant for improved readability and maintainability, and adding a clarifying comment.
|
|
||
| private static JarEntry jarEntry(String name) { | ||
| JarEntry entry = new JarEntry(name); | ||
| entry.setTime(1262304000000L); |
There was a problem hiding this comment.
To improve readability and maintainability, it's best to extract the magic number 1262304000000L into a named constant. This makes the purpose of the number clear and follows best practices. You could also add a comment explaining what this timestamp represents (e.g., January 1, 2010, 00:00:00 GMT), similar to the Bazel implementation you referenced.
// A constant time for all entries in the jar. This is January 1, 2010, 00:00:00 GMT.
// Using a constant time makes the jars deterministic.
final long defaultTimestampMillis = 1262304000000L;
entry.setTime(defaultTimestampMillis);
Set a fixed timestamp on all output Jar entries. This follows the approach of Bazel's Jar creation logic.
Fixes googleapis/sdk-platform-java#4096.