Skip to main content
Version: 5.0.0 (Unmaintained)

Selector

A Selector describes discovery criteria used by Runner when locating @Paramixel.Factory methods. Selectors constrain discovery by package name, fully qualified class name, tag value, or a composition of these.

All selector regular expressions use Pattern.matcher(CharSequence).find() semantics. For exact matches, use anchored expressions like ^smoke$.

import org.paramixel.api.selector.Selector;

Factory methods​

MethodDescription
Selector.all()Matches all action factories regardless of package, class, or tag
Selector.packageRegex(String)Matches package names by regex
Selector.classRegex(String)Matches fully qualified class names by regex
Selector.tagRegex(String)Matches tag values by regex
Selector.packageTreeOf(Class<?>)Matches a package and all subpackages below it
Selector.packageOf(Class<?>)Matches an exact package, excluding subpackages
Selector.classOf(Class<?>)Matches the exact fully qualified class name

Composition​

MethodDescription
Selector.and(Selector...)Logical AND — matches when all selectors match (at least two required)
Selector.and(List<Selector>)Logical AND from a list
Selector.or(Selector...)Logical OR — matches when any selector matches (at least two required)
Selector.or(List<Selector>)Logical OR from a list
Selector.not(Selector)Logical NOT — matches when the supplied selector does not match

Nested AND/OR selectors are automatically flattened.

Instance methods​

MethodDescription
matchesPackage(String)Tests whether a package name matches
matchesClass(String)Tests whether a fully qualified class name matches
matchesTag(String)Tests whether a tag value matches

Selector sub-interfaces​

InterfacePackageExtendsDescription
RegexSelectororg.paramixel.api.selectorSelectorBase for regex-based selectors; adds pattern()
PackageRegexSelectororg.paramixel.api.selectorRegexSelectorRegex selector that matches package names
ClassRegexSelectororg.paramixel.api.selectorRegexSelectorRegex selector that matches class names
TagRegexSelectororg.paramixel.api.selectorRegexSelectorRegex selector that matches tag values
AndSelectororg.paramixel.api.selectorSelectorComposed AND selector; adds selectors()
OrSelectororg.paramixel.api.selectorSelectorComposed OR selector; adds selectors()
NotSelectororg.paramixel.api.selectorSelectorNegated selector; adds selector()

Examples​

Select all factories in a package tree:

Selector selector = Selector.packageTreeOf(MyTest.class);
runner.run(selector);

Select factories by tag:

Selector selector = Selector.tagRegex("^smoke$");
runner.run(selector);

Compose criteria:

Selector selector = Selector.and(
Selector.packageTreeOf(MyTest.class),
Selector.tagRegex("^(smoke|critical)$"));

Negate a selector:

Selector selector = Selector.not(Selector.tagRegex("^slow$"));

Use with Runner​

Pass a selector to Runner.run(Selector), Runner.runAndReturnExitCode(Selector), or Runner.runAndExit(Selector):

Optional<Result> result = Runner.defaultRunner().run(
Selector.and(
Selector.packageTreeOf(MyTest.class),
Selector.not(Selector.tagRegex("^slow$"))));

Use with @Paramixel.Tag​

Combine selectors with @Paramixel.Tag annotations on factory methods:

@Paramixel.Factory
@Paramixel.Tag("smoke")
@Paramixel.Tag("critical")
public static Action<?> factory() {
return Instance.of(MyTest.class)
.child("test()", MyTest::test)
.resolve();
}

Then select by tag:

Selector selector = Selector.tagRegex("^smoke$");