use of org.syncany.config.to.RepoTO in project syncany by syncany.
the class ConfigHelper method loadConfig.
/**
* Loads a {@link Config} object from the given local directory.
*
* <p>If the config file (.syncany/config.xml) does not exist, <tt>null</tt>
* is returned. If it does, the method tries to do the following:
* <ul>
* <li>Load the .syncany/config.xml file and load the plugin given by the config file</li>
* <li>Read .syncany/repo, decrypt it using the master key (if necessary) and load it</li>
* <li>Instantiate a {@link Config} object with the transfer objects</li>
* </ul>
*
* @return Returns an instantiated {@link Config} object, or <tt>null</tt> if
* the config file does not exist
* @throws Throws an exception if the config is invalid
*/
public static Config loadConfig(File localDir) throws ConfigException {
if (localDir == null) {
throw new ConfigException("Argument localDir cannot be null.");
}
File appDir = new File(localDir, Config.DIR_APPLICATION);
if (appDir.exists()) {
logger.log(Level.INFO, "Loading config from {0} ...", localDir);
ConfigTO configTO = ConfigHelper.loadConfigTO(localDir);
RepoTO repoTO = ConfigHelper.loadRepoTO(localDir, configTO);
String pluginId = (configTO.getTransferSettings() != null) ? configTO.getTransferSettings().getType() : null;
TransferPlugin plugin = Plugins.get(pluginId, TransferPlugin.class);
if (plugin == null) {
logger.log(Level.WARNING, "Not loading config! Plugin with id '{0}' does not exist.", pluginId);
throw new ConfigException("Plugin with id '" + pluginId + "' does not exist. Try 'sy plugin install " + pluginId + "'.");
}
logger.log(Level.INFO, "Initializing Config instance ...");
return new Config(localDir, configTO, repoTO);
} else {
logger.log(Level.INFO, "Not loading config, app dir does not exist: {0}", appDir);
return null;
}
}
use of org.syncany.config.to.RepoTO in project syncany by syncany.
the class ConfigHelperTest method testConfigHelperLoadRepoTO.
@Test
public void testConfigHelperLoadRepoTO() throws Exception {
// Setup
Config testConfig = TestConfigUtil.createTestLocalConfig();
// Run
ConfigTO loadedConfigTO = ConfigHelper.loadConfigTO(testConfig.getLocalDir());
RepoTO repoConfigTO = ConfigHelper.loadRepoTO(testConfig.getLocalDir(), loadedConfigTO);
// Test
assertNotNull(repoConfigTO);
assertNotNull(repoConfigTO.getChunkerTO());
assertNotNull(repoConfigTO.getMultiChunker());
assertNotNull(repoConfigTO.getRepoId());
if (TestConfigUtil.getCrypto()) {
assertNotNull(repoConfigTO.getTransformers());
assertEquals(2, repoConfigTO.getTransformers().size());
assertEquals("gzip", repoConfigTO.getTransformers().get(0).getType());
assertEquals("cipher", repoConfigTO.getTransformers().get(1).getType());
} else {
assertNull(repoConfigTO.getTransformers());
}
assertEquals("fixed", repoConfigTO.getChunkerTO().getType());
assertEquals(1, repoConfigTO.getChunkerTO().getSettings().size());
assertEquals("zip", repoConfigTO.getMultiChunker().getType());
assertEquals(1, repoConfigTO.getMultiChunker().getSettings().size());
assertEquals("010203", StringUtil.toHex(repoConfigTO.getRepoId()));
// Tear down
TestConfigUtil.deleteTestLocalConfigAndData(testConfig);
}
use of org.syncany.config.to.RepoTO in project syncany by syncany.
the class ConfigTest method testConfigInitConfigTONull.
@Test(expected = ConfigException.class)
public void testConfigInitConfigTONull() throws Exception {
File localDir = new File("/some/folder");
ConfigTO configTO = null;
RepoTO repoTO = new RepoTO();
new Config(localDir, configTO, repoTO);
}
use of org.syncany.config.to.RepoTO in project syncany by syncany.
the class ConfigTest method testConfigCipherTransformersInvalidType.
@Test
public void testConfigCipherTransformersInvalidType() 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.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
// <<< valid
repoTO.setRepoId(new byte[] { 0x01, 0x02 });
// Set invalid transformer
TransformerTO invalidTransformerTO = new TransformerTO();
invalidTransformerTO.setType("invalid-typeXXX");
invalidTransformerTO.setSettings(new HashMap<String, String>());
List<TransformerTO> transformers = new ArrayList<TransformerTO>();
transformers.add(invalidTransformerTO);
// <<< INVALID !
repoTO.setTransformers(transformers);
// Run!
try {
new Config(localDir, configTO, repoTO);
fail("Transformer should NOT have been found.");
} catch (ConfigException e) {
TestAssertUtil.assertErrorStackTraceContains("invalid-typeXXX", e);
}
}
use of org.syncany.config.to.RepoTO in project syncany by syncany.
the class ConfigTest method testConfigCipherTransformersCipherNotFound.
@Test
@SuppressWarnings("serial")
public void testConfigCipherTransformersCipherNotFound() 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.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
// <<< valid
repoTO.setRepoId(new byte[] { 0x01, 0x02 });
// <<< valid
configTO.setMasterKey(createDummyMasterKey());
// Set invalid transformer
TransformerTO invalidTransformerTO = new TransformerTO();
invalidTransformerTO.setType("cipher");
invalidTransformerTO.setSettings(new HashMap<String, String>() {
{
// <<<< INVALID !
put("cipherspecs", "1,INVALIDXXXX");
}
});
List<TransformerTO> transformers = new ArrayList<TransformerTO>();
transformers.add(invalidTransformerTO);
repoTO.setTransformers(transformers);
// Run!
try {
new Config(localDir, configTO, repoTO);
fail("Transformer should NOT have been able to initialize.");
} catch (ConfigException e) {
TestAssertUtil.assertErrorStackTraceContains("INVALIDXXXX", e);
}
}
Aggregations