Search in sources :

Example 6 with Platform

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

the class JECommitOpTest method createInjector.

@Override
protected Context createInjector() {
    File workingDirectory;
    try {
        workingDirectory = mockWorkingDirTempFolder.getRoot();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    Platform testPlatform = new TestPlatform(workingDirectory);
    return Guice.createInjector(Modules.override(new GeogigModule()).with(new JETestStorageModule(), new TestModule(testPlatform))).getInstance(Context.class);
}
Also used : TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) GeogigModule(org.locationtech.geogig.di.GeogigModule)

Example 7 with Platform

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

the class ParseTimestampTest method setUp.

@Before
public void setUp() {
    File workingDirectory = tempFolder.newFolder("mockWorkingDir");
    Platform testPlatform = new TestPlatform(workingDirectory) {

        @Override
        public long currentTimeMillis() {
            return REFERENCE_DATE.getTime();
        }
    };
    Context injector = Guice.createInjector(Modules.override(new GeogigModule()).with(new MemoryModule(testPlatform))).getInstance(Context.class);
    fakeGeogig = new GeoGIG(injector, workingDirectory);
    assertNotNull(fakeGeogig.getOrCreateRepository());
    command = fakeGeogig.command(ParseTimestamp.class);
}
Also used : Context(org.locationtech.geogig.api.Context) TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) GeogigModule(org.locationtech.geogig.di.GeogigModule) MemoryModule(org.locationtech.geogig.api.MemoryModule) GeoGIG(org.locationtech.geogig.api.GeoGIG) Before(org.junit.Before)

Example 8 with Platform

use of org.locationtech.geogig.api.Platform 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 9 with Platform

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

the class OracleDescribeTest method setUpGeogig.

private void setUpGeogig(GeogigCLI cli) throws Exception {
    final File userhome = tempFolder.newFolder("mockUserHomeDir");
    final File workingDir = tempFolder.newFolder("mockWorkingDir");
    tempFolder.newFolder("mockWorkingDir/.geogig");
    final Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    when(platform.getUserHome()).thenReturn(userhome);
    cli.setPlatform(platform);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Example 10 with Platform

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

the class OracleImportTest method setUpGeogig.

private void setUpGeogig(GeogigCLI cli) throws Exception {
    final File userhome = tempFolder.newFolder("mockUserHomeDir");
    final File workingDir = tempFolder.newFolder("mockWorkingDir");
    tempFolder.newFolder("mockWorkingDir/.geogig");
    final Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    when(platform.getUserHome()).thenReturn(userhome);
    cli.setPlatform(platform);
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File)

Aggregations

Platform (org.locationtech.geogig.api.Platform)41 File (java.io.File)27 TestPlatform (org.locationtech.geogig.api.TestPlatform)10 Before (org.junit.Before)7 Context (org.locationtech.geogig.api.Context)7 GeogigModule (org.locationtech.geogig.di.GeogigModule)6 GeoGIG (org.locationtech.geogig.api.GeoGIG)5 ObjectId (org.locationtech.geogig.api.ObjectId)5 Repository (org.locationtech.geogig.repository.Repository)5 IOException (java.io.IOException)4 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)4 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)4 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)3 DefaultPlatform (org.locationtech.geogig.api.DefaultPlatform)3 MemoryModule (org.locationtech.geogig.api.MemoryModule)3 RevCommit (org.locationtech.geogig.api.RevCommit)3 RevTree (org.locationtech.geogig.api.RevTree)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 UnsupportedTerminal (jline.UnsupportedTerminal)2