skuzzle/restrict-imports-enforcer-rule

Replace deprecated EnforcerRule and EnforcerRule2 implementations

Opened this issue · 1 comments

The interfaces EnforcerRule and EnforcerRule2 have been deprecated in favor of the new abstract class AbstractEnforcerRule. However this poses a big problem as our rule implementation already need to inherit from BannedImportGroupDefinition in order to provide convenient XML configuration.

We probably need to give up on the convenience configuration in order to get rid of the deprecations.

Currently it is possible to either configure a single banned group or multiple groups. When configuring a single group, this group does not need to be nested in <groups></groups>. This is achieved by inheriting from BannedImportGroupDefinition.

Changing this would break existing rule usages and introduce inconveniences when configuring the rule for simple use cases

See also: https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html

I reckon we could still make this work by not inheriting from BannedImportGroupDefinition and instead copy its contents to the rule implementation. That's ugly to maintain though
Just tried it out and it was pretty straight forward. Instead of delegating to the super class, we can just delegate to an actual instance of BannedImportGroupDefinition.