TNG / ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
http://archunit.org
Apache License 2.0
3.24k stars 298 forks source link

Allow `@AnalyzeClasses` to be used as a meta annotation #182

Open bobtiernay-okta opened 5 years ago

bobtiernay-okta commented 5 years ago

Having @AnalyzeClasses allowed to be a meta annotation would allow one to encapsulate repeating options across tests:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@AnalyzeClasses(packages = {PACKAGE_X, PACKAGE_Y}, importOptions = {DoNotIncludeTests.class, DoNotIncludeJars.class, DoNotIncludeArchives.class})
public @interface AnalyzeStandardClasses

For similar features in Spring, checkout https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#integration-testing-annotations-meta.

codecholeric commented 5 years ago

Sounds like a reasonable addition :smiley: Would be worth it to ponder about the implications if several @AnalyzeClasses come together then. I.e.

@AnalyzeUi
@AnalyzeService
class MyGeneralArchRules {
    @ArchTest
    static final ArchRule firstRule = // ...
}

Because up to now this scenario was impossible by design. I guess since all the members of @AnalyzeClasses are varargs anyway, it would be easy to just aggregate all @AnalyzeClasses within the hierarchy and add all the varargs together. This means addition of locations to import and intersection of ImportOptions though... Also the use of two different cache modes would be a question to solve, who would win if one @AnalyzeClasses wants to clear the cache after the run and one wants to keep it? The safe thing would be to use the shorter one I guess.

I'll see if anyone wants to pitch in a PR here since I have to work on some other issues first.

Maiklins commented 1 year ago

Is this something that can still be picked up? Then I would give it a go.

codecholeric commented 1 year ago

Yes, I don't think anybody is actively working on this, so if you want to give it a shot I'm happy to support you where necessary :slightly_smiling_face:

mathze commented 6 months ago

As it seems that @Maiklins didn't found the time to take over, I would be happy to give it a try. Would it be ok for you @codecholeric?

mathze commented 6 months ago

Didn't got any response so I assume no one is working at this. So I've created #1300

Maiklins commented 6 months ago

@mathze I did not find the time to start on that one. So go ahead. :)

mathze commented 6 months ago

Note: My PR only allows the plain use as meta annotation. Atm. it does not respect merging nor inheritance from super classes. Imo support for merging and inheritance should be pulled out in a separate feature request, as it requires a quite more elaborated logic, which requires further discussion, shouldn't it?

mathze commented 5 months ago

@codecholeric did not received a response so far. Can you have a look at my PR #1300, please?