Search in sources :

Example 1 with TransferPlugin

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);
    }
}
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 TransferPlugin

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

Example 3 with TransferPlugin

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();
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferManager(org.syncany.plugins.transfer.TransferManager) ReadAfterWriteConsistent(org.syncany.plugins.transfer.features.ReadAfterWriteConsistent) TransferSettings(org.syncany.plugins.transfer.TransferSettings) TransferManagerBuilder(org.syncany.plugins.transfer.TransferManagerFactory.TransferManagerBuilder)

Example 4 with TransferPlugin

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());
}
Also used : DummyTransferPlugin(org.syncany.plugins.dummy.DummyTransferPlugin) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) DummyTransferSettings(org.syncany.plugins.dummy.DummyTransferSettings) Test(org.junit.Test)

Example 5 with TransferPlugin

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();
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferManager(org.syncany.plugins.transfer.TransferManager) TransactionAwareFeatureTransferManager(org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Aggregations

TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)12 TransferSettings (org.syncany.plugins.transfer.TransferSettings)7 Test (org.junit.Test)4 File (java.io.File)3 DummyTransferPlugin (org.syncany.plugins.dummy.DummyTransferPlugin)3 DummyTransferSettings (org.syncany.plugins.dummy.DummyTransferSettings)3 TransferManager (org.syncany.plugins.transfer.TransferManager)3 IOException (java.io.IOException)2 Persister (org.simpleframework.xml.core.Persister)2 ConfigTO (org.syncany.config.to.ConfigTO)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 StorageException (org.syncany.plugins.transfer.StorageException)2 TransactionAwareFeatureTransferManager (org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1