ClassFinder (Apache JMeter dist API)
Description: declaration: package: org.apache.jorphan.reflect, class: ClassFinder

Package org.apache.jorphan.reflect

# Class ClassFinder

java.lang.Object
org.apache.jorphan.reflect.ClassFinder

public final class ClassFinder extends Object
This class finds classes that extend one of a set of parent classes.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `ClassFinder.Closeable`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `JMETER_SKIP_CLASS_SCANNING_ATTRIBUTE`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static List<String>`
  `findAnnotatedClasses(String[] strPathsOrJars, Class<? extends Annotation>[] annotations)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static List<String>`
  `findAnnotatedClasses(String[] strPathsOrJars, Class<? extends Annotation>[] annotations, boolean innerClasses)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static List<String>`
  `findClasses(String[] searchPathsOrJars, ClassFilter filter)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static List<String>`
  `findClassesThatExtend(String[] paths, Class<?>[] superClasses)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static List<String>`
  `findClassesThatExtend(String[] strPathsOrJars, Class<?>[] superClasses, boolean innerClasses)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static List<String>`
  `findClassesThatExtend(String[] strPathsOrJars, Class<?>[] superClasses, boolean innerClasses, String contains, String notContains)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static List<String>`
  `findClassesThatExtend(String[] searchPathsOrJars, Class<?>[] classNames, boolean innerClasses, String contains, String notContains, boolean annotations)`
  Deprecated.
  use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
  `static boolean`
  `getSkipJarsWithJmeterSkipClassScanningAttribute()`
  `static <S> Collection<S>`
  `loadServices(Class<S> service, ServiceLoader<S> serviceLoader, ServiceLoadExceptionHandler<? super S> exceptionHandler)`
  Loads services implementing a given interface.
  `static ClassFinder.Closeable`
  `skipJarsWithJmeterSkipClassScanningAttribute()`
  Configures if `ClassFinder` should skip jar files that have `JMeter-Skip-Class-Scanning: true` manifest attribute.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### JMETER_SKIP_CLASS_SCANNING_ATTRIBUTE

    public static final String JMETER_SKIP_CLASS_SCANNING_ATTRIBUTE
    See Also:
      - Constant Field Values

- ## 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 if `ClassFinder` should skip jar files that have `JMeter-Skip-Class-Scanning: true` manifest attribute. JMeter will skip such jars when it uses both `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

    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 for `findClassesThatExtend`.
    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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
    Convenience method for `findClassesThatExtend(String[], Class[], boolean)` with the option to include inner classes in the search set to false.
    Parameters:
      `paths` - pathnames or jarfiles to search for classes
      `superClasses` - 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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
    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
    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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
    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
    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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
    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
    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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#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 classes
      `annotations` - 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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
    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
    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.
    use `loadServices(Class, ServiceLoader, ServiceLoadExceptionHandler)` or `JMeterUtils#loadServicesAndScanJars`
    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`
    Throws:
      `IOException` - when reading the jar files fails