Skip to content

Commit

Permalink
Simplify halo plugin manager (#5251)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind improvement
/area core
/area plugin
/milestone 2.12.x

#### What this PR does / why we need it:

This PR mainly simplifies halo plugin manager. Before this,
- we have too many repeat code from super class, which is uncessary
- we maintain plugin application context in ExtensionComponentsFinder, which is uncessary and is hard to manage
- we fire halo plugin event in halo plugin manager, which is complicated and leads to too many repeat code

This PR does:
- refactor halo plugin manager
- wrap base plugin with spring plugin which contains application context
- remove ExtensionComponentsFinder
- bridge halo plugin event and spring plugin event
- wait extensions fully deleted when stopping

Meanwhile, this PR will supersede PR <#5236>.

#### Which issue(s) this PR fixes:

Fixes #5226

#### Special notes for your reviewer:

Test installing, enabing, disabling, upgrading, reloading and deleting plugins.

#### Does this PR introduce a user-facing change?

```release-note
None
```
  • Loading branch information
JohnNiang authored Jan 26, 2024
1 parent 17a0fb9 commit 8288e4e
Show file tree
Hide file tree
Showing 53 changed files with 1,278 additions and 1,894 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ private void resolveStaticResources(Plugin plugin) {
var p = pluginManager.getPlugin(pluginName);
var classLoader = p.getPluginClassLoader();
var resLoader = new DefaultResourceLoader(classLoader);
var entryRes = resLoader.getResource("classpath:/console/main.js");
var cssRes = resLoader.getResource("classpath:/console/style.css");
var entryRes = resLoader.getResource("classpath:console/main.js");
var cssRes = resLoader.getResource("classpath:console/style.css");
if (entryRes.exists()) {
var entry = UriComponentsBuilder.newInstance()
.pathSegment("plugins", pluginName, "assets", "console", "main.js")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public Controller setupWith(ControllerBuilder builder) {

private void registerReverseProxy(ReverseProxy reverseProxy) {
String pluginId = getPluginId(reverseProxy);
routerFunctionRegistry.register(pluginId, reverseProxy).block();
routerFunctionRegistry.register(pluginId, reverseProxy);
}

private void cleanUpResources(ReverseProxy reverseProxy) {
String pluginId = getPluginId(reverseProxy);
routerFunctionRegistry.remove(pluginId, reverseProxy.getMetadata().getName()).block();
routerFunctionRegistry.remove(pluginId, reverseProxy.getMetadata().getName());
}

private void addFinalizerIfNecessary(ReverseProxy oldReverseProxy) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package run.halo.app.infra;

import com.github.zafarkhaja.semver.Version;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Objects;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.info.BuildProperties;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
Expand All @@ -17,21 +16,19 @@
public class DefaultSystemVersionSupplier implements SystemVersionSupplier {
private static final String DEFAULT_VERSION = "0.0.0";

@Nullable
private BuildProperties buildProperties;
private final ObjectProvider<BuildProperties> buildProperties;

@Autowired(required = false)
public void setBuildProperties(@Nullable BuildProperties buildProperties) {
public DefaultSystemVersionSupplier(ObjectProvider<BuildProperties> buildProperties) {
this.buildProperties = buildProperties;
}

@Override
public Version get() {
if (buildProperties == null) {
var properties = buildProperties.getIfUnique();
if (properties == null) {
return Version.valueOf(DEFAULT_VERSION);
}
String projectVersion =
StringUtils.defaultString(buildProperties.getVersion(), DEFAULT_VERSION);
var projectVersion = Objects.toString(properties.getVersion(), DEFAULT_VERSION);
return Version.valueOf(projectVersion);
}
}

This file was deleted.

Loading

0 comments on commit 8288e4e

Please sign in to comment.