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

Allow defining Onion Architecture components by predicates #894

Merged

Conversation

codecholeric
Copy link
Collaborator

@codecholeric codecholeric commented Jun 19, 2022

Similar to LayeredArchitecture this will extend OnionArchitecture to not only allow defining components via package identifiers (e.g. domainModels("..some.pkg..")) but also via predicates (e.g. domainModels(annotatedWith(DomainModel.class)) or domainModels(simpleNameEndingWith("Model"))).
This will allow users that follow a different convention than packages to identify their Onion Architecture components to also use OnionArchitecture to assert their architecture.

Note that this PR contains a breaking change in a preparatory refactoring, namely relocating PackageMatcher from package base to core.domain.

@codecholeric codecholeric added this to the 1.0.0 milestone Jun 19, 2022
@codecholeric codecholeric marked this pull request as draft June 19, 2022 10:27
@codecholeric codecholeric force-pushed the support-predicates-when-defining-onion-architecture branch from c4c2191 to 6af6dea Compare June 22, 2022 16:09
@codecholeric codecholeric marked this pull request as ready for review June 22, 2022 16:09
@spanierm42 spanierm42 self-requested a review June 24, 2022 09:05
@spanierm42 spanierm42 self-assigned this Jun 24, 2022
Copy link
Contributor

@spanierm42 spanierm42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than these minor findings, it looks good to me :)

@codecholeric codecholeric force-pushed the support-predicates-when-defining-onion-architecture branch 2 times, most recently from 2245e12 to f86eb90 Compare June 26, 2022 05:24
While these methods are not rocket-science and the delegating supplier is tested transitively by other methods we should still have rudimentary checks that these methods as public API are not broken.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
This class does not really match the generic nature of classes in the `base` package, since it is clearly related to ArchUnit's domain. When some predicates were moved from `lang.conditions` to `domain.core` `PackageMatcher` was moved to `base`, probably out of the idea that then "every place within ArchUnit can utilize it". But in turn `PackageMatcher` can then not use any utilities from `core`, which makes no sense. Or all such utilities will start to creep into `base` as well. In the end, `core.domain` is the next higher layer on top of `base` in the ArchUnit layered architecture. And within `base` there should be no need ever to match packages, etc., since that is already ArchUnit domain specific logic. Since we are about to release 1.0 and can thus break the public API this is a good point in time to move this class back into a more reasonable layer.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
It obviously is a reoccurring task to join some strings together on comma and single quote them as part of rule or violation descriptions. We can offer this through the public API so users can also benefit from it for their custom rules.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
Some users use different conventions, like class naming or annotations, to define the components of their Onion Architecture. To support such use cases we extend `OnionArchitecture` similar to `LayeredArchitecture` to also allow defining components via any arbitrary `DescribedPredicate`.

While extending the example I noticed that it might be a good addition to have a more generic `JavaClass.Predicates.belongTo(DescribedPredicate)` method additionally to `belongToAnyOf(Class<?>...)`. At least writing the example would otherwise have been tedious, since assigning nested and anonymous classes to the annotation of the outer class would always be necessary for this use case.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric force-pushed the support-predicates-when-defining-onion-architecture branch from f86eb90 to 6046075 Compare June 29, 2022 13:17
@codecholeric codecholeric merged commit 5b1b7c3 into main Jun 30, 2022
@codecholeric codecholeric deleted the support-predicates-when-defining-onion-architecture branch June 30, 2022 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants