Class ClassFinder
-
- All Implemented Interfaces:
public final class ClassFinderThis class finds classes that extend one of a set of parent classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceClassFinder.Closeable
-
Field Summary
Fields Modifier and Type Field Description public final static StringJMETER_SKIP_CLASS_SCANNING_ATTRIBUTE
-
Method Summary
Modifier and Type Method Description static booleangetSkipJarsWithJmeterSkipClassScanningAttribute()static ClassFinder.CloseableskipJarsWithJmeterSkipClassScanningAttribute()Configures if ClassFinder should skip jar files that have JMeter-Skip-Class-Scanning: truemanifest attribute.static <S> Collection<S>loadServices(Class<S> service, ServiceLoader<S> serviceLoader, ServiceLoadExceptionHandler<in S> exceptionHandler)Loads services implementing a given interface. static List<String>findClassesThatExtend(Array<String> paths, Array<Class<out Object>> superClasses)Convenience method for findClassesThatExtend with the option to include inner classes in the search set to false. static List<String>findClassesThatExtend(Array<String> strPathsOrJars, Array<Class<out Object>> superClasses, boolean innerClasses)Find classes in the provided path(s)/jar(s) that extend the class(es). static List<String>findClassesThatExtend(Array<String> strPathsOrJars, Array<Class<out Object>> superClasses, boolean innerClasses, String contains, String notContains)Find classes in the provided path(s)/jar(s) that extend the class(es). static List<String>findAnnotatedClasses(Array<String> strPathsOrJars, Array<Class<out Annotation>> annotations, boolean innerClasses)Find classes in the provided path(s)/jar(s) that extend the class(es). static List<String>findAnnotatedClasses(Array<String> strPathsOrJars, Array<Class<out Annotation>> annotations)Find classes in the provided path(s)/jar(s) that extend the class(es). static List<String>findClassesThatExtend(Array<String> searchPathsOrJars, Array<Class<out Object>> classNames, boolean innerClasses, String contains, String notContains, boolean annotations)Find classes in the provided path(s)/jar(s) that extend the class(es). static List<String>findClasses(Array<String> searchPathsOrJars, ClassFilter filter)Find all classes in the given jars that passes the class filter. -
-
Method Detail
-
getSkipJarsWithJmeterSkipClassScanningAttribute
@API(status = API.Status.EXPERIMENTAL, since = "5.6") static boolean getSkipJarsWithJmeterSkipClassScanningAttribute()
-
skipJarsWithJmeterSkipClassScanningAttribute
@API(status = API.Status.INTERNAL, since = "5.6") static ClassFinder.Closeable skipJarsWithJmeterSkipClassScanningAttribute()
Configures if ClassFinder should skip jar files that have
JMeter-Skip-Class-Scanning: truemanifest attribute. JMeter will skip such jars when it uses both java.util.ServiceLoader and ClassFinder. 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
static <S> Collection<S> loadServices(Class<S> service, ServiceLoader<S> serviceLoader, ServiceLoadExceptionHandler<in S> exceptionHandler)
Loads services implementing a given interface. This is an intended replacement for
findClassesThatExtend.- 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() static List<String> findClassesThatExtend(Array<String> paths, Array<Class<out Object>> superClasses)
Convenience method for findClassesThatExtend 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.
-
findClassesThatExtend
@Deprecated() static List<String> findClassesThatExtend(Array<String> strPathsOrJars, Array<Class<out Object>> superClasses, boolean innerClasses)
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
-
findClassesThatExtend
@API(status = API.Status.DEPRECATED, since = "5.6")@Deprecated() static List<String> findClassesThatExtend(Array<String> strPathsOrJars, Array<Class<out Object>> superClasses, boolean innerClasses, String contains, String notContains)
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
-
findAnnotatedClasses
@API(status = API.Status.DEPRECATED, since = "5.6")@Deprecated() static List<String> findAnnotatedClasses(Array<String> strPathsOrJars, Array<Class<out Annotation>> annotations, boolean innerClasses)
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
-
findAnnotatedClasses
@API(status = API.Status.DEPRECATED, since = "5.6")@Deprecated() static List<String> findAnnotatedClasses(Array<String> strPathsOrJars, Array<Class<out Annotation>> annotations)
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
-
findClassesThatExtend
@API(status = API.Status.DEPRECATED, since = "5.6")@Deprecated() static List<String> findClassesThatExtend(Array<String> searchPathsOrJars, Array<Class<out Object>> classNames, boolean innerClasses, String contains, String notContains, boolean annotations)
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
-
findClasses
@API(status = API.Status.DEPRECATED, since = "5.6")@Deprecated() static List<String> findClasses(Array<String> searchPathsOrJars, ClassFilter filter)
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
-
-
-
-