Skip to content

Commit

Permalink
To avoid issues with Git for Windows autocrlf it is safer to clean up…
Browse files Browse the repository at this point in the history
… any windows line breaks when reading an existing violations file (the files will still count as modified to Git in this case because the line breaks have changed from crlf to lf, but at least the test does not fail in strange ways)

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Jul 29, 2019
1 parent a88fb1f commit b040d90
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,24 @@ public List<String> getViolations(ArchRule rule) {
}

private List<String> readLines(String ruleDetailsFileName) {
String violationsText = readStoreFile(ruleDetailsFileName);
List<String> lines = Splitter.on(UNESCAPED_LINE_BREAK_PATTERN).splitToList(violationsText);
return unescape(lines);
}

private String readStoreFile(String fileName) {
try {
String violationsText = new String(toByteArray(new File(storeFolder, ruleDetailsFileName)), UTF_8);
List<String> lines = Splitter.on(UNESCAPED_LINE_BREAK_PATTERN).splitToList(violationsText);
return unescape(lines);
String result = new String(toByteArray(new File(storeFolder, fileName)), UTF_8);
return ensureUnixLineBreaks(result);
} catch (IOException e) {
throw new StoreReadException(e);
}
}

private String ensureUnixLineBreaks(String string) {
return string.replaceAll("\r\n", "\n");
}

private static class FileSyncedProperties {
private final File propertiesFile;
private final Properties loadedProperties;
Expand Down

0 comments on commit b040d90

Please sign in to comment.