修复:将消息中心运行目录移出工作区

This commit is contained in:
xiaowang
2026-03-24 16:16:10 +08:00
parent 23d794b261
commit d33036be63
2 changed files with 51 additions and 6 deletions
@@ -17,18 +17,21 @@ import java.nio.file.Paths;
@SpringBootApplication
public class MessageHubApplication {
private static final String APP_RUNTIME_DIR = "YumiNail";
private static final String MODULE_RUNTIME_DIR = "MessageHub";
public static void main(String[] args) {
configureNacosRuntimePaths();
SpringApplication.run(MessageHubApplication.class, args);
}
private static void configureNacosRuntimePaths() {
configurePathIfAbsent("JM.LOG.PATH", resolveRuntimePath("logs", true));
configurePathIfAbsent("JM.SNAPSHOT.PATH", resolveRuntimePath("nacos-snapshot", false));
configurePathIfAbsent("JM.LOG.PATH", "logs", true);
configurePathIfAbsent("JM.SNAPSHOT.PATH", "nacos-snapshot", false);
}
private static String resolveRuntimePath(String child, boolean includeNacosDir) {
Path path = Paths.get(System.getProperty("user.dir"), child);
Path path = resolveBaseRuntimePath().resolve(child);
try {
Files.createDirectories(path);
if (includeNacosDir) {
@@ -40,10 +43,22 @@ public class MessageHubApplication {
return path.toAbsolutePath().toString();
}
private static void configurePathIfAbsent(String key, String value) {
private static Path resolveBaseRuntimePath() {
String localAppData = System.getenv("LOCALAPPDATA");
if (hasText(localAppData)) {
return Paths.get(localAppData, APP_RUNTIME_DIR, MODULE_RUNTIME_DIR);
}
return Paths.get(System.getProperty("user.home"), ".yuminail", MODULE_RUNTIME_DIR.toLowerCase());
}
private static void configurePathIfAbsent(String key, String child, boolean includeNacosDir) {
String currentValue = System.getProperty(key);
if (currentValue == null || currentValue.trim().isEmpty()) {
System.setProperty(key, value);
if (!hasText(currentValue)) {
System.setProperty(key, resolveRuntimePath(child, includeNacosDir));
}
}
private static boolean hasText(String value) {
return value != null && !value.trim().isEmpty();
}
}