|
1 /* |
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 package common; |
|
24 |
|
25 import java.util.List; |
|
26 import java.util.stream.Collectors; |
|
27 |
|
28 /** |
|
29 * Common results of running an executable such as the saved exit code, the |
|
30 * saved stdout and stderr |
|
31 */ |
|
32 public class ToolResults { |
|
33 |
|
34 public int getExitCode() { |
|
35 return exitCode; |
|
36 } |
|
37 |
|
38 public List<String> getStdout() { |
|
39 return stdout; |
|
40 } |
|
41 |
|
42 public List<String> getStderr() { |
|
43 return stderr; |
|
44 } |
|
45 |
|
46 public String getStdoutString() { |
|
47 return stdout.stream().collect(Collectors.joining(System.getProperty("line.separator"))); |
|
48 } |
|
49 |
|
50 /** |
|
51 * Helper function to return a specified line from the saved stdout |
|
52 * |
|
53 * @return the line indexed with ndx from the saved stdout. The indexes are |
|
54 * zero-based so that getStdoutLine(0) returns the first line. |
|
55 */ |
|
56 public String getStdoutLine(int ndx) { |
|
57 return stdout.get(ndx); |
|
58 } |
|
59 |
|
60 public ToolResults(int exitCode, List<String> stdin, List<String> stderr) { |
|
61 this.exitCode = exitCode; |
|
62 this.stdout = stdin; |
|
63 this.stderr = stderr; |
|
64 } |
|
65 |
|
66 public ToolResults(ToolResults rawResults) { |
|
67 this(rawResults.exitCode, rawResults.stdout, rawResults.stderr); |
|
68 } |
|
69 |
|
70 @Override |
|
71 public String toString() { |
|
72 StringBuilder sb = new StringBuilder(); |
|
73 sb.append("Exit code: ").append(exitCode).append("\n"); |
|
74 sb.append("stdout:"); |
|
75 stdout.stream().forEach((s) -> { |
|
76 sb.append(s).append("\n"); |
|
77 }); |
|
78 sb.append("stderr:"); |
|
79 stderr.stream().forEach((s) -> { |
|
80 sb.append(s).append("\n"); |
|
81 }); |
|
82 return sb.toString(); |
|
83 } |
|
84 |
|
85 private final int exitCode; |
|
86 private final List<String> stdout; |
|
87 private final List<String> stderr; |
|
88 |
|
89 } |