List of usage examples for org.apache.commons.exec CommandLine setSubstitutionMap
public void setSubstitutionMap(final Map<String, ?> substitutionMap)
From source file:common.UglyLaunchTempPatch.java
/** * code for lunching external jar file/*w w w . ja v a2 s .c o m*/ * * @param jarFile * the jar file that is being lunched * @param Server * is this a server lunch or not * @throws IOException * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException * @throws InterruptedException */ public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException { Main.print("\"" + jarFile.getAbsolutePath() + "\""); // sets jar to deleate on exit of program jarFile.deleteOnExit(); //runs the client version of the forge installer. Map map = new HashMap(); map.put("file", jarFile); CommandLine cmdLine = new CommandLine("java"); cmdLine.addArgument("-jar"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); }
From source file:client.UglyLaunchTempPatch.java
/** * code for lunching external jar file//from w ww .j ava 2s .c o m * * @param jarFile * the jar file that is being lunched * @param Server * is this a server lunch or not * @throws IOException * @throws ClassNotFoundException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException * @throws InterruptedException */ public static void jar(File jarFile) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException { main.print("\"" + jarFile.getAbsolutePath() + "\""); // sets jar to deleate on exit of program jarFile.deleteOnExit(); //runs the client version of the forge installer. Map map = new HashMap(); map.put("file", jarFile); CommandLine cmdLine = new CommandLine("java"); cmdLine.addArgument("-jar"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); }
From source file:com.magnet.tools.tests.WebLogicStepDefs.java
public static void ensureDeployApp(String url, String name, String location) throws Exception { Executor exec = new DefaultExecutor(); CommandLine cl = new CommandLine(getScriptsDir() + File.separator + REDEPLOY_WLS_APP_SCRIPT); if (getArchetypeSettings() != null && getArchetypeSettings().length() != 0) { cl.addArgument(getArchetypeSettings()); }/*w ww. j a v a 2 s . c o m*/ cl.addArgument(url); cl.addArgument(name); cl.addArgument(location); cl.setSubstitutionMap(getSubstitutionMap()); int exitValue = exec.execute(cl); String msg = String.format("Server running at %s failed to deploy app %s at %s", url, name, expandVariables(location)); ensureBuildSuccessful("redeploy.log"); Assert.assertEquals(msg, 0, exitValue); }
From source file:com.magnet.tools.tests.WebLogicStepDefs.java
public static void ensureStartServer(String location, String httpPingUrl) throws Exception { Executor exec = new DefaultExecutor(); CommandLine cl = new CommandLine(getScriptsDir() + File.separator + START_WLS_SERVER_SCRIPT); if (getArchetypeSettings() != null && getArchetypeSettings().length() != 0) { cl.addArgument("--s"); cl.addArgument(getArchetypeSettings()); }/*from w w w . j a v a 2 s .com*/ cl.addArgument(String.format("-DdomainHome=%s", location)); cl.addArgument(String.format("-DhttpPingUrl=%s", httpPingUrl)); cl.setSubstitutionMap(getSubstitutionMap()); int exitValue = exec.execute(cl); ensureBuildSuccessful("start-server.log"); String msg = String.format("server failed to start at %s", expandVariables(location)); Assert.assertEquals(msg, 0, exitValue); }
From source file:at.treedb.util.Execute.java
public static ExecResult execute(String command, String[] param, Map<String, File> map) { DefaultExecutor executor = new DefaultExecutor(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); CommandLine cmdLine = null; int exitValue = 0; try {/* w ww . ja v a 2 s . c om*/ PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); cmdLine = new CommandLine(command); if (param != null) { for (String s : param) { s = s.trim(); if (s.isEmpty()) { continue; } cmdLine.addArgument(s); } } cmdLine.setSubstitutionMap(map); executor.setStreamHandler(streamHandler); exitValue = executor.execute(cmdLine); return new ExecResult(exitValue, outputStream.toString(), null); } catch (Exception e) { return new ExecResult(-1, outputStream.toString(), e); } }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME for the provided dem. * * @param operation Name used for the location on disk * @param dem File used to establish CRS and Bounds for the location * @return// www.j a va2s .c om * @throws Exception */ static File location(CoordinateReferenceSystem crs) throws Exception { String code = CRS.toSRS(crs, true); File geodb = new File(System.getProperty("user.home"), "grassdata"); File location = Files.createTempDirectory(geodb.toPath(), code).toFile(); KVP kvp = new KVP("geodb", geodb, "location", location); // grass70 + ' -c epsg:' + myepsg + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("epsg:" + code); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(kvp); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); executor.setWatchdog(new ExecuteWatchdog(60000)); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); return location; }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME/PERMANENT for the provided dem. * * The dem is staged in GISBASE/dem.tif and then moved to * GISBASE/LOCATION_NAME/PERMANENT/dem.tif * * @param operation/* ww w . j av a2 s. co m*/ * Name used for the location on disk * @param dem * File used to establish CRS and Bounds for the location * @return Array of files consisting of {GISBASE, LOCATION, MAPSET, dem.tif} * @throws Exception */ static File location(File location, File raster) throws Exception { // grass70 + ' -c ' + myfile + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("${raster}"); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(new KVP("raster", raster, "location", location)); LOGGER.info(cmd.toString()); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); executor.setStreamHandler(new PumpStreamHandler(System.out)); LOGGER.info(cmd.toString()); try { int exitValue = executor.execute(cmd); } catch (ExecuteException fail) { LOGGER.warning("grass70:" + fail.getLocalizedMessage()); throw fail; } File mapset = new File(location, "PERMANENT"); if (!mapset.exists()) { throw new IllegalStateException("Did not create mapset " + mapset); } return location; }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME/PERMANENT for the provided dem. * * The dem is staged in GISBASE/dem.tif and then moved to * GISBASE/LOCATION_NAME/PERMANENT/dem.tif * * @param operation/*from w w w. ja v a 2 s . com*/ * Name used for the location on disk * @param dem * File used to establish CRS and Bounds for the location * @return Array of files consisting of {GISBASE, LOCATION, MAPSET, dem.tif} * @throws Exception */ static File[] location(String operation, GridCoverage2D dem) throws Exception { File geodb = new File(System.getProperty("user.home"), "grassdata"); //File location = Files.createTempDirectory(geodb.toPath(),operation).toFile(); File location = new File(geodb, operation); File mapset = new File(location, "PERMANENT"); File file = new File(geodb, "dem.tif"); final GeoTiffFormat format = new GeoTiffFormat(); GridCoverageWriter writer = format.getWriter(file); writer.write(dem, null); System.out.println("Staging file:" + file); // grass70 + ' -c ' + myfile + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("${file}"); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(new KVP("file", file, "location", location)); LOGGER.info(cmd.toString()); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); File origional = file; file = new File(mapset, file.getName()); Files.move(origional.toPath(), file.toPath()); return new File[] { geodb, location, mapset, file }; }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
@DescribeProcess(title = "r.viewshed", description = "Computes the viewshed of a point on an elevation raster map.") @DescribeResult(description = "area visible from provided location") public static GridCoverage2D viewshed( @DescribeParameter(name = "dem", description = "digitial elevation model") GridCoverage2D dem, @DescribeParameter(name = "x", description = "x location in map units") double x, @DescribeParameter(name = "y", description = "y location in map units") double y) throws Exception { String COMMAND = "viewshed"; //Stage files in a temporary location File geodb = Files.createTempDirectory("grassdata").toFile(); geodb.deleteOnExit();/*from w w w. ja va 2 s . co m*/ File location = new File(geodb, COMMAND + Long.toString(random.nextLong()) + "location"); // stage dem file File file = new File(geodb, "dem.tif"); //The file must exist for FileImageOutputStreamExtImplSpi to create the output stream if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } final GeoTiffFormat format = new GeoTiffFormat(); GridCoverageWriter writer = format.getWriter(file); writer.write(dem, null); LOGGER.info("Staging file:" + file); // use file to create location with (returns PERMANENT mapset) File mapset = location(location, file); DefaultExecutor executor = new DefaultExecutor(); executor.setWatchdog(new ExecuteWatchdog(60000)); executor.setStreamHandler(new PumpStreamHandler(System.out)); executor.setWorkingDirectory(mapset); Map<String, String> env = customEnv(geodb, location, mapset); // EXPORT IMPORT DEM // r.in.gdal input=~/grassdata/viewshed/PERMANENT/dem.tif output=dem --overwrite File r_in_gdal = bin("r.in.gdal"); CommandLine cmd = new CommandLine(r_in_gdal); cmd.addArgument("input=${file}"); cmd.addArgument("output=dem"); cmd.addArgument("--overwrite"); cmd.setSubstitutionMap(new KVP("file", file)); try { LOGGER.info(cmd.toString()); executor.setExitValue(0); int exitValue = executor.execute(cmd, env); } catch (ExecuteException fail) { LOGGER.warning(r_in_gdal.getName() + ":" + fail.getLocalizedMessage()); throw fail; } // EXECUTE VIEWSHED File r_viewshed = bin("r.viewshed"); cmd = new CommandLine(r_viewshed); cmd.addArgument("input=dem"); cmd.addArgument("output=viewshed"); cmd.addArgument("coordinates=${x},${y}"); cmd.addArgument("--overwrite"); cmd.setSubstitutionMap(new KVP("x", x, "y", y)); try { LOGGER.info(cmd.toString()); executor.setExitValue(0); int exitValue = executor.execute(cmd, env); } catch (ExecuteException fail) { LOGGER.warning(r_viewshed.getName() + ":" + fail.getLocalizedMessage()); throw fail; } // EXECUTE EXPORT VIEWSHED // r.out.gdal --overwrite input=viewshed@PERMANENT output=/Users/jody/grassdata/viewshed/viewshed.tif format=GTiff File viewshed = new File(location, "viewshed.tif"); File r_out_gdal = bin("r.out.gdal"); cmd = new CommandLine(r_out_gdal); cmd.addArgument("input=viewshed"); cmd.addArgument("output=${viewshed}"); cmd.addArgument("--overwrite"); cmd.addArgument("format=GTiff"); cmd.setSubstitutionMap(new KVP("viewshed", viewshed)); try { LOGGER.info(cmd.toString()); executor.setExitValue(0); int exitValue = executor.execute(cmd, env); } catch (ExecuteException fail) { LOGGER.warning(r_out_gdal.getName() + ":" + fail.getLocalizedMessage()); throw fail; } // STAGE RESULT if (!viewshed.exists()) { throw new IOException("Generated viweshed.tif not found"); } GeoTiffReader reader = format.getReader(viewshed); GridCoverage2D coverage = reader.read(null); cleanup(new File(env.get("GISRC"))); return coverage; }
From source file:edu.emory.cci.aiw.neo4jetl.Neo4jHome.java
private void controlServer(String command) throws IOException, InterruptedException, CommandFailedException { LOGGER.debug("Executing neo4j command {}...", command); CommandLine serverControlCommand = new CommandLine(new File(this.home, SERVER_CONTROL_COMMAND)); serverControlCommand.addArgument("${command}"); Map<String, String> map = new HashMap<>(); map.put("command", command); serverControlCommand.setSubstitutionMap(map); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000); Executor executor = new DefaultExecutor(); executor.setExitValue(1);// ww w.j ava2 s.co m executor.setWatchdog(watchdog); executor.execute(serverControlCommand, resultHandler); LOGGER.debug("Neo4j command {} is completed, checking exit value...", command); resultHandler.waitFor(); int exitValue = resultHandler.getExitValue(); if (exitValue != 0) { ExecuteException exception = resultHandler.getException(); throw new CommandFailedException(exitValue, "Neo4j command '" + command + "' failed", exception); } LOGGER.debug("Neo4j command {} was successful", command); }