Apache Lucene open-source search software
LUCENE-10260: Luke's about window no longer shows version number (#473)
Dawid Weiss651755aab707
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 27739b46ad2..72dfba0b43f 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -239,6 +239,9 @@ API Changesunwrap wrappers/delegators that are added by Lucene's testing framework. This will allowtesting 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.mdindex 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 parentparse differently than before. If you need the exact previous behavior, clone the StandardSyntaxParser from the previous version of Lucene and create a custom query parserwith 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 withdiff --git a/lucene/core/src/java/org/apache/lucene/LucenePackage.java b/lucene/core/src/java/org/apache/lucene/LucenePackage.javadeleted file mode 100644index 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.javaindex 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.javaindex 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 =- "<p>[Implementation Version]</p>"+ "<p>[Lucene Implementation Version]</p>"+ "<p>"- + (Objects.nonNull(LUCENE_IMPLEMENTATION_VERSION) ? LUCENE_IMPLEMENTATION_VERSION : "")+ + LUCENE_IMPLEMENTATION_VERSION+ "</p>"+ "<p>[License]</p>"- + "<p>Luke is distributed under <a href=\"http://www.apache.org/licenses/LICENSE-2.0\">Apache License Version 2.0</a> (http://www.apache.org/licenses/LICENSE-2.0) "+ + "<p>Luke is distributed under <a href=\"https://www.apache.org/licenses/LICENSE-2.0\">Apache License Version 2.0</a> (https://www.apache.org/licenses/LICENSE-2.0) "+ "and includes <a href=\"https://www.elegantthemes.com/blog/resources/elegant-icon-font\">The Elegant Icon Font</a> (https://www.elegantthemes.com/blog/resources/elegant-icon-font) "+ "licensed under <a href=\"https://opensource.org/licenses/MIT\">MIT</a> (https://opensource.org/licenses/MIT)</p>"+ "<p>[Brief history]</p>"