Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ClassLoaderFactory {

/**
* Attempts to find {@code .jar} files in the path specified in {@value #PLUGIN_DIR_KEY} system property.
* A new class loader instance is returned that loads classes from the given classes.
* A new class loader instance is returned that loads classes from the given directory.
*
* @return A new URLClassLoader that is aware of all {@code .jar} files in the plugin dir
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class IntegrationsLoader {
private IntegrationsLoader() {
}

private static class PluginClassLoaderHolder {
private static final ClassLoader CLASS_LOADER = ClassLoaderFactory.forPluginDir();
}

private static ClassLoader getClassLoader() {
return PluginClassLoaderHolder.CLASS_LOADER;
}

/**
* Loads the best suited service provider, i.e. the one with the highest priority that is supported.
* <p>
Expand All @@ -44,7 +52,7 @@ public static <T> Optional<T> load(Class<T> clazz) {
* @param <T> Type of the service
*/
public static <T> Optional<T> loadSpecific(Class<T> clazz, String implementationClassName) {
return ServiceLoader.load(clazz, ClassLoaderFactory.forPluginDir()).stream()
return ServiceLoader.load(clazz, getClassLoader()).stream()
.filter(provider -> provider.type().getName().equals(implementationClassName))
.map(ServiceLoader.Provider::get)
.findAny();
Expand All @@ -61,7 +69,7 @@ public static <T> Optional<T> loadSpecific(Class<T> clazz, String implementation
* @return An ordered stream of all suited service providers
*/
public static <T> Stream<T> loadAll(Class<T> clazz) {
return loadAll(ServiceLoader.load(clazz, ClassLoaderFactory.forPluginDir()), clazz);
return loadAll(ServiceLoader.load(clazz, getClassLoader()), clazz);
}

/**
Expand Down
Loading