|
| 1 | +/* |
| 2 | + * Copyright 2015-2024 the original author or authors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials are |
| 5 | + * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | + * accompanies this distribution and is available at |
| 7 | + * |
| 8 | + * https://www.eclipse.org/legal/epl-v20.html |
| 9 | + */ |
| 10 | + |
| 11 | +package org.junit.platform.commons.support.scanning; |
| 12 | + |
| 13 | +import static org.apiguardian.api.API.Status; |
| 14 | + |
| 15 | +import java.net.URI; |
| 16 | +import java.util.List; |
| 17 | +import java.util.function.Predicate; |
| 18 | + |
| 19 | +import org.apiguardian.api.API; |
| 20 | +import org.junit.platform.commons.support.Resource; |
| 21 | + |
| 22 | +/** |
| 23 | + * {@code ClasspathScanner} allows to scan the classpath for classes and |
| 24 | + * resources. |
| 25 | + * |
| 26 | + * <p>An implementation of this interface can be registered via the |
| 27 | + * {@link java.util.ServiceLoader ServiceLoader} mechanism. |
| 28 | + * |
| 29 | + * @since 1.12 |
| 30 | + */ |
| 31 | +@API(status = Status.EXPERIMENTAL, since = "1.12") |
| 32 | +public interface ClasspathScanner { |
| 33 | + |
| 34 | + /** |
| 35 | + * Find all {@linkplain Class classes} in the supplied classpath {@code root} |
| 36 | + * that match the specified {@code classFilter} filter. |
| 37 | + * |
| 38 | + * <p>The classpath scanning algorithm searches recursively in subpackages |
| 39 | + * beginning with the root of the classpath. |
| 40 | + * |
| 41 | + * @param basePackageName the name of the base package in which to start |
| 42 | + * scanning; must not be {@code null} and must be valid in terms of Java |
| 43 | + * syntax |
| 44 | + * @param classFilter the class type filter; never {@code null} |
| 45 | + * @return a list of all such classes found; never {@code null} |
| 46 | + * but potentially empty |
| 47 | + */ |
| 48 | + List<Class<?>> scanForClassesInPackage(String basePackageName, ClassFilter classFilter); |
| 49 | + |
| 50 | + /** |
| 51 | + * Find all {@linkplain Class classes} in the supplied classpath {@code root} |
| 52 | + * that match the specified {@code classFilter} filter. |
| 53 | + * |
| 54 | + * <p>The classpath scanning algorithm searches recursively in subpackages |
| 55 | + * beginning with the root of the classpath. |
| 56 | + * |
| 57 | + * @param root the URI for the classpath root in which to scan; never |
| 58 | + * {@code null} |
| 59 | + * @param classFilter the class type filter; never {@code null} |
| 60 | + * @return a list of all such classes found; never {@code null} |
| 61 | + * but potentially empty |
| 62 | + */ |
| 63 | + List<Class<?>> scanForClassesInClasspathRoot(URI root, ClassFilter classFilter); |
| 64 | + |
| 65 | + /** |
| 66 | + * Find all {@linkplain Resource resources} in the supplied classpath {@code root} |
| 67 | + * that match the specified {@code resourceFilter} predicate. |
| 68 | + * |
| 69 | + * <p>The classpath scanning algorithm searches recursively in subpackages |
| 70 | + * beginning with the root of the classpath. |
| 71 | + * |
| 72 | + * @param basePackageName the name of the base package in which to start |
| 73 | + * scanning; must not be {@code null} and must be valid in terms of Java |
| 74 | + * syntax |
| 75 | + * @param resourceFilter the resource type filter; never {@code null} |
| 76 | + * @return a list of all such resources found; never {@code null} |
| 77 | + * but potentially empty |
| 78 | + */ |
| 79 | + List<Resource> scanForResourcesInPackage(String basePackageName, Predicate<Resource> resourceFilter); |
| 80 | + |
| 81 | + /** |
| 82 | + * Find all {@linkplain Resource resources} in the supplied classpath {@code root} |
| 83 | + * that match the specified {@code resourceFilter} predicate. |
| 84 | + * |
| 85 | + * <p>The classpath scanning algorithm searches recursively in subpackages |
| 86 | + * beginning with the root of the classpath. |
| 87 | + * |
| 88 | + * @param root the URI for the classpath root in which to scan; never |
| 89 | + * {@code null} |
| 90 | + * @param resourceFilter the resource type filter; never {@code null} |
| 91 | + * @return a list of all such resources found; never {@code null} |
| 92 | + * but potentially empty |
| 93 | + */ |
| 94 | + List<Resource> scanForResourcesInClasspathRoot(URI root, Predicate<Resource> resourceFilter); |
| 95 | + |
| 96 | +} |
0 commit comments