Skip to content

Commit

Permalink
Handle lineSeparator conversion with tokens LF / CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien LE MÉNER committed Aug 23, 2021
1 parent 4736bf6 commit 3ad787d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

import org.apache.commons.lang3.StringUtils;
import org.codehaus.mojo.license.Eol;
import org.codehaus.mojo.license.header.FileHeader;
import org.codehaus.mojo.license.model.Copyright;

Expand Down Expand Up @@ -273,7 +274,14 @@ public String getLineSeparator()
*/
public void setLineSeparator( String lineSeparator )
{
this.lineSeparator = lineSeparator;
if ( lineSeparator != null )
{
this.lineSeparator = Eol.valueOf(lineSeparator).getEolString();
}
else
{
this.lineSeparator = null;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ public void testSetTrimHeaderLine()
Assert.assertTrue(transformer.isTrimHeaderLine());
}

@Test
public void testSetLineSeparator()
{
transformer.setLineSeparator("LF");
Assert.assertEquals("\n", transformer.getLineSeparator());

transformer.setLineSeparator("CRLF");
Assert.assertEquals("\r\n", transformer.getLineSeparator());

transformer.setLineSeparator(null);
Assert.assertEquals(LINE_SEPARATOR, transformer.getLineSeparator());
}

@Test(expected = IllegalArgumentException.class)
public void testSetLineSeparatorUnknownEol()
{
transformer.setLineSeparator("INEXISTANT");
}

public static void assertEquals( FileHeader model, FileHeader model2 )
{
Assert.assertEquals( model.getDescription(), model2.getDescription() );
Expand Down

0 comments on commit 3ad787d

Please sign in to comment.