fix: plugin startup failed issue on Windows system (#3925)

#### 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 系统无法启动插件的问题
```
pull/3954/head
guqing 2023-05-15 11:44:47 +08:00 committed by GitHub
parent 017bb55521
commit 90723f5382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -577,7 +577,6 @@ public class PluginReconciler implements Reconciler<Request> {
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<Request> {
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) {

View File

@ -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