use of org.syncany.config.to.ConfigTO in project syncany by syncany.
the class ConnectCommand method parseOptions.
@Override
public ConnectOperationOptions parseOptions(String[] operationArgs) throws Exception {
ConnectOperationOptions operationOptions = new ConnectOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<String> optionPlugin = parser.acceptsAll(asList("P", "plugin")).withRequiredArg();
OptionSpec<String> optionPluginOpts = parser.acceptsAll(asList("o", "plugin-option")).withRequiredArg();
OptionSpec<Void> optionAddDaemon = parser.acceptsAll(asList("n", "add-daemon"));
OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
OptionSet options = parser.parse(operationArgs);
List<?> nonOptionArgs = options.nonOptionArguments();
// Set interactivity mode
isInteractive = !options.has(optionPlugin) && !options.has(optionPassword);
// Plugin
TransferSettings transferSettings = null;
if (nonOptionArgs.size() == 1) {
String connectLink = (String) nonOptionArgs.get(0);
operationOptions.setStrategy(ConnectOptionsStrategy.CONNECTION_LINK);
operationOptions.setConnectLink(connectLink);
transferSettings = null;
} else if (nonOptionArgs.size() == 0) {
operationOptions.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
operationOptions.setConnectLink(null);
transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
} else {
throw new Exception("Invalid syntax.");
}
ConfigTO configTO = createConfigTO(transferSettings);
operationOptions.setLocalDir(localDir);
operationOptions.setConfigTO(configTO);
operationOptions.setDaemon(options.has(optionAddDaemon));
operationOptions.setPassword(validateAndGetPassword(options, optionPassword));
return operationOptions;
}
use of org.syncany.config.to.ConfigTO in project syncany by syncany.
the class TransferSettingsTest method testDeserializeCorrectClass.
@Test
public void testDeserializeCorrectClass() throws Exception {
Serializer serializer = new Persister();
InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
// Always LocalTransferSettings
serializer.write(initOperationOptions.getConfigTO(), tmpFile);
ConfigTO confRestored = ConfigTO.load(tmpFile);
assertEquals(LocalTransferSettings.class, confRestored.getTransferSettings().getClass());
// Tear down
FileUtils.deleteDirectory(initOperationOptions.getLocalDir());
FileUtils.deleteDirectory(((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath());
}
use of org.syncany.config.to.ConfigTO in project syncany by syncany.
the class ConnectOperationTest method testConnectOperationFailureNoConnection.
@Test
public void testConnectOperationFailureNoConnection() throws Exception {
// A.init()
InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
InitOperationResult initOperationResultA = initOperationA.execute();
String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
assertNotNull(connectLinkA);
// B.connect()
File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("client-B", initOperationOptionsA));
File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
// <<< Point to non-existing repo
((LocalTransferSettings) connectionConfigToB.getTransferSettings()).setPath(new File("/does/not/exist"));
connectionConfigToB.setMachineName("client-B" + Math.abs(new Random().nextInt()));
connectionConfigToB.setMasterKey(null);
ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
connectOperationOptionsB.setConfigTO(connectionConfigToB);
connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
connectOperationOptionsB.setLocalDir(localDirB);
ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
ConnectOperationResult connectOperationResultB = connectOperationB.execute();
assertEquals(ConnectResultCode.NOK_TEST_FAILED, connectOperationResultB.getResultCode());
assertFalse(new File(localConnectDirB, Config.DIR_DATABASE).exists());
assertFalse(new File(localConnectDirB, Config.DIR_CACHE).exists());
assertFalse(new File(localConnectDirB, Config.FILE_CONFIG).exists());
assertFalse(new File(localConnectDirB, Config.DIR_LOG).exists());
assertFalse(new File(localConnectDirB, Config.FILE_REPO).exists());
// Tear down
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(localConnectDirB);
TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
use of org.syncany.config.to.ConfigTO 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.config.to.ConfigTO in project syncany by syncany.
the class TestCliUtil method fixMachineName.
private static void fixMachineName(Map<String, String> client) throws Exception {
File configFile = new File(client.get("localdir") + "/" + Config.DIR_APPLICATION + "/" + Config.FILE_CONFIG);
Serializer serializer = new Persister();
ConfigTO configTO = serializer.read(ConfigTO.class, configFile);
configTO.setMachineName(client.get("machinename"));
serializer.write(configTO, configFile);
}
Aggregations