-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
raise error for empty violation store and delete empty rule file #1405
base: main
Are you sure you want to change the base?
Conversation
a833065
to
90c5338
Compare
@@ -73,11 +73,17 @@ public final class TextFileBasedViolationStore implements ViolationStore { | |||
private static final String ALLOW_STORE_CREATION_DEFAULT = "false"; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -140,15 +148,38 @@ public boolean contains(ArchRule rule) { | |||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 <[email protected]> Resolves TNG#1264
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
default.warnEmptyRuleViolation=true
. For backward compatibility it is disabled by default.default.deleteEmptyRuleViolation=true
, it is disabled by default.Signed-off-by: Masoud Kiaeeha [email protected]
Resolves #1264