Source:
private static void writeToFile(Document document, ModuleDetails moduleDetails) throws TransformerException { final String rootOutputPath = System.getProperty("user.dir") + "/src/main/resources"; String fileSeperator = System.getProperty("file.separator"); if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win")) { fileSeperator = "\\" + fileSeperator; } final String moduleFilePath = FILEPATH_CONVERSION .matcher(moduleDetails.getFullQualifiedName()) .replaceAll(fileSeperator); final String modifiedPath; if (moduleFilePath.contains("puppycrawl")) { final int idxOfCheckstyle = moduleFilePath.indexOf("checkstyle") + "checkstyle".length(); modifiedPath = rootOutputPath + System.getProperty("file.separator") + moduleFilePath.substring(0, idxOfCheckstyle) + System.getProperty("file.separator") + "meta" + System.getProperty("file.separator") + moduleFilePath.substring(idxOfCheckstyle + 1) + ".xml"; } else { String moduleName = moduleDetails.getName(); if (moduleDetails.getModuleType() == ModuleType.CHECK) { moduleName += "Check"; } modifiedPath = rootOutputPath + System.getProperty("file.separator") + "checkstylemeta-" + moduleName + ".xml"; } if (!moduleDetails.getDescription().isEmpty()) { final TransformerFactory transformerFactory = TransformerFactory.newInstance(); final Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{<LINK_0>}indent-amount", "4"); final DOMSource source = new DOMSource(document); final StreamResult result = new StreamResult(new File(modifiedPath)); transformer.transform(source, result); } }

Target:
private static void writeToFile(Document document, ModuleDetails moduleDetails) throws TransformerException { final String rootOutputPath = System.getProperty("user.dir") + "/src/main/resources"; String fileSeparator = "/"; if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win")) { fileSeparator = "\\" + fileSeparator; } final String modifiedPath; if (moduleDetails.getFullQualifiedName().startsWith("com.puppycrawl.tools.checkstyle")) { final String moduleFilePath = FILEPATH_CONVERSION .matcher(moduleDetails.getFullQualifiedName()) .replaceAll(fileSeparator); final int indexOfCheckstyle = moduleFilePath.indexOf("checkstyle") + "checkstyle".length(); modifiedPath = rootOutputPath + "/" + moduleFilePath.substring(0, indexOfCheckstyle) + "/meta/" + moduleFilePath.substring(indexOfCheckstyle + 1) + ".xml"; } else { String moduleName = moduleDetails.getName(); if (moduleDetails.getModuleType() == ModuleType.CHECK) { moduleName += "Check"; } modifiedPath = rootOutputPath + "/checkstylemeta-" + moduleName + ".xml"; } if (!moduleDetails.getDescription().isEmpty()) { final TransformerFactory transformerFactory = TransformerFactory.newInstance(); final Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{<LINK_0>}indent-amount", "4"); final DOMSource source = new DOMSource(document); final StreamResult result = new StreamResult(new File(modifiedPath)); transformer.transform(source, result); } }