Search in sources :

Example 1 with TransferPluginOptionCallback

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);
    }
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferPluginOptionCallback(org.syncany.plugins.transfer.TransferPluginOptionCallback) TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) TransferSettings(org.syncany.plugins.transfer.TransferSettings) TimeoutException(java.util.concurrent.TimeoutException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with TransferPluginOptionCallback

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);
    }
}
Also used : TransferPluginOptionCallback(org.syncany.plugins.transfer.TransferPluginOptionCallback) TransferPluginOptionConverter(org.syncany.plugins.transfer.TransferPluginOptionConverter)

Example 3 with TransferPluginOptionCallback

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;
}
Also used : TransferPluginOptionCallback(org.syncany.plugins.transfer.TransferPluginOptionCallback)

Example 4 with TransferPluginOptionCallback

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);
    }
}
Also used : TransferPluginOptionCallback(org.syncany.plugins.transfer.TransferPluginOptionCallback) TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) TransferSettings(org.syncany.plugins.transfer.TransferSettings)

Aggregations

TransferPluginOptionCallback (org.syncany.plugins.transfer.TransferPluginOptionCallback)4 NestedTransferPluginOption (org.syncany.plugins.transfer.NestedTransferPluginOption)2 TransferPluginOption (org.syncany.plugins.transfer.TransferPluginOption)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 StorageException (org.syncany.plugins.transfer.StorageException)1 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)1 TransferPluginOptionConverter (org.syncany.plugins.transfer.TransferPluginOptionConverter)1