Search in sources :

Example 6 with TransferPlugin

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

the class AbstractTransferManagerTest method loadPluginAndCreateTransferManager.

private TransferManager loadPluginAndCreateTransferManager() throws StorageException {
    TransferPlugin pluginInfo = Plugins.get(getPluginId(), TransferPlugin.class);
    TransferSettings connection = pluginInfo.createEmptySettings();
    for (Map.Entry<String, String> pair : createPluginSettings().entrySet()) {
        connection.setField(pair.getKey(), pair.getValue());
    }
    TransferManager originalTransferManager = pluginInfo.createTransferManager(connection, null);
    return new TransactionAwareFeatureTransferManager(originalTransferManager, originalTransferManager, null, null);
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferManager(org.syncany.plugins.transfer.TransferManager) TransactionAwareFeatureTransferManager(org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager) TransactionAwareFeatureTransferManager(org.syncany.plugins.transfer.features.TransactionAwareFeatureTransferManager) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Map(java.util.Map)

Example 7 with TransferPlugin

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

the class ApplicationLink method createTransferSettings.

private TransferSettings createTransferSettings(byte[] plaintextPluginSettingsBytes) throws StorageException, IOException {
    // Find plugin ID and settings XML
    int pluginIdentifierLength = Ints.fromByteArray(Arrays.copyOfRange(plaintextPluginSettingsBytes, 0, INTEGER_BYTES));
    String pluginId = new String(Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES, INTEGER_BYTES + pluginIdentifierLength));
    byte[] gzippedPluginSettingsByteArray = Arrays.copyOfRange(plaintextPluginSettingsBytes, INTEGER_BYTES + pluginIdentifierLength, plaintextPluginSettingsBytes.length);
    String pluginSettings = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(gzippedPluginSettingsByteArray)));
    // Create transfer settings object
    try {
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            throw new StorageException("Link contains unknown connection type '" + pluginId + "'. Corresponding plugin not found.");
        }
        Class<? extends TransferSettings> pluginTransferSettingsClass = TransferPluginUtil.getTransferSettingsClass(plugin.getClass());
        TransferSettings transferSettings = new Persister().read(pluginTransferSettingsClass, pluginSettings);
        logger.log(Level.INFO, "(Decrypted) link contains: " + pluginId + " -- " + pluginSettings);
        return transferSettings;
    } catch (Exception e) {
        throw new StorageException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ByteArrayInputStream(java.io.ByteArrayInputStream) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Example 8 with TransferPlugin

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

the class ConfigHelper method loadConfig.

/**
	 * Loads a {@link Config} object from the given local directory.
	 *
	 * <p>If the config file (.syncany/config.xml) does not exist, <tt>null</tt>
	 * is returned. If it does, the method tries to do the following:
	 * <ul>
	 *  <li>Load the .syncany/config.xml file and load the plugin given by the config file</li>
	 *  <li>Read .syncany/repo, decrypt it using the master key (if necessary) and load it</li>
	 *  <li>Instantiate a {@link Config} object with the transfer objects</li>
	 * </ul>
	 *
	 * @return Returns an instantiated {@link Config} object, or <tt>null</tt> if
	 *         the config file does not exist
	 * @throws Throws an exception if the config is invalid
	 */
public static Config loadConfig(File localDir) throws ConfigException {
    if (localDir == null) {
        throw new ConfigException("Argument localDir cannot be null.");
    }
    File appDir = new File(localDir, Config.DIR_APPLICATION);
    if (appDir.exists()) {
        logger.log(Level.INFO, "Loading config from {0} ...", localDir);
        ConfigTO configTO = ConfigHelper.loadConfigTO(localDir);
        RepoTO repoTO = ConfigHelper.loadRepoTO(localDir, configTO);
        String pluginId = (configTO.getTransferSettings() != null) ? configTO.getTransferSettings().getType() : null;
        TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
        if (plugin == null) {
            logger.log(Level.WARNING, "Not loading config! Plugin with id '{0}' does not exist.", pluginId);
            throw new ConfigException("Plugin with id '" + pluginId + "' does not exist. Try 'sy plugin install " + pluginId + "'.");
        }
        logger.log(Level.INFO, "Initializing Config instance ...");
        return new Config(localDir, configTO, repoTO);
    } else {
        logger.log(Level.INFO, "Not loading config, app dir does not exist: {0}", appDir);
        return null;
    }
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 9 with TransferPlugin

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

the class AbstractInitCommand method createTransferSettingsFromOptions.

protected TransferSettings createTransferSettingsFromOptions(OptionSet options, OptionSpec<String> optionPlugin, OptionSpec<String> optionPluginOpts) throws Exception {
    TransferPlugin plugin;
    TransferSettings transferSettings;
    // Parse --plugin and --plugin-option values
    List<String> pluginOptionStrings = options.valuesOf(optionPluginOpts);
    Map<String, String> knownPluginSettings = parsePluginSettingsFromOptions(pluginOptionStrings);
    // Validation of some constraints
    if (!options.has(optionPlugin) && knownPluginSettings.size() > 0) {
        throw new IllegalArgumentException("Provided plugin settings without a plugin name.");
    }
    plugin = options.has(optionPlugin) ? initPlugin(options.valueOf(optionPlugin)) : askPlugin();
    transferSettings = askPluginSettings(plugin.createEmptySettings(), knownPluginSettings);
    return transferSettings;
}
Also used : TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) TransferSettings(org.syncany.plugins.transfer.TransferSettings)

Example 10 with TransferPlugin

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

the class TransferSettingsTest method testRestore.

@Test
public void testRestore() throws Exception {
    final String fooTest = "foo-test";
    final String bazTest = "baz";
    final int numberTest = 1234;
    final DummyTransferSettings ts = new DummyTransferSettings();
    final LocalTransferSettings lts = new LocalTransferSettings();
    final InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
    final ConfigTO conf = initOperationOptions.getConfigTO();
    File repoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = initOperationOptions.getLocalDir();
    conf.setTransferSettings(ts);
    ts.foo = fooTest;
    ts.baz = bazTest;
    ts.number = numberTest;
    lts.setPath(File.createTempFile("aaa", "bbb"));
    ts.subsettings = lts;
    assertTrue(ts.isValid());
    Serializer serializer = new Persister();
    serializer.write(conf, tmpFile);
    System.out.println(new String(Files.readAllBytes(Paths.get(tmpFile.toURI()))));
    ConfigTO confRestored = ConfigTO.load(tmpFile);
    TransferPlugin plugin = Plugins.get(confRestored.getTransferSettings().getType(), TransferPlugin.class);
    assertNotNull(plugin);
    TransferSettings tsRestored = confRestored.getTransferSettings();
    assertNotNull(tsRestored);
    DummyTransferManager transferManager = plugin.createTransferManager(tsRestored, config);
    assertNotNull(transferManager);
    // Tear down
    FileUtils.deleteDirectory(localDir);
    FileUtils.deleteDirectory(repoDir);
}
Also used : DummyTransferPlugin(org.syncany.plugins.dummy.DummyTransferPlugin) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) DummyTransferSettings(org.syncany.plugins.dummy.DummyTransferSettings) DummyTransferManager(org.syncany.plugins.dummy.DummyTransferManager) ConfigTO(org.syncany.config.to.ConfigTO) Persister(org.simpleframework.xml.core.Persister) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) DummyTransferSettings(org.syncany.plugins.dummy.DummyTransferSettings) File(java.io.File) Serializer(org.simpleframework.xml.Serializer) 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