Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build-resources.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ ext.coreProjects = [
project(':data-prepper-test'),
project(':data-prepper-plugin-framework'),
project(':data-prepper-plugin-schema'),
project(':data-prepper-plugin-schema-cli')
project(':data-prepper-plugin-schema-cli'),
project(':plugin-framework-osgi')
]
1 change: 1 addition & 0 deletions data-prepper-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
implementation project(':data-prepper-logstash-configuration')
implementation project(':data-prepper-pipeline-parser')
implementation project(':data-prepper-plugin-framework')
runtimeOnly project(':plugin-framework-osgi')
testImplementation project(':data-prepper-plugin-framework').sourceSets.test.output
testImplementation project(':data-prepper-plugins:common').sourceSets.test.output
testImplementation project(':data-prepper-plugins:file-source')
Expand Down
108 changes: 108 additions & 0 deletions data-prepper-gradle-plugins/osgi-plugin/README.md
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 |
42 changes: 42 additions & 0 deletions data-prepper-gradle-plugins/osgi-plugin/build.gradle
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'

Copy link
Copy Markdown
Member

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


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'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
id = 'org.opensearch.dataprepper.osgi'
id = 'org.opensearch.dataprepper.plugin'

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()
}
17 changes: 17 additions & 0 deletions data-prepper-gradle-plugins/osgi-plugin/settings.gradle
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'
Loading
Loading