Search in sources :

Example 1 with PluginOperationOptions

use of org.syncany.operations.plugin.PluginOperationOptions in project syncany by syncany.

the class PluginOperationTest method testPluginInstallUrl.

@Test
public void testPluginInstallUrl() throws Exception {
    if (EnvironmentUtil.isWindows()) {
        // Test is Unix-specific.
        return;
    }
    File configDir = setupCleanConfigDir();
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);
    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.LIST);
    pluginOptions.setListMode(PluginListMode.REMOTE);
    pluginOptions.setSnapshots(false);
    PluginOperationResult pluginResult = client.plugin(pluginOptions);
    String pluginDownloadUrl = null;
    for (ExtendedPluginInfo pluginInfo : pluginResult.getPluginList()) {
        if (pluginInfo.getRemotePluginInfo().getPluginId().equals("ftp")) {
            pluginDownloadUrl = pluginInfo.getRemotePluginInfo().getDownloadUrl();
        }
    }
    pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.INSTALL);
    pluginOptions.setPluginId(pluginDownloadUrl);
    pluginResult = client.plugin(pluginOptions);
    assertNotNull(pluginResult);
    assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
    // Only one file should be in here: the jar for ftp.
    assertEquals(1, (new File(configDir, "plugins/lib/")).list().length);
    // Tear down
    client.deleteTestData();
    TestFileUtil.deleteDirectory(configDir);
    System.setProperty("user.home", "/tmp");
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) ExtendedPluginInfo(org.syncany.operations.plugin.ExtendedPluginInfo) TestClient(org.syncany.tests.util.TestClient) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 2 with PluginOperationOptions

use of org.syncany.operations.plugin.PluginOperationOptions in project syncany by syncany.

the class PluginOperationTest method testPluginListRemoteOnlyIncludingSnapshots.

@Test
public void testPluginListRemoteOnlyIncludingSnapshots() throws Exception {
    // Tests which plugin snapshots are available. This is difficult because
    // that will change. So we can only test the bare minimum.
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);
    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.LIST);
    pluginOptions.setListMode(PluginListMode.REMOTE);
    pluginOptions.setSnapshots(true);
    PluginOperationResult pluginResult = client.plugin(pluginOptions);
    assertNotNull(pluginResult);
    assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
    // Tear down
    client.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) Test(org.junit.Test)

Example 3 with PluginOperationOptions

use of org.syncany.operations.plugin.PluginOperationOptions in project syncany by syncany.

the class PluginOperationTest method testPluginInstall.

@Test
public void testPluginInstall() throws Exception {
    if (EnvironmentUtil.isWindows()) {
        // Test is Unix-specific.
        return;
    }
    File configDir = setupCleanConfigDir();
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);
    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.INSTALL);
    pluginOptions.setPluginId("ftp");
    PluginOperationResult pluginResult = client.plugin(pluginOptions);
    assertNotNull(pluginResult);
    assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
    // Only one file should be in here: the jar for ftp.
    assertEquals(1, (new File(configDir, "plugins/lib/")).list().length);
    // Tear down
    client.deleteTestData();
    TestFileUtil.deleteDirectory(configDir);
    System.setProperty("user.home", "/tmp");
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) File(java.io.File) Test(org.junit.Test)

Example 4 with PluginOperationOptions

use of org.syncany.operations.plugin.PluginOperationOptions in project syncany by syncany.

the class PluginCommand method parseOptions.

@Override
public PluginOperationOptions parseOptions(String[] operationArgs) throws Exception {
    PluginOperationOptions operationOptions = new PluginOperationOptions();
    OptionParser parser = new OptionParser();
    OptionSpec<Void> optionLocal = parser.acceptsAll(asList("L", "local-only"));
    OptionSpec<Void> optionRemote = parser.acceptsAll(asList("R", "remote-only"));
    OptionSpec<Void> optionSnapshots = parser.acceptsAll(asList("s", "snapshot", "snapshots"));
    OptionSpec<Void> optionMinimalOutput = parser.acceptsAll(asList("m", "minimal-output"));
    OptionSpec<String> optionApiEndpoint = parser.acceptsAll(asList("a", "api-endpoint")).withRequiredArg();
    OptionSet options = parser.parse(operationArgs);
    // Files
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() == 0) {
        throw new Exception("Invalid syntax, please specify an action (list, install, remove, update).");
    }
    // <action>
    String actionStr = nonOptionArgs.get(0).toString();
    PluginOperationAction action = parsePluginAction(actionStr);
    operationOptions.setAction(action);
    // --minimal-output
    minimalOutput = options.has(optionMinimalOutput);
    // --snapshots
    operationOptions.setSnapshots(options.has(optionSnapshots));
    // --api-endpoint
    if (options.has(optionApiEndpoint)) {
        operationOptions.setApiEndpoint(options.valueOf(optionApiEndpoint));
    }
    // install|remove <plugin-id>
    if (action == PluginOperationAction.INSTALL || action == PluginOperationAction.REMOVE) {
        if (nonOptionArgs.size() != 2) {
            throw new Exception("Invalid syntax, please specify a plugin ID.");
        }
        // <plugin-id>
        String pluginId = nonOptionArgs.get(1).toString();
        operationOptions.setPluginId(pluginId);
    } else // --local-only, --remote-only
    if (action == PluginOperationAction.LIST) {
        if (options.has(optionLocal)) {
            operationOptions.setListMode(PluginListMode.LOCAL);
        } else if (options.has(optionRemote)) {
            operationOptions.setListMode(PluginListMode.REMOTE);
        } else {
            operationOptions.setListMode(PluginListMode.ALL);
        }
        // <plugin-id> (optional in 'list' or 'update')
        if (nonOptionArgs.size() == 2) {
            String pluginId = nonOptionArgs.get(1).toString();
            operationOptions.setPluginId(pluginId);
        }
    } else if (action == PluginOperationAction.UPDATE && nonOptionArgs.size() == 2) {
        String pluginId = nonOptionArgs.get(1).toString();
        operationOptions.setPluginId(pluginId);
    }
    return operationOptions;
}
Also used : PluginOperationAction(org.syncany.operations.plugin.PluginOperationAction) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 5 with PluginOperationOptions

use of org.syncany.operations.plugin.PluginOperationOptions in project syncany by syncany.

the class PluginOperationTest method testPluginListRemoteOnlyReleasesOnly.

@Test
public void testPluginListRemoteOnlyReleasesOnly() throws Exception {
    // Tests which plugin releases are available. This is difficult because
    // that will change. So we can only test the bare minimum.
    // Setup
    LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
    TestClient client = new TestClient("A", testConnection);
    PluginOperationOptions pluginOptions = new PluginOperationOptions();
    pluginOptions.setAction(PluginOperationAction.LIST);
    pluginOptions.setListMode(PluginListMode.REMOTE);
    pluginOptions.setSnapshots(false);
    PluginOperationResult pluginResult = client.plugin(pluginOptions);
    assertNotNull(pluginResult);
    assertEquals(PluginResultCode.OK, pluginResult.getResultCode());
    // Tear down
    client.deleteTestData();
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions) Test(org.junit.Test)

Aggregations

PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)7 PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)6 Test (org.junit.Test)5 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)5 TestClient (org.syncany.tests.util.TestClient)5 File (java.io.File)2 ExtendedPluginInfo (org.syncany.operations.plugin.ExtendedPluginInfo)2 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 PluginOperation (org.syncany.operations.plugin.PluginOperation)1 PluginOperationAction (org.syncany.operations.plugin.PluginOperationAction)1 Plugin (org.syncany.plugins.Plugin)1