ArchUnit icon indicating copy to clipboard operation
ArchUnit copied to clipboard

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

Open bobtiernay-okta opened this issue 6 years ago • 8 comments

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.

bobtiernay-okta avatar Jun 16 '19 12:06 bobtiernay-okta

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.

codecholeric avatar Jun 17 '19 18:06 codecholeric

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

Maiklins avatar Feb 22 '23 13:02 Maiklins

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:

codecholeric avatar Feb 27 '23 05:02 codecholeric

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 avatar May 04 '24 20:05 mathze

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

mathze avatar May 06 '24 17:05 mathze

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

Maiklins avatar May 07 '24 08:05 Maiklins

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 avatar May 11 '24 06:05 mathze