Search in sources :

Example 36 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class Init method runInternal.

/**
     * Executes the init command.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    // argument location if provided, or current directory otherwise
    final File targetDirectory;
    {
        File currDir = cli.getPlatform().pwd();
        if (location != null && location.size() == 1) {
            String target = location.get(0);
            File f = new File(target);
            if (!f.isAbsolute()) {
                f = new File(currDir, target).getCanonicalFile();
            }
            targetDirectory = f;
        } else {
            targetDirectory = currDir;
        }
    }
    final boolean repoExisted;
    final Repository repository;
    {
        GeoGIG geogig = cli.getGeogig();
        if (geogig == null) {
            Context geogigInjector = cli.getGeogigInjector();
            geogig = new GeoGIG(geogigInjector);
        }
        repoExisted = determineIfRepoExists(targetDirectory, geogig);
        final Map<String, String> suppliedConfiguration = splitConfig(config);
        try {
            repository = geogig.command(InitOp.class).setConfig(suppliedConfiguration).setTarget(targetDirectory).call();
        } catch (IllegalArgumentException e) {
            throw new CommandFailedException(e.getMessage(), e);
        } finally {
            geogig.close();
        }
    }
    File repoDirectory;
    try {
        repoDirectory = new File(repository.getLocation().toURI());
    } catch (URISyntaxException e) {
        throw new CommandFailedException("Environment home can't be resolved to a directory", e);
    }
    String message;
    if (repoExisted) {
        message = "Reinitialized existing Geogig repository in " + repoDirectory.getAbsolutePath();
    } else {
        message = "Initialized empty Geogig repository in " + repoDirectory.getAbsolutePath();
    }
    cli.getConsole().println(message);
}
Also used : Context(org.locationtech.geogig.api.Context) InitOp(org.locationtech.geogig.api.porcelain.InitOp) Repository(org.locationtech.geogig.repository.Repository) RequiresRepository(org.locationtech.geogig.cli.annotation.RequiresRepository) URISyntaxException(java.net.URISyntaxException) File(java.io.File) Map(java.util.Map) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 37 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class Serve method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws InvalidParameterException, CommandFailedException, IOException {
    String loc = repo != null && repo.size() > 0 ? repo.get(0) : ".";
    GeoGIG geogig = loadGeoGIG(loc, cli);
    Application application = new Main(geogig);
    Component comp = new Component();
    comp.getDefaultHost().attach(application);
    comp.getServers().add(Protocol.HTTP, port);
    cli.getConsole().println(String.format("Starting server on port %d, use CTRL+C to exit.", port));
    try {
        comp.start();
        cli.setExitOnFinish(false);
    } catch (BindException e) {
        String msg = String.format("Port %d already in use, use the --port parameter to specify a different port", port);
        throw new CommandFailedException(msg, e);
    } catch (Exception e) {
        throw new CommandFailedException("Unable to start server", e);
    }
}
Also used : BindException(java.net.BindException) Component(org.restlet.Component) Application(org.restlet.Application) Main(org.locationtech.geogig.web.Main) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) IOException(java.io.IOException) BindException(java.net.BindException) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 38 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class GeoJsonExportTest method testExportToFileThatAlreadyExists.

@Test
public void testExportToFileThatAlreadyExists() throws Exception {
    GeoJsonExport exportCommand = new GeoJsonExport();
    String geoJsonFileName = new File(geogig.getPlatform().pwd(), "TestPoints.geojson").getAbsolutePath();
    exportCommand.args = Arrays.asList("WORK_HEAD:Points", geoJsonFileName);
    exportCommand.run(cli);
    exportCommand.args = Arrays.asList("Lines", geoJsonFileName);
    try {
        exportCommand.run(cli);
        fail();
    } catch (CommandFailedException e) {
    } finally {
        deleteGeoJson(geoJsonFileName);
    }
}
Also used : File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) Test(org.junit.Test)

Example 39 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class ShpExportTest method testExportToFileThatAlreadyExists.

@Test
public void testExportToFileThatAlreadyExists() throws Exception {
    ShpExport exportCommand = new ShpExport();
    String shapeFileName = new File(geogig.getPlatform().pwd(), "TestPoints.shp").getAbsolutePath();
    ;
    exportCommand.args = Arrays.asList("WORK_HEAD:Points", shapeFileName);
    exportCommand.dataStoreFactory = TestHelper.createTestFactory();
    exportCommand.run(cli);
    exportCommand.args = Arrays.asList("Lines", shapeFileName);
    try {
        exportCommand.run(cli);
        fail();
    } catch (CommandFailedException e) {
    } finally {
        deleteShapeFile(shapeFileName);
    }
}
Also used : File(java.io.File) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) Test(org.junit.Test)

Example 40 with CommandFailedException

use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.

the class Reset method runInternal.

/**
     * Executes the reset command using the provided options.
     * 
     * @param cli
     * @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
@Override
public void runInternal(GeogigCLI cli) {
    final GeoGIG geogig = cli.getGeogig();
    ResetMode mode = resolveResetMode();
    ResetOp reset = cli.getGeogig().command(ResetOp.class);
    try {
        for (int i = 0; args != null && i < args.size(); i++) {
            reset.addPattern(args.get(i));
        }
        if (commit != null && commit.size() > 0) {
            Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit.get(0)).call();
            checkParameter(commitId.isPresent(), "Commit could not be resolved.");
            reset.setCommit(Suppliers.ofInstance(commitId.get()));
        }
        reset.setMode(mode);
        reset.call();
    } catch (IllegalArgumentException iae) {
        throw new CommandFailedException(iae.getMessage(), iae);
    } catch (IllegalStateException ise) {
        throw new CommandFailedException(ise.getMessage(), ise);
    }
    if (!geogig.getRepository().workingTree().isClean()) {
        try {
            Iterator<DiffEntry> unstaged = geogig.command(DiffWorkTree.class).setFilter(null).call();
            cli.getConsole().println("Unstaged changes after reset:");
            while (unstaged.hasNext()) {
                DiffEntry entry = unstaged.next();
                ChangeType type = entry.changeType();
                switch(type) {
                    case ADDED:
                        cli.getConsole().println("A\t" + entry.newPath());
                        break;
                    case MODIFIED:
                        cli.getConsole().println("M\t" + entry.newPath());
                        break;
                    case REMOVED:
                        cli.getConsole().println("D\t" + entry.oldPath());
                        break;
                }
            }
        } catch (IOException e) {
        }
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) IOException(java.io.IOException) ResetOp(org.locationtech.geogig.api.porcelain.ResetOp) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) ChangeType(org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType) ResetMode(org.locationtech.geogig.api.porcelain.ResetOp.ResetMode) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)58 DataStore (org.geotools.data.DataStore)28 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)24 File (java.io.File)16 GeoGIG (org.locationtech.geogig.api.GeoGIG)16 ObjectId (org.locationtech.geogig.api.ObjectId)15 IOException (java.io.IOException)14 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)12 ConsoleReader (jline.console.ConsoleReader)10 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)10 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)10 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)10 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)9 Serializable (java.io.Serializable)8 Optional (com.google.common.base.Optional)7 TYPE (org.locationtech.geogig.api.RevObject.TYPE)7 Map (java.util.Map)6 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 Connection (java.sql.Connection)4 Feature (org.opengis.feature.Feature)4