Class ClassFinder

  • All Implemented Interfaces:

    
    public final class ClassFinder
    
                        

    This class finds classes that extend one of a set of parent classes.

    • Constructor Detail

    • Method Detail

      • 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: true manifest 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 with JMeter-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> 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 classes
        superClasses - 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 classes
        superClasses - required parent class(es)
        innerClasses - should we include inner classes?
        contains - classname should contain this string
        notContains - 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 classes
        annotations - required annotations
        innerClasses - 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 classes
        annotations - 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 classes
        classNames - required parent class(es) or annotations
        innerClasses - should we include inner classes?
        contains - classname should contain this string
        notContains - classname should not contain this string
        annotations - 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 locations
        filter - ClassFilter that the classes in the jars should conform to
        Returns:

        list of all classes in the jars, that conform to filter