From 90723f5382ed2a45f3ddc3ab1430358fdba75413 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Mon, 15 May 2023 11:44:47 +0800 Subject: [PATCH] fix: plugin startup failed issue on Windows system (#3925) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 2.6.x #### What this PR does / why we need it: 修复在 Windows 系统无法启动插件的问题 how to test it? 1. 使用 windows 系统环境测试插件开发模式和生产模式是否正常工作 2. 测试从 2.0.0 版本安装插件然后切换到此 PR 后插件不会出现找不到文件的错误 3. 测试插件安装和升级是否正常 #### Which issue(s) this PR fixes: Fixes #3906 #### Does this PR introduce a user-facing change? ```release-note 修复在 Windows 系统无法启动插件的问题 ``` --- .../app/core/extension/reconciler/PluginReconciler.java | 7 +++++-- .../core/extension/reconciler/PluginReconcilerTest.java | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java b/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java index 8b0067460..b8cedd315 100644 --- a/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java +++ b/application/src/main/java/run/halo/app/core/extension/reconciler/PluginReconciler.java @@ -577,7 +577,6 @@ public class PluginReconciler implements Reconciler { return pluginPath.toString(); } - /** * Returns absolute plugin path. * if plugin path is absolute, use it directly in development mode. @@ -629,7 +628,11 @@ public class PluginReconciler implements Reconciler { if (StringUtils.isBlank(pathString)) { return null; } - return Paths.get(URI.create(pathString).getPath()); + String processedPathString = pathString; + if (processedPathString.startsWith("file:")) { + processedPathString = processedPathString.substring(7); + } + return Paths.get(processedPathString); } URI toUri(String pathString) { diff --git a/application/src/test/java/run/halo/app/core/extension/reconciler/PluginReconcilerTest.java b/application/src/test/java/run/halo/app/core/extension/reconciler/PluginReconcilerTest.java index 40a85f3e6..a540d1324 100644 --- a/application/src/test/java/run/halo/app/core/extension/reconciler/PluginReconcilerTest.java +++ b/application/src/test/java/run/halo/app/core/extension/reconciler/PluginReconcilerTest.java @@ -468,6 +468,14 @@ class PluginReconcilerTest { Path path = pluginReconciler.toPath("file:///path/to/file.txt"); assertThat(path).isNotNull(); assertThat(path.toString()).isEqualTo("/path/to/file.txt"); + + assertThat(pluginReconciler.toPath("C:\\Users\\faker\\halo\\plugins").toString()) + .isEqualTo("C:\\Users\\faker\\halo\\plugins"); + assertThat(pluginReconciler.toPath("C:/Users/faker/halo/plugins").toString()) + .isEqualTo("C:/Users/faker/halo/plugins"); + Path windowsPath = Paths.get("C:/Users/username/Documents/file.txt"); + assertThat(pluginReconciler.toPath("file://C:/Users/username/Documents/file.txt")) + .isEqualTo(windowsPath); } @Test