Skip to content
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

add automatic conversions to violation handling #1251

Merged
merged 2 commits into from
Mar 26, 2024

Commits on Mar 26, 2024

  1. fix containsInArchitecture check adding wrong object

    The corresponding object in a `ConditionEvent` should always be the object that caused the violation,
    not the condition that checked it.
    Otherwise, clients that analyse the violating objects can't correctly identify the respective culprit.
    
    Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
    codecholeric committed Mar 26, 2024
    Configuration menu
    Copy the full SHA
    201812d View commit details
    Browse the repository at this point in the history
  2. add automatic conversions to violation handling

    The extensive freedom of how to create a `ConditionEvent` causes problems for any client that needs more structured results (e.g. tools).
    `ViolationHandler` provides a convenient API to obtain only those sort of violations that can be handled by a client (e.g. tackling dependencies).
    However, the type of the `correspondingObject` attached to the `ConditionEvent` can take many forms.
    From classes to methods, method calls, dependencies or aggregated dependencies (like module dependencies) it's hard to determine the possibilities and handle them all.
    Furthermore, the type of some objects (e.g. `ComponentDependency` isn't even public,
    so there is hardly any clean way to handle these objects.
    
    To mitigate this a little we now support transparent conversions between compatible objects.
    E.g. a component dependency can also be considered a set of class dependencies.
    `ViolationHandler` now allows to be used including these conversions that are implemented by standard ArchUnit objects where reasonable.
    This allows e.g. to obtain all module dependencies as `Set<Dependency>` for every violation.
    
    Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
    codecholeric committed Mar 26, 2024
    Configuration menu
    Copy the full SHA
    771df06 View commit details
    Browse the repository at this point in the history