Skip to content

[MASSEMBLY-947] Normalize CR line endings to CRLF - #1341

Merged
slachiewicz merged 2 commits into
apache:masterfrom
wilx:issue-1154
Aug 5, 2026
Merged

[MASSEMBLY-947] Normalize CR line endings to CRLF#1341
slachiewicz merged 2 commits into
apache:masterfrom
wilx:issue-1154

Conversation

@wilx

@wilx wilx commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #1154.

Summary

Normalize old Mac CR-only line endings to CRLF when an assembly file set uses
<lineEnding>crlf</lineEnding> (or its windows/dos aliases).

WindowsLineFeedInputStream now treats CR, LF, and CRLF as logical line
separators and emits exactly one CRLF for each. A one-byte lookahead preserves
the byte following a lone CR, while the existing option to add a final line
ending at EOF continues to work without adding a duplicate CRLF.

Root cause

The previous stream converted a bare LF to CRLF and recognized an existing
CRLF, but passed a CR not followed by LF through unchanged. As a result,
filtering the CR-only source from the issue reproducer still left CR-only line
endings in the assembled file despite the requested crlf setting.

Unit tests cover lone and trailing CRs, consecutive CRs, and mixed CR/LF/CRLF
input. The existing Windows-line-ending Invoker project now also generates a
CR-only resource during setup, avoiding source-control newline conversion, and
verifies the assembled bytes exactly.

Compatibility and verification

  • Maven 3.6.3 with Java 8:
    mvn -DminimalMavenBuildVersion=3.6.3 -Prun-its clean verify passed with
    271 unit tests and all 150 Invoker builds.
  • Maven 3.9.16 with Java 21:
    mvn -Prun-its clean verify passed with 271 unit tests and all 150 Invoker
    builds.
  • Maven 4.0.0-rc-5 with Java 21: all 271 unit tests passed, and the focused
    Invoker run containing this regression passed. The full Invoker run passed
    145 of 150 projects; the remaining five are unrelated parent-cycle fixtures
    also failing on master.

Before the implementation change, the new focused unit coverage failed for
all four CR-only/mixed-ending cases.

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

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn 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 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.

Normalize lone carriage returns in WindowsLineFeedInputStream so all recognized line endings are emitted as CRLF. Add unit and integration coverage for CR-only and mixed line endings.

Fixes apache#1154
@wilx
wilx marked this pull request as ready for review July 27, 2026 20:16
@elharo
elharo requested a review from Copilot August 1, 2026 10:49

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

This PR fixes MASSEMBLY-947 by ensuring that when a file set requests CRLF (<lineEnding>crlf</lineEnding> and aliases), inputs using old Mac CR-only line endings are normalized to CRLF during assembly filtering, rather than leaving bare \r unchanged.

Changes:

  • Update WindowsLineFeedInputStream to treat CR, LF, and CRLF as line separators and emit exactly one CRLF per logical line ending (using a one-byte lookahead for lone CR).
  • Expand unit coverage to include CR-only, trailing CR, consecutive CRs, and mixed CR/LF/CRLF cases.
  • Strengthen the existing Invoker IT by generating a CR-only input during setup and asserting exact assembled output for both the existing and new fixture files.

Reviewed changes

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

Show a summary per file
File Description
src/main/java/org/apache/maven/plugins/assembly/utils/WindowsLineFeedInputStream.java Normalizes CR-only and mixed line separators to CRLF using lookahead and pending-byte buffering.
src/test/java/org/apache/maven/plugins/assembly/utils/WindowsLineFeedInputStreamTest.java Adds targeted tests covering CR-only and mixed-ending normalization behavior.
src/it/projects/file-sets/multimodule-win-lineEndings/setup.groovy Creates a CR-only resource at test runtime to avoid SCM newline conversion and reproduce the bug reliably.
src/it/projects/file-sets/multimodule-win-lineEndings/verify.groovy Verifies the assembled output content exactly (including line-ending bytes) for both fixtures.
src/it/projects/file-sets/multimodule-win-lineEndings/child/pom.xml Pins the parent relativePath to the shared IT parent POM for stable resolution in the IT layout.

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

Comment thread src/it/projects/file-sets/multimodule-win-lineEndings/verify.groovy Outdated
@slawekjaranowski slawekjaranowski added the bug Something isn't working label Aug 3, 2026
@slachiewicz
slachiewicz merged commit 23493c2 into apache:master Aug 5, 2026
11 checks passed
@github-actions github-actions Bot added this to the 3.8.1 milestone Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MASSEMBLY-947] fileSet lineEnding crlf does not convert old mac cr line endings

5 participants