Skip to content

feat(internal/librarian/java): support alternate license header files#6311

Open
sofisl wants to merge 13 commits into
mainfrom
addAlternateHeaderConfig
Open

feat(internal/librarian/java): support alternate license header files#6311
sofisl wants to merge 13 commits into
mainfrom
addAlternateHeaderConfig

Conversation

@sofisl

@sofisl sofisl commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Added support for custom external alternate license header files during Java code regeneration.
When alternate_headers is configured with a relative file path in the library's java configuration block, Librarian reads that file and appends its contents as the license header instead of the standard header. A temporary, backwards-compatible migration check ensures monolithic libraries retain their existing skip behavior until their config is updated.

There will be two f/u PRs: the first in google-cloud-java to add the property and the header. The second in librarian to remove the monolithic block since (I think) it only applies to grafeas, and just rely on the alternate headers path.

For #6178

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 introduces support for alternate license headers in Java modules by adding an AlternateHeaders configuration field and updating the post-processing logic to read from this file if provided. The review feedback focuses on improving test robustness by using bytes.HasPrefix instead of bytes.Contains to verify headers, optimizing the license text retrieval to return []byte directly to avoid unnecessary string conversions, and properly wrapping errors.

Comment thread internal/librarian/java/postprocess_test.go Outdated
Comment thread internal/librarian/java/postprocess_test.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
sofisl and others added 5 commits June 4, 2026 16:36
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: sofisl <55454395+sofisl@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: sofisl <55454395+sofisl@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: sofisl <55454395+sofisl@users.noreply.github.com>
Comment thread internal/librarian/java/postprocess.go Outdated
@sofisl

sofisl commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 introduces support for configuring alternate license headers in Java modules. It adds an alternate_headers field to the configuration schema and the JavaModule struct, and updates the post-processing logic to read and apply the alternate header text from the specified file path. Comprehensive unit tests have been added to verify this new behavior, including error handling for missing header files. No review comments were provided, so there is no additional feedback to address.

@sofisl sofisl marked this pull request as ready for review June 4, 2026 23:51
@sofisl sofisl requested a review from a team as a code owner June 4, 2026 23:51
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess_test.go Outdated
Comment thread internal/librarian/java/postprocess_test.go
Comment thread internal/librarian/java/postprocess_test.go Outdated
sofisl and others added 2 commits June 5, 2026 10:33
Co-authored-by: Joe Wang <106995533+JoeWang1127@users.noreply.github.com>
Signed-off-by: sofisl <55454395+sofisl@users.noreply.github.com>
@sofisl sofisl requested a review from JoeWang1127 June 5, 2026 22:02
Comment thread internal/librarian/java/postprocess_test.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess.go Outdated
@sofisl sofisl requested a review from JoeWang1127 June 6, 2026 00:31
Comment thread internal/librarian/java/postprocess.go Outdated
Comment thread internal/librarian/java/postprocess_test.go Outdated
content: "some text",
},
{
name: "alternate header",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this test case different from TestPostProcessAPI_AlternateHeaders?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right, can be safely removed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you remove this test? I still see it in the pull request.

@sofisl sofisl requested a review from JoeWang1127 June 9, 2026 23:40
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.

2 participants