Skip to content

Commit 6c40c39

Browse files
authored
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.
1 parent 3b46de8 commit 6c40c39

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

tika-annotation-processor/src/main/java/org/apache/tika/annotation/TikaComponentProcessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ private void writeServiceFiles() {
337337
writer.write("# Generated by TikaComponentProcessor\n");
338338
writer.write("# Do not edit manually\n");
339339
for (String impl : sortedImplementations) {
340+
// add comments for Bnd to generate OSGi metadata for Service Mediator spec (https://bnd.bndtools.org/chapters/230-manifest-annotations.html#meta-infservices-annotations)
341+
writer.write("#@aQute.bnd.annotation.spi.ServiceProvider()\n");
340342
writer.write(impl);
341343
writer.write("\n");
342344
}

tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,25 @@
3434
import java.util.Set;
3535
import java.util.regex.Pattern;
3636

37+
import aQute.bnd.annotation.spi.ServiceConsumer;
38+
39+
import org.apache.tika.detect.Detector;
3740
import org.apache.tika.exception.TikaConfigException;
41+
import org.apache.tika.parser.Parser;
3842
import org.apache.tika.utils.ServiceLoaderUtils;
3943

4044
/**
4145
* Internal utility class that Tika uses to look up service providers.
46+
* Supports both static service loading using the {@link ServiceLoader} mechanism (and via
47+
* <a href="https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html">OSGi Service Loader Mediator</a>)
48+
* as well as dynamic loading via OSGi service tracking (from the {@link TikaActivator} class).
49+
* However the Tika parsers don't register as regular OSGi services,
50+
* so the dynamic loading is only used for detectors and parser services from non-Tika bundles.
4251
*
4352
* @since Apache Tika 0.9
4453
*/
54+
@ServiceConsumer(Parser.class)
55+
@ServiceConsumer(Detector.class)
4556
public class ServiceLoader {
4657

4758
/**

tika-parent/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283

284284
<properties>
285285
<revision>4.0.0-SNAPSHOT</revision>
286+
<javaVersion>17</javaVersion>
286287
<maven.compiler.source>17</maven.compiler.source>
287288
<maven.compiler.target>17</maven.compiler.target>
288289
<maven.compiler.release>17</maven.compiler.release>
@@ -1462,6 +1463,20 @@
14621463
<groupId>org.apache.felix</groupId>
14631464
<artifactId>maven-bundle-plugin</artifactId>
14641465
<version>${maven.bundle.version}</version>
1466+
<configuration>
1467+
<instructions>
1468+
<!-- https://bnd.bndtools.org/instructions/metainf_services.html -->
1469+
<_metainf-services>auto</_metainf-services>
1470+
</instructions>
1471+
</configuration>
1472+
<dependencies>
1473+
<!-- upgrade to a newer version of Bnd to leverage https://bnd.bndtools.org/chapters/230-manifest-annotations.html#meta-infservices-annotations -->
1474+
<dependency>
1475+
<groupId>biz.aQute.bnd</groupId>
1476+
<artifactId>biz.aQute.bndlib</artifactId>
1477+
<version>${biz.aqute.version}</version>
1478+
</dependency>
1479+
</dependencies>
14651480
</plugin>
14661481
<plugin>
14671482
<groupId>org.apache.maven.plugins</groupId>

0 commit comments

Comments
 (0)