package com.perforce.hws.util; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.stream.Collectors; /** * Created by tjuricek on 2/4/16. */ public interface ProcessHelpers extends StreamUtils { default String execOutOrFail(String... command) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(); pb.redirectErrorStream(); pb.command(command); Process p = pb.start(); StreamReaderThread stdout = new StreamReaderThread(p.getInputStream()); stdout.start(); p.waitFor(); stdout.join(); if (p.exitValue() == 0) { return stdout.getStringBuffer().toString(); } else { String cmd = Arrays.stream(command).collect(Collectors.joining(" ")); throw new IllegalStateException(cmd + " failed with code " + p.exitValue() + "\n" + stdout.getStringBuffer().toString()); } } default String execOutOrFailInDir(String cwd, String... command) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(); pb.redirectErrorStream(); pb.command(command); pb.directory(new File(cwd)); Process p = pb.start(); StreamReaderThread stdout = new StreamReaderThread(p.getInputStream()); stdout.start(); p.waitFor(); stdout.join(); if (p.exitValue() == 0) { return stdout.getStringBuffer().toString(); } else { String cmd = Arrays.stream(command).collect(Collectors.joining(" ")); throw new IllegalStateException(cmd + " failed with code " + p.exitValue() + "\n" + stdout.getStringBuffer().toString()); } } default void execOrFail(String... command) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(); pb.command(command); pb.redirectErrorStream(true); Process p = pb.start(); StreamReaderThread stdout = new StreamReaderThread(p.getInputStream()); stdout.start(); p.waitFor(); stdout.join(); if (p.exitValue() != 0) { String cmd = Arrays.stream(command).collect(Collectors.joining(" ")); throw new IllegalStateException(cmd + " failed with code " + p.exitValue() + "\n" + stdout.getStringBuffer().toString()); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19535 | drobins | Refactor package names to hws | ||
//guest/perforce_software/helix-web-services/main/source/jdk_extensions/src/main/java/com/perforce/helix_web_services/jdk_extensions/ProcessHelpers.java | |||||
#5 | 19269 | tjuricek | Create infrastructure for calling python tests via TestNG, with our first (basic login) test. | ||
#4 | 19235 | tjuricek | The server spec crud test didn't run as super (hence a failure) and we needed to wait for buffered reading to finish before moving ahead with background processes. | ||
#3 | 19204 | tjuricek | Add StreamReaderThread concept for process launching, and using that by default to interact with background processes. | ||
#2 | 18262 | tjuricek |
The dpkg -l call seemed to hang because the process tried to wait before it finished reading the stream output. |
||
#1 | 18210 | tjuricek |
Switch to building RPMs via rpmbuild. The install4j .rpm works, but, doesn't give you access to metadata fields that are pretty important to repository managers. (Their workflow is that the user downloads the rpm and just installs it, which means no "yum install helix-web-services".) |
||
//guest/perforce_software/helix-web-services/main/source/deployment/src/main/java/com/perforce/helix_web_services/deployment/ProcessHelpers.java | |||||
#1 | 18035 | tjuricek |
Preliminary distribution formats with first-pass post-install configuration script for Linux only. This is *manually verified* at the moment. The testing framework is TBD. This contains *preliminary* hooks for .deb and .rpm packages. Those are *completely untested* and not configured. |