Search in sources :

Example 1 with ConfigException

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;
}
Also used : ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) URISyntaxException(java.net.URISyntaxException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Example 2 with ConfigException

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;
}
Also used : ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) File(java.io.File)

Example 3 with ConfigException

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);
    }
}
Also used : ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) IOException(java.io.IOException)

Example 4 with ConfigException

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();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 5 with ConfigException

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();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Aggregations

ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)14 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)6 ConfigOp (org.locationtech.geogig.api.porcelain.ConfigOp)5 Test (org.junit.Test)4 File (java.io.File)2 IOException (java.io.IOException)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 MemoryUsage (java.lang.management.MemoryUsage)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Platform (org.locationtech.geogig.api.Platform)1 Remote (org.locationtech.geogig.api.Remote)1 ResolveGeogigDir (org.locationtech.geogig.api.plumbing.ResolveGeogigDir)1 ConfigGet (org.locationtech.geogig.api.porcelain.ConfigGet)1 ConfigAction (org.locationtech.geogig.api.porcelain.ConfigOp.ConfigAction)1 ConfigScope (org.locationtech.geogig.api.porcelain.ConfigOp.ConfigScope)1 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)1