use of org.syncany.plugins.transfer.TransferPlugin in project syncany by syncany.
the class AbstractInitCommand method askGenericChildPluginSettings.
/**
* Queries the user for a plugin (which plugin to use?) and then
* asks for all of the plugin's settings.
*
* <p>This case is triggered by a field looking like this:
* <tt>private TransferSettings childPluginSettings;</tt>
*/
private void askGenericChildPluginSettings(TransferSettings settings, TransferPluginOption option, Map<String, String> knownPluginSettings, String nestPrefix) throws StorageException, IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
TransferPluginOptionCallback optionCallback = createOptionCallback(settings, option.getCallback());
if (isInteractive) {
callAndPrintPreQueryCallback(optionCallback);
out.println();
out.println(option.getDescription() + ":");
}
TransferPlugin childPlugin = null;
Class<? extends TransferPlugin> pluginClass = TransferPluginUtil.getTransferPluginClass(settings.getClass());
// Non-interactive: Plugin settings might be given via command line
try {
childPlugin = initPlugin(knownPluginSettings.get(nestPrefix + option.getName() + GENERIC_PLUGIN_TYPE_IDENTIFIER));
} catch (Exception e) {
if (!isInteractive) {
throw new IllegalArgumentException("Missing nested plugin type (" + nestPrefix + option.getName() + GENERIC_PLUGIN_TYPE_IDENTIFIER + ") in non-interactive mode.");
}
}
// Interactive mode: Ask for sub-plugin
while (childPlugin == null) {
childPlugin = askPlugin(pluginClass);
}
if (isInteractive) {
out.println();
}
// Create nested/child settings
TransferSettings childSettings = childPlugin.createEmptySettings();
settings.setField(option.getField().getName(), childSettings);
nestPrefix = nestPrefix + option.getName() + NESTED_OPTIONS_SEPARATOR;
for (TransferPluginOption nestedOption : TransferPluginOptions.getOrderedOptions(childSettings.getClass())) {
askPluginSettings(childSettings, nestedOption, knownPluginSettings, nestPrefix);
}
if (isInteractive) {
callAndPrintPostQueryCallback(optionCallback, null);
}
}
use of org.syncany.plugins.transfer.TransferPlugin in project syncany by syncany.
the class AbstractInitCommand method askPlugin.
protected TransferPlugin askPlugin(final Class<? extends TransferPlugin> ignoreTransferPluginClass) {
TransferPlugin plugin = null;
final List<TransferPlugin> plugins = Plugins.list(TransferPlugin.class);
Iterables.removeIf(plugins, new Predicate<TransferPlugin>() {
@Override
public boolean apply(TransferPlugin transferPlugin) {
return ignoreTransferPluginClass == transferPlugin.getClass();
}
});
String pluginsList = StringUtil.join(plugins, ", ", new StringJoinListener<TransferPlugin>() {
@Override
public String getString(TransferPlugin plugin) {
return plugin.getId();
}
});
while (plugin == null) {
out.println("Choose a storage plugin. Available plugins are: " + pluginsList);
out.print("Plugin: ");
String pluginStr = console.readLine();
plugin = Plugins.get(pluginStr, TransferPlugin.class);
if (plugin == null || ignoreTransferPluginClass == plugin.getClass()) {
out.println("ERROR: Plugin does not exist or cannot be used.");
out.println();
plugin = null;
}
}
return plugin;
}
use of org.syncany.plugins.transfer.TransferPlugin in project syncany by syncany.
the class AbstractInitOperation method createTransferManagerFromNullConfig.
protected TransferManager createTransferManagerFromNullConfig(ConfigTO configTo) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, StorageException {
// Init plugin and transfer manager
TransferPlugin plugin = Plugins.get(configTo.getTransferSettings().getType(), TransferPlugin.class);
TransferSettings transferSettings = configTo.getTransferSettings();
transferSettings.setUserInteractionListener(listener);
TransferManager transferManager = plugin.createTransferManager(transferSettings, config);
// constructor is not visible and config seems to be null at this point, hence we cannot use the build method here
Constructor<TransferManagerBuilder> tmbConstructor = TransferManagerBuilder.class.getDeclaredConstructor(Config.class, TransferManager.class);
tmbConstructor.setAccessible(true);
return tmbConstructor.newInstance(config, transferManager).withFeature(ReadAfterWriteConsistent.class).asDefault();
}
use of org.syncany.plugins.transfer.TransferPlugin in project syncany by syncany.
the class TransferSettingsTest method createNewInvalidConnectionTO.
@Test
public void createNewInvalidConnectionTO() throws Exception {
TransferPlugin p = Plugins.get("dummy", TransferPlugin.class);
DummyTransferSettings ts = p.createEmptySettings();
assertFalse(ts.isValid());
}
use of org.syncany.plugins.transfer.TransferPlugin in project syncany by syncany.
the class AbstractTransferManagerTest method testConnectWithInvalidSettings.
@Test(expected = StorageException.class)
public void testConnectWithInvalidSettings() throws StorageException {
TransferPlugin plugin = Plugins.get(getPluginId(), TransferPlugin.class);
TransferSettings connection = plugin.createEmptySettings();
// This should cause a Storage exception, because the path does not exist
TransferManager transferManager = plugin.createTransferManager(connection, null);
transferManager.connect();
}
Aggregations