Search in sources :

Example 1 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class HeapGraphDatabase method close.

@Override
public void close() {
    if (!isOpen()) {
        return;
    }
    graph = null;
    Optional<URL> url = new ResolveGeogigDir(platform).call();
    if (url.isPresent()) {
        synchronized (graphs) {
            URL key = url.get();
            Ref ref = graphs.get(key);
            if (ref != null && ref.release() <= -1) {
                ref.destroy();
                graphs.remove(key);
            }
        }
    }
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) URL(java.net.URL)

Example 2 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class FileRefDatabase method toFile.

/**
     * @param refPath
     * @return
     */
private File toFile(String refPath) {
    Optional<URL> envHome = new ResolveGeogigDir(platform).call();
    String[] path = refPath.split("/");
    try {
        File file = new File(envHome.get().toURI());
        for (String subpath : path) {
            file = new File(file, subpath);
        }
        return file;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RepositoryConnectionException(org.locationtech.geogig.repository.RepositoryConnectionException)

Example 3 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir 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 4 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class InitOp method callInternal.

private Repository callInternal() {
    final Platform platform = platform();
    final File workingDirectory = platform.pwd();
    final Optional<URL> repoUrl = new ResolveGeogigDir(platform).call();
    final boolean repoExisted = repoUrl.isPresent();
    final File envHome;
    if (repoExisted) {
        // we're at either the repo working dir or a subdirectory of it
        try {
            envHome = new File(repoUrl.get().toURI());
        } catch (URISyntaxException e) {
            throw Throwables.propagate(e);
        }
    } else {
        envHome = new File(workingDirectory, ".geogig");
        if (!envHome.mkdirs()) {
            throw new RuntimeException("Unable to create geogig environment at '" + envHome.getAbsolutePath() + "'");
        }
    }
    Map<String, String> effectiveConfigBuilder = Maps.newTreeMap();
    addDefaults(defaults, effectiveConfigBuilder);
    if (config != null) {
        effectiveConfigBuilder.putAll(config);
    }
    if (filterFile != null) {
        try {
            final String FILTER_FILE = "filter.ini";
            File oldFilterFile = new File(filterFile);
            if (!oldFilterFile.exists()) {
                throw new FileNotFoundException("No filter file found at " + filterFile + ".");
            }
            Optional<URL> envHomeURL = new ResolveGeogigDir(platform).call();
            Preconditions.checkState(envHomeURL.isPresent(), "Not inside a geogig directory");
            final URL url = envHomeURL.get();
            if (!"file".equals(url.getProtocol())) {
                throw new UnsupportedOperationException("Sparse clone works only against file system repositories. " + "Repository location: " + url.toExternalForm());
            }
            File repoDir;
            try {
                repoDir = new File(url.toURI());
            } catch (URISyntaxException e) {
                throw new IllegalStateException("Unable to access directory " + url.toExternalForm(), e);
            }
            File newFilterFile = new File(repoDir, FILTER_FILE);
            Files.copy(oldFilterFile, newFilterFile);
            effectiveConfigBuilder.put("sparse.filter", FILTER_FILE);
        } catch (Exception e) {
            throw new IllegalStateException("Unable to copy filter file at path " + filterFile + " to the new repository.", e);
        }
    }
    try {
        Preconditions.checkState(envHome.toURI().toURL().equals(new ResolveGeogigDir(platform).call().get()));
    } catch (MalformedURLException e) {
        Throwables.propagate(e);
    }
    Repository repository;
    try {
        if (!repoExisted) {
            ConfigDatabase configDB = context.configDatabase();
            try {
                for (Entry<String, String> pair : effectiveConfigBuilder.entrySet()) {
                    String key = pair.getKey();
                    String value = pair.getValue();
                    configDB.put(key, value);
                }
                repository = repository();
                repository.configure();
            } catch (RepositoryConnectionException e) {
                throw new IllegalStateException("Unable to initialize repository for the first time: " + e.getMessage(), e);
            }
        } else {
            repository = repository();
        }
        try {
            repository.open();
            // make sure the repo has the empty tree
            ObjectDatabase objectDatabase = repository.objectDatabase();
            objectDatabase.put(RevTree.EMPTY);
        } catch (RepositoryConnectionException e) {
            throw new IllegalStateException("Error opening repository databases: " + e.getMessage(), e);
        }
        createSampleHooks(envHome);
    } catch (ConfigException e) {
        throw e;
    } catch (RuntimeException e) {
        Throwables.propagateIfInstanceOf(e, IllegalStateException.class);
        throw new IllegalStateException("Can't access repository at '" + envHome.getAbsolutePath() + "'", e);
    }
    if (!repoExisted) {
        try {
            createDefaultRefs();
        } catch (IllegalStateException e) {
            Throwables.propagate(e);
        }
    }
    return repository;
}
Also used : MalformedURLException(java.net.MalformedURLException) Platform(org.locationtech.geogig.api.Platform) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RepositoryConnectionException(org.locationtech.geogig.repository.RepositoryConnectionException) RepositoryConnectionException(org.locationtech.geogig.repository.RepositoryConnectionException) Repository(org.locationtech.geogig.repository.Repository) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File)

Example 5 with ResolveGeogigDir

use of org.locationtech.geogig.api.plumbing.ResolveGeogigDir in project GeoGig by boundlessgeo.

the class ReadMergeCommitMessageOp method _call.

@Override
protected String _call() {
    URL envHome = new ResolveGeogigDir(platform()).call().get();
    try {
        File file = new File(envHome.toURI());
        file = new File(file, "MERGE_MSG");
        if (!file.exists()) {
            return "";
        }
        List<String> lines = Files.readLines(file, Charsets.UTF_8);
        return Joiner.on("\n").join(lines);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) URL(java.net.URL)

Aggregations

URL (java.net.URL)14 ResolveGeogigDir (org.locationtech.geogig.api.plumbing.ResolveGeogigDir)14 File (java.io.File)12 URISyntaxException (java.net.URISyntaxException)10 IOException (java.io.IOException)4 RepositoryConnectionException (org.locationtech.geogig.repository.RepositoryConnectionException)3 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 ByteSource (com.google.common.io.ByteSource)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 Platform (org.locationtech.geogig.api.Platform)1 ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)1 Repository (org.locationtech.geogig.repository.Repository)1 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)1 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)1