You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "efegokdemir (via GitHub)" <gi...@apache.org> on 2026/09/27 06:08:19 UTC
[PR] fix: avoid duplicate newlines in appended resources [maven-shade-plugin]
efegokdemir opened a new pull request, #862:
URL: https://github.com/apache/maven-shade-plugin/pull/862
## Summary
Avoid adding a second line feed when an appended resource already ends with one.
## Changes
- Add a separator only when the processed resource does not already end with a line feed.
- Add regression coverage for resources with and without a trailing line feed.
## Testing
- `mvn -q -Dspotless.skip=true -Dcheckstyle.skip=true -Dtest=AppendingTransformerTest test` — passed
- `mvn -q -Dspotless.skip=true -Dcheckstyle.skip=true verify` — passed
- `git diff --check` — passed
The local Spotless/Palantir formatter could not run because its installed formatter is incompatible with the local JDK; the repository's Java source formatting remains unchanged outside this focused diff.
Fixes #798
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: avoid duplicate newlines in appended resources [maven-shade-plugin]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #862:
URL: https://github.com/apache/maven-shade-plugin/pull/862#discussion_r4366929820
##########
src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java:
##########
@@ -46,8 +46,11 @@ public boolean canTransformResource(String r) {
@Override
public void processResource(String resource, InputStream is, List<Relocator> relocators, long time)
throws IOException {
+ int previousSize = data.size();
IOUtil.copy(is, data);
- data.write('\n');
+ if (data.size() > previousSize && data.toByteArray()[data.size() - 1] != '\n') {
Review Comment:
When all matching inputs are empty, this guard leaves `data` empty, so `hasTransformedResource()` remains false. `DefaultShader` consumes those inputs but then skips `modifyOutputStream()`, causing the resource to disappear from the shaded JAR rather than preserving an empty entry. Track whether a resource was processed independently of the buffer size, and add an empty-only regression test.
##########
src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java:
##########
@@ -46,8 +46,11 @@ public boolean canTransformResource(String r) {
@Override
public void processResource(String resource, InputStream is, List<Relocator> relocators, long time)
throws IOException {
+ int previousSize = data.size();
IOUtil.copy(is, data);
- data.write('\n');
+ if (data.size() > previousSize && data.toByteArray()[data.size() - 1] != '\n') {
Review Comment:
`toByteArray()` copies the entire accumulated resource on every nonempty append just to inspect its final byte. For N equal-sized inputs, this introduces quadratic copying and allocation instead of the previous linear append cost, increasing build time and garbage collection pressure for projects merging many resources. Inspect only the incoming resource's bytes, or track the last byte during copying, without repeatedly cloning the accumulated buffer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: avoid duplicate newlines in appended resources [maven-shade-plugin]
Posted by "github-actions[bot] (via GitHub) via issues" <is...@maven.apache.org>.
github-actions[bot] commented on PR #862:
URL: https://github.com/apache/maven-shade-plugin/pull/862#issuecomment-6542666101
<!-- license-declaration-check -->
### ⚠️ License declaration missing
The pull request description must contain at least one of the following lines with a **checked** box (`[x]`):
```markdown
- [ ] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [ ] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
```
This comment will be hidden automatically once the description is fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org