From 651755aab707a25a5833f5d75044aaf66d608432 Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Fri, 26 Nov 2021 08:32:23 +0100 Subject: [PATCH] LUCENE-10260: Luke's about window no longer shows version number (#473) --- lucene/CHANGES.txt | 3 ++ lucene/MIGRATE.md | 5 ++ .../java/org/apache/lucene/LucenePackage.java | 28 ----------- .../java/org/apache/lucene/util/Version.java | 48 +++++++++++++++++++ .../dialog/menubar/AboutDialogFactory.java | 11 ++--- 5 files changed, 61 insertions(+), 34 deletions(-) delete mode 100644 lucene/core/src/java/org/apache/lucene/LucenePackage.java diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 27739b46ad2..72dfba0b43f 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -239,6 +239,9 @@ API Changes unwrap wrappers/delegators that are added by Lucene's testing framework. This will allow testing new MMapDirectory implementation based on JDK Project Panama. (Uwe Schindler) +* LUCENE-10260: LucenePackage class has been removed. The implementation string can be + retrieved from Version.getPackageImplementationVersion(). (Uwe Schindler, Dawid Weiss) + Improvements --------------------- diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.md index 20bc5519223..5eb87c61ea2 100644 --- a/lucene/MIGRATE.md +++ b/lucene/MIGRATE.md @@ -24,6 +24,11 @@ means that interval function prefixes ("fn:") and the '@' character after parent parse differently than before. If you need the exact previous behavior, clone the StandardSyntaxParser from the previous version of Lucene and create a custom query parser with that parser. +## LucenePackage class removed (LUCENE-10260) + +LucenePackage class has been removed. The implementation string can be +retrieved from Version.getPackageImplementationVersion(). + ## Directory API is now little endian (LUCENE-9047) DataOutput's writeShort, writeInt, and writeLong methods now encode with diff --git a/lucene/core/src/java/org/apache/lucene/LucenePackage.java b/lucene/core/src/java/org/apache/lucene/LucenePackage.java deleted file mode 100644 index da903f40ebf..00000000000 --- a/lucene/core/src/java/org/apache/lucene/LucenePackage.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.lucene; - -/** Lucene's package information, including version. */ -public final class LucenePackage { - - private LucenePackage() {} // can't construct - - /** Return Lucene's package, including version information. */ - public static Package get() { - return LucenePackage.class.getPackage(); - } -} diff --git a/lucene/core/src/java/org/apache/lucene/util/Version.java b/lucene/core/src/java/org/apache/lucene/util/Version.java index 222371f4105..5aa7f844e38 100644 --- a/lucene/core/src/java/org/apache/lucene/util/Version.java +++ b/lucene/core/src/java/org/apache/lucene/util/Version.java @@ -16,8 +16,11 @@ */ package org.apache.lucene.util; +import java.io.IOException; +import java.io.UncheckedIOException; import java.text.ParseException; import java.util.Locale; +import java.util.jar.Manifest; /** * Use by certain classes to match version compatibility across releases of Lucene. @@ -67,6 +70,9 @@ public final class Version { */ public static final int MIN_SUPPORTED_MAJOR = Version.LATEST.major - 1; + /** @see #getPackageImplementationVersion() */ + private static String implementationVersion; + /** * Parse a version number of the form {@code "major.minor.bugfix.prerelease"}. * @@ -302,4 +308,46 @@ public final class Version { public int hashCode() { return encodedValue; } + + /** + * Return Lucene's full implementation version. This version is saved in Lucene's metadata at + * build time (JAR manifest, module info). If it is not available, an {@code unknown} + * implementation version is returned. + * + * @return Lucene implementation version string, never {@code null}. + */ + public static String getPackageImplementationVersion() { + // Initialize the lazy value. + synchronized (Version.class) { + if (implementationVersion == null) { + String version; + + Package p = Version.class.getPackage(); + version = p.getImplementationVersion(); + + if (version == null) { + var module = Version.class.getModule(); + if (module.isNamed()) { + // Running as a module? Try parsing the manifest manually. + try (var is = module.getResourceAsStream("/META-INF/MANIFEST.MF")) { + if (is != null) { + Manifest m = new Manifest(is); + version = m.getMainAttributes().getValue("Implementation-Version"); + } + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + + if (version == null) { + version = "unknown"; + } + + implementationVersion = version; + } + + return implementationVersion; + } + } } diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/AboutDialogFactory.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/AboutDialogFactory.java index 94c9a11b702..d7cbd98a834 100644 --- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/AboutDialogFactory.java +++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/AboutDialogFactory.java @@ -29,7 +29,6 @@ import java.awt.Insets; import java.awt.Window; import java.io.IOException; import java.net.URISyntaxException; -import java.util.Objects; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; @@ -42,7 +41,6 @@ import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; -import org.apache.lucene.LucenePackage; import org.apache.lucene.luke.app.desktop.Preferences; import org.apache.lucene.luke.app.desktop.PreferencesFactory; import org.apache.lucene.luke.app.desktop.util.DialogOpener; @@ -51,6 +49,7 @@ import org.apache.lucene.luke.app.desktop.util.ImageUtils; import org.apache.lucene.luke.app.desktop.util.MessageUtils; import org.apache.lucene.luke.app.desktop.util.URLLabel; import org.apache.lucene.luke.models.LukeException; +import org.apache.lucene.util.Version; /** Factory of about dialog */ public final class AboutDialogFactory implements DialogOpener.DialogFactory { @@ -173,15 +172,15 @@ public final class AboutDialogFactory implements DialogOpener.DialogFactory { } private static final String LUCENE_IMPLEMENTATION_VERSION = - LucenePackage.get().getImplementationVersion(); + Version.getPackageImplementationVersion(); private static final String LICENSE_NOTICE = - "

[Implementation Version]

" + "

[Lucene Implementation Version]

" + "

" - + (Objects.nonNull(LUCENE_IMPLEMENTATION_VERSION) ? LUCENE_IMPLEMENTATION_VERSION : "") + + LUCENE_IMPLEMENTATION_VERSION + "

" + "

[License]

" - + "

Luke is distributed under Apache License Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) " + + "

Luke is distributed under Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0) " + "and includes The Elegant Icon Font (https://www.elegantthemes.com/blog/resources/elegant-icon-font) " + "licensed under MIT (https://opensource.org/licenses/MIT)

" + "

[Brief history]

"