org.zeroturnaround.exec.InvalidExitValueException Java Examples
The following examples show how to use
org.zeroturnaround.exec.InvalidExitValueException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandLine.java From testcontainers-java with MIT License | 6 votes |
/** * Run a shell command synchronously. * * @param command command to run and arguments * @return the stdout output of the command */ public static String runShellCommand(String... command) { String joinedCommand = String.join(" ", command); LOGGER.debug("Executing shell command: `{}`", joinedCommand); try { ProcessResult result = new ProcessExecutor() .command(command) .readOutput(true) .exitValueNormal() .execute(); return result.outputUTF8().trim(); } catch (IOException | InterruptedException | TimeoutException | InvalidExitValueException e) { throw new ShellCommandException("Exception when executing " + joinedCommand, e); } }
Example #2
Source File: BaseMojo.java From jax-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); log.info("Starting " + cmd + " mojo"); List<File> outputDirectories = cmd. // getDirectoryParameters() // .stream() // .map(param -> Util.createOutputDirectoryIfSpecifiedOrDefault(log, param, arguments)) .collect(Collectors.toList()); try { List<String> command = createCommand(); new ProcessExecutor() // .command(command) // .directory((project.getBasedir())) .exitValueNormal() // .redirectOutput(System.out) // .redirectError(System.out) // .execute(); outputDirectories.forEach(buildContext::refresh); addSources(log); addResources(log); } catch (InvalidExitValueException | IOException | InterruptedException | TimeoutException | DependencyResolutionRequiredException e) { throw new MojoExecutionException(e.getMessage(), e); } log.info(cmd + " mojo finished"); }
Example #3
Source File: GolangGetMojo.java From mvn-golang with Apache License 2.0 | 5 votes |
private boolean processCustomScriptCallForPackage(@Nonnull final String packageName, @Nonnull final File rootCvsFolder, @Nonnull final CustomScript script) { final List<String> command = new ArrayList<>(); command.add(script.path); if (script.options != null) { command.addAll(Arrays.asList(script.options)); } if (getLog().isDebugEnabled()) { getLog().debug("CLI : " + command); getLog().debug("Package name : " + packageName); getLog().debug("Root CVS folder : " + rootCvsFolder); } getLog().warn(String.format("Starting script in VCS folder [%s] : %s", packageName, StringUtils.join(command.toArray(), ' '))); final ProcessExecutor processExecutor = new ProcessExecutor(command.toArray(new String[0])); processExecutor .exitValueAny() .directory(rootCvsFolder) .environment("MVNGO_CVS_BRANCH", GetUtils.ensureNonNull(this.branch, "")) .environment("MVNGO_CVS_TAG", GetUtils.ensureNonNull(this.tag, "")) .environment("MVNGO_CVS_REVISION", GetUtils.ensureNonNull(this.revision, "")) .environment("MVNGO_CVS_PACKAGE", packageName) .redirectError(System.err) .redirectOutput(System.out); boolean result = false; try { final ProcessResult process = processExecutor.executeNoTimeout(); final int exitValue = process.getExitValue(); result = script.ignoreFail || exitValue == 0; } catch (IOException | InterruptedException | InvalidExitValueException ex) { getLog().error("Error in proces custom script", ex); } return result; }
Example #4
Source File: AbstractRepo.java From mvn-golang with Apache License 2.0 | 5 votes |
public int execute(@Nullable String customCommand, @Nonnull final Log logger, @Nonnull final File cvsFolder, @Nonnull @MustNotContainNull final String... args) { final List<String> cli = new ArrayList<>(); cli.add(GetUtils.findFirstNonNull(customCommand, this.command)); cli.addAll(Arrays.asList(args)); if (logger.isDebugEnabled()) { logger.debug("Executing repo command : " + cli); } final ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); final ProcessExecutor executor = new ProcessExecutor(cli); int result = -1; try { final ProcessResult processResult = executor.directory(cvsFolder).redirectError(errorStream).redirectOutput(outStream).executeNoTimeout(); result = processResult.getExitValue(); if (logger.isDebugEnabled()) { logger.debug("Exec.out........................................."); logger.debug(new String(errorStream.toByteArray(), Charset.defaultCharset())); logger.debug("................................................."); } if (result != 0) { logger.error(new String(errorStream.toByteArray(), Charset.defaultCharset())); } } catch (IOException | InterruptedException | InvalidExitValueException ex) { if (ex instanceof InterruptedException) { Thread.currentThread().interrupt(); } logger.error("Unexpected error", ex); } return result; }
Example #5
Source File: S3MockClientFactory.java From bender with Apache License 2.0 | 5 votes |
public S3MockClientFactory(int port, String username, String pass) { try { this.s3.start(port, username, pass); } catch (IOException | InterruptedException | InvalidExitValueException | TimeoutException e) { throw new RuntimeException(e); } BasicAWSCredentials awsCredentials = new BasicAWSCredentials(username, pass); this.client = new AmazonS3Client(awsCredentials, new ClientConfiguration()); this.client.setEndpoint("http://127.0.0.1:" + port); this.client.createBucket(S3_BUCKET); }
Example #6
Source File: ProcessExecutorExitValueTest.java From zt-exec with Apache License 2.0 | 4 votes |
@Test(expected=InvalidExitValueException.class) public void testJavaVersionExitValueCheck() throws Exception { new ProcessExecutor().command("java", "-version").exitValues(3).execute(); }
Example #7
Source File: ProcessExecutorExitValueTest.java From zt-exec with Apache License 2.0 | 4 votes |
@Test(expected=InvalidExitValueException.class) public void testJavaVersionExitValueCheckTimeout() throws Exception { new ProcessExecutor().command("java", "-version").exitValues(3).timeout(60, TimeUnit.SECONDS).execute(); }
Example #8
Source File: ProcessExecutorExitValueTest.java From zt-exec with Apache License 2.0 | 4 votes |
@Test(expected=InvalidExitValueException.class) public void testCustomExitValueInvalid() throws Exception { new ProcessExecutor(exitLikeABoss(17)).exitValues(15).execute(); }