-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement include and exclude filtering when calling registerAutoDetectedExtensions in MutableExtensionRegistry #4120
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
Merged
marcphilipp
merged 33 commits into
junit-team:main
from
YongGoose:feature/enable-specific-global-extensions-in-junit
Dec 16, 2024
Merged
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
cfb6845
Enable specific global extension in JUnit 5
YongGoose 07a6ae3
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/ex…
YongGoose 4a896f1
Add Java 9+ variant for optimized ServiceLoader filtering
YongGoose 7c58f66
Merge branch 'main' into feature/enable-specific-global-extensions-in…
YongGoose 09dca93
Remove final keyword
YongGoose 355e113
Merge branch 'main' into feature/enable-specific-global-extensions-in…
YongGoose 2568ffe
Avoid instantiating deactivated TestExecutionListeners
marcphilipp d5a3511
Pass ServiceLoader to Utils to avoid failing its caller check
marcphilipp a599008
Merge pull request #1 from junit-team/marc/avoid-deactivated-test-exe…
YongGoose 8b2f41e
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/ex…
YongGoose eb32053
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/ex…
YongGoose 1597992
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/ex…
YongGoose eb1b5b3
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/ex…
YongGoose f86c1d6
Add constants and javadoc for supported syntax
YongGoose 02c91b5
move code to JupiterConfiguration
YongGoose 3c95ac9
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/co…
YongGoose 624760b
Rename method
YongGoose 6c5d6c3
Add javadoc
YongGoose 13645f0
Update user-guide
YongGoose 9daa88a
Merge branch 'main' into feature/enable-specific-global-extensions-in…
YongGoose f870747
Log excluded classes once
YongGoose 671e387
Update junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/ex…
YongGoose 87ac022
Merge branch 'main' into feature/enable-specific-global-extensions-in…
YongGoose a190de6
Apply spotless
YongGoose 13c1b19
Update user-guide
YongGoose 6e5b161
Document new configuration parameters
marcphilipp ec13b6d
Add integration test
YongGoose ff30825
Merge remote-tracking branch 'origin/feature/enable-specific-global-e…
YongGoose 4b3c670
Avoid 2nd loop and loading all extensions
marcphilipp 6279713
Polish tests
marcphilipp 93f0e2f
Improve readability
marcphilipp f92b14d
Return "constant" predicates for default case
marcphilipp fbefdc9
Remove orphaned anchor
marcphilipp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,76 @@ | |
| @API(status = STABLE, since = "5.0") | ||
| public final class Constants { | ||
|
|
||
| /** | ||
| * Property name used to include patterns for auto-detecting extensions: {@value} | ||
| * | ||
| * <h4>Pattern Matching Syntax</h4> | ||
| * | ||
| * <p>If the property value consists solely of an asterisk ({@code *}), all | ||
| * extensions will be included. Otherwise, the property value will be treated | ||
| * as a comma-separated list of patterns where each individual pattern will be | ||
| * matched against the fully qualified class name (<em>FQCN</em>) of each extension. | ||
| * Any dot ({@code .}) in a pattern will match against a dot ({@code .}) | ||
| * or a dollar sign ({@code $}) in a FQCN. Any asterisk ({@code *}) will match | ||
| * against one or more characters in a FQCN. All other characters in a pattern | ||
| * will be matched one-to-one against a FQCN. | ||
| * | ||
| * <h4>Examples</h4> | ||
| * | ||
| * <ul> | ||
| * <li>{@code *}: includes all extensions. | ||
| * <li>{@code org.junit.*}: includes every extension under the {@code org.junit} | ||
| * base package and any of its subpackages. | ||
| * <li>{@code *.MyExtension}: includes every extension whose simple class name is | ||
| * exactly {@code MyExtension}. | ||
| * <li>{@code *System*}: includes every extension whose FQCN contains | ||
| * {@code System}. | ||
| * <li>{@code *System*, *Dev*}: includes every extension whose FQCN contains | ||
| * {@code System} or {@code Dev}. | ||
| * <li>{@code org.example.MyExtension, org.example.TheirExtension}: includes | ||
| * extensions whose FQCN is exactly {@code org.example.MyExtension} or | ||
| * {@code org.example.TheirExtension}. | ||
| * </ul> | ||
| * | ||
| * @see JupiterConfiguration#EXTENSIONS_AUTODETECTION_INCLUDE_PROPERTY_NAME | ||
| */ | ||
| public static final String EXTENSIONS_AUTODETECTION_INCLUDE_PROPERTY_NAME = JupiterConfiguration.EXTENSIONS_AUTODETECTION_INCLUDE_PROPERTY_NAME; | ||
|
|
||
| /** | ||
| * Property name used to exclude patterns for auto-detecting extensions: {@value} | ||
| * | ||
| * <h4>Pattern Matching Syntax</h4> | ||
| * | ||
| * <p>If the property value consists solely of an asterisk ({@code *}), all | ||
| * extensions will be excluded. Otherwise, the property value will be treated | ||
| * as a comma-separated list of patterns where each individual pattern will be | ||
| * matched against the fully qualified class name (<em>FQCN</em>) of each extension. | ||
| * Any dot ({@code .}) in a pattern will match against a dot ({@code .}) | ||
| * or a dollar sign ({@code $}) in a FQCN. Any asterisk ({@code *}) will match | ||
| * against one or more characters in a FQCN. All other characters in a pattern | ||
| * will be matched one-to-one against a FQCN. | ||
| * | ||
| * <h4>Examples</h4> | ||
| * | ||
| * <ul> | ||
| * <li>{@code *}: excludes all extensions. | ||
| * <li>{@code org.junit.*}: excludes every extension under the {@code org.junit} | ||
| * base package and any of its subpackages. | ||
| * <li>{@code *.MyExtension}: excludes every extension whose simple class name is | ||
| * exactly {@code MyExtension}. | ||
| * <li>{@code *System*}: excludes every extension whose FQCN contains | ||
| * {@code System}. | ||
| * <li>{@code *System*, *Dev*}: excludes every extension whose FQCN contains | ||
| * {@code System} or {@code Dev}. | ||
| * <li>{@code org.example.MyExtension, org.example.TheirExtension}: excludes | ||
| * extensions whose FQCN is exactly {@code org.example.MyExtension} or | ||
| * {@code org.example.TheirExtension}. | ||
| * </ul> | ||
| * | ||
| * @see JupiterConfiguration#EXTENSIONS_AUTODETECTION_EXCLUDE_PROPERTY_NAME | ||
| */ | ||
| public static final String EXTENSIONS_AUTODETECTION_EXCLUDE_PROPERTY_NAME = JupiterConfiguration.EXTENSIONS_AUTODETECTION_EXCLUDE_PROPERTY_NAME; | ||
|
|
||
| /** | ||
| * Property name used to provide patterns for deactivating conditions: {@value} | ||
| * | ||
|
|
@@ -93,6 +163,15 @@ public final class Constants { | |
| */ | ||
| public static final String DEACTIVATE_ALL_CONDITIONS_PATTERN = ClassNamePatternFilterUtils.ALL_PATTERN; | ||
|
|
||
| /** | ||
| * A blank pattern used for class name filtering: {@value} | ||
| * | ||
| * <p>This constant is used to represent an empty or blank pattern in class name filtering operations. | ||
| * | ||
| * @see ClassNamePatternFilterUtils#BLANK | ||
| */ | ||
| public static final String BLANK = ClassNamePatternFilterUtils.BLANK; | ||
|
|
||
|
||
| /** | ||
| * Property name used to set the default display name generator class name: {@value} | ||
| * | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
junit-platform-commons/src/main/java/org/junit/platform/commons/util/ServiceLoaderUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright 2015-2024 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|
|
||
| package org.junit.platform.commons.util; | ||
|
|
||
| import java.util.ServiceLoader; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Stream; | ||
| import java.util.stream.StreamSupport; | ||
|
|
||
| import org.apiguardian.api.API; | ||
|
|
||
| /** | ||
| * Collection of utilities for working with {@link ServiceLoader}. | ||
| * | ||
| * <h2>DISCLAIMER</h2> | ||
| * | ||
| * <p>These utilities are intended solely for usage within the JUnit framework | ||
| * itself. <strong>Any usage by external parties is not supported.</strong> | ||
| * Use at your own risk! | ||
| * | ||
| * @since 5.11 | ||
| */ | ||
| @API(status = API.Status.INTERNAL, since = "5.11") | ||
| public class ServiceLoaderUtils { | ||
|
|
||
| private ServiceLoaderUtils() { | ||
| /* no-op */ | ||
| } | ||
|
|
||
| /** | ||
| * Filters the supplied service loader using the supplied predicate. | ||
| * | ||
| * @param <T> the type of the service | ||
| * @param serviceLoader the service loader to be filtered | ||
| * @param providerPredicate the predicate to filter the loaded services | ||
| * @return a stream of loaded services that match the predicate | ||
| */ | ||
| public static <T> Stream<T> filter(ServiceLoader<T> serviceLoader, | ||
| Predicate<? super Class<? extends T>> providerPredicate) { | ||
| return StreamSupport.stream(serviceLoader.spliterator(), false).filter(it -> { | ||
| @SuppressWarnings("unchecked") | ||
| Class<? extends T> type = (Class<? extends T>) it.getClass(); | ||
| return providerPredicate.test(type); | ||
| }); | ||
| } | ||
|
|
||
| } |
56 changes: 56 additions & 0 deletions
56
...t-platform-commons/src/main/java9/org/junit/platform/commons/util/ServiceLoaderUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright 2015-2024 the original author or authors. | ||
| * | ||
| * All rights reserved. This program and the accompanying materials are | ||
| * made available under the terms of the Eclipse Public License v2.0 which | ||
| * accompanies this distribution and is available at | ||
| * | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| */ | ||
|
|
||
| package org.junit.platform.commons.util; | ||
|
|
||
| import java.util.ServiceLoader; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.apiguardian.api.API; | ||
| import org.apiguardian.api.API.Status; | ||
|
|
||
| /** | ||
| * Collection of utilities for working with {@link ServiceLoader}. | ||
| * | ||
| * <h2>DISCLAIMER</h2> | ||
| * | ||
| * <p>These utilities are intended solely for usage within the JUnit framework | ||
| * itself. <strong>Any usage by external parties is not supported.</strong> | ||
| * Use at your own risk! | ||
| * | ||
| * @since 5.11 | ||
| */ | ||
| @API(status = Status.INTERNAL, since = "5.11") | ||
| public class ServiceLoaderUtils { | ||
|
|
||
| private ServiceLoaderUtils() { | ||
| /* no-op */ | ||
| } | ||
|
|
||
| /** | ||
| * Filters the supplied service loader using the supplied predicate. | ||
| * | ||
| * @param <T> the type of the service | ||
| * @param serviceLoader the service loader to be filtered | ||
| * @param providerPredicate the predicate to filter the loaded services | ||
| * @return a stream of loaded services that match the predicate | ||
| */ | ||
| public static <T> Stream<T> filter(ServiceLoader<T> serviceLoader, | ||
| Predicate<? super Class<? extends T>> providerPredicate) { | ||
| // @formatter:off | ||
| return serviceLoader | ||
| .stream() | ||
| .filter(provider -> providerPredicate.test(provider.type())) | ||
| .map(ServiceLoader.Provider::get); | ||
| // @formatter:on | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.