Skip to content

Commit

Permalink
Add lineSeparator support to Maven Plugin
Browse files Browse the repository at this point in the history
Update the Maven Plugin with support for a custom line separator.

See gh-212
  • Loading branch information
Hccake authored and philwebb committed Dec 3, 2020
1 parent 84c456e commit 14fefea
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@ public abstract class FormatMojo extends AbstractMojo {
@Parameter(property = "spring-javaformat.includeGeneratedSource", defaultValue = "false")
private boolean includeGeneratedSource;

/**
* Specifies the line separator to use when formatting.
*/
@Parameter(property = "spring-javaformat.lineSeparator")
private LineSeparator lineSeparator;

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
if (this.lineSeparator != null) {
System.getProperties().setProperty("line.separator", this.lineSeparator.getSymbol());
}

List<File> directories = new ArrayList<>();
resolve(this.sourceDirectories).forEach(directories::add);
resolve(this.testSourceDirectories).forEach(directories::add);
Expand Down Expand Up @@ -158,4 +168,35 @@ private boolean hasLength(Object[] array) {
protected abstract void execute(List<File> files, Charset encoding)
throws MojoExecutionException, MojoFailureException;


/*
* The types of line separator. {@link FormatMojo#lineSeparator}
*/
enum LineSeparator {

/**
* Carriage Return.
*/
CR("\r"),

/**
* Linefeed.
*/
LF("\n"),

/**
* Carriage Return & Linefeed.
*/
CRLF("\r\n");

LineSeparator(String symbol) {
this.symbol = symbol;
}

private final String symbol;

private String getSymbol() {
return this.symbol;
}
}
}

0 comments on commit 14fefea

Please sign in to comment.