use of org.projectnessie.tools.compatibility.api.NessieAPI in project nessie by projectnessie.
the class AbstractNessieApiHolder method createNessieClient.
/**
* Used to construct {@link NessieApi} instances, for both current (in-tree) and old Nessie
* versions.
*
* <p>Must use {@link AutoCloseable} instead of {@link NessieApi}, because it loads the class via
* the given class loader, so instances of {@link NessieApi} for <em>old</em> Nessie versions will
* return a different class.
*/
protected static AutoCloseable createNessieClient(ClassLoader classLoader, ClientKey clientKey) {
try {
Class<?> builderClazz = classLoader.loadClass(clientKey.getBuilderClass());
Object builderInstance = builderClazz.getMethod("builder").invoke(null);
Method fromConfigMethod = builderInstance.getClass().getMethod("fromConfig", Function.class);
Function<String, String> getCfg = k -> {
String v = clientKey.getConfigs().get(k);
if (v != null) {
return v;
}
return System.getProperty(k);
};
builderInstance = fromConfigMethod.invoke(builderInstance, getCfg);
Class<?> targetClass = classLoader.loadClass(clientKey.getType().getName());
Method buildMethod = builderInstance.getClass().getMethod("build", Class.class);
Object apiInstance = buildMethod.invoke(builderInstance, targetClass);
LOGGER.info("Created Nessie client for version {} for {}", clientKey.getVersion(), getCfg.apply("nessie.uri"));
return (AutoCloseable) apiInstance;
} catch (InvocationTargetException e) {
throw throwUnchecked(e.getTargetException());
} catch (Exception e) {
throw throwUnchecked(e);
}
}
use of org.projectnessie.tools.compatibility.api.NessieAPI in project nessie by projectnessie.
the class AbstractNessieApiHolder method createClientKey.
private static ClientKey createClientKey(ExtensionContext context, Field field, Version version, Function<ExtensionContext, NessieServer> nessieServerSupplier) {
Map<String, String> configs = buildApiBuilderConfig(context, field, nessieServerSupplier);
// This method is only called for fields that are annotated with NessieAPI.
NessieAPI nessieAPI = field.getAnnotation(NessieAPI.class);
@SuppressWarnings("unchecked") Class<? extends NessieApi> apiType = (Class<? extends NessieApi>) field.getType();
ClientKey clientKey = new ClientKey(version, nessieAPI.builderClassName(), apiType, configs);
return clientKey;
}
Aggregations