HADOOP-12479. ProtocMojo does not log the reason for a protoc compilation failure. Contributed by Chris Nauroth.

(cherry picked from commit fdd7406224)
This commit is contained in:
cnauroth 2015-10-15 15:54:48 -07:00
parent afa57f1b48
commit adb015847d
3 changed files with 26 additions and 2 deletions

View File

@ -643,6 +643,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12475. Replace guava Cache with ConcurrentHashMap for caching HADOOP-12475. Replace guava Cache with ConcurrentHashMap for caching
Connection in ipc Client (Walter Su via sjlee) Connection in ipc Client (Walter Su via sjlee)
HADOOP-12479. ProtocMojo does not log the reason for a protoc compilation
failure. (cnauroth)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

View File

@ -248,11 +248,15 @@ public class ProtocMojo extends AbstractMojo {
exec = new Exec(this); exec = new Exec(this);
out = new ArrayList<String>(); out = new ArrayList<String>();
if (exec.run(command, out) != 0) { List<String> err = new ArrayList<>();
if (exec.run(command, out, err) != 0) {
getLog().error("protoc compiler error"); getLog().error("protoc compiler error");
for (String s : out) { for (String s : out) {
getLog().error(s); getLog().error(s);
} }
for (String s : err) {
getLog().error(s);
}
throw new MojoExecutionException("protoc failure"); throw new MojoExecutionException("protoc failure");
} }
// Write the new checksum file on success. // Write the new checksum file on success.

View File

@ -48,6 +48,20 @@ public class Exec {
* @return int exit code of command * @return int exit code of command
*/ */
public int run(List<String> command, List<String> output) { public int run(List<String> command, List<String> output) {
return this.run(command, output, null);
}
/**
* Runs the specified command and saves each line of the command's output to
* the given list and each line of the command's stderr to the other list.
*
* @param command List containing command and all arguments
* @param output List in/out parameter to receive command output
* @param errors List in/out parameter to receive command stderr
* @return int exit code of command
*/
public int run(List<String> command, List<String> output,
List<String> errors) {
int retCode = 1; int retCode = 1;
ProcessBuilder pb = new ProcessBuilder(command); ProcessBuilder pb = new ProcessBuilder(command);
try { try {
@ -66,6 +80,9 @@ public class Exec {
stdOut.join(); stdOut.join();
stdErr.join(); stdErr.join();
output.addAll(stdOut.getOutput()); output.addAll(stdOut.getOutput());
if (errors != null) {
errors.addAll(stdErr.getOutput());
}
} catch (Exception ex) { } catch (Exception ex) {
mojo.getLog().warn(command + " failed: " + ex.toString()); mojo.getLog().warn(command + " failed: " + ex.toString());
} }