@@ -52,21 +52,38 @@ public List<String> run(List<String> command) {
52
52
return run (command .toArray (new String [0 ]));
53
53
}
54
54
55
+ public List <String > runSilently (List <String > command ) {
56
+ return run (false , command .toArray (new String [0 ]));
57
+ }
58
+
59
+ public List <String > runSilently (String ... command ) {
60
+ return run (false , command );
61
+ }
62
+
55
63
public List <String > run (String ... command ) {
64
+ return run (true , command );
65
+ }
66
+
67
+ private List <String > run (boolean shouldLog , String ... command ) {
56
68
List <String > lines = new ArrayList <>();
57
69
String [] processedCommand = processCommand (command );
58
70
try {
71
+ log .info ("About to start command {}" , (Object ) processedCommand );
59
72
Process process = startProcess (processedCommand );
60
73
61
- log .info ("Printing out process logs:\n \n " );
74
+ if (shouldLog ) {
75
+ log .info ("Printing out process logs:\n \n " );
76
+ }
62
77
63
78
List <String > errorLines = new ArrayList <>();
64
79
65
80
Thread outputThread = new Thread (() -> {
66
81
try (BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()))) {
67
82
String line ;
68
83
while ((line = reader .readLine ()) != null ) {
69
- log .info (line );
84
+ if (shouldLog ) {
85
+ log .info (line );
86
+ }
70
87
lines .add (line );
71
88
}
72
89
}
@@ -99,12 +116,13 @@ public List<String> run(String... command) {
99
116
if (exitCode != 0 ) {
100
117
String errorMessage = String .format ("Failed to run the command %s. Exit code: %d.%nError output:%n%s" ,
101
118
Arrays .toString (processedCommand ), exitCode , String .join ("\n " , errorLines ));
102
- throw new RuntimeException (errorMessage );
119
+ throw new IllegalStateException (errorMessage );
103
120
}
104
121
}
105
122
catch (IOException | InterruptedException e ) {
106
- throw new RuntimeException ("A failure around the process execution happened" , e );
123
+ throw new IllegalStateException ("A failure around the process execution happened" , e );
107
124
}
125
+ log .info ("Command executed successfully" );
108
126
return lines ;
109
127
}
110
128
0 commit comments