Skip to content

Commit debea33

Browse files
authored
Support custom line separators (#132)
1 parent 6b249f9 commit debea33

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/main/java/io/fabric8/maven/XMLFormat.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ public class XMLFormat {
3030

3131
private final TextMode textMode;
3232

33+
private final String lineSeparator;
34+
3335
private XMLFormat(Builder builder) {
3436
this.indent = builder.indent;
3537
this.insertLineBreakBetweenMajorSections = builder.insertLineBreakBetweenMajorSections;
3638
this.textMode = builder.textMode;
39+
this.lineSeparator = builder.lineSeparator;
3740
}
3841

3942
/**
@@ -90,7 +93,7 @@ XMLOutputter createXmlOutputter() {
9093
XMLOutputter xmlOutputter = new XMLOutputter();
9194
Format format = Format.getRawFormat();
9295
format.setIndent(indent);
93-
format.setLineSeparator(LineSeparator.UNIX);
96+
format.setLineSeparator(lineSeparator);
9497
format.setTextMode(Format.TextMode.valueOf(textMode.name()));
9598
if (insertLineBreakBetweenMajorSections) {
9699
// Insert line breaks between major sections
@@ -177,6 +180,8 @@ public static class Builder {
177180

178181
private TextMode textMode = TextMode.TRIM;
179182

183+
private String lineSeparator = LineSeparator.UNIX.value();
184+
180185
Builder() {
181186
}
182187

@@ -199,6 +204,11 @@ public Builder textMode(TextMode textMode) {
199204
return this;
200205
}
201206

207+
public Builder lineSeparator(String lineSeparator) {
208+
this.lineSeparator = lineSeparator;
209+
return this;
210+
}
211+
202212
public XMLFormat build() {
203213
return new XMLFormat(this);
204214
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion></project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
</project>
8+

src/test/java/io/fabric8/maven/MavenTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,20 @@ void should_write_attributes() throws Exception {
333333
Approvals.verify(sw.toString());
334334
}
335335

336+
@Test
337+
void should_use_line_separator() {
338+
Model model = Maven.newModel();
339+
StringWriter sw = new StringWriter();
340+
Maven.writeModel(model, sw, XMLFormat.builder().lineSeparator("\n\n").build());
341+
Approvals.verify(sw.toString());
342+
}
343+
344+
@Test
345+
void should_support_no_line_separator() {
346+
Model model = Maven.newModel();
347+
StringWriter sw = new StringWriter();
348+
Maven.writeModel(model, sw, XMLFormat.builder().lineSeparator(null).build());
349+
Approvals.verify(sw.toString());
350+
}
351+
336352
}

0 commit comments

Comments
 (0)