Skip to content

Commit 14fefea

Browse files
Hccakephilwebb
authored andcommitted
Add lineSeparator support to Maven Plugin
Update the Maven Plugin with support for a custom line separator. See gh-212
1 parent 84c456e commit 14fefea

File tree

1 file changed

+41
-0
lines changed
  • spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven

1 file changed

+41
-0
lines changed

spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven/FormatMojo.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,18 @@ public abstract class FormatMojo extends AbstractMojo {
8888
@Parameter(property = "spring-javaformat.includeGeneratedSource", defaultValue = "false")
8989
private boolean includeGeneratedSource;
9090

91+
/**
92+
* Specifies the line separator to use when formatting.
93+
*/
94+
@Parameter(property = "spring-javaformat.lineSeparator")
95+
private LineSeparator lineSeparator;
96+
9197
@Override
9298
public final void execute() throws MojoExecutionException, MojoFailureException {
99+
if (this.lineSeparator != null) {
100+
System.getProperties().setProperty("line.separator", this.lineSeparator.getSymbol());
101+
}
102+
93103
List<File> directories = new ArrayList<>();
94104
resolve(this.sourceDirectories).forEach(directories::add);
95105
resolve(this.testSourceDirectories).forEach(directories::add);
@@ -158,4 +168,35 @@ private boolean hasLength(Object[] array) {
158168
protected abstract void execute(List<File> files, Charset encoding)
159169
throws MojoExecutionException, MojoFailureException;
160170

171+
172+
/*
173+
* The types of line separator. {@link FormatMojo#lineSeparator}
174+
*/
175+
enum LineSeparator {
176+
177+
/**
178+
* Carriage Return.
179+
*/
180+
CR("\r"),
181+
182+
/**
183+
* Linefeed.
184+
*/
185+
LF("\n"),
186+
187+
/**
188+
* Carriage Return & Linefeed.
189+
*/
190+
CRLF("\r\n");
191+
192+
LineSeparator(String symbol) {
193+
this.symbol = symbol;
194+
}
195+
196+
private final String symbol;
197+
198+
private String getSymbol() {
199+
return this.symbol;
200+
}
201+
}
161202
}

0 commit comments

Comments
 (0)