After writing server.xml ensure <server> element is on a new line.
@@ -21,6 +21,8 @@ import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -273,9 +275,13 @@ public class GenerateFeaturesMojo extends InstallFeatureSupport {
return;
}
try {
- if (doc.findFMComment(FEATURES_FILE_MESSAGE) == null) {
- doc.createFMComment(FEATURES_FILE_MESSAGE);
+ if (doc.createFMComment(FEATURES_FILE_MESSAGE)) {
doc.writeXMLDocument(serverXml);
+ // look for "<?xml version="1.0" ... ?><server .../>" and add a newline
+ byte[] contents = Files.readAllBytes(serverXml.toPath());
+ String xmlContents = new String(contents, StandardCharsets.UTF_8);
+ xmlContents = xmlContents.replace("?><", "?>"+System.getProperty("line.separator")+"<");
+ Files.write(serverXml.toPath(), xmlContents.getBytes());
}
} catch (IOException | TransformerException e) {
log.debug("Exception adding comment to server.xml", e);
