use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.
the class OlderNessieClientsExtension method populateFields.
private void populateFields(ExtensionContext context, Object instance) {
Version version = populateNessieVersionAnnotatedFields(context, instance);
if (version == null) {
return;
}
populateNessieVersionAnnotatedFields(context, instance);
ServerKey serverKey = new ServerKey(Version.CURRENT, "In-Memory", Collections.emptyMap());
BooleanSupplier initializeRepository = () -> true;
populateNessieAnnotatedFields(context, instance, field -> apiInstanceForField(classContext(context), field, version, ctx -> nessieServer(ctx, serverKey, initializeRepository)));
}
use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.
the class OlderNessieServersExtension method populateFields.
private void populateFields(ExtensionContext context, Object instance) {
Version version = populateNessieVersionAnnotatedFields(context, instance);
if (version == null) {
return;
}
BooleanSupplier initializeRepository = () -> true;
ServerKey serverKey = new ServerKey(version, "In-Memory", Collections.emptyMap());
NessieServer nessieServer = nessieServer(classContext(context), serverKey, initializeRepository);
Function<Field, Object> fieldValue = field -> apiInstanceForField(classContext(context), field, Version.CURRENT, ctx -> nessieServer);
populateNessieAnnotatedFields(context, instance, fieldValue);
}
use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.
the class NessieUpgradesExtension method buildServerKey.
private ServerKey buildServerKey(Version version, ExtensionContext context) {
Path tempDir = globalForClass(context).getOrCompute("temporary-directory", x -> new TemporaryDirectory(), TemporaryDirectory.class).getPath();
// Eagerly create the Nessie server instance
String databaseAdapterName = "RocksDB";
Map<String, String> configuration = Collections.singletonMap("nessie.store.db.path", tempDir.resolve("persist").toString());
return new ServerKey(version, databaseAdapterName, configuration);
}
use of org.projectnessie.tools.compatibility.api.Version in project nessie by projectnessie.
the class AbstractMultiVersionExtension method populateNessieVersionAnnotatedFields.
Version populateNessieVersionAnnotatedFields(ExtensionContext context, Object instance) {
Optional<Version> nessieVersion = nessieVersionFromContext(context);
if (!nessieVersion.isPresent()) {
return null;
}
Version version = nessieVersion.get();
populateAnnotatedFields(context, instance, NessieVersion.class, f -> version);
return version;
}
use of org.projectnessie.tools.compatibility.api.Version 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);
}
}
Aggregations