Interface ArchUnitExtension


  • @PublicAPI(usage=INHERITANCE,
               state=EXPERIMENTAL)
    public 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

    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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void configure​(java.util.Properties properties)
      Before calling handle(EvaluatedRule), ArchUnit will call this method, to pass configured properties to the extension.
      java.lang.String getUniqueIdentifier()
      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 any AssertionError is thrown from possible violations of the rule.
    • Method Detail

      • getUniqueIdentifier

        java.lang.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

        void configure​(java.util.Properties properties)
        Before calling handle(EvaluatedRule), ArchUnit will call this method, to pass configured properties to the extension. Properties for an extension can be configured via "archunit.properties" (compare ArchConfiguration). Extension properties are identified by prefixing each property to pass with
        extension.${extension-id}
        (where ${extension-id} refers to the unique id of this extension configured via getUniqueIdentifier()). This way, configuration follows an uniform way.

        Example:
        
         extension.my-extension.foo=bar
         extension.my-extension.baz=quux
         
        will pass a Properties object to the extension with getUniqueIdentifier() == "my-extension", which contains the entries
        
         foo=bar
         baz=quux
         
        Parameters:
        properties - Object holding the configured properties of this extension
      • handle

        void handle​(EvaluatedRule evaluatedRule)
        ArchUnit will call this method after evaluating any rule against imported classes, but before any AssertionError 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