Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow define lineseparator for strip-jaxb #71

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading