Skip to content

Trim the last EOL in AppendingTransformer processing - #247

Open
Goooler wants to merge 1 commit into
apache:masterfrom
Goooler:g/tweak-eol-writing
Open

Trim the last EOL in AppendingTransformer processing#247
Goooler wants to merge 1 commit into
apache:masterfrom
Goooler:g/tweak-eol-writing

Conversation

@Goooler

@Goooler Goooler commented Jan 19, 2025

Copy link
Copy Markdown
Member

This is useful for supporting the custom line separator in the future. In that case we can handle resources/application.yml files, that are separated by ---.
I did the same patch for Gradle Shadow plugin in GradleUp/shadow#1169.

I'm not very familiar with MVN or MSHADE, please tell me if I am missing something in related use cases or integration tests.


Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MSHADE-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MSHADE-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

This is useful for supporting the custom line separator in the future. In that case we can handle `resources/application.yml` files, that are separated by `---`.
I did the same patch for Gradle Shadow plugin in GradleUp/shadow@8300f91.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Updates AppendingTransformer to avoid leaving a trailing end-of-line (EOL) after concatenating multiple resources, enabling future support for custom line separators (e.g., YAML ---).

Changes:

  • Change AppendingTransformer.processResource(...) to prepend a newline before subsequent appended resources rather than appending a newline after each resource.
  • Add a unit test that verifies concatenation output has a newline between resources but not at the end.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java Adjusts concatenation logic to avoid writing a trailing newline at the end of the merged resource.
src/test/java/org/apache/maven/plugins/shade/resource/AppendingTransformerTest.java Adds a regression test validating output content and absence of trailing EOL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to 53
if (data.size() > 0) {
// Append the EOL before the new content to ensure the EOL is not at the end of the file.
data.write('\n');
}
IOUtil.copy(is, data);
Comment on lines +49 to 53
if (data.size() > 0) {
// Append the EOL before the new content to ensure the EOL is not at the end of the file.
data.write('\n');
}
IOUtil.copy(is, data);
Comment on lines +71 to +74
String firstLine = "first line";
String secondLine = "second line";
InputStream firstIs = new ByteArrayInputStream(firstLine.getBytes());
InputStream secondIs = new ByteArrayInputStream(secondLine.getBytes());
Comment on lines +95 to +97
while ((read = jar.read(buffer)) >= 0) {
builder.append(new String(buffer, 0, read));
}
Comment on lines +49 to 53
if (data.size() > 0) {
// Append the EOL before the new content to ensure the EOL is not at the end of the file.
data.write('\n');
}
IOUtil.copy(is, data);
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.

3 participants