You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2022/01/04 14:07:30 UTC

[lucene] branch branch_9x updated: LUCENE-10348: Make stopwords resources from analyzers modules visible to ClasspathResourceLoader and ModuleResourceLoader (#581)

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

uschindler pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new d17c54b  LUCENE-10348: Make stopwords resources from analyzers modules visible to ClasspathResourceLoader and ModuleResourceLoader (#581)
     new fbc8923  Merge branch 'branch_9x' of https://gitbox.apache.org/repos/asf/lucene into branch_9x
d17c54b is described below

commit d17c54b5ff56ffadd8692e45629215eaf479d8e3
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Tue Jan 4 15:05:29 2022 +0100

    LUCENE-10348: Make stopwords resources from analyzers modules visible to ClasspathResourceLoader and ModuleResourceLoader (#581)
---
 lucene/analysis/common/src/java/module-info.java   | 55 ++++++++++++++++++++++
 lucene/analysis/icu/src/java/module-info.java      |  3 ++
 lucene/analysis/kuromoji/src/java/module-info.java |  5 ++
 .../analysis/morfologik/src/java/module-info.java  |  3 ++
 lucene/analysis/smartcn/src/java/module-info.java  |  3 ++
 lucene/analysis/stempel/src/java/module-info.java  |  3 ++
 .../lucene/distribution/TestModularLayer.java      | 39 +++++++++++++--
 7 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/lucene/analysis/common/src/java/module-info.java b/lucene/analysis/common/src/java/module-info.java
index e736a95..ec83795 100644
--- a/lucene/analysis/common/src/java/module-info.java
+++ b/lucene/analysis/common/src/java/module-info.java
@@ -89,6 +89,61 @@ module org.apache.lucene.analysis.common {
   exports org.tartarus.snowball.ext;
   exports org.tartarus.snowball;
 
+  opens org.apache.lucene.analysis.ar to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.bg to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.bn to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.br to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ca to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.cjk to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ckb to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.cz to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.el to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.et to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.eu to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.fa to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ga to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.gl to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.hi to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.hy to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.id to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.lt to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.lv to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ne to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ro to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.snowball to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.sr to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ta to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.te to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.th to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.tr to
+      org.apache.lucene.core;
+
   provides org.apache.lucene.analysis.CharFilterFactory with
       org.apache.lucene.analysis.charfilter.HTMLStripCharFilterFactory,
       org.apache.lucene.analysis.charfilter.MappingCharFilterFactory,
diff --git a/lucene/analysis/icu/src/java/module-info.java b/lucene/analysis/icu/src/java/module-info.java
index c901af4..746580d 100644
--- a/lucene/analysis/icu/src/java/module-info.java
+++ b/lucene/analysis/icu/src/java/module-info.java
@@ -26,6 +26,9 @@ module org.apache.lucene.analysis.icu {
   exports org.apache.lucene.analysis.icu.segmentation;
   exports org.apache.lucene.analysis.icu.tokenattributes;
 
+  opens org.apache.lucene.analysis.icu.segmentation to
+      org.apache.lucene.core;
+
   provides org.apache.lucene.analysis.CharFilterFactory with
       org.apache.lucene.analysis.icu.ICUNormalizer2CharFilterFactory;
   provides org.apache.lucene.analysis.TokenizerFactory with
diff --git a/lucene/analysis/kuromoji/src/java/module-info.java b/lucene/analysis/kuromoji/src/java/module-info.java
index 7c829fd..0cd0960 100644
--- a/lucene/analysis/kuromoji/src/java/module-info.java
+++ b/lucene/analysis/kuromoji/src/java/module-info.java
@@ -26,6 +26,11 @@ module org.apache.lucene.analysis.kuromoji {
   exports org.apache.lucene.analysis.ja.tokenattributes;
   exports org.apache.lucene.analysis.ja.util;
 
+  opens org.apache.lucene.analysis.ja to
+      org.apache.lucene.core;
+  opens org.apache.lucene.analysis.ja.completion to
+      org.apache.lucene.core;
+
   provides org.apache.lucene.analysis.CharFilterFactory with
       org.apache.lucene.analysis.ja.JapaneseIterationMarkCharFilterFactory;
   provides org.apache.lucene.analysis.TokenizerFactory with
diff --git a/lucene/analysis/morfologik/src/java/module-info.java b/lucene/analysis/morfologik/src/java/module-info.java
index 3268d4b..4657752 100644
--- a/lucene/analysis/morfologik/src/java/module-info.java
+++ b/lucene/analysis/morfologik/src/java/module-info.java
@@ -27,6 +27,9 @@ module org.apache.lucene.analysis.morfologik {
   exports org.apache.lucene.analysis.morfologik;
   exports org.apache.lucene.analysis.uk;
 
+  opens org.apache.lucene.analysis.uk to
+      org.apache.lucene.core;
+
   provides org.apache.lucene.analysis.TokenFilterFactory with
       org.apache.lucene.analysis.morfologik.MorfologikFilterFactory;
 }
diff --git a/lucene/analysis/smartcn/src/java/module-info.java b/lucene/analysis/smartcn/src/java/module-info.java
index 44f4eb5..6b51ae9 100644
--- a/lucene/analysis/smartcn/src/java/module-info.java
+++ b/lucene/analysis/smartcn/src/java/module-info.java
@@ -23,6 +23,9 @@ module org.apache.lucene.analysis.smartcn {
   exports org.apache.lucene.analysis.cn.smart;
   exports org.apache.lucene.analysis.cn.smart.hhmm;
 
+  opens org.apache.lucene.analysis.cn.smart to
+      org.apache.lucene.core;
+
   provides org.apache.lucene.analysis.TokenizerFactory with
       org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory;
 }
diff --git a/lucene/analysis/stempel/src/java/module-info.java b/lucene/analysis/stempel/src/java/module-info.java
index d559548..b285d78 100644
--- a/lucene/analysis/stempel/src/java/module-info.java
+++ b/lucene/analysis/stempel/src/java/module-info.java
@@ -24,6 +24,9 @@ module org.apache.lucene.analysis.stempel {
   exports org.apache.lucene.analysis.stempel;
   exports org.egothor.stemmer;
 
+  opens org.apache.lucene.analysis.pl to
+      org.apache.lucene.core;
+
   provides org.apache.lucene.analysis.TokenFilterFactory with
       org.apache.lucene.analysis.stempel.StempelPolishStemFilterFactory;
 }
diff --git a/lucene/distribution.tests/src/test/org/apache/lucene/distribution/TestModularLayer.java b/lucene/distribution.tests/src/test/org/apache/lucene/distribution/TestModularLayer.java
index 3fb92c3..ed9b188 100644
--- a/lucene/distribution.tests/src/test/org/apache/lucene/distribution/TestModularLayer.java
+++ b/lucene/distribution.tests/src/test/org/apache/lucene/distribution/TestModularLayer.java
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.function.Predicate;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -262,9 +263,9 @@ public class TestModularLayer {
    * module layer.
    */
   @Test
-  public void testAllOpenPackagesInSync() throws IOException {
+  public void testAllExportedPackagesInSync() throws IOException {
     for (var module : allCoreModules) {
-      Set<String> jarPackages = getJarPackages(module);
+      Set<String> jarPackages = getJarPackages(module, entry -> true);
       Set<ModuleDescriptor.Exports> moduleExports = new HashSet<>(module.descriptor().exports());
 
       if (module.descriptor().name().equals("org.apache.lucene.luke")) {
@@ -307,7 +308,36 @@ public class TestModularLayer {
     }
   }
 
-  private Set<String> getJarPackages(ModuleReference module) throws IOException {
+  /** This test ensures that all analysis modules open their resources files to core. */
+  @Test
+  public void testAllOpenAnalysisPackagesInSync() throws IOException {
+    for (var module : allCoreModules) {
+      if (false == module.descriptor().name().startsWith("org.apache.lucene.analysis.")) {
+        continue; // at moment we only want to open resources inside analysis packages
+      }
+
+      // We only collect resources from the JAR file which are:
+      // - stopword files (*.txt)
+      // - ICU break iterator rules (*.brk)
+      var filter = Pattern.compile("/[^/]+\\.(txt|brk)$");
+      Set<String> jarPackages = getJarPackages(module, filter.asPredicate());
+      Set<ModuleDescriptor.Opens> moduleOpens = module.descriptor().opens();
+
+      Assertions.assertThat(moduleOpens)
+          .as("Open packages in module: " + module.descriptor().name())
+          .allSatisfy(
+              export -> {
+                Assertions.assertThat(export.targets())
+                    .as("Opens should only be targeted to Lucene Core.")
+                    .containsExactly("org.apache.lucene.core");
+              })
+          .map(ModuleDescriptor.Opens::source)
+          .containsExactlyInAnyOrderElementsOf(jarPackages);
+    }
+  }
+
+  private Set<String> getJarPackages(ModuleReference module, Predicate<String> entryFilter)
+      throws IOException {
     try (ModuleReader reader = module.open()) {
       return reader
           .list()
@@ -315,7 +345,8 @@ public class TestModularLayer {
               entry ->
                   !entry.startsWith("META-INF/")
                       && !entry.equals("module-info.class")
-                      && !entry.endsWith("/"))
+                      && !entry.endsWith("/")
+                      && entryFilter.test(entry))
           .map(entry -> entry.replaceAll("/[^/]+$", ""))
           .map(entry -> entry.replace('/', '.'))
           .collect(Collectors.toCollection(TreeSet::new));