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