-
Notifications
You must be signed in to change notification settings - Fork 338
feat(osgi): add opt-in Apache Felix plugin framework #6917
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
Open
kiran536
wants to merge
1
commit into
opensearch-project:main
Choose a base branch
from
kiran536:feat/osgi-plugin-framework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Data Prepper OSGi Gradle Plugin | ||
|
|
||
| A standalone, publishable Gradle plugin that prepares a Data Prepper plugin JAR | ||
| for OSGi consumption by baking an OSGi-compliant manifest into it at build time. | ||
|
|
||
| This replaces the runtime JAR-to-bundle adaptation previously performed by | ||
| `BundleAdapter` in `plugin-framework-osgi`. By generating the manifest at build | ||
| time, plugins are valid OSGi bundles from the moment they are built — no runtime | ||
| repackaging is required. | ||
|
|
||
| ## Plugin ID | ||
|
|
||
| ``` | ||
| org.opensearch.dataprepper.osgi | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Internal Data Prepper plugin projects | ||
|
|
||
| In your plugin's `build.gradle`: | ||
|
|
||
| ```groovy | ||
| plugins { | ||
| id 'org.opensearch.dataprepper.osgi' | ||
| } | ||
| ``` | ||
|
|
||
| ### External plugin authors | ||
|
|
||
| Add the plugin to your `buildscript` dependencies or plugin management: | ||
|
|
||
| ```groovy | ||
| // settings.gradle | ||
| pluginManagement { | ||
| repositories { | ||
| mavenCentral() | ||
| // or wherever Data Prepper publishes its artifacts | ||
| } | ||
| plugins { | ||
| id 'org.opensearch.dataprepper.osgi' version '<data-prepper-version>' | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Then in your plugin project's `build.gradle`: | ||
|
|
||
| ```groovy | ||
| plugins { | ||
| id 'org.opensearch.dataprepper.osgi' | ||
| } | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| Your project must include a resource file at: | ||
|
|
||
| ``` | ||
| src/main/resources/META-INF/data-prepper.plugins.properties | ||
| ``` | ||
|
|
||
| With the following property: | ||
|
|
||
| ```properties | ||
| org.opensearch.dataprepper.plugin.packages=com.example.myplugin | ||
| ``` | ||
|
|
||
| The value is a comma-separated list of Java package names that contain your | ||
| `@DataPrepperPlugin`-annotated classes. The plugin scans these packages at | ||
| bundle activation time to register your plugin classes with the OSGi service | ||
| registry. | ||
|
|
||
| If this file is absent, the build will fail with a clear error message. | ||
|
|
||
| ## Generated Manifest Headers | ||
|
|
||
| When applied, this plugin produces the following OSGi manifest headers in the | ||
| output JAR: | ||
|
|
||
| | Header | Value | Derivation | | ||
| |--------|-------|------------| | ||
| | `Bundle-SymbolicName` | `org.opensearch.dataprepper.plugin.<sanitized-name>` | Project name with non-alphanumeric chars replaced by dots | | ||
| | `Bundle-Version` | OSGi-normalized project version | `2.16.0-SNAPSHOT` becomes `2.16.0`; ensures 3-part numeric | | ||
| | `Export-Package` | All packages except `*.internal.*` | Computed by bnd from compiled bytecode | | ||
| | `Import-Package` | `*` (bnd default) | Computed by bnd from bytecode dependency analysis | | ||
| | `Bundle-Activator` | `org.opensearch.dataprepper.plugin.osgi.LegacyPluginBundleActivator` | Fixed; provided by `plugin-framework-osgi` at runtime | | ||
| | `DataPrepper-Plugin-Classes` | Comma-separated package names | Read from `data-prepper.plugins.properties` | | ||
|
|
||
| ## How it works | ||
|
|
||
| 1. The plugin applies `biz.aQute.bnd.builder` to the consuming project. | ||
| 2. After project evaluation, it reads `data-prepper.plugins.properties` from the | ||
| main resource directories. | ||
| 3. It configures the jar task's bnd instructions with the headers listed above. | ||
| 4. At jar time, bnd analyzes the compiled bytecode to compute accurate | ||
| `Import-Package` and `Export-Package` values — this is more reliable than the | ||
| runtime heuristic approach that `BundleAdapter` used. | ||
|
|
||
| ## Comparison with BundleAdapter | ||
|
|
||
| | Aspect | BundleAdapter (runtime) | This plugin (build time) | | ||
| |--------|------------------------|--------------------------| | ||
| | When it runs | At application startup | At build time | | ||
| | Import-Package | Static list of shared API packages | bnd computes from actual bytecode | | ||
| | Export-Package | Discovered by scanning JAR entries | bnd computes from compiled classes | | ||
| | Bundle-Version | Always `1.0.0` | Actual project version (OSGi-normalized) | | ||
| | Performance | Rewrites JARs at startup | Zero startup cost | | ||
| | External plugins | Must be adapted at runtime | Already valid bundles | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| /* | ||||||
| * Copyright OpenSearch Contributors | ||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||
| * | ||||||
| * The OpenSearch Contributors require contributions made to | ||||||
| * this file be licensed under the Apache-2.0 license or a | ||||||
| * compatible open source license. | ||||||
| * | ||||||
| */ | ||||||
|
|
||||||
| plugins { | ||||||
| id 'java-gradle-plugin' | ||||||
| id 'maven-publish' | ||||||
| } | ||||||
|
|
||||||
| group = 'org.opensearch.dataprepper' | ||||||
|
|
||||||
| repositories { | ||||||
| mavenCentral() | ||||||
| gradlePluginPortal() | ||||||
| } | ||||||
|
|
||||||
| dependencies { | ||||||
| implementation gradleApi() | ||||||
| implementation 'biz.aQute.bnd:biz.aQute.bnd.gradle:7.0.0' | ||||||
| testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' | ||||||
| testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' | ||||||
| testImplementation 'org.hamcrest:hamcrest:2.2' | ||||||
| } | ||||||
|
|
||||||
| gradlePlugin { | ||||||
| plugins { | ||||||
| dataPrepperOsgi { | ||||||
| id = 'org.opensearch.dataprepper.osgi' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think this can really just be a Gradle plugin for setting up a Data Prepper plugin. As OSGI is just the implementation detail, we can give it a more generic name. |
||||||
| implementationClass = 'org.opensearch.dataprepper.gradle.plugin.osgi.DataPrepperOsgiPlugin' | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| test { | ||||||
| useJUnitPlatform() | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| pluginManagement { | ||
| repositories { | ||
| mavenCentral() | ||
| gradlePluginPortal() | ||
| } | ||
| } | ||
|
|
||
| rootProject.name = 'osgi-plugin' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to
org.opensearch.dataprepper.gradle