List of usage examples for org.apache.commons.exec CommandLine addArgument
public CommandLine addArgument(final String argument, final boolean handleQuoting)
From source file:io.selendroid.builder.SelendroidServerBuilderTest.java
@Test public void testShouldBeAbleToCreateASignedSelendroidServer() throws Exception { SelendroidServerBuilder builder = getDefaultBuilder(); builder.init(new DefaultAndroidApp(new File(APK_FILE))); builder.cleanUpPrebuildServer();//w w w . j a v a2 s.c om File file = File.createTempFile("testserver", "apk"); builder.signTestServer(builder.createAndAddCustomizedAndroidManifestToSelendroidServer(), file); // Verify that apk is signed CommandLine cmd = new CommandLine(AndroidSdk.aapt()); cmd.addArgument("list", false); cmd.addArgument(file.getAbsolutePath(), false); String output = ShellCommand.exec(cmd); assertResultDoesNotContainFile(output, "META-INF/CERT.RSA"); assertResultDoesNotContainFile(output, "META-INF/CERT.SF"); assertResultDoesContainFile(output, "META-INF/ANDROIDD.SF"); assertResultDoesContainFile(output, "META-INF/ANDROIDD.RSA"); assertResultDoesContainFile(output, "AndroidManifest.xml"); }
From source file:io.gatling.mojo.GatlingJavaMainCallerByFork.java
@Override public boolean run(boolean displayCmd, boolean throwFailure) throws Exception { List<String> cmd = buildCommand(); displayCmd(displayCmd, cmd);//from w w w.j av a 2 s. c o m Executor exec = new DefaultExecutor(); // err and out are redirected to out exec.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in)); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); CommandLine cl = new CommandLine(cmd.get(0)); for (int i = 1; i < cmd.size(); i++) { cl.addArgument(cmd.get(i), false); } try { int exitValue = exec.execute(cl); if (exitValue != 0) { if (throwFailure) { throw new MojoFailureException("command line returned non-zero value:" + exitValue); } return false; } return true; } catch (ExecuteException exc) { if (throwFailure) { throw exc; } return false; } }
From source file:it.drwolf.ridire.utility.RIDIREReTagger.java
public String retagFile(File f) throws ExecuteException, IOException { // Map<String, File> map = new HashMap<String, File>(); String fileIN = f.getAbsolutePath(); String fileOut = f.getAbsolutePath() + ".iso"; String posOld = f.getAbsolutePath() + ".iso.pos"; String posNew = f.getAbsolutePath() + ".pos"; // first convert from utf8 to iso8859-1 CommandLine commandLine = CommandLine.parse("iconv"); commandLine.addArgument("-c").addArgument("-s").addArgument("-f").addArgument("utf8").addArgument("-t") .addArgument("iso8859-1//TRANSLIT").addArgument("-o").addArgument(fileOut, false) .addArgument(fileIN, false); DefaultExecutor executor = new DefaultExecutor(); ExecuteWatchdog watchdog = new ExecuteWatchdog(RIDIREReTagger.TREETAGGER_TIMEOUT); executor.setWatchdog(watchdog);/*from w w w . j a v a 2s . c o m*/ int exitValue = executor.execute(commandLine); if (exitValue == 0) { // tag using latin1 and Baroni's tagset commandLine = CommandLine.parse(this.treeTaggerBin); commandLine.addArgument(fileOut, false); executor = new DefaultExecutor(); executor.setExitValue(0); watchdog = new ExecuteWatchdog(RIDIREReTagger.TREETAGGER_TIMEOUT); executor.setWatchdog(watchdog); TreeTaggerLog treeTaggerLog = new TreeTaggerLog(); PumpStreamHandler executeStreamHandler = new PumpStreamHandler(treeTaggerLog, null); executor.setStreamHandler(executeStreamHandler); int exitValue2 = executor.execute(commandLine); if (exitValue2 == 0) { // FileUtils.deleteQuietly(new File(fileOut)); File posTagFile = new File(posOld); FileUtils.writeLines(posTagFile, treeTaggerLog.getLines()); } // reconvert to utf8 commandLine = CommandLine.parse("iconv"); commandLine.addArgument("-s").addArgument("-f").addArgument("iso8859-1").addArgument("-t") .addArgument("utf8//TRANSLIT").addArgument("-o").addArgument(posNew, false) .addArgument(posOld, false); executor = new DefaultExecutor(); watchdog = new ExecuteWatchdog(RIDIREReTagger.TREETAGGER_TIMEOUT); executor.setWatchdog(watchdog); int exitValue3 = executor.execute(commandLine); if (exitValue3 == 0) { // FileUtils.deleteQuietly(new File(f.getPath() + ".iso.pos")); return new File(posNew).getCanonicalPath(); } } return null; }
From source file:hoot.services.nativeinterfaces.CommandRunnerImpl.java
@Override public CommandResult exec(String[] command) throws IOException { logger.debug("Executing the following command: {}", Arrays.toString(command)); try (OutputStream stdout = new ByteArrayOutputStream(); OutputStream stderr = new ByteArrayOutputStream()) { this.stdout = stdout; this.stderr = stderr; CommandLine cmdLine = new CommandLine(command[0]); for (int i = 1; i < command.length; i++) { cmdLine.addArgument(command[i], false); }/* ww w.j ava 2 s . c om*/ ExecuteStreamHandler executeStreamHandler = new PumpStreamHandler(stdout, stderr); DefaultExecutor executor = new DefaultExecutor(); this.watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(this.watchDog); executor.setStreamHandler(executeStreamHandler); int exitValue; try { exitValue = executor.execute(cmdLine); if (executor.isFailure(exitValue) && this.watchDog.killedProcess()) { // it was killed on purpose by the watchdog logger.info("Process for '{}' command was killed!", cmdLine); } } catch (Exception e) { exitValue = -1; logger.warn("Error executing: {}", cmdLine, e); } CommandResult commandResult = new CommandResult(cmdLine.toString(), exitValue, stdout.toString(), stderr.toString()); logger.debug("Finished executing: {}", commandResult); return commandResult; } }
From source file:io.gatling.mojo.Fork.java
public void run() throws Exception { if (propagateSystemProperties) { for (Entry<Object, Object> systemProp : System.getProperties().entrySet()) { String name = systemProp.getKey().toString(); String value = systemProp.getValue().toString(); if (isPropagatableProperty(name)) { String escapedValue = StringUtils.escape(value); String safeValue = escapedValue.contains(" ") ? '"' + escapedValue + '"' : escapedValue; this.jvmArgs.add("-D" + name + "=" + safeValue); }//from www. j a va 2 s .c o m } } this.jvmArgs.add("-jar"); this.jvmArgs .add(MojoUtils.createBooterJar(classpath, MainWithArgsInFile.class.getName()).getCanonicalPath()); List<String> command = buildCommand(); Executor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in)); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); CommandLine cl = new CommandLine(javaExecutable); for (String arg : command) { cl.addArgument(arg, false); } int exitValue = exec.execute(cl); if (exitValue != 0) { throw new MojoFailureException("command line returned non-zero value:" + exitValue); } }
From source file:hoot.services.command.CommandRunnerImpl.java
@Override public CommandResult exec(String[] command) throws IOException { logger.debug("Executing the following command: {}", Arrays.toString(command)); try (OutputStream stdout = new ByteArrayOutputStream(); OutputStream stderr = new ByteArrayOutputStream()) { CommandLine cmdLine = new CommandLine(command[0]); for (int i = 1; i < command.length; i++) { cmdLine.addArgument(command[i], false); }// w w w. ja v a2 s . c o m ExecuteStreamHandler executeStreamHandler = new PumpStreamHandler(stdout, stderr); DefaultExecutor executor = new DefaultExecutor(); executor.setStreamHandler(executeStreamHandler); int exitValue; try { exitValue = executor.execute(cmdLine); } catch (Exception e) { exitValue = -1; logger.warn("Error executing: {}", cmdLine, e); } CommandResult commandResult = new CommandResult(cmdLine.toString(), exitValue, stdout.toString(), stderr.toString()); this.stdout = stdout.toString(); logger.debug("Finished executing: {}", commandResult); return commandResult; } }
From source file:com.blackducksoftware.tools.scmconnector.integrations.teamfoundation.TeamFoundationConnector.java
private int mapWorkpace() { CommandLine command = CommandLine.parse(executable); command.addArgument("workfold", false); command.addArgument("-map", false); command.addArgument("-workspace:" + workspace, false); command.addArgument("-login:" + user + "," + password, false); command.addArgument("$" + view, false); // Don't mess with quoting command.addArgument(getFinalSourceDirectory(), false); int exitStatus = 1; try {/*from ww w. j a va 2 s.co m*/ exitStatus = commandLineExecutor.executeCommand(log, command, new File(getFinalSourceDirectory())); } catch (Exception e) { log.error("Failure executing TF Command", e); } return exitStatus; }
From source file:io.selendroid.standalone.builder.SelendroidServerBuilderTest.java
@Test public void testShouldBeAbleToResignAnSignedApp() throws Exception { SelendroidServerBuilder builder = getDefaultBuilder(); File androidApp = File.createTempFile("testapp", ".apk"); FileUtils.copyFile(new File(APK_FILE), androidApp); AndroidApp resignedApp = builder.resignApp(androidApp); assertResignedApp(resignedApp, androidApp); // Verify that apk is signed CommandLine cmd = new CommandLine(AndroidSdk.aapt()); cmd.addArgument("list", false); cmd.addArgument(resignedApp.getAbsolutePath(), false); String output = ShellCommand.exec(cmd); assertResultDoesNotContainFile(output, "META-INF/CERT.RSA"); assertResultDoesNotContainFile(output, "META-INF/CERT.SF"); assertResultDoesContainFile(output, "META-INF/ANDROIDD.SF"); assertResultDoesContainFile(output, "META-INF/ANDROIDD.RSA"); assertResultDoesContainFile(output, "AndroidManifest.xml"); }
From source file:io.selendroid.standalone.builder.SelendroidServerBuilderTest.java
@Test public void testShouldBeAbleToCreateASignedSelendroidServerWithCustomKeystore() throws Exception { SelendroidServerBuilder builder = getDefaultBuilderWithCustomKeystore(); builder.init(new DefaultAndroidApp(new File(APK_FILE))); builder.cleanUpPrebuildServer();//from w w w .j av a 2 s . c o m File file = File.createTempFile("testserver1", "apk"); builder.signTestServer(builder.createAndAddCustomizedAndroidManifestToSelendroidServer(), file); // Verify that apk is signed CommandLine cmd = new CommandLine(AndroidSdk.aapt()); cmd.addArgument("list", false); cmd.addArgument(file.getAbsolutePath(), false); String output = ShellCommand.exec(cmd); String sigFileName = selendroidConfiguration.getKeystoreAlias().toUpperCase(); if (sigFileName.length() > 8) { sigFileName = sigFileName.substring(0, 8); } assertResultDoesNotContainFile(output, "META-INF/CERT.RSA"); assertResultDoesNotContainFile(output, "META-INF/CERT.SF"); assertResultDoesContainFile(output, "META-INF/" + sigFileName + ".SF"); assertResultDoesContainFile(output, "META-INF/" + sigFileName + ".RSA"); assertResultDoesContainFile(output, "AndroidManifest.xml"); }
From source file:com.blackducksoftware.tools.scmconnector.integrations.teamfoundation.TeamFoundationConnector.java
private int workspaceExists() { CommandLine command = CommandLine.parse(executable); command.addArgument("workspaces", false); command.addArgument("-server:" + server + "/" + collection, false); command.addArgument("-login:" + user + "," + password, false); int commandReturnStatus = 1; String commandOutput = null;// ww w. j a v a 2s.c om try { CommandResults results = commandLineExecutor.executeCommandForOutput(log, command, new File(getFinalSourceDirectory())); commandReturnStatus = results.getStatus(); commandOutput = results.getOutput(); if (commandOutput.contains(workspace)) { workspaceExists = true; log.info("The workspace exists"); } else { workspaceExists = false; log.info("The workspace does not exist"); } } catch (Exception e) { log.error("Failure executing TF Command: " + command.toString() + "; output: " + commandOutput); workspaceExists = false; } return commandReturnStatus; }