List of usage examples for org.apache.commons.exec CommandLine parse
public static CommandLine parse(final String line)
From source file:com.jaeksoft.searchlib.ocr.OcrManager.java
public void ocerize(File input, File outputFile, LanguageEnum lang, boolean hocr) throws SearchLibException, IOException { rwl.r.lock();//from w w w. j av a2s.c om try { if (!enabled) return; if (tesseractPath == null || tesseractPath.length() == 0) throw new SearchLibException("No path for the OCR"); CommandLine cmdLine = CommandLine.parse(tesseractPath); cmdLine.addArgument(input.getAbsolutePath()); cmdLine.addArgument(checkOutputPath(outputFile, hocr)); TesseractLanguageEnum tle = TesseractLanguageEnum.find(lang); if (tle == null) tle = defaultLanguage; if (tle != null && tle != TesseractLanguageEnum.None) cmdLine.addArgument("-l " + tle.option); if (hocr) cmdLine.addArgument("hocr"); int ev = run(cmdLine, 3600, null, null); if (ev == 3) Logging.warn("Image format not supported by Tesseract (" + input.getName() + ")"); } finally { rwl.r.unlock(); } }
From source file:io.vertx.config.vault.utils.VaultProcess.java
public void runAndProcess(String command, Consumer<String> processor) { String cli = executable.getAbsolutePath() + " " + command; System.out.println(">> " + cli); CommandLine parse = CommandLine.parse(cli); DefaultExecutor executor = new DefaultExecutor(); PumpStreamHandler pump = new PumpStreamHandler(new VaultOutputStream().addExtractor(processor), System.err); ExecuteWatchdog watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchDog);/* w ww . j a v a2s. co m*/ executor.setStreamHandler(pump); try { executor.execute(parse); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.bugvm.maven.surefire.BugVMSurefireProvider.java
@Override public RunResult invoke(Object forkTestSet) throws TestSetFailedException, ReporterException { if (testsToRun == null) { if (forkTestSet instanceof TestsToRun) { testsToRun = (TestsToRun) forkTestSet; } else if (forkTestSet instanceof Class) { testsToRun = TestsToRun.fromClass((Class<?>) forkTestSet); } else {//from w w w . j a va2 s . c om testsToRun = scanClassPath(); } } final ReporterFactory reporterFactory = providerParameters.getReporterFactory(); final RunListener reporter = reporterFactory.createReporter(); ConsoleOutputCapture.startCapture((ConsoleOutputReceiver) reporter); final JUnit4RunListener jUnit4TestSetReporter = new JUnit4RunListener(reporter); Result result = new Result(); final RunNotifier runNotifier = getRunNotifier(jUnit4TestSetReporter, result, customRunListeners); TestClient testClient = new TestClient(); testClient.setRunListener(new org.junit.runner.notification.RunListener() { public void testRunStarted(Description description) throws Exception { runNotifier.fireTestRunStarted(description); } public void testRunFinished(Result result) throws Exception { runNotifier.fireTestRunFinished(result); } public void testStarted(Description description) throws Exception { runNotifier.fireTestStarted(description); } public void testFinished(Description description) throws Exception { runNotifier.fireTestFinished(description); } public void testFailure(Failure failure) throws Exception { runNotifier.fireTestFailure(failure); } public void testAssumptionFailure(Failure failure) { runNotifier.fireTestAssumptionFailed(failure); } public void testIgnored(Description description) throws Exception { runNotifier.fireTestIgnored(description); } }); String runArgs = System.getProperty(PROP_RUN_ARGS, ""); if (!runArgs.isEmpty()) { testClient .setRunArgs(new ArrayList<>(Arrays.asList(CommandLine.parse("cmd " + runArgs).getArguments()))); } Process process = null; try { Config config = testClient.configure(createConfig(), isIOS()).build(); config.getLogger().info("Building BugVM tests for: %s (%s)", config.getOs(), config.getArch()); config.getLogger().info("This could take a while, especially the first time round"); AppCompiler appCompiler = new AppCompiler(config); appCompiler.build(); LaunchParameters launchParameters = config.getTarget().createLaunchParameters(); if (Boolean.getBoolean(PROP_SERVER_DEBUG)) { launchParameters.getArguments().add("-rvm:Dbugvm.debug=true"); } if (System.getProperty(PROP_IOS_SIMULATOR_NAME) != null && launchParameters instanceof IOSSimulatorLaunchParameters) { DeviceType type = DeviceType.getDeviceType(System.getProperty(PROP_IOS_SIMULATOR_NAME)); ((IOSSimulatorLaunchParameters) launchParameters).setDeviceType(type); } else if (launchParameters instanceof IOSSimulatorLaunchParameters) { if (config.getArch() == Arch.x86_64) { ((IOSSimulatorLaunchParameters) launchParameters) .setDeviceType(DeviceType.getBestDeviceType(config.getArch(), null, null, null)); } } process = appCompiler.launchAsync(launchParameters); runNotifier.fireTestRunStarted(null); for (Class<?> clazz : testsToRun) { executeTestSet(testClient, clazz, reporter, runNotifier); } testClient.terminate(); process.waitFor(); runNotifier.fireTestRunFinished(result); JUnit4RunListener.rethrowAnyTestMechanismFailures(result); } catch (Throwable t) { throw new RuntimeException("BugVM test run failed", t); } finally { if (process != null) { process.destroy(); } } return reporterFactory.close(); }
From source file:com.blackducksoftware.tools.scmconnector.integrations.git.GitConnector.java
/** * Checks to see if there is an existing git clone * * @param targetDir// w w w . j a v a 2 s .c om * @return * @throws Exception */ private boolean doesGitCloneExist(File targetDir) throws Exception { validateExecutableInstance(EXECUTABLE); CommandLine command = CommandLine.parse(EXECUTABLE); command.addArgument(GIT_COMMAND_STATUS); command.addArgument(repositoryURL); // Check to see if there are any files in the target directory // If not, return false File[] files = targetDir.listFiles(); if (files == null || files.length == 0) { log.info("Nothing inside the target directory: " + targetDir); log.info("Skipping status check."); return false; } int exitStatus = commandLineExecutor.executeCommand(log, command, targetDir); if (exitStatus == 0) { log.info("repository exists in directory: " + targetDir.getAbsolutePath()); return true; } else { log.info("repository does not exist in directory: " + targetDir.getAbsolutePath()); return false; } }
From source file:com.dangdang.ddframe.job.cloud.scheduler.mesos.TaskLaunchProcessor.java
private Protos.CommandInfo buildCommand(final Protos.CommandInfo.URI uri, final String bootstrapScript, final ShardingContexts shardingContexts, final boolean useDefaultExecutor) { Protos.CommandInfo.Builder result = Protos.CommandInfo.newBuilder().addUris(uri).setShell(true); if (useDefaultExecutor) { CommandLine commandLine = CommandLine.parse(bootstrapScript); commandLine.addArgument(GsonFactory.getGson().toJson(shardingContexts), false); result.setValue(Joiner.on(" ").join(commandLine.getExecutable(), Joiner.on(" ").join(commandLine.getArguments()))); } else {/* w w w . j a va2 s . com*/ result.setValue(bootstrapScript); } return result.build(); }
From source file:com.blackducksoftware.tools.scmconnector.core.Connector.java
/** * This performs a check to ensure that whatever executable is being * invoked, actually exists.// w w w . j ava 2 s .co m * * @throws Exception */ protected void validateExecutableInstance(String EXECUTABLE) throws Exception { log.info("Verifying installation"); CommandLine command = CommandLine.parse(EXECUTABLE); command.addArgument("--version"); String workingDir = System.getProperty("user.dir"); if (workingDir != null) { int returnCode = (new CommandLineExecutor()).executeCommand(log, command, new File(workingDir)); if (returnCode == 0) { log.info("Found installation of: " + EXECUTABLE); } else { log.warn("Unable to determine location of: " + EXECUTABLE); log.warn("Please install and add to path."); } } }
From source file:net.openbyte.gui.WorkFrame.java
private void menuItem3ActionPerformed(ActionEvent e) { if (this.api == ModificationAPI.BUKKIT) { showBukkitIncompatibleFeature(); return;/*from w ww.j a v a 2s .c o m*/ } System.out.println("Building modification JAR."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { GradleConnector.newConnector().forProjectDirectory(workDirectory).connect().newBuild() .forTasks("build").run(); return null; } }; if (this.api == ModificationAPI.MCP) { // recompile and reobfuscate worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { if (System.getProperty("os.name").startsWith("Windows")) { Runtime.getRuntime().exec("cmd /c recompile.bat", null, workDirectory); Runtime.getRuntime().exec("cmd /c reobfuscate.bat", null, workDirectory); return null; } try { CommandLine recompile = CommandLine.parse("python " + new File(new File(workDirectory, "runtime"), "recompile.py").getAbsolutePath() + " $@"); CommandLine reobfuscate = CommandLine.parse("python " + new File(new File(workDirectory, "runtime"), "reobfuscate.py").getAbsolutePath() + " $@"); File recompilePy = new File(new File(workDirectory, "runtime"), "recompile.py"); File reobfuscatePy = new File(new File(workDirectory, "runtime"), "reobfuscate.py"); CommandLine authRecompile = CommandLine.parse("chmod 755 " + recompilePy.getAbsolutePath()); CommandLine authReobfuscate = CommandLine .parse("chmod 755 " + reobfuscatePy.getAbsolutePath()); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(workDirectory); executor.execute(authRecompile); executor.execute(authReobfuscate); executor.execute(recompile); executor.execute(reobfuscate); System.out.println("Finished building modification JAR."); } catch (Exception e) { e.printStackTrace(); } return null; } }; } worker.execute(); }
From source file:gr.upatras.ece.nam.baker.impl.InstalledBunLifecycleMgmt.java
public int executeSystemCommand(String cmdStr) { logger.info(" ================> Execute :" + cmdStr); CommandLine cmdLine = CommandLine.parse(cmdStr); final Executor executor = new DefaultExecutor(); // create the executor and consider the exitValue '0' as success executor.setExitValue(0);// w w w. ja v a2s.c om ByteArrayOutputStream out = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(out); executor.setStreamHandler(streamHandler); int exitValue = -1; try { exitValue = executor.execute(cmdLine); logger.info(" ================> EXIT (" + exitValue + ") FROM :" + cmdStr); } catch (ExecuteException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } logger.info("out>" + out); return exitValue; }
From source file:com.mooregreatsoftware.gitprocess.lib.Pusher.java
private static ThePushResult doGitProgPush(GitLib gitLib, Branch localBranch, String remoteBranchName, boolean forcePush, String remoteName) { String cmd = String.format("git push --porcelain %s %s %s:%s", remoteName, forcePush ? "--force" : "", localBranch.shortName(), remoteBranchName); CommandLine commandLine = CommandLine.parse(cmd); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(gitLib.workingDirectory()); final StringWriter stdOutWriter = new StringWriter(); final StringWriter stdErrWriter = new StringWriter(); executor.setStreamHandler(/*from w w w .jav a 2 s . c o m*/ new PumpStreamHandler(new WriterOutputStream(stdOutWriter), new WriterOutputStream(stdErrWriter))); final int exitCode = Try.of(() -> { try { return executor.execute(commandLine); } catch (ExecuteException e) { return e.getExitValue(); } catch (IOException e) { final String message = e.getMessage(); if (message != null && message.contains("No such file or directory")) { return 1; } e.printStackTrace(); return -1; } }).get(); return new ProcPushResult(stdOutWriter, stdErrWriter, exitCode); }
From source file:hr.fer.zemris.vhdllab.service.impl.GhdlSimulator.java
private CommandLine createCommandLine(String cmd) { return CommandLine.parse(cmd); }