diff --git a/cobigen/cobigen-textmerger/pom.xml b/cobigen/cobigen-textmerger/pom.xml index 71f7bedac0..8e53b6c82f 100644 --- a/cobigen/cobigen-textmerger/pom.xml +++ b/cobigen/cobigen-textmerger/pom.xml @@ -2,7 +2,7 @@ 4.0.0 textmerger jar - 7.1.0 + 7.1.1 CobiGen - Text Merger Plug-in CobiGen - Text Merger Plug-in diff --git a/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextAppender.java b/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextAppender.java index e2ba0bafca..ccf123352c 100644 --- a/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextAppender.java +++ b/cobigen/cobigen-textmerger/src/main/java/com/devonfw/cobigen/textmerger/TextAppender.java @@ -77,22 +77,22 @@ public String merge(File base, String patch, String targetCharset) throws MergeE String mergedString; String lineDelimiterBase; - Path path = Paths.get(base.getAbsolutePath()); + Path basePath = Paths.get(base.getAbsolutePath()); try { mergedString = FileUtils.readFileToString(base, targetCharset); - lineDelimiterBase = SystemUtil.determineLineDelimiter(path, targetCharset); + lineDelimiterBase = SystemUtil.determineLineDelimiter(basePath, targetCharset); } catch (IOException e) { throw new MergeException(base, "Could not read base file.", e); } try { - if (lineDelimiterBase.isEmpty()) { - lineDelimiterBase = System.lineSeparator(); + if (lineDelimiterBase == null) { + mergedString = merge(mergedString, patch, lineDelimiterBase); + } else { + mergedString = + merge(mergedString, StringUtil.consolidateLineEndings(patch, lineDelimiterBase), lineDelimiterBase); } - - mergedString = - merge(mergedString, StringUtil.consolidateLineEndings(patch, lineDelimiterBase), lineDelimiterBase); } catch (Exception e) { throw new MergeException(base, e.getMessage(), e); } diff --git a/cobigen/cobigen-textmerger/src/test/java/com/devonfw/cobigen/textmerger/TextAppenderTest.java b/cobigen/cobigen-textmerger/src/test/java/com/devonfw/cobigen/textmerger/TextAppenderTest.java index c3562a4401..cb80dd85fd 100644 --- a/cobigen/cobigen-textmerger/src/test/java/com/devonfw/cobigen/textmerger/TextAppenderTest.java +++ b/cobigen/cobigen-textmerger/src/test/java/com/devonfw/cobigen/textmerger/TextAppenderTest.java @@ -316,6 +316,21 @@ public void testMerge_normalizeToBaseLineDelimiter() throws Exception { .isEqualTo(FileUtils.readFileToString(new File(testFileRootPath + "MergedBaseLineDelimiter.txt"))); } + /** + * Tests if a merge of a base file without line endings with a patch file with line endings will create a + * valid result + * @throws Exception + * if errors occur while merging + */ + @Test + public void testMerge_noBaseLineDelimiterToConsolidate() throws Exception { + TextAppender appender = new TextAppender("textmerge_append", false); + String mergedString = appender.merge(new File(testFileRootPath + "TestBaseNoLineDelimiter.txt"), + FileUtils.readFileToString(new File(testFileRootPath + "PatchBaseNoLineDelimiter.txt")), "UTF-8"); + assertThat(mergedString) + .isEqualTo(FileUtils.readFileToString(new File(testFileRootPath + "MergedBaseNoLineDelimiter.txt"))); + } + /** * Helper method that creates a String matching the usual look of a merge exception * @param base diff --git a/cobigen/cobigen-textmerger/src/test/resources/MergedBaseNoLineDelimiter.txt b/cobigen/cobigen-textmerger/src/test/resources/MergedBaseNoLineDelimiter.txt new file mode 100644 index 0000000000..9bfeb69237 --- /dev/null +++ b/cobigen/cobigen-textmerger/src/test/resources/MergedBaseNoLineDelimiter.txt @@ -0,0 +1,2 @@ +ab +c \ No newline at end of file diff --git a/cobigen/cobigen-textmerger/src/test/resources/PatchBaseNoLineDelimiter.txt b/cobigen/cobigen-textmerger/src/test/resources/PatchBaseNoLineDelimiter.txt new file mode 100644 index 0000000000..588234ab44 --- /dev/null +++ b/cobigen/cobigen-textmerger/src/test/resources/PatchBaseNoLineDelimiter.txt @@ -0,0 +1,2 @@ +b +c \ No newline at end of file diff --git a/cobigen/cobigen-textmerger/src/test/resources/TestBaseNoLineDelimiter.txt b/cobigen/cobigen-textmerger/src/test/resources/TestBaseNoLineDelimiter.txt new file mode 100644 index 0000000000..2e65efe2a1 --- /dev/null +++ b/cobigen/cobigen-textmerger/src/test/resources/TestBaseNoLineDelimiter.txt @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/documentation/master-cobigen.asciidoc b/documentation/master-cobigen.asciidoc index c3ee54d21f..e755514e74 100644 --- a/documentation/master-cobigen.asciidoc +++ b/documentation/master-cobigen.asciidoc @@ -22,7 +22,7 @@ DISCLAIMER: All Cobigen plugins are compatible with the latest release of Devonf * CobiGen - XML Plug-in v7.0.0 * CobiGen - TypeScript Plug-in v7.1.0 * CobiGen - Property Plug-in v7.1.0 -* CobiGen - Text Merger v7.1.0 +* CobiGen - Text Merger v7.1.1 * CobiGen - JSON Plug-in v7.0.0 * CobiGen - HTML Plug-in v7.0.0 * CobiGen - Open API Plug-in v7.1.0