Search in sources :

Example 1 with TransferSettings

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

use of org.syncany.plugins.transfer.TransferSettings 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;
}
Also used : TransferSettings(org.syncany.plugins.transfer.TransferSettings) ConfigTO(org.syncany.config.to.ConfigTO) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) ConnectOperationOptions(org.syncany.operations.init.ConnectOperationOptions)

Example 3 with TransferSettings

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

the class MixedUpDownScenarioTest method testMixedScenario1.

@Test
@Ignore
public void testMixedScenario1() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    TestClient clientC = new TestClient("C", testConnection);
    // Run 
    clientC.createNewFile("C1");
    clientC.up();
    clientC.createNewFile("C2");
    clientC.up();
    clientC.createNewFile("C3");
    clientC.up();
    // NO CONFLICT
    clientB.down();
    assertFileListEquals("Client B and C should be on the same versions.", clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    // up without down! Evil!
    clientC.createNewFile("C4");
    clientC.up();
    // NO CONFLICT
    clientA.down();
    assertFileListEquals("Client A and C should be on the same versions.", clientA.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    assertEquals("Client A should have C4, client B should not", clientA.getLocalFilesExcludeLockedAndNoRead().size() - 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
    clientB.createNewFile("B1,C3");
    clientB.up();
    clientA.createNewFile("A1,C4");
    clientA.up();
    clientA.createNewFile("A2,C4");
    clientA.up();
    clientA.createNewFile("A3,C4");
    clientA.up();
    // CONFLICT 1
    clientB.down();
    fail("Add some asserts");
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    // CONFLICT 2
    clientA.down();
    // CONFLICT 3
    clientC.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    clientA.createNewFile("A4,C4");
    clientA.up();
    clientA.createNewFile("A5,C4");
    clientA.up();
    clientC.createNewFile("A3,C5");
    clientC.up();
    clientC.createNewFile("A3,C6");
    clientC.up();
    clientC.createNewFile("A3,C7");
    clientC.up();
    clientB.createNewFile("A3,B2,C4");
    clientB.up();
    clientB.createNewFile("A3,B3,C4");
    clientB.up();
    clientB.createNewFile("A3,B4,C4");
    clientB.up();
    clientA.createNewFile("A6,C4");
    clientA.up();
    clientB.createNewFile("A3,B5,C4");
    clientB.up();
    clientC.createNewFile("A3,C8");
    clientC.up();
    // CONFLICT 4
    clientB.down();
    // CONFLICT 5
    clientA.down();
    // CONFLICT 6
    clientC.down();
    clientA.up();
    clientA.down();
    clientB.up();
    clientB.down();
    clientC.up();
    clientC.down();
    clientC.up();
    clientB.up();
    // CONFLICT 7
    clientC.down();
    // CONFLICT 8
    clientB.down();
    // CONFLICT 9
    clientA.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertFileListEquals(clientB.getLocalFilesExcludeLockedAndNoRead(), clientC.getLocalFilesExcludeLockedAndNoRead());
    assertEquals("File list count does not match.", 19, clientA.getLocalFilesExcludeLockedAndNoRead().size());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
    clientC.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with TransferSettings

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

the class RenameDeleteScenarioTest method testDeleteFileThatHasAlreadyMoved.

@Test
public void testDeleteFileThatHasAlreadyMoved() throws Exception {
    // Scenario: A deletes a file that B has already moved
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // A new/up
    clientA.createNewFile("A-original");
    clientA.up();
    // B down/move/up
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // A moves, and up
    clientA.deleteFile("A-original");
    clientA.up();
    // B deletes, then down; this should not fail or throw exceptions
    clientB.moveFile("A-original", "B-moved");
    clientB.down();
    assertFalse("File A-orginal should not be recreated.", clientB.getLocalFile("A-original").exists());
    // Sync them
    clientB.sync();
    clientA.sync();
    assertFalse("File A-orginal should not be recreated.", clientA.getLocalFile("A-original").exists());
    assertFalse("File A-orginal should not be recreated.", clientB.getLocalFile("A-original").exists());
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 5 with TransferSettings

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

the class RenameFileWithDiffModifiedDateScenarioTest method testChangedModifiedDate.

@Test
public void testChangedModifiedDate() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run 
    // A, create two files with identical content and change mod. date of one of them
    clientA.createNewFile("A-file1.jpg", 50 * 1024);
    clientA.copyFile("A-file1.jpg", "A-file1-with-different-modified-date.jpg");
    clientA.getLocalFile("A-file1.jpg").setLastModified(0);
    clientA.up();
    // B, down, then move BOTH files
    clientB.down();
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    clientB.moveFile("A-file1.jpg", "A-file1-moved.jpg");
    clientB.moveFile("A-file1-with-different-modified-date.jpg", "A-file1-with-different-modified-date-moved.jpg");
    clientB.up();
    TestSqlDatabase clientDatabaseB = clientB.loadLocalDatabase();
    PartialFileHistory file1Orig = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-moved.jpg");
    PartialFileHistory file1WithDiffLastModDate = clientDatabaseB.getFileHistoryWithFileVersions("A-file1-with-different-modified-date-moved.jpg");
    assertNotNull(file1Orig);
    assertNotNull(file1WithDiffLastModDate);
    FileVersion fileVersion1OrigV1 = file1Orig.getFileVersion(1);
    FileVersion fileVersion1OrigV2 = file1Orig.getFileVersion(2);
    FileVersion fileVersion1WithDiffLastModDateV1 = file1WithDiffLastModDate.getFileVersion(1);
    FileVersion fileVersion1WithDiffLastModDateV2 = file1WithDiffLastModDate.getFileVersion(2);
    assertNotNull(fileVersion1OrigV1);
    assertNotNull(fileVersion1OrigV2);
    assertNotNull(fileVersion1WithDiffLastModDateV1);
    assertNotNull(fileVersion1WithDiffLastModDateV2);
    assertEquals("A-file1.jpg", fileVersion1OrigV1.getName());
    assertEquals("A-file1-moved.jpg", fileVersion1OrigV2.getName());
    assertEquals("A-file1-with-different-modified-date.jpg", fileVersion1WithDiffLastModDateV1.getName());
    assertEquals("A-file1-with-different-modified-date-moved.jpg", fileVersion1WithDiffLastModDateV2.getName());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) Test(org.junit.Test)

Aggregations

TransferSettings (org.syncany.plugins.transfer.TransferSettings)78 Test (org.junit.Test)67 TestClient (org.syncany.tests.util.TestClient)65 File (java.io.File)20 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)10 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)7 SqlDatabase (org.syncany.database.SqlDatabase)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 CreateFileTree (org.syncany.tests.integration.scenarios.framework.CreateFileTree)4 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 Path (java.nio.file.Path)3 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3