List of usage examples for org.apache.commons.exec CommandLine setSubstitutionMap
public void setSubstitutionMap(final Map<String, ?> substitutionMap)
From source file:org.jboss.windup.decorator.java.decompiler.JadretroDecompilerAdapter.java
private void executeJad(File classLocation, File sourceOutputLocation) { try {//from ww w . j a v a 2 s .c o m // Build command array CommandLine cmdLine = new CommandLine(APP_NAME); cmdLine.addArgument("-d"); cmdLine.addArgument("${outputLocation}"); cmdLine.addArgument("-f"); cmdLine.addArgument("-o"); cmdLine.addArgument("-s"); cmdLine.addArgument("java"); cmdLine.addArgument("${classLocation}"); Map<String, Object> argMap = new HashMap<String, Object>(); argMap.put("outputLocation", sourceOutputLocation); argMap.put("classLocation", classLocation); cmdLine.setSubstitutionMap(argMap); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); LOG.debug("Decompiler exited with exit code: " + exitValue); if (!sourceOutputLocation.exists()) { LOG.error("Expected decompiled source: " + sourceOutputLocation.getAbsolutePath() + "; did not find file. This likey means that the decompiler did not successfully decompile the class."); } else { LOG.debug("Decompiled to: " + sourceOutputLocation.getAbsolutePath()); } } catch (IOException e) { throw new FatalWindupException( "Error running " + APP_NAME + " decompiler. Validate that " + APP_NAME + " is on your PATH.", e); } }
From source file:org.ng200.openolympus.cerberus.compilers.FPCCompiler.java
@Override public void compile(final List<Path> inputFiles, final Path outputFile, final Map<String, Object> additionalParameters) throws CompilationException { FPCCompiler.logger.debug("Compiling {} to {} using FPC", inputFiles, outputFile); final CommandLine commandLine = new CommandLine("ppcx64"); commandLine.setSubstitutionMap(additionalParameters); this.arguments.forEach((arg) -> commandLine.addArgument(arg)); commandLine.addArgument("-o" + outputFile.toAbsolutePath().toString()); // Set // outuput/* w w w . j a v a2 s . com*/ // file commandLine.addArgument("-l-"); commandLine.addArgument("-v0"); inputFiles.forEach((file) -> commandLine .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add // input // files FPCCompiler.logger.debug("Running FPC with arguments: {}", commandLine.toString()); final DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, 1 }); final ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(errorStream, null, null)); executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to // compile int result; try { result = executor.execute(commandLine); } catch (final IOException e) { FPCCompiler.logger.error("Could not execute FPC: {}", e); throw new CompilationException("Could not execute FPC", e); } switch (result) { case 0: return; case 1: try { final String errorString = errorStream.toString("UTF-8"); final Pattern pattern = Pattern.compile( "^(" + inputFiles.stream().map(file -> Pattern.quote(file.getFileName().toString())) .collect(Collectors.joining("|")) + ")", Pattern.MULTILINE); FPCCompiler.logger.debug("Compilation error: {}", errorString); throw new CompilerError("fpc.wrote.stdout", errorString); } catch (final UnsupportedEncodingException e) { throw new CompilationException("Unsupported encoding! The compiler should output UTF-8!", e); } } }
From source file:org.ng200.openolympus.cerberus.compilers.GNUCompiler.java
@Override public void compile(final List<Path> inputFiles, final Path outputFile, final Map<String, Object> additionalParameters) throws CompilationException { GNUCompiler.logger.debug("Compiling {} to {} using GCC", inputFiles, outputFile); final CommandLine commandLine = new CommandLine("g++"); commandLine.setSubstitutionMap(additionalParameters); this.arguments.forEach((arg) -> commandLine.addArgument(arg)); commandLine.addArgument("-w"); // Prohibit warnings because they screw // up error detection commandLine.addArgument("-o"); commandLine.addArgument(MessageFormat.format("\"{0}\"", outputFile.toAbsolutePath().toString())); // Set outuput file inputFiles.forEach((file) -> commandLine .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add // input//from w w w . j ava 2s . c o m // files GNUCompiler.logger.debug("Running GCC with arguments: {}", Arrays.asList(commandLine.getArguments())); final DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, 1 }); final ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(null, errorStream, null)); executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to // compile int result; try { result = executor.execute(commandLine); } catch (final IOException e) { GNUCompiler.logger.error("Could not execute GCC: {}", e); throw new CompilationException("Could not execute GCC", e); } switch (result) { case 0: return; case 1: try { String errorString = errorStream.toString(StandardCharsets.UTF_8.name()); final Pattern pattern = Pattern.compile( "^(" + inputFiles.stream().map(file -> Pattern.quote(file.toAbsolutePath().toString())) .collect(Collectors.joining("|")) + "):", Pattern.MULTILINE); errorString = pattern.matcher(errorString).replaceAll(""); GNUCompiler.logger.debug("Compilation error: {}", errorString); throw new CompilerError("gcc.wrote.stderr", errorString); } catch (final UnsupportedEncodingException e) { throw new CompilationException("Unsupported encoding! The compiler should output UTF-8!", e); } } }
From source file:org.ng200.openolympus.cerberus.compilers.JavaCompiler.java
@Override public void compile(final List<Path> inputFiles, final Path outputFile, final Map<String, Object> additionalParameters) throws CompilationException, IOException { FileAccess.createDirectories(outputFile); final CommandLine commandLine = new CommandLine("javac"); commandLine.setSubstitutionMap(additionalParameters); this.arguments.forEach((arg) -> commandLine.addArgument(arg)); commandLine.addArgument("-d"); commandLine.addArgument(outputFile.toAbsolutePath().toString()); commandLine.addArgument("-nowarn"); // Prohibit warnings because they // screw//ww w. j a v a 2s.c o m // up error detection inputFiles.forEach((file) -> commandLine .addArguments(MessageFormat.format("\"{0}\"", file.toAbsolutePath().toString()))); // Add // input // files JavaCompiler.logger.info("Running javac with arguments: {}", Arrays.asList(commandLine.getArguments())); final DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, 1 }); final ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); executor.setStreamHandler(new PumpStreamHandler(null, errorStream, null)); executor.setWatchdog(new ExecuteWatchdog(20000));// 20 seconds to // compile int result; try { result = executor.execute(commandLine); } catch (final IOException e) { JavaCompiler.logger.error("Could not execute javac: {}", e); throw new CompilationException("Could not execute javac", e); } switch (result) { case 0: return; case 1: try { String errorString = errorStream.toString("UTF-8"); final Pattern pattern = Pattern.compile( "^(" + inputFiles.stream().map(file -> Pattern.quote(file.toAbsolutePath().toString())) .collect(Collectors.joining("|")) + "):", Pattern.MULTILINE); errorString = pattern.matcher(errorString).replaceAll(""); JavaCompiler.logger.debug("Compilation error: {}", errorString); throw new CompilerError("javac.wrote.stderr", errorString); } catch (final UnsupportedEncodingException e) { throw new CompilationException("Unsupported encoding! The compiler should output UTF-8!", e); } } }
From source file:org.opennms.gizmo.k8s.portforward.KubeCtlPortForwardingStrategy.java
@Override public ForwardedPort portForward(String namespace, String pod, int remotePort) { CommandLine cmdLine = new CommandLine("kubectl"); cmdLine.addArgument("--namespace=${namespace}"); cmdLine.addArgument("port-forward"); cmdLine.addArgument("${pod}"); cmdLine.addArgument(":${remotePort}"); HashMap<String, String> map = new HashMap<>(); map.put("namespace", namespace); map.put("pod", pod); map.put("remotePort", Integer.toString(remotePort)); cmdLine.setSubstitutionMap(map); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); PumpStreamHandler psh = new PumpStreamHandler(out, err); DefaultExecutor executor = new DefaultExecutor(); final ExecuteWatchdog wd = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(wd);//from w w w. j a va 2 s.c o m executor.setStreamHandler(psh); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); try { executor.execute(cmdLine, resultHandler); } catch (IOException e) { throw Throwables.propagate(e); } final int localPort = waitForLocalPort(wd, out, err); return new ForwardedPort() { @Override public InetSocketAddress getAddress() { return new InetSocketAddress(InetAddress.getLoopbackAddress(), localPort); } @Override public void close() throws IOException { wd.destroyProcess(); } @Override public String toString() { return String.format("ForwardedPort[localPort=%d]", localPort); } }; }
From source file:org.owasp.goatdroid.gui.emulator.EmulatorWorker.java
static public String pushAppOntoDevice(String appPath, String deviceSerial) { ByteArrayOutputStream stdout = new ByteArrayOutputStream(); PumpStreamHandler psh = new PumpStreamHandler(stdout); CommandLine cmdLine = new CommandLine(sdkPath + getSlash() + "platform-tools" + getSlash() + "adb"); Map<String, String> map = new HashMap<String, String>(); map.put("deviceSerial", deviceSerial); cmdLine.addArgument("-s", false); cmdLine.addArgument("${deviceSerial}", false); cmdLine.addArgument("install", false); cmdLine.addArgument(appPath, false); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); try {/*from ww w . java2s .c om*/ executor.setStreamHandler(psh); executor.execute(cmdLine); return stdout.toString(); } catch (ExecuteException e) { return Constants.UNEXPECTED_ERROR; } catch (IOException e) { return Constants.UNEXPECTED_ERROR; } }
From source file:org.rbr8.script_runner.util.BatchScriptRunner.java
public void processFile(File file) throws IOException { CommandLine cmdLine = new CommandLine(executable); cmdLine.addArguments(arguments);//from www. j av a2s. co m Map<String, Object> map = new HashMap<>(); map.put(SubstitutionHelper.FILE, file); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); // executor.setExitValue(1); // NotifierLogOutputStream outputLog = new NotifierLogOutputStream(); PumpStreamHandler psh = new PumpStreamHandler(logOutputStream); executor.setStreamHandler(psh); // ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); // executor.setWatchdog(watchdog); int exitValue = executor.execute(cmdLine); }
From source file:org.silverpeas.core.io.media.video.ffmpeg.FFmpegUtil.java
static CommandLine buildFFmpegThumbnailExtractorCommandLine(File inputFile, File outputFile, double position) { Map<String, File> files = new HashMap<>(2); files.put("inputFile", inputFile); files.put("outputFile", outputFile); CommandLine commandLine = new CommandLine("ffmpeg"); // Time of extract in seconds commandLine.addArgument("-ss", false); commandLine.addArgument(Double.toString(position), false); commandLine.addArgument("-i", false); commandLine.addArgument("${inputFile}", false); // Only one frame commandLine.addArgument("-vframes", false); commandLine.addArgument("1", false); // Resize/scale of output picture keeping aspect ratio commandLine.addArgument("-vf", false); commandLine.addArgument("scale=600:-1", false); commandLine.addArgument("${outputFile}", false); commandLine.setSubstitutionMap(files); return commandLine; }
From source file:org.silverpeas.core.viewer.util.JsonPdfUtil.java
static CommandLine buildJsonPdfCommandLine(File inputFile, File outputFile) { Map<String, File> files = new HashMap<String, File>(2); files.put("inputFile", inputFile); files.put("outputFile", outputFile); CommandLine commandLine = new CommandLine("pdf2json"); commandLine.addArgument("${inputFile}", false); commandLine.addArguments(PDF_TO_JSON_COMMON_PARAMS, false); commandLine.addArgument("${outputFile}", false); commandLine.setSubstitutionMap(files); return commandLine; }
From source file:org.silverpeas.core.viewer.util.SwfUtil.java
static CommandLine buildPdfToSwfCommandLine(final String endingCommand, File inputFile, File outputFile) { Map<String, File> files = new HashMap<>(2); files.put("inputFile", inputFile); files.put("outputFile", outputFile); CommandLine commandLine = new CommandLine("pdf2swf"); commandLine.addArgument("${inputFile}", false); commandLine.addArgument(OUTPUT_COMMAND); commandLine.addArgument("${outputFile}", false); commandLine.addArguments(TO_SWF_ENDING_COMMAND, false); if (StringUtil.isDefined(endingCommand)) { commandLine.addArguments(endingCommand, false); }/*from www . j a v a 2s . c om*/ commandLine.setSubstitutionMap(files); return commandLine; }