Skip to content

chore: Enable sharing spring context in pf4j plugins#37002

Closed
nidhi-nair wants to merge 2 commits intoreleasefrom
chore/enable-spring-plugins
Closed

chore: Enable sharing spring context in pf4j plugins#37002
nidhi-nair wants to merge 2 commits intoreleasefrom
chore/enable-spring-plugins

Conversation

@nidhi-nair
Copy link
Contributor

@nidhi-nair nidhi-nair commented Oct 22, 2024

Description

As of today, we do not use any DI concepts in plugins because our extensions are unable to use the same application context as server. This PR allows us to extend from the same application context. Implications of clashes across plugins will need to be checked, and conventions and compile time checks for it need to be established.

Automation

/ok-to-test tags="@tag.Git,@tag.Sanity"

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11452764576
Commit: 7547480
Cypress dashboard.
Tags: @tag.Git,@tag.Sanity
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ServerSide/OnLoadTests/OnLoadActions_Spec.ts
  2. cypress/e2e/Regression/ServerSide/QueryPane/DSDocs_Spec.ts
List of identified flaky tests.
Tue, 22 Oct 2024 04:34:00 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Integrated the PF4J (Plugin Framework for Java) with Spring, enhancing plugin management capabilities.
    • Added a new dependency for pf4j-spring to facilitate this integration.
  • Improvements

    • Updated the BasePlugin class to extend SpringPlugin, allowing better compatibility with Spring's plugin architecture.
    • Enhanced PluginConfiguration to utilize Spring's ApplicationContext, improving plugin lifecycle management and extension creation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes introduced in this pull request involve the addition of a new dependency to the pom.xml file and significant modifications to the BasePlugin and PluginConfiguration classes. The pf4j-spring library is added to enhance plugin management capabilities, while the BasePlugin class now extends SpringPlugin, indicating a shift towards Spring's plugin architecture. The PluginConfiguration class has been updated to integrate Spring's ApplicationContext, improving the plugin lifecycle management.

Changes

File Change Summary
app/server/appsmith-interfaces/pom.xml Added new dependency: org.pf4j:pf4j-spring:0.8.0 with scope compile.
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/BasePlugin.java Changed inheritance from Plugin to SpringPlugin, updated import statements, and added method createApplicationContext().
app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/PluginConfiguration.java Updated pluginManager method to accept ApplicationContext, added CustomPluginManager and CustomSpringExtensionFactory classes, and modified methods for plugin lifecycle management.

Possibly related PRs

  • chore: Enable netty metrics #36104: Involves modifications to the ReactorNettyConfiguration class, which is part of the same package as the PluginConfiguration class modified in the main PR, indicating a potential connection in terms of plugin management and server configuration.
  • chore: Enable netty metrics based on env var #36108: Similar to chore: Enable netty metrics #36104, this PR also modifies the ReactorNettyConfiguration class and introduces a dependency on CommonConfig, which may relate to the overall configuration and management of plugins in the context of the changes made in the main PR.

Suggested reviewers

  • ApekshaBhosale
  • sondermanish

Poem

In the realm of code, changes unfold,
New plugins emerge, as stories are told.
Spring's embrace, a dance so fine,
With pf4j added, our plugins align.
So here's to the code, and all that we share,
In the world of Java, we craft with care! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Oct 22, 2024
@nidhi-nair nidhi-nair added the ok-to-test Required label for CI label Oct 22, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1f72d75 and 45fd2e1.

📒 Files selected for processing (3)
  • app/server/appsmith-interfaces/pom.xml (1 hunks)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/BasePlugin.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/PluginConfiguration.java (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/BasePlugin.java (2)

6-6: LGTM: Import statement added for SpringPlugin.

The import statement for SpringPlugin is correctly added, aligning with the change in class inheritance.


8-8: Inheritance changed to SpringPlugin. Verify plugin behavior.

The change from Plugin to SpringPlugin aligns with the PR objectives. This modification enables sharing of the Spring context in pf4j plugins.

Ensure that all plugins extending BasePlugin still function correctly with this change. Run the following script to identify all classes that extend BasePlugin:

✅ Verification successful

Inheritance changed to SpringPlugin successfully. All extending classes are accounted for.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all classes that extend BasePlugin

# Test: Search for classes extending BasePlugin
rg -t java "class\s+\w+\s+extends\s+BasePlugin"

Length of output: 6564

app/server/appsmith-interfaces/pom.xml (1)

64-69: Consider updating pf4j-spring to a newer version.

The addition of pf4j-spring aligns with the PR objectives. However, version 0.8.0 is from 2020. A newer version might offer improved features or bug fixes.

To check for newer versions, run:

app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/PluginConfiguration.java (4)

21-22: Method signature update aligns with context sharing

The pluginManager now accepts ApplicationContext, which is necessary for enabling plugins to share the Spring context.


52-55: Verify ApplicationContext consistency in setApplicationContext

Ensure that setApplicationContext is called appropriately so that both the CustomPluginManager and its CustomSpringExtensionFactory have the correct ApplicationContext.


64-75: Plugin initialization sequence is correctly implemented

The init method properly loads and starts plugins and injects extensions into the Spring context.


91-99: Extension creation handles context inheritance properly

The create method in CustomSpringExtensionFactory correctly sets the parent ApplicationContext for plugin extensions.

Comment on lines +31 to +34
public CustomPluginManager(ApplicationContext applicationContext) {
super();
this.applicationContext = applicationContext;
this.ef = new CustomSpringExtensionFactory(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Eliminate redundant initialization of ef

The CustomSpringExtensionFactory instance ef is initialized both in the constructor and in createExtensionFactory(). This duplication is unnecessary.

Apply this diff to remove the redundant initialization:

- this.ef = new CustomSpringExtensionFactory(this);

Also applies to: 41-44

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 45fd2e1 and 7547480.

📒 Files selected for processing (1)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/BasePlugin.java (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/BasePlugin.java (2)

6-7: LGTM: Import statements are correct.

The new imports for SpringPlugin and ApplicationContext are necessary for the changes made to the class.


18-21: Clarify the purpose of returning null in createApplicationContext().

The createApplicationContext() method currently returns null. This might not be the intended behavior for creating an application context. Consider implementing this method to return a valid ApplicationContext or provide a comment explaining why it returns null.

Could you clarify the reasoning behind this implementation?

@github-actions
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Oct 29, 2024
@nidhi-nair
Copy link
Contributor Author

Closing as not important right now without native git

@nidhi-nair nidhi-nair closed this Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant