use of org.syncany.plugins.transfer.TransferPluginOptionCallback 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.TransferPluginOptionCallback in project syncany by syncany.
the class AbstractInitCommand method askNormalPluginSettings.
private void askNormalPluginSettings(TransferSettings settings, TransferPluginOption option, Map<String, String> knownPluginSettings, String nestPrefix) throws StorageException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
TransferPluginOptionCallback optionCallback = createOptionCallback(settings, option.getCallback());
TransferPluginOptionConverter optionConverter = createOptionConverter(settings, option.getConverter());
if (!isInteractive && !knownPluginSettings.containsKey(nestPrefix + option.getName())) {
throw new IllegalArgumentException("Missing plugin option (" + nestPrefix + option.getName() + ") in non-interactive mode.");
} else if (knownPluginSettings.containsKey(nestPrefix + option.getName())) {
settings.setField(option.getField().getName(), knownPluginSettings.get(nestPrefix + option.getName()));
} else if (!option.isVisible()) {
// Do nothing. Invisible option!
} else {
callAndPrintPreQueryCallback(optionCallback);
String optionValue = askPluginOption(settings, option);
if (optionConverter != null) {
optionValue = optionConverter.convert(optionValue);
}
settings.setField(option.getField().getName(), optionValue);
callAndPrintPostQueryCallback(optionCallback, optionValue);
}
}
use of org.syncany.plugins.transfer.TransferPluginOptionCallback in project syncany by syncany.
the class AbstractInitCommand method createOptionCallback.
private TransferPluginOptionCallback createOptionCallback(TransferSettings settings, Class<? extends TransferPluginOptionCallback> optionCallbackClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
TransferPluginOptionCallback optionCallback = null;
if (optionCallbackClass != null) {
Constructor<? extends TransferPluginOptionCallback> optionCallbackClassConstructor = optionCallbackClass.getDeclaredConstructor(settings.getClass());
optionCallback = optionCallbackClassConstructor.newInstance(settings);
}
return optionCallback;
}
use of org.syncany.plugins.transfer.TransferPluginOptionCallback in project syncany by syncany.
the class AbstractInitCommand method askConreteChildPluginSettings.
/**
* Asks the user for all of the child plugin's settings.
*
* <p>This case is triggered by a field looking like this:
* <tt>private LocalTransferSettings localChildPluginSettings;</tt>
*/
private void askConreteChildPluginSettings(TransferSettings settings, NestedTransferPluginOption 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() + ":");
}
for (TransferPluginOption nestedPluginOption : option.getOptions()) {
Class<?> nestedTransferSettingsClass = ReflectionUtil.getClassFromType(option.getType());
if (nestedTransferSettingsClass == null) {
throw new RuntimeException("No class found for type: " + option.getType());
}
TransferSettings nestedSettings = (TransferSettings) nestedTransferSettingsClass.newInstance();
settings.setField(option.getField().getName(), nestedSettings);
nestPrefix = nestPrefix + option.getName() + NESTED_OPTIONS_SEPARATOR;
askPluginSettings(nestedSettings, nestedPluginOption, knownPluginSettings, nestPrefix);
}
if (isInteractive) {
callAndPrintPostQueryCallback(optionCallback, null);
}
}
Aggregations