Class PackageMatcher

java.lang.Object
com.tngtech.archunit.base.PackageMatcher

public final class PackageMatcher extends Object
Matches packages with a syntax similar to AspectJ. In particular '*' stands for any sequence of characters but not the dot '.', while '..' stands for any sequence of packages, including zero packages.
For example
  • '..pack..' matches 'a.pack', 'a.pack.b' or 'a.b.pack.c.d', but not 'a.packa.b'
  • '*.pack.*' matches 'a.pack.b', but not 'a.b.pack.c'
  • '..*pack*..' matches 'a.prepackfix.b'
  • '*.*.pack*..' matches 'a.b.packfix.c.d', but neither 'a.packfix.b' nor 'a.b.prepack.d'
Furthermore, the use of capturing groups is supported. In this case '(*)' matches any sequence of characters, but not the dot '.', while '(**)' matches any sequence including the dot.
For example
  • '..service.(*)..' matches 'a.service.hello.b' and group 1 would be 'hello'
  • '..service.(**)' matches 'a.service.hello.more' and group 1 would be 'hello.more'
  • 'my.(*)..service.(**)' matches 'my.company.some.service.hello.more' and group 1 would be 'company', while group 2 would be 'hello.more'
Create via PackageMatcher.of(packageIdentifier)