Apache Lucene open-source search software
LUCENE-10213: Use unicode escapes in message property files in Luke (remove hacks)
Dawid Weiss98b17952f902
diff --git a/lucene/luke/build.gradle b/lucene/luke/build.gradleindex 760e8392699..23c843a39ab 100644--- a/lucene/luke/build.gradle+++ b/lucene/luke/build.gradle@@ -57,6 +57,13 @@ tasks.withType(Jar) {}}+// Process UTF8 property files to unicode escapes.+tasks.withType(ProcessResources).configureEach { task ->+ task.filesMatching("**/messages*.properties", {+ filteringCharset = 'UTF-8'+ filter(EscapeUnicode)+ })+}// Configure "stand-alone" JAR with proper dependency classpath links.task standaloneJar(type: Jar) {diff --git a/lucene/luke/src/distribution/README.md b/lucene/luke/src/distribution/README.mdindex b0672ae2bca..c23dba02875 100644--- a/lucene/luke/src/distribution/README.md+++ b/lucene/luke/src/distribution/README.md@@ -20,6 +20,14 @@This is Luke, Apache Lucene low-level index inspection and repair utility.Luke requires Java ${required.java.version}. You can start it with:+```java -jar ${luke.cmd}+```++or, using Java modules:++```+java --module-path . --add-modules org.apache.logging.log4j --module lucene.luke+```Happy index hacking!diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/MessageUtils.java b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/MessageUtils.javaindex 2afb62b754a..453ef388b08 100644--- a/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/MessageUtils.java+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/desktop/util/MessageUtils.java@@ -17,13 +17,8 @@package org.apache.lucene.luke.app.desktop.util;-import java.io.IOException;-import java.io.InputStream;-import java.io.InputStreamReader;-import java.nio.charset.StandardCharsets;import java.text.MessageFormat;import java.util.Locale;-import java.util.PropertyResourceBundle;import java.util.ResourceBundle;/** Utilities for accessing message resources. */@@ -41,33 +36,8 @@ public class MessageUtils {return new MessageFormat(pattern, Locale.ENGLISH).format(args);}- // https://stackoverflow.com/questions/4659929/how-to-use-utf-8-in-resource-properties-with-resourcebundle- private static ResourceBundle.Control UTF8_RESOURCEBUNDLE_CONTROL =- new ResourceBundle.Control() {- @Override- public ResourceBundle newBundle(- String baseName, Locale locale, String format, ClassLoader loader, boolean reload)- throws IllegalAccessException, InstantiationException, IOException {- String bundleName = toBundleName(baseName, locale);- String resourceName = toResourceName(bundleName, "properties");- try (InputStream is = loader.getResourceAsStream(resourceName)) {- return new PropertyResourceBundle(new InputStreamReader(is, StandardCharsets.UTF_8));- }- }- };-- private static ResourceBundle bundle;-- static {- Class<?> self = MessageUtils.class;- if (self.getModule().isNamed()) {- bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE_BASENAME, Locale.ENGLISH, self.getModule());- } else {- bundle =- ResourceBundle.getBundle(- MESSAGE_BUNDLE_BASENAME, Locale.ENGLISH, UTF8_RESOURCEBUNDLE_CONTROL);- }- }+ private static ResourceBundle bundle =+ ResourceBundle.getBundle(MESSAGE_BUNDLE_BASENAME, Locale.ENGLISH);private MessageUtils() {}}diff --git a/lucene/luke/src/resources/org/apache/lucene/luke/app/desktop/messages/messages.properties b/lucene/luke/src/resources/org/apache/lucene/luke/app/desktop/messages/messages.propertiesindex 30b43cf18b7..e8143297121 100644--- a/lucene/luke/src/resources/org/apache/lucene/luke/app/desktop/messages/messages.properties+++ b/lucene/luke/src/resources/org/apache/lucene/luke/app/desktop/messages/messages.properties@@ -15,6 +15,9 @@# limitations under the License.#+# This file must use UTF8 encoding. UTF8 is replaced with unicode+# escapes at build time.+# Commonlabel.status=Status:label.help=Help