You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/11/26 07:50:11 UTC

[lucene] branch branch_9_0 updated: LUCENE-10260: Luke's about window no longer shows version number (#473)

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

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


The following commit(s) were added to refs/heads/branch_9_0 by this push:
     new 1ddce84  LUCENE-10260: Luke's about window no longer shows version number (#473)
1ddce84 is described below

commit 1ddce848cf3d5067efcafc6569d5f8203e56af0b
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Fri Nov 26 08:32:23 2021 +0100

    LUCENE-10260: Luke's about window no longer shows version number (#473)
---
 lucene/CHANGES.txt                                 |  3 ++
 lucene/MIGRATE.md                                  |  5 +++
 .../src/java/org/apache/lucene/LucenePackage.java  | 28 -------------
 .../src/java/org/apache/lucene/util/Version.java   | 48 ++++++++++++++++++++++
 .../dialog/menubar/AboutDialogFactory.java         | 11 +++--
 5 files changed, 61 insertions(+), 34 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4b88da4..45c215fe 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -167,6 +167,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 d24e7b6..f2ec458 100644
--- a/lucene/MIGRATE.md
+++ b/lucene/MIGRATE.md
@@ -17,6 +17,11 @@
 
 # Apache Lucene Migration Guide
 
+## 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 da903f4..0000000
--- 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 81a1319..a131981 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.
@@ -232,6 +235,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"}.
    *
@@ -467,4 +473,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 94c9a11..d7cbd98 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>"