You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2026/04/08 09:53:27 UTC

(tika) branch TIKA-4700-part2 created (now b60477c0a8)

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a change to branch TIKA-4700-part2
in repository https://gitbox.apache.org/repos/asf/tika.git


      at b60477c0a8 TIKA-4700 -- this adds a few more components to the activator and service loader for osgi.

This branch includes the following new commits:

     new b60477c0a8 TIKA-4700 -- this adds a few more components to the activator and service loader for osgi.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(tika) 01/01: TIKA-4700 -- this adds a few more components to the activator and service loader for osgi.

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch TIKA-4700-part2
in repository https://gitbox.apache.org/repos/asf/tika.git

commit b60477c0a8030353c8d329f5586ec3c14bd490b9
Author: tallison <ta...@apache.org>
AuthorDate: Wed Apr 8 05:53:14 2026 -0400

    TIKA-4700 -- this adds a few more components to the activator and service loader for osgi.
---
 .../java/org/apache/tika/config/ServiceLoader.java | 10 ++++---
 .../java/org/apache/tika/config/TikaActivator.java | 31 +++++++++++++++-------
 2 files changed, 28 insertions(+), 13 deletions(-)

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 86cdd97711..ad2c616f0a 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
@@ -37,22 +37,26 @@ import java.util.regex.Pattern;
 import aQute.bnd.annotation.spi.ServiceConsumer;
 
 import org.apache.tika.detect.Detector;
+import org.apache.tika.detect.EncodingDetector;
 import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.language.detect.LanguageDetector;
+import org.apache.tika.metadata.filter.MetadataFilter;
 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>) 
+ * <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)
+@ServiceConsumer(EncodingDetector.class)
+@ServiceConsumer(LanguageDetector.class)
+@ServiceConsumer(MetadataFilter.class)
 public class ServiceLoader {
 
     /**
diff --git a/tika-core/src/main/java/org/apache/tika/config/TikaActivator.java b/tika-core/src/main/java/org/apache/tika/config/TikaActivator.java
index e076f1c2dd..271a1683fb 100644
--- a/tika-core/src/main/java/org/apache/tika/config/TikaActivator.java
+++ b/tika-core/src/main/java/org/apache/tika/config/TikaActivator.java
@@ -16,6 +16,9 @@
  */
 package org.apache.tika.config;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -24,6 +27,9 @@ import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 import org.apache.tika.detect.Detector;
+import org.apache.tika.detect.EncodingDetector;
+import org.apache.tika.language.detect.LanguageDetector;
+import org.apache.tika.metadata.filter.MetadataFilter;
 import org.apache.tika.parser.Parser;
 
 /**
@@ -39,26 +45,31 @@ import org.apache.tika.parser.Parser;
  */
 public class TikaActivator implements BundleActivator, ServiceTrackerCustomizer {
 
-    private ServiceTracker detectorTracker;
-
-    private ServiceTracker parserTracker;
+    private final List<ServiceTracker> trackers = new ArrayList<>();
 
     private BundleContext bundleContext;
-    //-----------------------------------------------------< BundleActivator >
 
     public void start(final BundleContext context) throws Exception {
         bundleContext = context;
 
-        detectorTracker = new ServiceTracker(context, Detector.class.getName(), this);
-        parserTracker = new ServiceTracker(context, Parser.class.getName(), this);
+        trackService(context, Detector.class);
+        trackService(context, Parser.class);
+        trackService(context, EncodingDetector.class);
+        trackService(context, LanguageDetector.class);
+        trackService(context, MetadataFilter.class);
+    }
 
-        detectorTracker.open();
-        parserTracker.open();
+    private void trackService(BundleContext context, Class<?> iface) {
+        ServiceTracker tracker = new ServiceTracker(context, iface.getName(), this);
+        trackers.add(tracker);
+        tracker.open();
     }
 
     public void stop(BundleContext context) throws Exception {
-        parserTracker.close();
-        detectorTracker.close();
+        for (ServiceTracker tracker : trackers) {
+            tracker.close();
+        }
+        trackers.clear();
     }
 
     public Object addingService(ServiceReference reference) {