From d45720d3e42c6c5a66e43547fa43cc6999ce8d44 Mon Sep 17 00:00:00 2001 From: jade Date: Tue, 8 Sep 2026 14:11:29 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20HTTP=20Tool=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=8B=9C=20dat-was-lib=EC=9D=98=20application-glow-local.yml?= =?UTF-8?q?=20=ED=83=90=EC=83=89=20=EB=B0=8F=20append=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dat/lib/util/ToolScaffolder.java | 99 +++++++++++++++++-- 1 file changed, 89 insertions(+), 10 deletions(-) diff --git a/dat-was-lib/src/main/java/io/shinhanlife/dat/lib/util/ToolScaffolder.java b/dat-was-lib/src/main/java/io/shinhanlife/dat/lib/util/ToolScaffolder.java index 55b612bc..a9d2282f 100644 --- a/dat-was-lib/src/main/java/io/shinhanlife/dat/lib/util/ToolScaffolder.java +++ b/dat-was-lib/src/main/java/io/shinhanlife/dat/lib/util/ToolScaffolder.java @@ -8,6 +8,7 @@ import java.nio.file.Paths; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; @@ -139,8 +140,9 @@ public class ToolScaffolder { for (ToolMethodDefinition tool : tools) { writeGroupedToolFiles(moduleRoot, sourceRoot, dtoDir, definitionDir, bizPackage, tool, moduleName, log); if ("HTTP".equalsIgnoreCase(tool.routingType())) { - ensureLocalHttpApiConfiguration(moduleRoot, tool.httpApiName(), + Path glowConfig = ensureLocalHttpApiConfiguration(moduleRoot, tool.httpApiName(), toToolName(moduleName, tool.group(), toPascalCase(tool.baseName()))); + log.append("[HTTP Config] ").append(glowConfig).append("\n"); } } log.append("[Converter] ").append(converterFile).append("\n"); @@ -1546,7 +1548,8 @@ public class ToolScaffolder { if (isHttp) { Path moduleRoot = rootDir.resolve(moduleName).toAbsolutePath().normalize(); Path projectRoot = moduleRoot.getParent(); - ensureLocalHttpApiConfiguration(projectRoot, httpApiName, toolName); + Path glowConfig = ensureLocalHttpApiConfiguration(projectRoot, httpApiName, toolName); + log.append("[HTTP Config] ").append(glowConfig).append("\n"); } Path generatedTestDir = rootDir.resolve(Paths.get(moduleName, "src/test/java/io/shinhanlife/dat/mcc/biz", group.toLowerCase(), "usecase")); @@ -1757,13 +1760,76 @@ public class ToolScaffolder { .toLowerCase(Locale.ROOT); } - private static void ensureLocalHttpApiConfiguration(Path projectRoot, String httpApiName, String toolName) throws IOException { - Path localConfigPath = projectRoot.resolve("src/main/resources/glow/application-glow-local.yml"); + private static Path findGlowLocalConfigPath(Path startPath) { + String sourceDir = System.getProperty("AXHUB_SOURCE_DIR"); + if (sourceDir == null) { + sourceDir = System.getenv("AXHUB_SOURCE_DIR"); + } + + List baseDirs = new ArrayList<>(); + if (startPath != null) { + baseDirs.add(startPath); + if (startPath.getParent() != null) { + baseDirs.add(startPath.getParent()); + } + } + if (sourceDir != null && !sourceDir.isBlank()) { + baseDirs.add(Paths.get(sourceDir.trim())); + } + baseDirs.add(Paths.get(".")); + + String[] subPaths = { + "dat-was-lib/src/main/resources/glow", + "src/main/resources/glow" + }; + String[] fileNames = { + "application-glow-local.yml", + "application-glow-local.yaml", + "application-glow-local.xml" + }; + + // 1. 이미 존재하는 파일 우선 탐색 (dat-was-lib 우선) + for (Path base : baseDirs) { + for (String sub : subPaths) { + for (String name : fileNames) { + Path candidate = base.resolve(sub).resolve(name).normalize(); + if (Files.exists(candidate)) { + return candidate; + } + } + } + } + + // 2. dat-was-lib 디렉토리가 존재하는 디렉토리 찾기 + for (Path base : baseDirs) { + Path libDir = base.resolve("dat-was-lib"); + if (Files.isDirectory(libDir)) { + return libDir.resolve("src/main/resources/glow/application-glow-local.yml").normalize(); + } + } + + // 3. startPath 형제(sibling)로 dat-was-lib 찾기 + if (startPath != null) { + Path libSibling = startPath.resolveSibling("dat-was-lib"); + if (Files.isDirectory(libSibling)) { + return libSibling.resolve("src/main/resources/glow/application-glow-local.yml").normalize(); + } + } + + // 4. Fallback + if (sourceDir != null && !sourceDir.isBlank()) { + return Paths.get(sourceDir.trim()).resolve("dat-was-lib/src/main/resources/glow/application-glow-local.yml").normalize(); + } + return Paths.get("dat-was-lib/src/main/resources/glow/application-glow-local.yml").normalize(); + } + + private static Path ensureLocalHttpApiConfiguration(Path projectRoot, String httpApiName, String toolName) throws IOException { + Path localConfigPath = findGlowLocalConfigPath(projectRoot); Files.createDirectories(localConfigPath.getParent()); String existing = Files.exists(localConfigPath) ? Files.readString(localConfigPath, StandardCharsets.UTF_8) : ""; if (java.util.regex.Pattern.compile("(?m)^\\s*-\\s+name:\\s*" + java.util.regex.Pattern.quote(httpApiName) + "\\s*$").matcher(existing).find()) { - return; + return localConfigPath; } String environmentKey = toPackageSegment(httpApiName).toUpperCase(Locale.ROOT).replace('-', '_'); String apiEntry = """ @@ -1774,6 +1840,9 @@ public class ToolScaffolder { content-type: application/json;charset=UTF-8 biz-pod: false """.formatted(httpApiName, environmentKey, environmentKey, toolName).stripTrailing() + "\n"; + boolean isCrlf = existing.contains("\r\n"); + String formattedApiEntry = isCrlf ? apiEntry.replace("\n", "\r\n") : apiEntry; + if (existing.isBlank()) { existing = """ spring: @@ -1786,25 +1855,35 @@ public class ToolScaffolder { http: api-list: """ + apiEntry; + if (isCrlf) { + existing = existing.replace("\n", "\r\n"); + } + } else if (existing.contains("\r\n mci:")) { + existing = existing.replace("\r\n mci:", "\r\n" + formattedApiEntry + " mci:"); } else if (existing.contains("\n mci:")) { - existing = existing.replace("\n mci:", "\n" + apiEntry + " mci:"); + existing = existing.replace("\n mci:", "\n" + formattedApiEntry + " mci:"); + } else if (existing.contains("\r\naxhub:")) { + existing = existing.replace("\r\naxhub:", "\r\n" + formattedApiEntry + "axhub:"); } else if (existing.contains("\naxhub:")) { - existing = existing.replace("\naxhub:", apiEntry + "axhub:"); + existing = existing.replace("\naxhub:", "\n" + formattedApiEntry + "axhub:"); } else if (existing.contains("api-list:")) { - existing += apiEntry; + existing += formattedApiEntry; } else { throw new IllegalStateException("application-glow-local.yml must define glow.communication.http.api-list"); } - if (!existing.contains("axhub:\n mock:\n http:\n enabled: true")) { - existing += """ + if (!existing.contains("axhub:\n mock:\n http:\n enabled: true") + && !existing.contains("axhub:\r\n mock:\r\n http:\r\n enabled: true")) { + String mockConfig = """ axhub: mock: http: enabled: true """; + existing += isCrlf ? mockConfig.replace("\n", "\r\n") : mockConfig; } writeUtf8(localConfigPath, existing); + return localConfigPath; } private static void writeUtf8(Path path, String content) throws IOException {