Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for publishing events among plugins #6081

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

JohnNiang
Copy link
Member

@JohnNiang JohnNiang commented Jun 14, 2024

What type of PR is this?

/kind feature
/area core
/area plugin

What this PR does / why we need it:

This PR enhance usage of SharedEvent annotation to add support for publishing events among plugins.

How to test?

  1. Clone repository https://github.com/halo-dev/plugin-starter

  2. Change build.gradle as following:

    dependencies {
        implementation platform('run.halo.tools.platform:plugin:2.17.0-SNAPSHOT')
  3. Change StarterPlugin as following:

    @Component
    public class StarterPlugin extends BasePlugin {
    
        private final ApplicationContext appContext;
    
        public StarterPlugin(PluginContext pluginContext, ApplicationContext appContext) {
            super(pluginContext);
            this.appContext = appContext;
        }
    
        @Override
        public void start() {
            appContext.publishEvent(new PostDeletedEvent(this, "fake-plugin"));
        }
    
        @Override
        public void stop() {
        }
    
        @EventListener(PostDeletedEvent.class)
        public void onApplicationEvent(PostDeletedEvent event) {
            System.out.println("Post deleted event received in plugin: " + event.getName());
        }
    }
  4. Add a listener to Halo core

	    @EventListener(PostDeletedEvent.class)
	    public void onApplicationEvent(PostDeletedEvent event) {
	        System.out.println("Post deleted event received in core: " + event.getName());
	    }
  1. Build plugin and install plugin
  2. Enable the plugin and see the result

Does this PR introduce a user-facing change?

为插件提供发送共享事件的支持。

@f2c-ci-robot f2c-ci-robot bot added release-note-none Denotes a PR that doesn't merit a release note. kind/feature Categorizes issue or PR as related to a new feature. area/core Issues or PRs related to the Halo Core labels Jun 14, 2024
@f2c-ci-robot f2c-ci-robot bot requested review from ruibaby and wan92hen June 14, 2024 05:15
@f2c-ci-robot f2c-ci-robot bot added the area/plugin Issues or PRs related to the Plugin Provider label Jun 14, 2024
Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 47.16981% with 28 lines in your changes missing coverage. Please review.

Project coverage is 56.48%. Comparing base (5fdf6c0) to head (495d3db).
Report is 238 commits behind head on main.

Files Patch % Lines
.../run/halo/app/plugin/PluginApplicationContext.java 0.00% 12 Missing ⚠️
...un/halo/app/plugin/PluginSharedEventDelegator.java 36.36% 7 Missing ⚠️
.../run/halo/app/plugin/HaloSharedEventDelegator.java 45.45% 4 Missing and 2 partials ⚠️
...plugin/DefaultPluginApplicationContextFactory.java 0.00% 2 Missing ⚠️
...ava/run/halo/app/plugin/SharedEventDispatcher.java 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6081      +/-   ##
============================================
- Coverage     56.91%   56.48%   -0.43%     
- Complexity     3319     3549     +230     
============================================
  Files           587      625      +38     
  Lines         18968    20981    +2013     
  Branches       1401     1484      +83     
============================================
+ Hits          10795    11852    +1057     
- Misses         7594     8527     +933     
- Partials        579      602      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JohnNiang JohnNiang added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 14, 2024
@JohnNiang JohnNiang force-pushed the refactor/shared-events branch from 7112a06 to 0df68f2 Compare June 14, 2024 09:31
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.2% Duplication on New Code

See analysis details on SonarCloud

@JohnNiang JohnNiang removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 14, 2024
@ruibaby
Copy link
Member

ruibaby commented Jun 17, 2024

@JohnNiang 是否需要补充一下插件开发的文档?

@JohnNiang
Copy link
Member Author

@JohnNiang 是否需要补充一下插件开发的文档?

目前确实缺少相关的文档,稍后我完善一下。

@JohnNiang JohnNiang force-pushed the refactor/shared-events branch from 0df68f2 to 8c40bf4 Compare June 19, 2024 03:03
@ruibaby
Copy link
Member

ruibaby commented Jun 19, 2024

docs/plugin/shared-event.md Outdated Show resolved Hide resolved
Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Jun 19, 2024
Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

Copy link

f2c-ci-robot bot commented Jun 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guqing

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 19, 2024
@f2c-ci-robot f2c-ci-robot bot merged commit a94596a into halo-dev:main Jun 19, 2024
7 checks passed
@ruibaby ruibaby added this to the 2.17.0 milestone Jun 23, 2024
@JohnNiang JohnNiang deleted the refactor/shared-events branch June 25, 2024 02:35
@f2c-ci-robot f2c-ci-robot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/core Issues or PRs related to the Halo Core area/plugin Issues or PRs related to the Plugin Provider kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants