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);
}
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);
}
}
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);
}
}
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);
}
}
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) {
}
}
}
Aggregations