use of org.syncany.plugins.transfer.TransferPluginOption in project syncany by syncany.
the class AbstractInitCommand method askPluginSettings.
private TransferSettings askPluginSettings(TransferSettings settings, Map<String, String> knownPluginSettings) throws StorageException {
if (isInteractive) {
out.println();
out.println("Connection details for " + settings.getType() + " connection:");
} else {
logger.log(Level.INFO, "Non interactive mode");
}
try {
// Show OAuth output
printOAuthInformation(settings);
// Ask for plugin settings
List<TransferPluginOption> pluginOptions = TransferPluginOptions.getOrderedOptions(settings.getClass());
for (TransferPluginOption option : pluginOptions) {
askPluginSettings(settings, option, knownPluginSettings, "");
}
} catch (NoSuchFieldException e) {
logger.log(Level.SEVERE, "No token could be found, maybe user denied access", e);
throw new StorageException("No token found. Did you accept the authorization?", e);
} catch (TimeoutException e) {
logger.log(Level.SEVERE, "No token was received in the given time interval", e);
throw new StorageException("No token was received in the given time interval", e);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | IOException | InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, "Unable to execute option generator", e);
throw new RuntimeException("Unable to execute option generator: " + e.getMessage());
}
if (!settings.isValid()) {
if (askRetryInvalidSettings(settings.getReasonForLastValidationFail())) {
return askPluginSettings(settings, knownPluginSettings);
}
throw new StorageException("Validation failed: " + settings.getReasonForLastValidationFail());
}
logger.log(Level.INFO, "Settings are " + settings.toString());
return settings;
}
use of org.syncany.plugins.transfer.TransferPluginOption 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);
}
}
use of org.syncany.plugins.transfer.TransferPluginOption in project syncany by syncany.
the class PluginOptionsTest method nestedSettingsTest.
@Test
@Ignore
public // TODO rewrite to make this test work again with generic nested transfer settings
void nestedSettingsTest() throws Exception {
DummyTransferSettings dts = new DummyTransferSettings();
for (TransferPluginOption option : TransferPluginOptions.getOrderedOptions(DummyTransferSettings.class)) {
askNestedPluginSettings(dts, option, 0);
}
assertNotNull(dts.baz);
assertNotNull(dts.foo);
assertNotNull(dts.number);
assertNotNull(dts.subsettings);
}
use of org.syncany.plugins.transfer.TransferPluginOption in project syncany by syncany.
the class PluginOptionsTest method testOrderingOfOptions.
@Test
@Ignore
public void testOrderingOfOptions() throws Exception {
final String[] expectedOrder = new String[] { "foo", "number", "baz", "nest" };
List<TransferPluginOption> items = TransferPluginOptions.getOrderedOptions(DummyTransferSettings.class);
int i = 0;
for (TransferPluginOption item : items) {
assertEquals(expectedOrder[i++], item.getName());
}
}
use of org.syncany.plugins.transfer.TransferPluginOption 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);
}
}
Aggregations