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 e4cb26bfa..1ba7f1356 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 @@ -118,15 +118,13 @@ public class PluginReconciler implements Reconciler { client.fetch(Plugin.class, name).ifPresent(plugin -> { Map annotations = nullSafeAnnotations(plugin); String oldPluginPath = annotations.get(PLUGIN_PATH); - String pluginPath = oldPluginPath; - if (StringUtils.isBlank(pluginPath)) { - URI loadLocation = plugin.statusNonNull().getLoadLocation(); - pluginPath = Optional.ofNullable(loadLocation) - .map(URI::getPath) - .orElseGet(() -> PluginUtils.generateFileName(plugin)); - } - annotations.put(PLUGIN_PATH, pluginPath); - if (!StringUtils.equals(pluginPath, oldPluginPath)) { + String pluginPath = StringUtils.isBlank(oldPluginPath) + ? Optional.ofNullable(plugin.statusNonNull().getLoadLocation()) + .map(URI::getPath) + .orElseGet(() -> PluginUtils.generateFileName(plugin)) : oldPluginPath; + String pluginPathAnno = resolvePluginPathForAnno(pluginPath); + annotations.put(PLUGIN_PATH, pluginPathAnno); + if (!StringUtils.equals(pluginPathAnno, oldPluginPath)) { client.update(plugin); } }); @@ -555,7 +553,7 @@ public class PluginReconciler implements Reconciler { Map newAnnotations = nullSafeAnnotations(persisted); newAnnotations.putAll(nullSafeAnnotations(pluginInPath)); - newAnnotations.put(PLUGIN_PATH, resolvePluginPathAnnotation(newPluginPath)); + newAnnotations.put(PLUGIN_PATH, resolvePluginPathForAnno(newPluginPath)); newAnnotations.remove(RELOAD_ANNO); nullSafeLabels(persisted).putAll(nullSafeLabels(pluginInPath)); persisted.statusNonNull().setLoadLocation(toUri(newPluginPath)); @@ -567,7 +565,7 @@ public class PluginReconciler implements Reconciler { }); } - String resolvePluginPathAnnotation(String pluginPathString) { + String resolvePluginPathForAnno(String pluginPathString) { Path pluginsRoot = toPath(haloPluginManager.getPluginsRoot().toString()); Path pluginPath = toPath(pluginPathString); if (pluginPath.startsWith(pluginsRoot)) { 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 a540d1324..9d6d72094 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 @@ -79,6 +79,7 @@ class PluginReconcilerTest { @BeforeEach void setUp() { pluginReconciler = new PluginReconciler(extensionClient, haloPluginManager, eventPublisher); + lenient().when(haloPluginManager.getPluginsRoot()).thenReturn(Paths.get("plugins")); lenient().when(haloPluginManager.validatePluginVersion(any())).thenReturn(true); lenient().when(haloPluginManager.getSystemVersion()).thenReturn("0.0.0"); lenient().when(haloPluginManager.getPlugin(any())).thenReturn(pluginWrapper); @@ -378,10 +379,10 @@ class PluginReconcilerTest { @Test void resolvePluginPathAnnotation() { when(haloPluginManager.getPluginsRoot()).thenReturn(Paths.get("/tmp/plugins")); - String path = pluginReconciler.resolvePluginPathAnnotation("/tmp/plugins/sitemap-1.0.jar"); + String path = pluginReconciler.resolvePluginPathForAnno("/tmp/plugins/sitemap-1.0.jar"); assertThat(path).isEqualTo("sitemap-1.0.jar"); - path = pluginReconciler.resolvePluginPathAnnotation("/abc/plugins/sitemap-1.0.jar"); + path = pluginReconciler.resolvePluginPathForAnno("/abc/plugins/sitemap-1.0.jar"); assertThat(path).isEqualTo("/abc/plugins/sitemap-1.0.jar"); }