From 74afa1935359a34586ad0257e53964c0c52cd45c Mon Sep 17 00:00:00 2001 From: Wykiki Date: Sun, 16 Jul 2023 12:37:04 +0200 Subject: [PATCH] feat: Converts LF and CRLF to appropriate line ending character --- .../mojo/license/AbstractFileHeaderMojo.java | 14 ++++++++++++++ .../apt/examples/update-file-header-config.apt.vm | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java index d7c361bf0..3330edcd8 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java @@ -396,6 +396,20 @@ public abstract class AbstractFileHeaderMojo extends AbstractLicenseNameMojo { */ protected abstract boolean isFailOnNotUptodateHeader(); + /** + * Converts line ending string, like LF or CRLF, to proper line separator character. + * + * @param lineSeparator Line separator that may be converted. + */ + public void setLineSeparator(String lineSeparator) { + try { + this.lineSeparator = Eol.valueOf(lineSeparator).getEolString(); + } catch (IllegalArgumentException e) { + LOG.warn("Unable to parse lineSeparator '{}', using it as-is.", lineSeparator); + this.lineSeparator = lineSeparator; + } + } + // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementaton // ---------------------------------------------------------------------- diff --git a/src/site/apt/examples/update-file-header-config.apt.vm b/src/site/apt/examples/update-file-header-config.apt.vm index a00e44efd..3ed1b60d4 100644 --- a/src/site/apt/examples/update-file-header-config.apt.vm +++ b/src/site/apt/examples/update-file-header-config.apt.vm @@ -41,6 +41,9 @@ Update File Header Examples * customize description section: Define a template to change the description section of a file header. + * lineSeparator: Use a custom chain of character as line separator. Providing "LF" and "CRLF" will instead use the + characters "\n" and "\r\n", respectively. + To see all extensions accepted run the <> goal. -------------------------------------------------------------------------------