You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2026/10/03 20:08:20 UTC

(opennlp) branch main updated: Minor: Build the jar mask from getJarModelPrefix on each model finder scan (#1387)

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

mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/main by this push:
     new deaae403d Minor: Build the jar mask from getJarModelPrefix on each model finder scan (#1387)
deaae403d is described below

commit deaae403dd8923a96187152cff7b72f5156931d1
Author: Richard Zowalla <13...@users.noreply.github.com>
AuthorDate: Sat Oct 3 22:08:14 2026 +0200

    Minor: Build the jar mask from getJarModelPrefix on each model finder scan (#1387)
---
 .../tools/models/AbstractClassPathModelFinder.java |  3 +--
 .../models/AbstractClassPathModelFinderTest.java   | 28 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/opennlp-core/opennlp-model-resolver/src/main/java/opennlp/tools/models/AbstractClassPathModelFinder.java b/opennlp-core/opennlp-model-resolver/src/main/java/opennlp/tools/models/AbstractClassPathModelFinder.java
index 206bcaf2b..99f51389e 100644
--- a/opennlp-core/opennlp-model-resolver/src/main/java/opennlp/tools/models/AbstractClassPathModelFinder.java
+++ b/opennlp-core/opennlp-model-resolver/src/main/java/opennlp/tools/models/AbstractClassPathModelFinder.java
@@ -66,7 +66,6 @@ public abstract class AbstractClassPathModelFinder implements ClassPathModelFind
   private static final String URL_MUST_NOT_BE_NULL = "url must not be null";
 
   private final String jarModelPrefix;
-  private final String jarWildcard;
   private Set<ClassPathModelEntry> models;
 
   /**
@@ -86,7 +85,6 @@ public abstract class AbstractClassPathModelFinder implements ClassPathModelFind
       throw new IllegalArgumentException("jarModelPrefix must not be null");
     }
     this.jarModelPrefix = jarModelPrefix;
-    this.jarWildcard = ANY_RUN + jarModelPrefix;
   }
 
   @Override
@@ -179,6 +177,7 @@ public abstract class AbstractClassPathModelFinder implements ClassPathModelFind
     }
 
     final boolean isWindows = isWindows();
+    final String jarWildcard = ANY_RUN + getJarModelPrefix();
     final String fileWildcard = ANY_RUN + wildcardPattern;
     for (URL url : candidates) {
       if (matchesWildcard(url, jarWildcard)) {
diff --git a/opennlp-core/opennlp-model-resolver/src/test/java/opennlp/tools/models/AbstractClassPathModelFinderTest.java b/opennlp-core/opennlp-model-resolver/src/test/java/opennlp/tools/models/AbstractClassPathModelFinderTest.java
index 77edd7cf8..731c1e2fd 100644
--- a/opennlp-core/opennlp-model-resolver/src/test/java/opennlp/tools/models/AbstractClassPathModelFinderTest.java
+++ b/opennlp-core/opennlp-model-resolver/src/test/java/opennlp/tools/models/AbstractClassPathModelFinderTest.java
@@ -256,6 +256,34 @@ public class AbstractClassPathModelFinderTest {
     Assertions.assertEquals(List.of(), finder.getMatchingJarEntryURIs(List.of(), "*.bin"));
   }
 
+  /**
+   * Checks that the jar scan uses the prefix returned by an overridden
+   * {@link AbstractClassPathModelFinder#getJarModelPrefix()}.
+   */
+  @Test
+  void testGetMatchingJarEntryURIsUsesOverriddenJarModelPrefix(@TempDir Path dir) throws Exception {
+    final URL custom = writeJar(dir.resolve("custom-models.jar"), "opennlp/en-pos.bin");
+    final AbstractClassPathModelFinder finder = new AbstractClassPathModelFinder() {
+      @Override
+      protected String getJarModelPrefix() {
+        return "custom-*.jar";
+      }
+
+      @Override
+      protected Object getContext() {
+        return null;
+      }
+
+      @Override
+      protected List<URI> getMatchingURIs(String wildcardPattern, Object context) {
+        return List.of();
+      }
+    };
+
+    Assertions.assertEquals(List.of(new URI("jar:" + custom + "!/opennlp/en-pos.bin")),
+        finder.getMatchingJarEntryURIs(List.of(custom), "*.bin"));
+  }
+
   /**
    * Checks that a null candidate list is rejected.
    */