Skip to content

Commit 314b35e

Browse files
authored
TIKA-4865 -- tika-grpc: resolve the plugin-roots fallback via DefaultPluginsDir and WARN when no plugins directory exists (#3109)
1 parent 2bd52a0 commit 314b35e

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Release 4.1.0 - unreleased
22

3+
* tika-grpc resolves its plugin-roots fallback against the install
4+
layout via DefaultPluginsDir instead of a working-directory-relative
5+
pf4j default, and a WARN names the resolved directory when no plugins
6+
directory exists (TIKA-4865).
7+
38
* The tika-server full and tika-grpc Docker images install fonts-noto-cjk:
49
without any CJK face, PDFs using non-embedded CJK fonts render (and OCR)
510
as .notdef boxes in every renderer, even though the images ship Japanese

tika-grpc/src/main/java/org/apache/tika/pipes/grpc/TikaGrpcServerImpl.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.tika.pipes.core.PipesParser;
5555
import org.apache.tika.pipes.core.config.ConfigStore;
5656
import org.apache.tika.pipes.core.config.ConfigStoreFactory;
57+
import org.apache.tika.pipes.core.config.DefaultPluginsDir;
5758
import org.apache.tika.pipes.core.fetcher.FetcherManager;
5859
import org.apache.tika.pipes.grpc.proto.DeleteFetcherReply;
5960
import org.apache.tika.pipes.grpc.proto.DeleteFetcherRequest;
@@ -135,8 +136,20 @@ class TikaGrpcServerImpl extends TikaGrpc.TikaImplBase {
135136
pluginManager.loadPlugins();
136137
pluginManager.startPlugins();
137138
} catch (TikaConfigException e) {
138-
LOG.warn("Could not load plugin manager, using default: {}", e.getMessage());
139-
pluginManager = new org.pf4j.DefaultPluginManager();
139+
// plugin-roots not configured: probe the install layout like the
140+
// other pipes entry points (TIKA-4864/TIKA-4865)
141+
String defaultRoot = DefaultPluginsDir.resolve(TikaGrpcServerImpl.class);
142+
LOG.warn("plugin-roots not configured ({}); falling back to {}",
143+
e.getMessage(), defaultRoot);
144+
try {
145+
pluginManager = TikaPluginManager.loadFromPaths(defaultRoot);
146+
pluginManager.loadPlugins();
147+
pluginManager.startPlugins();
148+
} catch (TikaConfigException | IOException e2) {
149+
LOG.warn("could not load plugins from {}, starting with none: {}",
150+
defaultRoot, e2.getMessage());
151+
pluginManager = new org.pf4j.DefaultPluginManager();
152+
}
140153
}
141154

142155
if (pluginManager.getPlugins().isEmpty()) {

tika-pipes/tika-pipes-core/src/main/java/org/apache/tika/pipes/core/config/DefaultPluginsDir.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.nio.file.Files;
2020
import java.nio.file.Path;
2121

22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
2225
/**
2326
* Resolves the default {@code plugins} directory when {@code plugin-roots}
2427
* is not configured (TIKA-4864). The probe order matches the install
@@ -37,6 +40,8 @@
3740
*/
3841
public final class DefaultPluginsDir {
3942

43+
private static final Logger LOG = LoggerFactory.getLogger(DefaultPluginsDir.class);
44+
4045
/**
4146
* The directory name probed in each location.
4247
*/
@@ -88,6 +93,11 @@ public static Path resolve(Path codeSourceDir, Path cwd) {
8893
}
8994
}
9095
}
91-
return cwd.resolve(PLUGINS_DIR_NAME).toAbsolutePath();
96+
Path fallback = cwd.resolve(PLUGINS_DIR_NAME).toAbsolutePath();
97+
if (!Files.isDirectory(fallback)) {
98+
LOG.warn("no plugins directory found in the install layout or at {}; "
99+
+ "pipes plugins will not load unless plugin-roots is configured", fallback);
100+
}
101+
return fallback;
92102
}
93103
}

0 commit comments

Comments
 (0)