use of org.syncany.plugins.transfer.TransferSettings 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.TransferSettings in project syncany by syncany.
the class AbstractInitCommand method askConreteChildPluginSettings.
/**
* Asks the user for all of the child plugin's settings.
*
* <p>This case is triggered by a field looking like this:
* <tt>private LocalTransferSettings localChildPluginSettings;</tt>
*/
private void askConreteChildPluginSettings(TransferSettings settings, NestedTransferPluginOption 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() + ":");
}
for (TransferPluginOption nestedPluginOption : option.getOptions()) {
Class<?> nestedTransferSettingsClass = ReflectionUtil.getClassFromType(option.getType());
if (nestedTransferSettingsClass == null) {
throw new RuntimeException("No class found for type: " + option.getType());
}
TransferSettings nestedSettings = (TransferSettings) nestedTransferSettingsClass.newInstance();
settings.setField(option.getField().getName(), nestedSettings);
nestPrefix = nestPrefix + option.getName() + NESTED_OPTIONS_SEPARATOR;
askPluginSettings(nestedSettings, nestedPluginOption, knownPluginSettings, nestPrefix);
}
if (isInteractive) {
callAndPrintPostQueryCallback(optionCallback, null);
}
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class AllFilePossibilitiesScenarioTest method testAllPossibilities.
@Test
public void testAllPossibilities() throws Exception {
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
ClientActions.run(clientA, new Executable() {
@Override
public void execute() throws Exception {
// Nothing.
}
}, new AbstractClientAction[] { new CreateFileTree(), new ChangeContentWithoutFileSize(), new ChangeFileSize(), new ChangeLastModifiedDate(), new ChangePermissionsOfFile(), new ChangePermissionsOfFolder(), new ChangeSymlinkTarget(), new ChangeTypeFileToFolder(), new ChangeTypeFileToSymlinkWithNonExistingTarget(), new ChangeTypeFileToSymlinkWithTargetFile(), new ChangeTypeFileToSymlinkWithTargetFolder(), new ChangeTypeSymlinkWithNonExistingTargetToFile(), new ChangeTypeSymlinkWithTargetFileToFile(), new ChangeTypeSymlinkWithTargetFolderToFile(), new ChangeTypeSymlinkWithNonExistingTargetToFolder(), new ChangeTypeSymlinkWithTargetFileToFolder(), new ChangeTypeSymlinkWithTargetFolderToFolder(), new ChangeTypeFolderToFile(), new ChangeTypeFolderToSymlinkWithNonExistingTarget(), new ChangeTypeFolderToSymlinkWithTargetFile(), new ChangeTypeFolderToSymlinkWithTargetFolder(), new CreateFile(), new CreateFolder(), new CreateSymlinkToFile(), new CreateSymlinkToFolder(), new CreateSymlinkToNonExisting(), new DeleteFile(), new DeleteFolder(), new MoveFileToOtherFolder(), new MoveFileWithinFolder(), new MoveFolderToOtherFolder(), new MoveFolderWithinFolder() // new LockFile() and new UnlockFile() are not compatible with these tests
}, new Executable() {
@Override
public void execute() throws Exception {
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
}
});
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class AllFilePossibilitiesScenarioTest method testChangeTypeSymlinkWithTargetFileToFolder.
@Test
public void testChangeTypeSymlinkWithTargetFileToFolder() throws Exception {
final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
final TestClient clientA = new TestClient("A", testConnection);
final TestClient clientB = new TestClient("B", testConnection);
ClientActions.run(clientA, null, new CreateFileTree(), null);
ClientActions.run(clientA, null, new ChangeTypeFileToSymlinkWithTargetFolder(), null);
clientA.upWithForceChecksum();
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class ChangedAttributesScenarioTest method testNewFileWithDifferingAttributes.
@Test
public void testNewFileWithDifferingAttributes() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Create new file with differing attributes
clientA.createNewFile("file1.jpg");
FileUtils.copyFile(clientA.getLocalFile("file1.jpg"), clientB.getLocalFile("file1.jpg"));
// Client B's attributes differ!
File aFile = clientA.getLocalFile("file1.jpg");
Path aFilePath = Paths.get(aFile.getAbsolutePath());
Object aReadOnlyAttribute = null;
Set<PosixFilePermission> aPosixFilePermissions = null;
// Client B's attributes differ!
File bFile = clientB.getLocalFile("file1.jpg");
Path bFilePath = Paths.get(bFile.getAbsolutePath());
if (EnvironmentUtil.isWindows()) {
aReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
Files.setAttribute(bFilePath, "dos:readonly", true);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
aPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
Files.setPosixFilePermissions(bFilePath, PosixFilePermissions.fromString("rwxrwxrwx"));
}
clientA.upWithForceChecksum();
// This is the key operation
DownOperationResult downResult = clientB.down();
// Test 1: Check result sets for inconsistencies
assertTrue("File should be downloaded.", downResult.getChangeSet().hasChanges());
// Test 2: file1.jpg permissions (again!
if (EnvironmentUtil.isWindows()) {
Object bReadOnlyAttribute = Files.getAttribute(aFilePath, "dos:readonly");
assertEquals("Read-only should be true.", aReadOnlyAttribute, bReadOnlyAttribute);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
Set<PosixFilePermission> bPosixFilePermissions = Files.getPosixFilePermissions(aFilePath);
assertEquals("Should be rwxrwxrwx.", PosixFilePermissions.toString(aPosixFilePermissions), PosixFilePermissions.toString(bPosixFilePermissions));
}
// Test 3: The rest
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
Aggregations