From fa480d5e95b0a0a00cb3b3dc82e600f6e14461e8 Mon Sep 17 00:00:00 2001 From: Vitalii Chepeliuk Date: Thu, 15 Feb 2018 16:29:25 +0100 Subject: [PATCH] Send notifications only once when process output was read --- .../intellij/mobile/api/CLIRunnerImpl.java | 26 ++++++++++--------- .../ServiceDeployedNotification.java | 2 ++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java b/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java index bc3f030..e7a8662 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/api/CLIRunnerImpl.java @@ -79,15 +79,15 @@ public void executeAsync(List args, Watcher w) { final Process p = pb.start(); Callable inputRead = () -> readOutput(OUTPUT_TYPE_STD,p.getInputStream(), true); Callable errorRead = () -> readOutput(OUTPUT_TYPE_ERROR,p.getErrorStream(),true); - Future cmdInput = executorService.submit(inputRead); + Future cmdOut = executorService.submit(inputRead); Future 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) { @@ -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() { diff --git a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java index bc2b62a..aa17020 100644 --- a/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java +++ b/src/main/java/org/aerogear/plugin/intellij/mobile/ui/sdkconfig/ServiceDeployedNotification.java @@ -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."); } }; }