Search in sources :

Example 1 with PluginOperationResult

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

the class PluginManagementRequestHandler method handleRequest.

@Override
public Response handleRequest(final ManagementRequest request) {
    final PluginManagementRequest concreteRequest = (PluginManagementRequest) request;
    logger.log(Level.SEVERE, "Executing PluginOperation for action " + concreteRequest.getOptions().getAction() + " ...");
    Thread pluginThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                PluginOperation pluginOperation = new PluginOperation(null, concreteRequest.getOptions());
                PluginOperationResult operationResult = pluginOperation.execute();
                switch(operationResult.getResultCode()) {
                    case OK:
                        eventBus.post(new PluginManagementResponse(PluginManagementResponse.OK, operationResult, request.getId()));
                        break;
                    case NOK:
                        eventBus.post(new PluginManagementResponse(PluginManagementResponse.NOK_FAILED_UNKNOWN, operationResult, request.getId()));
                        break;
                }
            } catch (Exception e) {
                logger.log(Level.WARNING, "Error executing plugin management request.", e);
                eventBus.post(new PluginManagementResponse(PluginManagementResponse.NOK_OPERATION_FAILED, new PluginOperationResult(), request.getId()));
            }
        }
    }, "PlugRq/" + concreteRequest.getOptions().getAction());
    pluginThread.start();
    return null;
}
Also used : PluginOperation(org.syncany.operations.plugin.PluginOperation) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult)

Example 2 with PluginOperationResult

use of org.syncany.operations.plugin.PluginOperationResult 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 3 with PluginOperationResult

use of org.syncany.operations.plugin.PluginOperationResult 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 4 with PluginOperationResult

use of org.syncany.operations.plugin.PluginOperationResult 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 5 with PluginOperationResult

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

the class PluginCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    PluginOperationOptions operationOptions = parseOptions(operationArgs);
    PluginOperationResult operationResult = new PluginOperation(config, operationOptions).execute();
    printResults(operationResult);
    return 0;
}
Also used : PluginOperation(org.syncany.operations.plugin.PluginOperation) PluginOperationResult(org.syncany.operations.plugin.PluginOperationResult) PluginOperationOptions(org.syncany.operations.plugin.PluginOperationOptions)

Aggregations

PluginOperationResult (org.syncany.operations.plugin.PluginOperationResult)7 PluginOperationOptions (org.syncany.operations.plugin.PluginOperationOptions)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 PluginOperation (org.syncany.operations.plugin.PluginOperation)2 Plugin (org.syncany.plugins.Plugin)1