Skip to content

Commit

Permalink
Allow define lineseparator for strip-jaxb (#71)
Browse files Browse the repository at this point in the history
Co-authored-by: Lumír Návrat <[email protected]>
  • Loading branch information
rimuln and Lumír Návrat authored Sep 3, 2024
1 parent ac3e0e2 commit 0c6ddc9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
/** Removes a given line in a text file based on the line number. */
class LineNumberStripper implements Stripper
{
private int lineNumber;

private final int lineNumber;
private final LineSeparators lineSeparator;

/**
* Constructor.
*
* @param lineNumber the line number to remove.
* @param lineEnding the line ending of file.
*/
public LineNumberStripper(int lineNumber)
public LineNumberStripper(int lineNumber, LineSeparators lineEnding)
{
this.lineNumber = lineNumber;
this.lineSeparator = lineEnding;
}

@Override
Expand All @@ -51,7 +55,7 @@ public void strip(File in, File out) throws IOException
try
{
writer.write(lines.get(i));
writer.write("\r\n");
writer.write(lineSeparator.get());
}
catch (IOException e)
{
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/io/github/zlika/reproducible/LineSeparators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.zlika.reproducible;

public enum LineSeparators
{
/**
* windows line separator.
*/
CRLF("\r\n"),

/**
* unix line separator.
*/
LF("\n"),

/**
* mac line separator.
*/
CR("\r"),

/**
* system derived line separator.
*/
SYSTEM(System.lineSeparator());

private final String lineSeparator;

LineSeparators(String lineSeparator)
{
this.lineSeparator = lineSeparator;
}

public String get()
{
return lineSeparator;
}
}
9 changes: 7 additions & 2 deletions src/main/java/io/github/zlika/reproducible/StripJaxbMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public String getMatchingCommentText()
@Parameter(defaultValue = "", property = "reproducible.matchingCommentText")
private String matchingCommentText;

@Parameter(defaultValue = "CRLF", property = "reproducible.lineSeparator")
private LineSeparators lineSeparator;

@Override
public void execute() throws MojoExecutionException
{
Expand All @@ -135,8 +138,10 @@ private void fix() throws MojoExecutionException
final Charset charset = Charset.forName(encoding);
final JaxbObjectFactoryFixer objectFactoryFixer = new JaxbObjectFactoryFixer(getMatchingCommentTexts(),
charset);
final LineNumberStripper jaxbFileDateStripper = new LineNumberStripper(JAXB_FILE_TIMESTAMP_LINE_NUMBER);
final LineNumberStripper jaxbEpisodeDateStripper = new LineNumberStripper(JAXB_EPISODE_TIMESTAMP_LINE_NUMBER);
final LineNumberStripper jaxbFileDateStripper =
new LineNumberStripper(JAXB_FILE_TIMESTAMP_LINE_NUMBER, lineSeparator);
final LineNumberStripper jaxbEpisodeDateStripper =
new LineNumberStripper(JAXB_EPISODE_TIMESTAMP_LINE_NUMBER, lineSeparator);
final File tmpFile = createTempFile();

try
Expand Down

0 comments on commit 0c6ddc9

Please sign in to comment.