Skip to content

fix: make gapic-generator-java output zip timestamps deterministic#12200

Open
benjaminp wants to merge 1 commit intogoogleapis:mainfrom
benjaminp:deterministic-generator
Open

fix: make gapic-generator-java output zip timestamps deterministic#12200
benjaminp wants to merge 1 commit intogoogleapis:mainfrom
benjaminp:deterministic-generator

Conversation

@benjaminp
Copy link

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.

@benjaminp benjaminp requested a review from a team as a code owner March 25, 2026 18:27
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 gapic-generator-java by ensuring that all generated JAR files have deterministic timestamps for their entries. By setting a fixed timestamp, the build process becomes more reproducible, which is vital for consistent development and deployment environments. This change aligns with best practices for build systems like Bazel, improving the reliability and verifiability of the generated artifacts.

Highlights

  • Deterministic JAR Timestamps: Implemented a mechanism to set a fixed timestamp on all entries within generated JAR files, ensuring deterministic output. This addresses issues with build reproducibility caused by varying timestamps.
  • New Helper Method for JarEntry Creation: Introduced a private static helper method jarEntry(String name) in Writer.java that creates a JarEntry and explicitly sets its time to a predefined fixed value (1262304000000L).
  • Consistent JarEntry Usage: Modified all existing JarEntry instantiations across various write methods in Writer.java to utilize the newly created jarEntry helper method, centralizing the timestamp control.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gapic-generator-java embeds timestmaps in output

1 participant