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

Is there a way log/trace files that are not covered by any layer of a LayeredArchitecture? #222

Closed
gadton opened this issue Aug 27, 2019 · 3 comments · Fixed by #278
Closed

Comments

@gadton
Copy link

gadton commented Aug 27, 2019

Defining layers and allowed access is easy but how to check if all loaded classes are covered by at least one layer?

@codecholeric
Copy link
Collaborator

I don't think there is a way at the moment. Originally I thought, that the white list way to define layers would draw in all relevant classes in in time anyway. E.g. define layer persistence may only be accessed by service, and also only persistence may use the EntityManager. Now any class that wants to access the database must reside in the persistence layer, or use a class from the persistence layer, but then it must reside in the service layer, and so on.
I guess LayeredArchitecture could be extended to allow some strict mode, where all classes must be covered by layers, similar like how a PlantUML rule fails, if not all checked classes are covered by the diagram. But LayeredArchitecture as opposed to the PlantUML rules, allows no way to filter the classes before.
Anyway, you can still somewhat mitigate your pain by simply writing a second rule

classes().should().resideInAnyPackage(allLayerPackageIdentifiers);

@codecholeric
Copy link
Collaborator

I think this would by a nice addition, so if anybody is looking for a simple starter to contributions, this here is open for grabs 😉
I guess we could introduce something like enforceAllClassesResideInLayers(), but we also would need an additional ignoreClasses(Class<?>...) and ignoreClasses(DescribedPredicate<JavaClass>) to enable specific ignores (let's be realistic about the world out there 😉).

@clojj
Copy link

clojj commented Feb 10, 2021

Very nice to see this addition! exactly the thin I tried to test by using something like this

ArchRuleDefinition.classes().that()
            .resideOutsideOfPackage("$orderBoundedContext..").should()
            .containNumberOfElements(DescribedPredicate.equalTo(0))

...really hope this gets merged soon !?

codecholeric added a commit that referenced this issue Jul 2, 2022
This will add possibilities to ensure that all classes under test are contained within the respective `LayeredArchitecture`/`OnionArchitecture`. It will help users to make sure they don't overlook any classes when defining their architectures. Furthermore, it will help with maintainability of the architectures when new classes are added to the code base later on. In detail the following methods have been added to `LayeredArchitecture` and `OnionArchitecture`:

* `ensureAllClassesAreContainedInArchitecture()`
* `ensureAllClassesAreContainedInArchitectureIgnoring(packageIdentifiers)`
* `ensureAllClassesAreContainedInArchitectureIgnoring(predicate)`

Resolves #222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants