Interface ArchUnitExtension
ArchUnit extensions need to implement this interface. To register the extension,
add a text file (UTF-8 encoded) to the folder /META-INF/services, named
/META-INF/services/com.tngtech.archunit.lang.extension.ArchUnitExtension
and add a line with the fully qualified class name(s) to it
For further details, check the documentation of
Whenever a rule is evaluated, ArchUnit will dispatch the result to all extensions configured this way, before reacting to the result (e.g. by failing the test, if violations exist).
/META-INF/services/com.tngtech.archunit.lang.extension.ArchUnitExtension
and add a line with the fully qualified class name(s) to it
com.mycompany.MyArchUnitExtension
For further details, check the documentation of
ServiceLoader
.Whenever a rule is evaluated, ArchUnit will dispatch the result to all extensions configured this way, before reacting to the result (e.g. by failing the test, if violations exist).
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(Properties properties) Before callinghandle(EvaluatedRule)
, ArchUnit will call this method, to pass configured properties to the extension.A unique String, identifying this extension, so ArchUnit can associate configured properties.void
handle
(EvaluatedRule evaluatedRule) ArchUnit will call this method after evaluating any rule against imported classes, but before anyAssertionError
is thrown from possible violations of the rule.
-
Method Details
-
getUniqueIdentifier
String getUniqueIdentifier()A unique String, identifying this extension, so ArchUnit can associate configured properties. The String must not contain '.' (dot). The return value MUST BE UNIQUE between all configured extensions, or an exception will be thrown, thus it's good practice, to use some company specific namespace.- Returns:
- A unique String identifier of this extension
-
configure
Before callinghandle(EvaluatedRule)
, ArchUnit will call this method, to pass configured properties to the extension. Properties for an extension can be configured via"archunit.properties"
(compareArchConfiguration
). Extension properties are identified by prefixing each property to pass with
(whereextension.${extension-id}
${extension-id}
refers to the unique id of this extension configured viagetUniqueIdentifier()
). This way, configuration follows an uniform way.
Example:
will pass aextension.my-extension.foo=bar extension.my-extension.baz=quux
Properties
object to the extension withgetUniqueIdentifier()
== "my-extension", which contains the entriesfoo=bar baz=quux
- Parameters:
properties
- Object holding the configured properties of this extension
-
handle
ArchUnit will call this method after evaluating any rule against imported classes, but before anyAssertionError
is thrown from possible violations of the rule.- Parameters:
evaluatedRule
- Contains details about the evaluated rule, i.e. which rule was evaluated, the imported classes and the result of the evaluation
-