Skip to content

Commit 002503d

Browse files
committed
HBX-2916: Move XMLPrettyPrinter to the API and offer the ability to specify the XMLPrettyPrinterStrategy
- Move class 'org.hibernate.tool.internal.xml.XMLPrettyPrinter' to 'org.hibernate.tool.api.xml.XMLPrettyPrinter' - Add a new test class 'org.hibernate.tool.api.xml.XMLPrettyPrinterTest' Signed-off-by: Koen Aers <[email protected]>
1 parent f2c8234 commit 002503d

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

orm/src/main/java/org/hibernate/tool/internal/xml/XMLPrettyPrinter.java renamed to orm/src/main/java/org/hibernate/tool/api/xml/XMLPrettyPrinter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Created on 17-Dec-2004
33
*
44
*/
5-
package org.hibernate.tool.internal.xml;
5+
package org.hibernate.tool.api.xml;
66

77
import java.io.File;
88
import java.io.IOException;
@@ -11,6 +11,8 @@
1111
import java.nio.file.Files;
1212
import java.nio.file.Paths;
1313

14+
import org.hibernate.tool.internal.xml.XMLPrettyPrinterStrategyFactory;
15+
1416
/**
1517
* @author max
1618
*

orm/src/main/java/org/hibernate/tool/internal/export/common/DefaultArtifactCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import java.util.Set;
1111

1212
import org.hibernate.tool.api.export.ArtifactCollector;
13-
import org.hibernate.tool.internal.xml.XMLPrettyPrinter;
13+
import org.hibernate.tool.api.xml.XMLPrettyPrinter;
1414

1515
/**
1616
* Callback class that all exporters are given to allow better feedback and

orm/src/main/java/org/hibernate/tool/internal/xml/XMLPrettyPrinterStrategyFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ private static XMLPrettyPrinterStrategy loadFromSystemProperty() {
3030
throw new RuntimeException(e);
3131
}
3232
}
33-
3433
return null;
3534
}
3635
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.hibernate.tool.api.xml;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.io.File;
6+
import java.io.PrintWriter;
7+
import java.nio.file.Files;
8+
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.io.TempDir;
12+
13+
public class XMLPrettyPrinterTest {
14+
15+
private static final String XML_BEFORE = "<foo><bar>foobar</bar></foo>";
16+
17+
private static final String XML_AFTER =
18+
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
19+
"<foo>\n" +
20+
" <bar>foobar</bar>\n" +
21+
"</foo>\n";
22+
23+
private static final String fileName = "foobarfile.xml";
24+
25+
@TempDir
26+
private File tempDir;
27+
28+
private File xmlFile = null;
29+
30+
@BeforeEach
31+
public void beforeEach() throws Exception {
32+
xmlFile = new File(tempDir, fileName);
33+
PrintWriter writer = new PrintWriter(xmlFile);
34+
writer.print(XML_BEFORE);
35+
writer.flush();
36+
writer.close();
37+
}
38+
39+
@Test
40+
public void testXmlPrettyPrintDefault() throws Exception {
41+
XMLPrettyPrinter.prettyPrintFile(xmlFile);
42+
String result = Files.readString(xmlFile.toPath());
43+
assertEquals(XML_AFTER, result);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)