From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目
---
yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java | 32 ++++++++++++++++++++++++++------
1 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java
index 7d1be13..ba0850a 100644
--- a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java
+++ b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java
@@ -108,12 +108,21 @@
asserts.forEach(assertMap -> {
String contentPath = (String) assertMap.get("contentPath");
String filePath = (String) assertMap.get("filePath");
- String expected = ResourceUtil.readUtf8Str("codegen/" + path + "/" + contentPath)
- .replace("\r\n", "\n");
+ String expected = normalizeLineEndings(ResourceUtil.readUtf8Str("codegen/" + path + "/" + contentPath));
String actual = result.get(filePath);
- assertEquals(expected, actual == null ? null : actual.replace("\r\n", "\n"),
- filePath + "锛氫笉鍖归厤");
+ assertEquals(expected, normalizeLineEndings(actual), filePath + "锛氫笉鍖归厤");
});
+ }
+
+ /**
+ * 缁熶竴鎹㈣绗﹀苟蹇界暐鏂囦欢鏈熬鎹㈣锛岄伩鍏� Windows/Unix 钀界洏宸紓瀵艰嚧蹇収鏂█澶辫触
+ */
+ private static String normalizeLineEndings(String content) {
+ if (content == null) {
+ return null;
+ }
+ content = content.replace("\r\n", "\n").replace('\r', '\n');
+ return content.replaceAll("\\n+\\z", "");
}
// ==================== 璋冭瘯涓撶敤 ====================
@@ -143,10 +152,21 @@
protected void writeResult(Map<String, String> result, String basePath) {
// 鍐欏叆鏂囦欢鍐呭
List<Map<String, String>> asserts = new ArrayList<>();
+ Set<String> usedContentPaths = new LinkedHashSet<>();
result.forEach((filePath, fileContent) -> {
String lastFilePath = StrUtil.subAfter(filePath, '/', true);
- String contentPath = StrUtil.subAfter(lastFilePath, '.', true)
- + '/' + StrUtil.subBefore(lastFilePath, '.', true);
+ String ext = StrUtil.subAfter(lastFilePath, '.', true);
+ String name = StrUtil.subBefore(lastFilePath, '.', true);
+ String contentPath = ext + '/' + name;
+ // 鍚屽悕鏂囦欢锛堝 index.vue 鍚屾椂鍑虹幇鍦� 鍒楄〃/form/detail锛変細鎾炲悕锛屾挒鍚嶆椂鍓嶇紑琛ヤ笂绾х洰褰曞尯鍒嗭紱浠嶆挒鍒欏姞搴忓彿鍏滃簳锛岄伩鍏嶅揩鐓т簰鐩歌鐩�
+ if (usedContentPaths.contains(contentPath)) {
+ String parentDir = StrUtil.subAfter(StrUtil.subBefore(filePath, '/' + lastFilePath, true), '/', true);
+ contentPath = ext + '/' + parentDir + '/' + name;
+ for (int i = 2; usedContentPaths.contains(contentPath); i++) {
+ contentPath = ext + '/' + parentDir + '/' + name + '-' + i;
+ }
+ }
+ usedContentPaths.add(contentPath);
asserts.add(MapUtil.<String, String>builder().put("filePath", filePath)
.put("contentPath", contentPath).build());
FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath);
--
Gitblit v1.9.3