@Override protected void runWithForkedJvm(List<String> args) throws MojoExecutionException { try { RunProcess runProcess = new RunProcess(new JavaExecutable().toString()); Runtime.getRuntime() .addShutdownHook(new Thread(new RunProcessKiller(runProcess))); int exitCode = runProcess.run(true, args.toArray(new String[args.size()])); if (exitCode != 0) { throw new MojoExecutionException( "Application finished with non-zero exit code: " + exitCode); } } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex); } }
protected ExitStatus run(Collection<String> args) throws IOException { this.process = new RunProcess(this.command); int code = this.process.run(true, args.toArray(new String[args.size()])); if (code == 0) { return ExitStatus.OK; } else { return new ExitStatus(code, "EXTERNAL_ERROR"); } }
@Override protected void runWithForkedJvm(List<String> args) throws MojoExecutionException { try { RunProcess runProcess = new RunProcess(new JavaExecutable().toString()); Runtime.getRuntime() .addShutdownHook(new Thread(new RunProcessKiller(runProcess))); runProcess.run(true, args.toArray(new String[args.size()])); } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex); } }
@Override protected void runWithForkedJvm(List<String> args) throws MojoExecutionException { try { new RunProcess(new JavaExecutable().toString()).run(true, args.toArray(new String[args.size()])); } catch (Exception ex) { throw new MojoExecutionException("Could not exec java", ex); } }
private void sh(String line) { // Remove leading command line = line.substring(Constants.SHELL_ESCAPE.length()); // Expand all env variables line = StringUtils.expandEnvironmentVarsAndHomeDir(line); // Split multiple commands into several commands that we run one ofter the other String[] cmds = line.split("&&"); // Iterate all commands Arrays.stream(cmds).forEach(c -> { String[] args = CommandUtils.splitCommandline(c); RunProcess process = new RunProcess(SystemUtils.getUserDir(), args[0]); try { // Change the working directory of this shell if ("cd".equals(args[0])) { if (args.length > 1) { String path = args[1]; File p = new File(path); if (p.exists()) { System.setProperty("user.dir", p.getCanonicalPath()); } else { File workingDir = new File(SystemUtils.getUserDir(), path); System.setProperty("user.dir", workingDir.getCanonicalPath()); } } } else { int rc = process.run(true, Arrays.copyOfRange(args, 1, args.length)); if (rc > 0) { throw new CommandException("Command excited with " + rc + " return code"); } } } catch (IOException e) { log.error(e.getMessage()); throw new RunnerException(e); } }); // After a shell command we need to restore the signal handler lineReader().getTerminal().handle(Terminal.Signal.INT, signalHandler()); }
private RunProcessKiller(RunProcess runProcess) { this.runProcess = runProcess; }