LUCENE-10213: Use unicode escapes in message property files in Luke (remove hacks)

This commit is contained in:
Dawid Weiss 2021-10-31 10:02:15 +01:00
parent ded915b29b
commit 98b17952f9
4 changed files with 20 additions and 32 deletions

View File

@ -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. // Configure "stand-alone" JAR with proper dependency classpath links.
task standaloneJar(type: Jar) { task standaloneJar(type: Jar) {

View File

@ -20,6 +20,14 @@
This is Luke, Apache Lucene low-level index inspection and repair utility. This is Luke, Apache Lucene low-level index inspection and repair utility.
Luke requires Java ${required.java.version}. You can start it with: Luke requires Java ${required.java.version}. You can start it with:
```
java -jar ${luke.cmd} java -jar ${luke.cmd}
```
or, using Java modules:
```
java --module-path . --add-modules org.apache.logging.log4j --module lucene.luke
```
Happy index hacking! Happy index hacking!

View File

@ -17,13 +17,8 @@
package org.apache.lucene.luke.app.desktop.util; 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.text.MessageFormat;
import java.util.Locale; import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle; import java.util.ResourceBundle;
/** Utilities for accessing message resources. */ /** Utilities for accessing message resources. */
@ -41,33 +36,8 @@ public class MessageUtils {
return new MessageFormat(pattern, Locale.ENGLISH).format(args); 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 bundle =
private static ResourceBundle.Control UTF8_RESOURCEBUNDLE_CONTROL = ResourceBundle.getBundle(MESSAGE_BUNDLE_BASENAME, Locale.ENGLISH);
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 MessageUtils() {} private MessageUtils() {}
} }

View File

@ -15,6 +15,9 @@
# limitations under the License. # limitations under the License.
# #
# This file must use UTF8 encoding. UTF8 is replaced with unicode
# escapes at build time.
# Common # Common
label.status=Status: label.status=Status:
label.help=Help label.help=Help