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; + } + }