Search in sources :

Example 6 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class WatchServer method startWatchOperations.

private void startWatchOperations(Map<File, FolderTO> newWatchedFolderTOs) throws ConfigException, ServiceAlreadyStartedException {
    for (Map.Entry<File, FolderTO> folderEntry : newWatchedFolderTOs.entrySet()) {
        File localDir = folderEntry.getKey();
        try {
            Config watchConfig = ConfigHelper.loadConfig(localDir);
            if (watchConfig != null) {
                logger.log(Level.INFO, "- Starting watch operation at " + localDir + " ...");
                WatchOperationOptions watchOptions = folderEntry.getValue().getWatchOptions();
                if (watchOptions == null) {
                    watchOptions = new WatchOperationOptions();
                }
                WatchRunner watchRunner = new WatchRunner(watchConfig, watchOptions, daemonConfig.getPortTO());
                watchRunner.start();
                watchOperations.put(localDir, watchRunner);
            } else {
                logger.log(Level.INFO, "- CANNOT start watch, because no config found at " + localDir + " ...");
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "  + Cannot start watch operation at " + localDir + ". IGNORING.", e);
        }
    }
}
Also used : WatchOperationOptions(org.syncany.operations.watch.WatchOperationOptions) Config(org.syncany.config.Config) FolderTO(org.syncany.config.to.FolderTO) Map(java.util.Map) TreeMap(java.util.TreeMap) File(java.io.File) ConfigException(org.syncany.config.ConfigException)

Example 7 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTO method load.

public static ConfigTO load(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter());
        return new Persister(strategy).read(ConfigTO.class, file);
    } catch (ClassNotFoundException ex) {
        // Ugly hack to catch common case of non-existing plugin
        String message = ex.getMessage();
        if (!message.startsWith("org.syncany.plugins.")) {
            // Apparently there are other ClassNotFoundExceptions possible.
            throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
        }
        message = message.replaceFirst("org.syncany.plugins.", "");
        message = message.replaceAll("\\..*", "");
        throw new ConfigException("Is the " + message + " plugin installed?");
    } catch (Exception ex) {
        throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Example 8 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTest method testConfigMultiChunkerNull.

@Test
public void testConfigMultiChunkerNull() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // <<< INVALID !!
    repoTO.setMultiChunker(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Config should not been have initialized.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("No multichunker", e);
    }
}
Also used : Config(org.syncany.config.Config) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 9 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTest method testConfigMachineNameInvalidChars.

@Test
public void testConfigMachineNameInvalidChars() throws Exception {
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    configTO.setMachineName("invalid machine name");
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Machine name should not have been accepted.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("Machine name", e);
    }
}
Also used : Config(org.syncany.config.Config) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 10 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTest method testConfigChunkerNull.

@Test
@Ignore
public // TODO [low] ChunkerTO is not used yet; so no test for it.
void testConfigChunkerNull() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // <<< INVALID !!
    repoTO.setChunkerTO(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Config should not been have initialized.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("No multichunker", e);
    }
}
Also used : Config(org.syncany.config.Config) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ConfigException (org.syncany.config.ConfigException)10 File (java.io.File)7 Config (org.syncany.config.Config)7 Test (org.junit.Test)6 ConfigTO (org.syncany.config.to.ConfigTO)6 RepoTO (org.syncany.config.to.RepoTO)6 Persister (org.simpleframework.xml.core.Persister)3 ArrayList (java.util.ArrayList)2 Registry (org.simpleframework.xml.convert.Registry)2 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)2 Strategy (org.simpleframework.xml.strategy.Strategy)2 TransformerTO (org.syncany.config.to.RepoTO.TransformerTO)2 SaltedSecretKeyConverter (org.syncany.crypto.SaltedSecretKeyConverter)2 EncryptedTransferSettingsConverter (org.syncany.plugins.transfer.EncryptedTransferSettingsConverter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Ignore (org.junit.Ignore)1