Skip to content
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

Retain comments / licenses in service provider files when merging jars #1123

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

vinnybod
Copy link
Contributor

@vinnybod vinnybod commented May 1, 2024

I have a situation where I need a license to be on the META-INF/services files in the final jar.
The current behavior sorts the lines of the service file, including lines that are just comments, resulting in a jumbled output.

The desired behavior is to preserve the comments/licenses

Examples below and in this repo: https://github.com/vinnybod/bazel_java_example/tree/service-file-issues

For an input of:

 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements. See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.
 # The ASF licenses this file to You under the Apache License, Version 2.0
 # (the "License"); you may not use this file except in compliance with
 # the License. You may obtain a copy of the License at
 #
 #    http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
com.example.ThingProviderImpl

The current output is:

 #
 #    http://www.apache.org/licenses/LICENSE-2.0
 # (the "License"); you may not use this file except in compliance with
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # See the License for the specific language governing permissions and
 # The ASF licenses this file to You under the Apache License, Version 2.0
 # Unless required by applicable law or agreed to in writing, software
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # contributor license agreements. See the NOTICE file distributed with
 # distributed under the License is distributed on an "AS IS" BASIS,
 # limitations under the License.
 # the License. You may obtain a copy of the License at
 # this work for additional information regarding copyright ownership.
com.example.ThingProviderImpl

@vinnybod vinnybod changed the title Allow text to prepended to service provider files in java_export Allow text to be prepended to service provider files in java_export May 1, 2024
@shs96c
Copy link
Collaborator

shs96c commented May 7, 2024

Thank you for the PR. Keeping the license may or may not be necessary, but any approach we take that requires user intervention is a problem: people forget, and that's a pain. One question: is the header you're adding for your code, or something you're preserving?

If we're attempting to preserve comments and license information already present in the file, we may want to do something like ordering the inputs deterministically, and then concatenating service files. Assuming that the creation of the service files is deterministic (oh boy), this should be enough to ensure a repeatable build.

If it's the case that you're adding the header yourself, that seems pretty unusual, and it may be worth gently pushing back on that requirement. If it's inescapable, creating the service file yourself and then using the above solution may work.

@vinnybod
Copy link
Contributor Author

vinnybod commented May 7, 2024

is the header you're adding for your code, or something you're preserving?

I am trying to preserve the header that already exists in the service file

If we're attempting to preserve comments and license information already present in the file, we may want to do something like ordering the inputs deterministically, and then concatenating service files.

This could work. Are you opposed to just concatenating the input service files and not doing any sorting of the input lines?
Example:

# Input 1 License
com.inputone.name

# Input 2 License
com.inputtwo.name

If so, I'd prefer this too, because managing the additional property will likely lead to errors in the future, like you said.

@shs96c
Copy link
Collaborator

shs96c commented May 8, 2024

Concatenating in a deterministic order is what I'm suggesting.

@vinnybod vinnybod changed the title Allow text to be prepended to service provider files in java_export Retain comments / licenses in service provider files when merging jars May 8, 2024
@vinnybod
Copy link
Contributor Author

vinnybod commented May 8, 2024

Updated with @shs96c 's suggestions.

It now concatenates the service provider files, retaining the comments/licenses. It should be in a deterministic order given that sources is a LinkedHashSet already.

@vinnybod
Copy link
Contributor Author

@shs96c I think this change should be uncontroversial now.

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.

None yet

2 participants