From bc59fff79a5682b0bea1d9007abb7c2343a64a35 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 2 Sep 2012 00:56:13 +0100 Subject: [PATCH] Change local jline checks to not use String literals. Fixes BUKKIT-2455. Refactoring dependencies 'changes' the string literal in the code. This commit changes the literal to instead use a char[] to initialize a new String. On a bytecode level, there will not exist a String literal for these two values; the shade plugin will no longer refactor them. Refactoring jline also changes the other String literals we use for notifying jline of the current state. To insure that our local code reflects the inner logic in jline, the key value was changed to the static final variable located in TerminalFactory. Likewise, UnsupportedTerminal uses the explicit class name (as reflection is used later with the value that has been set). By: Luke Granger-Brown --- .../src/main/java/org/bukkit/craftbukkit/Main.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java b/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java index c6fa9ab86c..9aa28c85bb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java @@ -128,14 +128,23 @@ public class Main { System.out.println(CraftServer.class.getPackage().getImplementationVersion()); } else { try { - useJline = !"jline.UnsupportedTerminal".equals(System.getProperty("jline.terminal")); + // This trick bypasses Maven Shade's clever rewriting of our getProperty call when using String literals + String jline_UnsupportedTerminal = new String(new char[] {'j','l','i','n','e','.','U','n','s','u','p','p','o','r','t','e','d','T','e','r','m','i','n','a','l'}); + String jline_terminal = new String(new char[] {'j','l','i','n','e','.','t','e','r','m','i','n','a','l'}); + + useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal)); if (options.has("nojline")) { - System.setProperty("jline.terminal", "jline.UnsupportedTerminal"); System.setProperty("user.language", "en"); useJline = false; } + if (!useJline) { + // This ensures the terminal literal will always match the jline implementation + System.setProperty(jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName()); + } + + if (options.has("noconsole")) { useConsole = false; }