use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.
the class SQLiteConfigDatabase method local.
Config local() {
if (local == null || !lastWorkingDir.equals(platform.pwd())) {
final Optional<URL> url = new ResolveGeogigDir(platform).call();
if (!url.isPresent()) {
throw new ConfigException(StatusCode.INVALID_LOCATION);
}
URL u = url.get();
File localFile;
try {
localFile = new File(new File(u.toURI()), "config.db");
} catch (URISyntaxException e) {
localFile = new File(u.getPath(), "config.db");
}
lastWorkingDir = platform.pwd();
local = new Config(localFile);
}
return local;
}
use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.
the class SQLiteConfigDatabase method global.
Config global() {
if (global == null || !lastUserDir.equals(platform.getUserHome())) {
File home = platform.getUserHome();
if (home == null) {
throw new ConfigException(StatusCode.USERHOME_NOT_SET);
}
File globalDir = new File(home.getPath(), ".geogig");
if (globalDir.exists() && !globalDir.isDirectory()) {
throw new IllegalStateException(globalDir.getAbsolutePath() + " exists but is not a directory");
}
if (!globalDir.exists() && !globalDir.mkdir()) {
throw new ConfigException(StatusCode.CANNOT_WRITE);
}
lastUserDir = home;
global = new Config(new File(globalDir, "config.db"));
}
return global;
}
use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.
the class IniFileConfigDatabase method get.
public Optional<String> get(String key) {
try {
String[] parsed = parse(key);
Optional<String> result = local.get(parsed[0], parsed[1]);
if (result.isPresent() && result.get().length() > 0) {
return result;
} else {
return Optional.absent();
}
} catch (StringIndexOutOfBoundsException e) {
throw new ConfigException(e, StatusCode.SECTION_OR_KEY_INVALID);
} catch (IllegalArgumentException e) {
throw new ConfigException(e, null);
} catch (IOException e) {
throw new ConfigException(e, null);
}
}
use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.
the class ConfigOpTest method testGetDefaultWithNoLocalRepository.
@Test
public void testGetDefaultWithNoLocalRepository() {
ConfigDatabase database = mock(ConfigDatabase.class);
when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
when(database.getGlobal(anyString())).thenReturn(Optional.of("value"));
ConfigOp config = new ConfigOp(database);
config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_GET).setName("section.key").setValue(null).call();
}
use of org.locationtech.geogig.api.porcelain.ConfigException in project GeoGig by boundlessgeo.
the class ConfigOpTest method testListDefaultWithNoLocalRepository.
@Test
public void testListDefaultWithNoLocalRepository() {
ConfigDatabase database = mock(ConfigDatabase.class);
when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
ConfigOp config = new ConfigOp(database);
config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_LIST).setName(null).setValue(null).call();
}
Aggregations