From f0a38f75f840344cc7d49fae684a70b39e379a7e Mon Sep 17 00:00:00 2001 From: linhplus Date: Thu, 1 May 2025 22:11:35 +0700 Subject: [PATCH] fix: Do not copy Tomcat configs file when /.smarttomcat//conf folder is empty --- .../tomcat/conf/TomcatCommandLineState.java | 2 +- .../idea/plugins/tomcat/utils/PluginUtils.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/poratu/idea/plugins/tomcat/conf/TomcatCommandLineState.java b/src/main/java/com/poratu/idea/plugins/tomcat/conf/TomcatCommandLineState.java index fda6bd6..06d27e6 100644 --- a/src/main/java/com/poratu/idea/plugins/tomcat/conf/TomcatCommandLineState.java +++ b/src/main/java/com/poratu/idea/plugins/tomcat/conf/TomcatCommandLineState.java @@ -120,7 +120,7 @@ protected JavaParameters createJavaParameters() { //copy to project folder, and then user is able to update server.xml under the project. Path projectConfPath = Paths.get(project.getBasePath(), ".smarttomcat", module.getName(), "conf"); - if (!projectConfPath.toFile().exists()) { + if (!projectConfPath.toFile().exists() || PluginUtils.isEmptyFolder(projectConfPath)) { FileUtil.createDirectory(projectConfPath.toFile()); FileUtil.copyDir(tomcatInstallationPath.resolve("conf").toFile(), projectConfPath.toFile()); } diff --git a/src/main/java/com/poratu/idea/plugins/tomcat/utils/PluginUtils.java b/src/main/java/com/poratu/idea/plugins/tomcat/utils/PluginUtils.java index 33d6363..2ace189 100644 --- a/src/main/java/com/poratu/idea/plugins/tomcat/utils/PluginUtils.java +++ b/src/main/java/com/poratu/idea/plugins/tomcat/utils/PluginUtils.java @@ -309,4 +309,22 @@ public static List getModules(Project project) { return ModuleUtilCore.findModuleForFile(virtualFile, project); } + + /** + * Checks if the given folder is empty. + * + * @param path the path to the folder + * @return {@code true} if the folder exists and is empty, {@code false} otherwise + * @throws IOException if an I/O error occurs + */ + + public static boolean isEmptyFolder(Path path) throws IOException { + if (Files.isDirectory(path)) { + try (Stream entries = Files.list(path)) { + return !entries.findFirst().isPresent(); + } + } + return false; + } + }