raise error for empty violation store and delete empty rule file#1405
raise error for empty violation store and delete empty rule file#1405
Conversation
a833065 to
90c5338
Compare
| private static final String ALLOW_STORE_UPDATE_PROPERTY_NAME = "default.allowStoreUpdate"; | ||
| private static final String ALLOW_STORE_UPDATE_DEFAULT = "true"; | ||
| private static final String DELETE_EMPTY_RULE_VIOLATION_PROPERTY_NAME = "default.deleteEmptyRuleViolation"; | ||
| private static final String DELETE_EMPTY_RULE_VIOLATION_DEFAULT = "false"; |
There was a problem hiding this comment.
we can discuss the above default value. I would prefer to have default true here, but I'd like to first hear the opinions from the maintainers.
| @Override | ||
| public void save(ArchRule rule, List<String> violations) { | ||
| log.trace("Storing evaluated rule '{}' with {} violations: {}", rule.getDescription(), violations.size(), violations); | ||
| if (violations.isEmpty() && warnEmptyRuleViolation) { |
There was a problem hiding this comment.
this check has to be placed here at the top, because for empty frozen rule violations you don't necessarily need to update the store. By seeing such warning the developer could change the test to non-freezing rather than decide to update the store.
90c5338 to
60de7ab
Compare
| throw new StoreEmptyException(String.format("Saving empty violations for freezing rule is disabled (enable by configuration %s.%s=true)", | ||
| ViolationStoreFactory.FREEZE_STORE_PROPERTY_NAME, WARN_EMPTY_RULE_VIOLATION_PROPERTY_NAME)); | ||
| } | ||
| if (violations.isEmpty() && deleteEmptyRule && !contains(rule)) { |
There was a problem hiding this comment.
another way to write this check would be
| if (violations.isEmpty() && deleteEmptyRule && !contains(rule)) { | |
| if (violations.isEmpty() && (deleteEmptyRule || skipEmptyRule) && !contains(rule)) { |
where skipEmptyRule condition is only used for skipping creation of empty rule file. To keep the configuration simple, I decided to use deleteEmptyRule for both skipping file creation and deleting the empty file.
These changes introduce two new features for FreezingRule default store * Raise error when a freezing rule has zero violations. This can be enabled by setting the property `default.warnEmptyRuleViolation=true`. For backward compatibility it is disabled by default. * Skip rule violation file creation or delete if it already exists, when there are zero violations. This can be enabled by setting the property `default.deleteEmptyRuleViolation=true`, it is disabled by default. Signed-off-by: Masoud Kiaeeha <6916434+maxxkia@users.noreply.github.com> Resolves TNG#1264
60de7ab to
4952aae
Compare
These changes introduce two new features for FreezingRule default store
default.warnEmptyRuleViolation=true. For backward compatibility it is disabled by default.default.deleteEmptyRuleViolation=true, it is disabled by default.Signed-off-by: Masoud Kiaeeha 6916434+maxxkia@users.noreply.github.com
Resolves #1264