From b040d90a987e6e032bc0534ea5e7efdbfe1e1c53 Mon Sep 17 00:00:00 2001 From: Peter Gafert Date: Tue, 30 Jul 2019 00:28:13 +0200 Subject: [PATCH] To avoid issues with Git for Windows autocrlf it is safer to clean up 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 --- .../library/freeze/ViolationStoreFactory.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/archunit/src/main/java/com/tngtech/archunit/library/freeze/ViolationStoreFactory.java b/archunit/src/main/java/com/tngtech/archunit/library/freeze/ViolationStoreFactory.java index 1ba6777d24..69dcc1a5d9 100644 --- a/archunit/src/main/java/com/tngtech/archunit/library/freeze/ViolationStoreFactory.java +++ b/archunit/src/main/java/com/tngtech/archunit/library/freeze/ViolationStoreFactory.java @@ -155,15 +155,24 @@ public List getViolations(ArchRule rule) { } private List readLines(String ruleDetailsFileName) { + String violationsText = readStoreFile(ruleDetailsFileName); + List 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 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;