diff --git a/modules/common/src/main/java/org/dromara/jpom/JpomApplication.java b/modules/common/src/main/java/org/dromara/jpom/JpomApplication.java index f1e68c408..e8d1e5fe7 100644 --- a/modules/common/src/main/java/org/dromara/jpom/JpomApplication.java +++ b/modules/common/src/main/java/org/dromara/jpom/JpomApplication.java @@ -255,7 +255,7 @@ public class JpomApplication implements DisposableBean, InitializingBean { public static void shutdownGlobalThreadPool() { LINK_EXECUTOR_SERVICE.forEach((s, executorService) -> { if (!executorService.isShutdown()) { - log.debug("shutdown {} ThreadPool", s); + log.debug(I18nMessageUtil.get("i18n.close_thread_pool.4cd9"), s); executorService.shutdownNow(); } }); diff --git a/modules/common/src/main/resources/i18n/messages_en_US.properties b/modules/common/src/main/resources/i18n/messages_en_US.properties index 4cf3d0d18..1f7a8ac1f 100644 --- a/modules/common/src/main/resources/i18n/messages_en_US.properties +++ b/modules/common/src/main/resources/i18n/messages_en_US.properties @@ -1,5 +1,5 @@ #i18n en -#Fri Jun 14 12:12:55 CST 2024 +#Fri Jun 14 12:53:47 CST 2024 i18n.ssh_info_does_not_exist.5ed0=SSH information does not exist i18n.incompatible_program_versions.5291=The current program version {} The new version of the program is minimum compatible {} and cannot be upgraded directly i18n.no_projects_configured.e873=No items are configured @@ -1051,6 +1051,7 @@ i18n.unsupported_mode_with_script_log.6a7a=Unsupported mode, script log i18n.ssh_connection_failed.74ab=SSH connection failed, please check whether the username, password, host, port, etc. are filled in correctly, and whether the timeout time is reasonable\: i18n.node_name_required.5bdf=Please fill in the node name i18n.client_terminated_connection.6886=Client side terminates connection\: {} +i18n.close_thread_pool.4cd9=Close the {} thread pool i18n.no_corresponding_folder.621f=No corresponding folder i18n.no_online_manager_node_found.05d7=The current cluster does not find an online management node i18n.command_execution_failed.90ef=Command execution failed diff --git a/modules/common/src/main/resources/i18n/messages_zh_CN.properties b/modules/common/src/main/resources/i18n/messages_zh_CN.properties index b6544b498..fd5af9f75 100644 --- a/modules/common/src/main/resources/i18n/messages_zh_CN.properties +++ b/modules/common/src/main/resources/i18n/messages_zh_CN.properties @@ -1,5 +1,5 @@ #i18n zh -#Fri Jun 14 12:12:44 CST 2024 +#Fri Jun 14 12:53:46 CST 2024 i18n.ssh_info_does_not_exist.5ed0=ssh 信息不存在啦 i18n.incompatible_program_versions.5291=当前程序版本 {} 新版程序最低兼容 {} 不能直接升级 i18n.no_projects_configured.e873=没有配置任何项目 @@ -1051,6 +1051,7 @@ i18n.unsupported_mode_with_script_log.6a7a=不支持的模式,script log i18n.ssh_connection_failed.74ab=ssh连接失败,请检查用户名、密码、host、端口等填写是否正确,超时时间是否合理: i18n.node_name_required.5bdf=请填写节点名称 i18n.client_terminated_connection.6886=客户端终止连接:{} +i18n.close_thread_pool.4cd9=关闭 {} 线程池 i18n.no_corresponding_folder.621f=没有对应文件夹 i18n.no_online_manager_node_found.05d7=当前集群未找到在线的管理节点 i18n.command_execution_failed.90ef=执行命令失败 diff --git a/modules/common/src/main/resources/i18n/words.json b/modules/common/src/main/resources/i18n/words.json index 26661b479..cb448651c 100644 --- a/modules/common/src/main/resources/i18n/words.json +++ b/modules/common/src/main/resources/i18n/words.json @@ -176,6 +176,7 @@ "i18n.close_session_exception.3491":"关闭会话异常", "i18n.close_session_exception_with_detail.85f0":"关闭会话异常:{}", "i18n.close_success.8a31":"关闭成功", + "i18n.close_thread_pool.4cd9":"关闭 {} 线程池", "i18n.cloud_server_network_issues.a865":"云服务器的安全组配置等网络相关问题排查定位。", "i18n.cluster_address_check_exception.cd92":"填写的集群地址检查异常,请确认集群地址是正确的服务端地址,", "i18n.cluster_binding_success.eb7e":"集群绑定成功", diff --git a/modules/common/src/test/java/i8n/ExtractI18nTest.java b/modules/common/src/test/java/i8n/ExtractI18nTest.java index 4f10f0ed8..0ab5b9170 100644 --- a/modules/common/src/test/java/i8n/ExtractI18nTest.java +++ b/modules/common/src/test/java/i8n/ExtractI18nTest.java @@ -29,12 +29,8 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; import java.util.function.Consumer; @@ -232,22 +228,16 @@ public class ExtractI18nTest { } // 代码中已经使用到的 key Collection useKeys = new HashSet<>(); - // 临时文件 - File tempDir = FileUtil.file(rootFile, "i18n-temp"); - // 删除临时文件 - FileUtil.del(tempDir); // 替换中文 walkFile(rootFile, file1 -> { try { for (Pattern chinesePattern : chinesePatterns) { - replaceQuotedChineseInFile(file1, tempDir, chinesePattern, chineseMap, useKeys); + replaceQuotedChineseInFile(file1, chinesePattern, chineseMap, useKeys); } } catch (Exception e) { throw Lombok.sneakyThrow(e); } }); - // 删除临时文件 - FileUtil.del(tempDir); // boolean isChange = false; for (Object keyObj : CollUtil.newArrayList(zhProperties.keySet())) { @@ -397,11 +387,11 @@ public class ExtractI18nTest { // 变动才保存 // 根据 key 排序 TreeMap sort = MapUtil.sort(updateAfter); - FileUtil.writeString(JSONArray.toJSONString(sort, JSONWriter.Feature.PrettyFormat), wordsFile, StandardCharsets.UTF_8); + FileUtil.writeString(JSONArray.toJSONString(sort, JSONWriter.Feature.PrettyFormat), wordsFile, charset); } } else { TreeMap sort = MapUtil.sort(jsonObject); - FileUtil.writeString(JSONArray.toJSONString(sort, JSONWriter.Feature.PrettyFormat), wordsFile, StandardCharsets.UTF_8); + FileUtil.writeString(JSONArray.toJSONString(sort, JSONWriter.Feature.PrettyFormat), wordsFile, charset); } } @@ -465,7 +455,7 @@ public class ExtractI18nTest { return; } String path = FileUtil.getAbsolutePath(file1); - if (StrUtil.containsAny(path, "/test/", "/i18n-temp/", "\\test\\", "\\i18n-temp\\")) { + if (StrUtil.containsAny(path, "/test/", "\\test\\")) { return; } if (StrUtil.equals("java", FileUtil.extName(file1))) { @@ -482,14 +472,12 @@ public class ExtractI18nTest { * @param pattern 当前匹配的正则 * @throws IOException io 异常 */ - private void replaceQuotedChineseInFile(File file, File tempDir, Pattern pattern, Map chineseMap, Collection useKeys) throws Exception { - String subPath = FileUtil.subPath(rootFile.getAbsolutePath(), file); + private void replaceQuotedChineseInFile(File file, Pattern pattern, Map chineseMap, Collection useKeys) throws Exception { + //String subPath = FileUtil.subPath(rootFile.getAbsolutePath(), file); // 先存储于临时文件 - File tempFile = FileUtil.file(tempDir, subPath); - FileUtil.mkParentDirs(tempFile); boolean modified = false; - try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); - BufferedWriter writer = Files.newBufferedWriter(tempFile.toPath())) { + StringWriter writer = new StringWriter(); + try (BufferedReader reader = Files.newBufferedReader(file.toPath(), charset)) { String line; while ((line = reader.readLine()) != null) { if (canIgnore(line)) { @@ -538,16 +526,16 @@ public class ExtractI18nTest { throw new IllegalStateException("替换后成为忽略行:" + line + " \n" + lineString); } writer.write(lineString); - modified = true; + if (!modified) { + modified = !StrUtil.equals(line, lineString); + } } - writer.newLine(); + writer.write(FileUtil.getLineSeparator()); } } if (modified) { // 移动到原路径 - FileUtil.move(tempFile, file, true); - } else { - FileUtil.del(tempFile); + FileUtil.writeString(writer.toString(), file, charset); } } diff --git a/modules/common/src/test/java/i8n/RestoreI18nTest.java b/modules/common/src/test/java/i8n/RestoreI18nTest.java index 2e1017cbb..3be854f15 100644 --- a/modules/common/src/test/java/i8n/RestoreI18nTest.java +++ b/modules/common/src/test/java/i8n/RestoreI18nTest.java @@ -16,12 +16,8 @@ import lombok.Lombok; import org.junit.Before; import org.junit.Test; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Properties; import java.util.regex.Matcher; @@ -53,13 +49,11 @@ public class RestoreI18nTest { try (BufferedReader inputStream = FileUtil.getReader(zhPropertiesFile, charset)) { zhProperties.load(inputStream); } - // 临时文件 - File tempDir = FileUtil.file(rootFile, "i18n-temp"); // 提取中文 ExtractI18nTest.walkFile(rootFile, file1 -> { try { for (Pattern pattern : ExtractI18nTest.messageKeyPatterns) { - restoreChineseInFile(file1, tempDir, pattern, zhProperties); + restoreChineseInFile(file1, pattern, zhProperties); } } catch (Exception e) { throw Lombok.sneakyThrow(e); @@ -67,14 +61,10 @@ public class RestoreI18nTest { }); } - private void restoreChineseInFile(File file, File tempDir, Pattern pattern, Properties zhProperties) throws Exception { - String subPath = FileUtil.subPath(rootFile.getAbsolutePath(), file); - // 先存储于临时文件 - File tempFile = FileUtil.file(tempDir, subPath); - FileUtil.mkParentDirs(tempFile); + private void restoreChineseInFile(File file, Pattern pattern, Properties zhProperties) throws Exception { + StringWriter writer = new StringWriter(); boolean modified = false; - try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); - BufferedWriter writer = Files.newBufferedWriter(tempFile.toPath())) { + try (BufferedReader reader = Files.newBufferedReader(file.toPath(), charset)) { String line; while ((line = reader.readLine()) != null) { if (ExtractI18nTest.canIgnore(line)) { @@ -114,17 +104,18 @@ public class RestoreI18nTest { } matcher.appendTail(modifiedLine); } - writer.write(modifiedLine.toString()); - modified = true; + String lineString = modifiedLine.toString(); + writer.write(lineString); + if (!modified) { + modified = !StrUtil.equals(line, lineString); + } } - writer.newLine(); + writer.write(FileUtil.getLineSeparator()); } } if (modified) { // 移动到原路径 - FileUtil.move(tempFile, file, true); - } else { - FileUtil.del(tempFile); + FileUtil.writeString(writer.toString(), file, charset); } } }