Skip to content

Commit

Permalink
#1045: refactors TextFileBasedViolationStore so that file name mechan…
Browse files Browse the repository at this point in the history
…ism can be more easily overridden
  • Loading branch information
danhaywood committed Jan 20, 2023
1 parent 2c183aa commit 4d0c574
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,26 @@ private List<String> replaceCharacter(List<String> violations, String characterT
}

private String ensureRuleFileName(ArchRule rule) {
String ruleDescription = rule.getDescription();

String ruleFileName;
if (storedRules.containsKey(rule.getDescription())) {
ruleFileName = storedRules.getProperty(rule.getDescription());
log.debug("Rule '{}' is already stored in file {}", rule.getDescription(), ruleFileName);
if (storedRules.containsKey(ruleDescription)) {
ruleFileName = storedRules.getProperty(ruleDescription);
log.debug("Rule '{}' is already stored in file {}", ruleDescription, ruleFileName);
} else {
ruleFileName = createNewRuleId(rule).toString();
ruleFileName = newRuleFileName(ruleDescription);
log.debug("Assigning new ID {} to rule '{}'", ruleFileName, ruleDescription);
storedRules.setProperty(ruleDescription, ruleFileName);
}
return ruleFileName;
}

private UUID createNewRuleId(ArchRule rule) {
UUID ruleId = UUID.randomUUID();
log.debug("Assigning new ID {} to rule '{}'", ruleId, rule.getDescription());
storedRules.setProperty(rule.getDescription(), ruleId.toString());
return ruleId;
/**
* This has <code>protected</code> visibility so that it can be more easily overridden in alternative
* implementations of {@link ViolationStore} based on this implementation.
*/
protected String newRuleFileName(String description) {
return UUID.randomUUID().toString();
}

@Override
Expand Down

0 comments on commit 4d0c574

Please sign in to comment.