Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
Send notifications only once when process output was read
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii Chepeliuk committed Feb 15, 2018
1 parent 66115fa commit fa480d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public void executeAsync(List<String> args, Watcher w) {
final Process p = pb.start();
Callable<String> inputRead = () -> readOutput(OUTPUT_TYPE_STD,p.getInputStream(), true);
Callable<String> errorRead = () -> readOutput(OUTPUT_TYPE_ERROR,p.getErrorStream(),true);
Future<String> cmdInput = executorService.submit(inputRead);
Future<String> cmdOut = executorService.submit(inputRead);
Future<String> cmdErr = executorService.submit(errorRead);
String input = cmdInput.get();
String out = cmdOut.get();
String error = cmdErr.get();
if (!error.isEmpty()) {
w.onError(new CLIException(error));
}
else if (!input.isEmpty()) {
w.onSuccess(input);
else if (!out.isEmpty()) {
w.onSuccess(out);
} else
p.destroyForcibly();
} catch (Exception e) {
Expand All @@ -103,17 +103,19 @@ private String readOutput(String outputType,InputStream in, Boolean shouldNotify
try (BufferedReader bf = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = bf.readLine()) != null) {
if (shouldNotify) {
if (outputType.equals(OUTPUT_TYPE_ERROR)) {
this.notificationsService.notifyError("cli error", line);
} else {
this.notificationsService.notifyInformation("cli output", line);
}
}
sb.append(line).append(System.lineSeparator());
}
}
return sb.toString();

String out = sb.toString();
if (shouldNotify) {
if (outputType.equals(OUTPUT_TYPE_ERROR)) {
this.notificationsService.notifyError("cli error", out);
} else {
this.notificationsService.notifyInformation("cli output", out);
}
}
return out;
}

public static CLIRunner getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ private NotificationListener getNotificationListener() {
MobileNotificationsService.getInstance().notifyError("Error from mobile plugin: " + ex.toString());
}
break;
default:
throw new CLIException("no other settings are supported atm.");
}
};
}
Expand Down

0 comments on commit fa480d5

Please sign in to comment.