From 100057a34b58c6e36a20d8c38475a19fe09639b2 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 8 Jun 2023 14:59:25 -0500 Subject: [PATCH 1/2] Make handling of temp config dir better and tolerate exceptions during shutdown/cleanup --- .../tools/common/plugins/util/DevUtil.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java b/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java index b358bec7..73951854 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java @@ -2024,7 +2024,7 @@ public void cleanUpServerEnv() { // Delete server.env file serverEnvFile.delete(); } - } catch (IOException e) { + } catch (Exception e) { error("Could not retrieve server.env: " + e.getMessage()); } } @@ -2036,7 +2036,7 @@ public void cleanUpTempConfig() { try { FileUtils.deleteDirectory(tempConfig); debug("Successfully deleted liberty:dev temporary configuration folder"); - } catch (IOException e) { + } catch (Exception e) { warn("Could not delete liberty:dev temporary configuration folder: " + e.getMessage()); } } @@ -2050,7 +2050,7 @@ public void cleanUpTempDockerfile() { try { Files.delete(tempDockerfilePath); debug("Successfully deleted dev mode temporary Dockerfile"); - } catch (IOException e) { + } catch (Exception e) { warn("Could not delete dev mode temporary Dockerfile: " + e.getMessage()); } } @@ -2078,30 +2078,34 @@ public void run() { } private void runShutdownHook(final ThreadPoolExecutor executor) { - if (!calledShutdownHook.getAndSet(true)) { - - if (trackingMode == FileTrackMode.POLLING || trackingMode == FileTrackMode.NOT_SET) { - disablePolling(); - } - - setDevStop(true); - cleanUpTempConfig(); - cleanUpServerEnv(); - - if (hotkeyReader != null) { - hotkeyReader.shutdown(); - } - - // shutdown tests - executor.shutdown(); + try { + if (!calledShutdownHook.getAndSet(true)) { - // stopping server - if (container) { - cleanUpTempDockerfile(); - stopContainer(); - } else { - stopServer(); + if (trackingMode == FileTrackMode.POLLING || trackingMode == FileTrackMode.NOT_SET) { + disablePolling(); + } + + setDevStop(true); + cleanUpTempConfig(); + cleanUpServerEnv(); + + if (hotkeyReader != null) { + hotkeyReader.shutdown(); + } + + // shutdown tests + executor.shutdown(); + + // stopping server + if (container) { + cleanUpTempDockerfile(); + stopContainer(); + } else { + stopServer(); + } } + } catch (Exception e) { + warn("Received exception during server shutdown and cleanup: " + e.getMessage()); } } @@ -4556,8 +4560,8 @@ public boolean accept(File pathname) { // - ignore list // - workarea and logs dirs from the server directory, since those can be // changing - boolean skip = ignoreFileOrDir(pathname) - || (pathname.isDirectory() && (name.equals("workarea") || name.equals("logs"))); + boolean skip = ignoreFileOrDir(pathname) || (pathname.isDirectory() && + (name.equals("workarea") || name.equals("logs") || name.equals("messageStore") || name.equals("Log"))); return !skip; } }, true); From c2b9fcb1471a1fc9e2d9a280055a000912e2109b Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Thu, 8 Jun 2023 15:36:08 -0500 Subject: [PATCH 2/2] Tweaked check for messaging dir --- .../io/openliberty/tools/common/plugins/util/DevUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java b/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java index 73951854..380624af 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/DevUtil.java @@ -4556,12 +4556,14 @@ public void installFeaturesToTempDir(File fileChanged, File srcDir, String targe FileUtils.copyDirectory(serverDirectory, tempConfig, new FileFilter() { public boolean accept(File pathname) { String name = pathname.getName(); + String parent = pathname.getParentFile().getName(); + String serverDirName = serverDirectory.getName(); // skip: // - ignore list - // - workarea and logs dirs from the server directory, since those can be + // - workarea, messaging and logs dirs from the server directory, since those can be // changing boolean skip = ignoreFileOrDir(pathname) || (pathname.isDirectory() && - (name.equals("workarea") || name.equals("logs") || name.equals("messageStore") || name.equals("Log"))); + (name.equals("workarea") || name.equals("logs") || (name.equals("messaging") && parent.equals(serverDirName)))); return !skip; } }, true);