From 3d0d9875596eb911952f94cf46b74656270c0bac Mon Sep 17 00:00:00 2001 From: Ed Merks Date: Sun, 15 Dec 2024 13:30:47 +0100 Subject: [PATCH] Relax dependencies on lucene to include 10.x - Update PrebuiltIndexCompatibility.checkReadable so that it compiles for both 9.x and 10.x and passes the tests in both case. - This prepares for updating the target platform to use lucene 10.x, which requires Java 21. https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/2654 --- ua/org.eclipse.help.base/META-INF/MANIFEST.MF | 6 +++--- .../help/search/PrebuiltIndexCompatibility.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ua/org.eclipse.help.base/META-INF/MANIFEST.MF b/ua/org.eclipse.help.base/META-INF/MANIFEST.MF index 5cd5d34c77f..25da284e04a 100644 --- a/ua/org.eclipse.help.base/META-INF/MANIFEST.MF +++ b/ua/org.eclipse.help.base/META-INF/MANIFEST.MF @@ -43,9 +43,9 @@ Require-Bundle: org.eclipse.ant.core;bundle-version="[3.2.200,4.0.0)";resolution org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", org.eclipse.help;bundle-version="[3.5.0,4.0.0)";visibility:=reexport, org.eclipse.core.net;bundle-version="[1.2.200,2.0.0)", - org.apache.lucene.analysis-common;bundle-version="[9.5.0,10.0.0)", - org.apache.lucene.core;bundle-version="[9.5.0,10.0.0)", - org.apache.lucene.analysis-smartcn;bundle-version="[9.5.0,10.0.0)" + org.apache.lucene.analysis-common;bundle-version="[9.5.0,11.0.0)", + org.apache.lucene.core;bundle-version="[9.5.0,11.0.0)", + org.apache.lucene.analysis-smartcn;bundle-version="[9.5.0,11.0.0)" Import-Package: org.eclipse.equinox.http.jetty;resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy diff --git a/ua/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java b/ua/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java index 32e350c1717..928e5631a17 100644 --- a/ua/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java +++ b/ua/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java @@ -28,6 +28,7 @@ import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.TopDocs; @@ -121,10 +122,22 @@ private void checkReadable(String indexPath) throws IOException, IndexSearcher searcher; try (Directory luceneDirectory = new NIOFSDirectory(new File(filePath).toPath())) { try (DirectoryReader luceneDirectoryReader = DirectoryReader.open(luceneDirectory)) { + // This code never reached because the index is not + // readable. searcher = new IndexSearcher(luceneDirectoryReader); TopDocs hits = searcher.search(luceneQuery, 500); - assertTrue(hits.totalHits.value >= 1); + assertTrue(hits.totalHits != null); } + } catch (IndexFormatTooOldException ex) { + // Lucene 10.x throws this more explicit exception whereas 9.x + // throws IllegalArgumentException. + // Note that in + // org.eclipse.help.internal.search.SearchIndex.SearchIndex(File, + // String, AnalyzerDescriptor, TocManager, String) + // it catches all these: + // catch (IndexFormatTooOldException | IndexNotFoundException | + // IllegalArgumentException e) + throw new IllegalArgumentException(ex); } } else { fail("Cannot resolve to file protocol");