in knights/jsch-knight/src/main/java/org/apache/geronimo/arthur/knight/jsch/JschExtension.java [34:79]
public void execute(final Context context) {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final Function<String, Class<?>> load = name -> {
try {
return loader.loadClass(name);
} catch (final ClassNotFoundException e) {
return null;
}
};
try {
final Class<?> jsch = load.apply("com.jcraft.jsch.JSch");
if (jsch == null) {
log.info("JSch no available, skipping");
return;
}
final Field config = jsch.getDeclaredField("config");
if (!config.isAccessible()) {
config.setAccessible(true);
}
final Collection<String> values = Hashtable.class.cast(config.get(null)).values();
values.stream()
.filter(it -> !"com.jcraft.jsch.jcraft.Compression".equalsIgnoreCase(it)) // requires other libs
.map(load)
.filter(Objects::nonNull)
.distinct()
.map(clazz -> {
final ClassReflectionModel model = new ClassReflectionModel();
model.setName(clazz.getName());
model.setAllDeclaredConstructors(true);
return model;
})
.forEach(context::register);
context.enableAllSecurityServices();
context.initializeAtBuildTime(
Stream.of(jsch.getName(), jsch.getName() + "$1") // JSch.DEVNULL
.filter(it -> load.apply(it) != null) // tolerate jsch extraction of DEVNULL in a root class
.toArray(String[]::new));
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}