Skip to content

Commit

Permalink
Merge branch 'dev_textmerger'
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSchumacherCapgemini committed Dec 17, 2020
2 parents 26f6227 + afccf6d commit 084e992
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cobigen/cobigen-textmerger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>textmerger</artifactId>
<packaging>jar</packaging>
<version>7.1.0</version>
<version>7.1.1</version>
<name>CobiGen - Text Merger Plug-in</name>
<description>CobiGen - Text Merger Plug-in</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ab
c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
b
c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a
2 changes: 1 addition & 1 deletion documentation/master-cobigen.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 084e992

Please sign in to comment.