This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new 6c40c399ce TIKA-4700 Support OSGi Service Loader Mediator (#2714)
6c40c399ce is described below
commit 6c40c399ce2811f2a772763799b35bab8a8e49d1
Author: Konrad Windszus <[email protected]>
AuthorDate: Wed Apr 8 11:48:13 2026 +0200
TIKA-4700 Support OSGi Service Loader Mediator (#2714)
Generate according capabilities headers for providers via TikaComponent
annotations and Bnd's
https://bnd.bndtools.org/chapters/230-manifest-annotations.html#meta-infservices-annotations.
According capabilities headers for the consumer are generated via Bnd's
ServiceConsumer annotations.
---
.../apache/tika/annotation/TikaComponentProcessor.java | 2 ++
.../main/java/org/apache/tika/config/ServiceLoader.java | 11 +++++++++++
tika-parent/pom.xml | 15 +++++++++++++++
3 files changed, 28 insertions(+)
diff --git
a/tika-annotation-processor/src/main/java/org/apache/tika/annotation/TikaComponentProcessor.java
b/tika-annotation-processor/src/main/java/org/apache/tika/annotation/TikaComponentProcessor.java
index 132e022dfa..3e82c52d72 100644
---
a/tika-annotation-processor/src/main/java/org/apache/tika/annotation/TikaComponentProcessor.java
+++
b/tika-annotation-processor/src/main/java/org/apache/tika/annotation/TikaComponentProcessor.java
@@ -337,6 +337,8 @@ public class TikaComponentProcessor extends
AbstractProcessor {
writer.write("# Generated by TikaComponentProcessor\n");
writer.write("# Do not edit manually\n");
for (String impl : sortedImplementations) {
+ // add comments for Bnd to generate OSGi metadata for
Service Mediator spec
(https://bnd.bndtools.org/chapters/230-manifest-annotations.html#meta-infservices-annotations)
+
writer.write("#@aQute.bnd.annotation.spi.ServiceProvider()\n");
writer.write(impl);
writer.write("\n");
}
diff --git a/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
b/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
index c49b336214..86cdd97711 100644
--- a/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
+++ b/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
@@ -34,14 +34,25 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
+import aQute.bnd.annotation.spi.ServiceConsumer;
+
+import org.apache.tika.detect.Detector;
import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.parser.Parser;
import org.apache.tika.utils.ServiceLoaderUtils;
/**
* Internal utility class that Tika uses to look up service providers.
+ * Supports both static service loading using the {@link ServiceLoader}
mechanism (and via
+ * <a
href="https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html">OSGi
Service Loader Mediator</a>)
+ * as well as dynamic loading via OSGi service tracking (from the {@link
TikaActivator} class).
+ * However the Tika parsers don't register as regular OSGi services,
+ * so the dynamic loading is only used for detectors and parser services from
non-Tika bundles.
*
* @since Apache Tika 0.9
*/
+@ServiceConsumer(Parser.class)
+@ServiceConsumer(Detector.class)
public class ServiceLoader {
/**
diff --git a/tika-parent/pom.xml b/tika-parent/pom.xml
index 4d461da3d3..d8655625cf 100644
--- a/tika-parent/pom.xml
+++ b/tika-parent/pom.xml
@@ -283,6 +283,7 @@
<properties>
<revision>4.0.0-SNAPSHOT</revision>
+ <javaVersion>17</javaVersion>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
@@ -1462,6 +1463,20 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.version}</version>
+ <configuration>
+ <instructions>
+ <!-- https://bnd.bndtools.org/instructions/metainf_services.html
-->
+ <_metainf-services>auto</_metainf-services>
+ </instructions>
+ </configuration>
+ <dependencies>
+ <!-- upgrade to a newer version of Bnd to leverage
https://bnd.bndtools.org/chapters/230-manifest-annotations.html#meta-infservices-annotations
-->
+ <dependency>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>biz.aQute.bndlib</artifactId>
+ <version>${biz.aqute.version}</version>
+ </dependency>
+ </dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>