Skip to content

Commit

Permalink
Log of existing rule should not be level error, since this will happe…
Browse files Browse the repository at this point in the history
…n during the normal flow if an existing stored violation is adjusted.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Jul 4, 2019
1 parent 5feb2fa commit 8b0b6a9
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ public void save(ArchRule rule, List<String> violations) {
}

private void write(List<String> violations, File ruleDetails) {
String updatedViolations = Joiner.on("\n").join(escaped(violations));
String updatedViolations = Joiner.on("\n").join(escape(violations));
try {
Files.write(updatedViolations, ruleDetails, UTF_8);
} catch (IOException e) {
throw new StoreUpdateFailedException(e);
}
}

private List<String> escaped(List<String> violations) {
private List<String> escape(List<String> violations) {
return replaceCharacter(violations, "\n", "\\\n");
}

// FIXME: Correct word for 'deescaped'?
private List<String> deescaped(List<String> violations) {
private List<String> unescape(List<String> violations) {
return replaceCharacter(violations, "\\\n", "\n");
}

Expand All @@ -132,9 +131,9 @@ private String ensureRuleFileName(ArchRule rule) {
String ruleFileName;
if (storedRules.containsKey(rule.getDescription())) {
ruleFileName = storedRules.getProperty(rule.getDescription());
log.error("Rule '{}' is already stored in file {}", rule.getDescription(), ruleFileName);
log.debug("Rule '{}' is already stored in file {}", rule.getDescription(), ruleFileName);
} else {
ruleFileName = createNewRuleId(rule).toString();
ruleFileName = createNewRuleId(rule).toString();
}
return ruleFileName;
}
Expand All @@ -159,7 +158,7 @@ private List<String> readLines(String ruleDetailsFileName) {
try {
String violationsText = new String(toByteArray(new File(storeFolder, ruleDetailsFileName)), UTF_8);
List<String> lines = Splitter.on(UNESCAPED_LINE_BREAK_PATTERN).splitToList(violationsText);
return deescaped(lines);
return unescape(lines);
} catch (IOException e) {
throw new StoreReadException(e);
}
Expand Down

0 comments on commit 8b0b6a9

Please sign in to comment.