From 354d85e3600f0d51cfd16dbdbd877a9af99a8df1 Mon Sep 17 00:00:00 2001 From: Sudharaka Palamakumbura Date: Sun, 16 Aug 2020 12:25:16 -0700 Subject: [PATCH] feat: add generation process error stream to debug log (#220) This adds the generation process error stream to debug log since otherwise there's a possibility that the buffer gets filled up and blocks the generation process. Related to https://github.com/jhipster/jhipster-online/issues/184 --- .../online/service/JHipsterService.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/jhipster/online/service/JHipsterService.java b/src/main/java/io/github/jhipster/online/service/JHipsterService.java index 1b11211a..f46c5770 100644 --- a/src/main/java/io/github/jhipster/online/service/JHipsterService.java +++ b/src/main/java/io/github/jhipster/online/service/JHipsterService.java @@ -86,6 +86,7 @@ public void addCiCd(String generationId, File workingDir, CiCdTool ciCdTool) thr private void runProcess(String generationId, File workingDir, String command) throws IOException { log.info("Running command: \"{}\" in directory: \"{}\"", command, workingDir); BufferedReader input = null; + BufferedReader error = null; try { String line; Process p = Runtime.getRuntime().exec @@ -94,28 +95,37 @@ private void runProcess(String generationId, File workingDir, String command) th taskExecutor.execute(() -> { try { p.waitFor(timeout, TimeUnit.SECONDS); - if (p.isAlive()) { - p.destroyForcibly(); - } + p.destroyForcibly(); } catch (InterruptedException e) { log.error("Unable to execute process successfully.", e); Thread.currentThread().interrupt(); } }); + error = new BufferedReader( + new InputStreamReader(p.getErrorStream())); + while ((line = error.readLine()) != null) { + log.debug(line); + } + input = new BufferedReader (new InputStreamReader(p.getInputStream())); - while (input.ready() && (line = input.readLine()) != null) { + while ((line = input.readLine()) != null) { log.debug(line); this.logsService.addLog(generationId, line); } + input.close(); + error.close(); } catch (Exception e) { log.error("Error while running the process", e); if (input != null) { input.close(); } + if (error != null) { + error.close(); + } throw e; } }