Package org.apache.jorphan.reflect
Class ClassFinder
java.lang.Object
org.apache.jorphan.reflect.ClassFinder
This class finds classes that extend one of a set of parent classes.
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionfindAnnotatedClasses
(String[] strPathsOrJars, Class<? extends Annotation>[] annotations) Deprecated.findAnnotatedClasses
(String[] strPathsOrJars, Class<? extends Annotation>[] annotations, boolean innerClasses) Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
findClasses
(String[] searchPathsOrJars, ClassFilter filter) Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
findClassesThatExtend
(String[] paths, Class<?>[] superClasses) Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
findClassesThatExtend
(String[] strPathsOrJars, Class<?>[] superClasses, boolean innerClasses) Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
findClassesThatExtend
(String[] strPathsOrJars, Class<?>[] superClasses, boolean innerClasses, String contains, String notContains) Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
findClassesThatExtend
(String[] searchPathsOrJars, Class<?>[] classNames, boolean innerClasses, String contains, String notContains, boolean annotations) Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
static boolean
static <S> Collection<S>
loadServices
(Class<S> service, ServiceLoader<S> serviceLoader, ServiceLoadExceptionHandler<? super S> exceptionHandler) Loads services implementing a given interface.static ClassFinder.Closeable
Configures ifClassFinder
should skip jar files that haveJMeter-Skip-Class-Scanning: true
manifest attribute.
-
Field Details
-
JMETER_SKIP_CLASS_SCANNING_ATTRIBUTE
- See Also:
-
-
Method Details
-
getSkipJarsWithJmeterSkipClassScanningAttribute
@API(status=EXPERIMENTAL, since="5.6") public static boolean getSkipJarsWithJmeterSkipClassScanningAttribute() -
skipJarsWithJmeterSkipClassScanningAttribute
@API(status=INTERNAL, since="5.6") public static ClassFinder.Closeable skipJarsWithJmeterSkipClassScanningAttribute()Configures ifClassFinder
should skip jar files that haveJMeter-Skip-Class-Scanning: true
manifest attribute. JMeter will skip such jars when it uses bothServiceLoader
andClassFinder
. However,ClassFinder
was public, so it was possible that custom plugins could use it, and they should be able to find the implementations even if they are in jars withJMeter-Skip-Class-Scanning: true
.Sample usage:
List<String> classNames; try (ClassFinder.Closeable ignored = ClassFinder.skipJarsWithJmeterSkipClassScanningAttribute()) { // findClassesThatExtend will not skip jars with JMeter-Skip-Class-Scanning: true manifest attribute classNames = ClassFinder.findClassesThatExtend(...);
- Returns:
- closeable that will reset "skip jar files with manifest entry" flag when closed. Use it in try-with-resources
-
loadServices
public static <S> Collection<S> loadServices(Class<S> service, ServiceLoader<S> serviceLoader, ServiceLoadExceptionHandler<? super S> exceptionHandler) Loads services implementing a given interface. This is an intended replacement forfindClassesThatExtend
.- Type Parameters:
S
- type of service (class or interface)- Parameters:
service
- interface that services should extend.serviceLoader
- ServiceLoader to fetch services.exceptionHandler
- exception handler to use for services that fail to load.- Returns:
- collection of services that load successfully
-
findClassesThatExtend
@Deprecated public static List<String> findClassesThatExtend(String[] paths, Class<?>[] superClasses) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Convenience method forfindClassesThatExtend(String[], Class[], boolean)
with the option to include inner classes in the search set to false.- Parameters:
paths
- pathnames or jarfiles to search for classessuperClasses
- required parent class(es)- Returns:
- List of Strings containing discovered class names.
- Throws:
IOException
- when scanning the classes fails
-
findClassesThatExtend
@Deprecated public static List<String> findClassesThatExtend(String[] strPathsOrJars, Class<?>[] superClasses, boolean innerClasses) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Find classes in the provided path(s)/jar(s) that extend the class(es).- Parameters:
strPathsOrJars
- pathnames or jarfiles to search for classessuperClasses
- required parent class(es)innerClasses
- should we include inner classes?- Returns:
- List containing discovered classes
- Throws:
IOException
- when scanning for classes fails
-
findClassesThatExtend
@API(status=DEPRECATED, since="5.6") @Deprecated public static List<String> findClassesThatExtend(String[] strPathsOrJars, Class<?>[] superClasses, boolean innerClasses, String contains, String notContains) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Find classes in the provided path(s)/jar(s) that extend the class(es).- Parameters:
strPathsOrJars
- pathnames or jarfiles to search for classessuperClasses
- required parent class(es)innerClasses
- should we include inner classes?contains
- classname should contain this stringnotContains
- classname should not contain this string- Returns:
- List containing discovered classes
- Throws:
IOException
- when scanning classes fails
-
findAnnotatedClasses
@API(status=DEPRECATED, since="5.6") @Deprecated public static List<String> findAnnotatedClasses(String[] strPathsOrJars, Class<? extends Annotation>[] annotations, boolean innerClasses) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Find classes in the provided path(s)/jar(s) that extend the class(es).- Parameters:
strPathsOrJars
- pathnames or jarfiles to search for classesannotations
- required annotationsinnerClasses
- should we include inner classes?- Returns:
- List containing discovered classes
- Throws:
IOException
- when scanning classes fails
-
findAnnotatedClasses
@API(status=DEPRECATED, since="5.6") @Deprecated public static List<String> findAnnotatedClasses(String[] strPathsOrJars, Class<? extends Annotation>[] annotations) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Find classes in the provided path(s)/jar(s) that extend the class(es). Inner classes are not searched.- Parameters:
strPathsOrJars
- pathnames or jarfiles to search for classesannotations
- required annotations- Returns:
- List containing discovered classes
- Throws:
IOException
- when scanning classes fails
-
findClassesThatExtend
@API(status=DEPRECATED, since="5.6") @Deprecated public static List<String> findClassesThatExtend(String[] searchPathsOrJars, Class<?>[] classNames, boolean innerClasses, String contains, String notContains, boolean annotations) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Find classes in the provided path(s)/jar(s) that extend the class(es).- Parameters:
searchPathsOrJars
- pathnames or jarfiles to search for classesclassNames
- required parent class(es) or annotationsinnerClasses
- should we include inner classes?contains
- classname should contain this stringnotContains
- classname should not contain this stringannotations
- true if classnames are annotations- Returns:
- List containing discovered classes
- Throws:
IOException
- when scanning classes fails
-
findClasses
@API(status=DEPRECATED, since="5.6") @Deprecated public static List<String> findClasses(String[] searchPathsOrJars, ClassFilter filter) throws IOException Deprecated.useloadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars
Find all classes in the given jars that passes the class filter.- Parameters:
searchPathsOrJars
- list of strings representing the jar locationsfilter
-ClassFilter
that the classes in the jars should conform to- Returns:
- list of all classes in the jars, that conform to
filter
- Throws:
IOException
- when reading the jar files fails
-
loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)
orJMeterUtils#loadServicesAndScanJars