Search in sources :

Example 1 with TransferPluginOption

use of org.syncany.plugins.transfer.TransferPluginOption in project syncany by syncany.

the class AbstractInitCommand method askPluginSettings.

private TransferSettings askPluginSettings(TransferSettings settings, Map<String, String> knownPluginSettings) throws StorageException {
    if (isInteractive) {
        out.println();
        out.println("Connection details for " + settings.getType() + " connection:");
    } else {
        logger.log(Level.INFO, "Non interactive mode");
    }
    try {
        // Show OAuth output
        printOAuthInformation(settings);
        // Ask for plugin settings
        List<TransferPluginOption> pluginOptions = TransferPluginOptions.getOrderedOptions(settings.getClass());
        for (TransferPluginOption option : pluginOptions) {
            askPluginSettings(settings, option, knownPluginSettings, "");
        }
    } catch (NoSuchFieldException e) {
        logger.log(Level.SEVERE, "No token could be found, maybe user denied access", e);
        throw new StorageException("No token found. Did you accept the authorization?", e);
    } catch (TimeoutException e) {
        logger.log(Level.SEVERE, "No token was received in the given time interval", e);
        throw new StorageException("No token was received in the given time interval", e);
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | IOException | InterruptedException | ExecutionException e) {
        logger.log(Level.SEVERE, "Unable to execute option generator", e);
        throw new RuntimeException("Unable to execute option generator: " + e.getMessage());
    }
    if (!settings.isValid()) {
        if (askRetryInvalidSettings(settings.getReasonForLastValidationFail())) {
            return askPluginSettings(settings, knownPluginSettings);
        }
        throw new StorageException("Validation failed: " + settings.getReasonForLastValidationFail());
    }
    logger.log(Level.INFO, "Settings are " + settings.toString());
    return settings;
}
Also used : TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) StorageException(org.syncany.plugins.transfer.StorageException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with TransferPluginOption

use of org.syncany.plugins.transfer.TransferPluginOption 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 3 with TransferPluginOption

use of org.syncany.plugins.transfer.TransferPluginOption in project syncany by syncany.

the class PluginOptionsTest method nestedSettingsTest.

@Test
@Ignore
public // TODO rewrite to make this test work again with generic nested transfer settings
void nestedSettingsTest() throws Exception {
    DummyTransferSettings dts = new DummyTransferSettings();
    for (TransferPluginOption option : TransferPluginOptions.getOrderedOptions(DummyTransferSettings.class)) {
        askNestedPluginSettings(dts, option, 0);
    }
    assertNotNull(dts.baz);
    assertNotNull(dts.foo);
    assertNotNull(dts.number);
    assertNotNull(dts.subsettings);
}
Also used : DummyTransferSettings(org.syncany.plugins.dummy.DummyTransferSettings) NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with TransferPluginOption

use of org.syncany.plugins.transfer.TransferPluginOption in project syncany by syncany.

the class PluginOptionsTest method testOrderingOfOptions.

@Test
@Ignore
public void testOrderingOfOptions() throws Exception {
    final String[] expectedOrder = new String[] { "foo", "number", "baz", "nest" };
    List<TransferPluginOption> items = TransferPluginOptions.getOrderedOptions(DummyTransferSettings.class);
    int i = 0;
    for (TransferPluginOption item : items) {
        assertEquals(expectedOrder[i++], item.getName());
    }
}
Also used : NestedTransferPluginOption(org.syncany.plugins.transfer.NestedTransferPluginOption) TransferPluginOption(org.syncany.plugins.transfer.TransferPluginOption) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with TransferPluginOption

use of org.syncany.plugins.transfer.TransferPluginOption 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

NestedTransferPluginOption (org.syncany.plugins.transfer.NestedTransferPluginOption)6 TransferPluginOption (org.syncany.plugins.transfer.TransferPluginOption)6 TransferSettings (org.syncany.plugins.transfer.TransferSettings)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 DummyTransferSettings (org.syncany.plugins.dummy.DummyTransferSettings)2 StorageException (org.syncany.plugins.transfer.StorageException)2 TransferPluginOptionCallback (org.syncany.plugins.transfer.TransferPluginOptionCallback)2 UnknownHostException (java.net.UnknownHostException)1 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)1