From 5d64fc9030cc57ac35049929b5de13d5445a686e Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Wed, 4 Apr 2018 19:47:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BB=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authlibinjector/AuthlibInjector.java | 17 ++++--------- .../httpd/DeprecatedApiHandle.java | 2 +- .../httpd/DeprecatedApiHttpd.java | 4 ++-- .../javaagent/AuthlibInjectorPremain.java | 4 ++-- .../transform/ClassTransformer.java | 4 ++-- .../transform/LdcTransformUnit.java | 2 +- .../authlibinjector/util/LoggingUtils.java | 24 +++++++++++++++++++ 7 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 src/main/java/org/to2mbn/authlibinjector/util/LoggingUtils.java diff --git a/src/main/java/org/to2mbn/authlibinjector/AuthlibInjector.java b/src/main/java/org/to2mbn/authlibinjector/AuthlibInjector.java index ada48b2..80193bb 100644 --- a/src/main/java/org/to2mbn/authlibinjector/AuthlibInjector.java +++ b/src/main/java/org/to2mbn/authlibinjector/AuthlibInjector.java @@ -6,9 +6,11 @@ import static java.util.Optional.of; import static org.to2mbn.authlibinjector.util.IOUtils.asString; import static org.to2mbn.authlibinjector.util.IOUtils.getURL; import static org.to2mbn.authlibinjector.util.IOUtils.removeNewLines; +import static org.to2mbn.authlibinjector.util.LoggingUtils.debug; +import static org.to2mbn.authlibinjector.util.LoggingUtils.info; +import static org.to2mbn.authlibinjector.util.LoggingUtils.isDebugOn; import java.io.IOException; import java.lang.instrument.ClassFileTransformer; -import java.text.MessageFormat; import java.util.Base64; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; @@ -30,17 +32,6 @@ public final class AuthlibInjector { private AuthlibInjector() {} private static AtomicBoolean booted = new AtomicBoolean(false); - private static boolean debug = "true".equals(System.getProperty("org.to2mbn.authlibinjector.debug")); - - public static void info(String message, Object... args) { - System.err.println("[authlib-injector] " + MessageFormat.format(message, args)); - } - - public static void debug(String message, Object... args) { - if (debug) { - info(message, args); - } - } public static void bootstrap(Consumer transformerRegistry) { if (!booted.compareAndSet(false, true)) { @@ -103,7 +94,7 @@ public final class AuthlibInjector { private static ClassTransformer createTransformer(YggdrasilConfiguration config) { ClassTransformer transformer = new ClassTransformer(); - transformer.debugSaveClass = debug; + transformer.debugSaveClass = isDebugOn(); for (String ignore : nonTransformablePackages) transformer.ignores.add(ignore); diff --git a/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHandle.java b/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHandle.java index 4e2009b..04706d9 100644 --- a/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHandle.java +++ b/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHandle.java @@ -1,6 +1,6 @@ package org.to2mbn.authlibinjector.httpd; -import static org.to2mbn.authlibinjector.AuthlibInjector.info; +import static org.to2mbn.authlibinjector.util.LoggingUtils.info; import java.io.IOException; import org.to2mbn.authlibinjector.YggdrasilConfiguration; import org.to2mbn.authlibinjector.transform.DeprecatedApiTransformUnit; diff --git a/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHttpd.java b/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHttpd.java index bcfbcd5..9ebd783 100644 --- a/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHttpd.java +++ b/src/main/java/org/to2mbn/authlibinjector/httpd/DeprecatedApiHttpd.java @@ -3,11 +3,11 @@ package org.to2mbn.authlibinjector.httpd; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Optional.empty; import static java.util.Optional.of; -import static org.to2mbn.authlibinjector.AuthlibInjector.debug; -import static org.to2mbn.authlibinjector.AuthlibInjector.info; import static org.to2mbn.authlibinjector.util.IOUtils.asString; import static org.to2mbn.authlibinjector.util.IOUtils.getURL; import static org.to2mbn.authlibinjector.util.IOUtils.postURL; +import static org.to2mbn.authlibinjector.util.LoggingUtils.debug; +import static org.to2mbn.authlibinjector.util.LoggingUtils.info; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.UncheckedIOException; diff --git a/src/main/java/org/to2mbn/authlibinjector/javaagent/AuthlibInjectorPremain.java b/src/main/java/org/to2mbn/authlibinjector/javaagent/AuthlibInjectorPremain.java index 7d64df5..98847e9 100644 --- a/src/main/java/org/to2mbn/authlibinjector/javaagent/AuthlibInjectorPremain.java +++ b/src/main/java/org/to2mbn/authlibinjector/javaagent/AuthlibInjectorPremain.java @@ -1,9 +1,9 @@ package org.to2mbn.authlibinjector.javaagent; import static org.to2mbn.authlibinjector.AuthlibInjector.bootstrap; -import static org.to2mbn.authlibinjector.AuthlibInjector.debug; -import static org.to2mbn.authlibinjector.AuthlibInjector.info; import static org.to2mbn.authlibinjector.AuthlibInjector.nonTransformablePackages; +import static org.to2mbn.authlibinjector.util.LoggingUtils.debug; +import static org.to2mbn.authlibinjector.util.LoggingUtils.info; import java.lang.instrument.Instrumentation; import java.util.Arrays; diff --git a/src/main/java/org/to2mbn/authlibinjector/transform/ClassTransformer.java b/src/main/java/org/to2mbn/authlibinjector/transform/ClassTransformer.java index 75f37aa..9e4de46 100644 --- a/src/main/java/org/to2mbn/authlibinjector/transform/ClassTransformer.java +++ b/src/main/java/org/to2mbn/authlibinjector/transform/ClassTransformer.java @@ -1,7 +1,7 @@ package org.to2mbn.authlibinjector.transform; -import static org.to2mbn.authlibinjector.AuthlibInjector.debug; -import static org.to2mbn.authlibinjector.AuthlibInjector.info; +import static org.to2mbn.authlibinjector.util.LoggingUtils.debug; +import static org.to2mbn.authlibinjector.util.LoggingUtils.info; import java.io.IOException; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; diff --git a/src/main/java/org/to2mbn/authlibinjector/transform/LdcTransformUnit.java b/src/main/java/org/to2mbn/authlibinjector/transform/LdcTransformUnit.java index 986c330..0332003 100644 --- a/src/main/java/org/to2mbn/authlibinjector/transform/LdcTransformUnit.java +++ b/src/main/java/org/to2mbn/authlibinjector/transform/LdcTransformUnit.java @@ -1,7 +1,7 @@ package org.to2mbn.authlibinjector.transform; import static org.objectweb.asm.Opcodes.ASM6; -import static org.to2mbn.authlibinjector.AuthlibInjector.info; +import static org.to2mbn.authlibinjector.util.LoggingUtils.info; import java.util.Optional; import java.util.function.Function; import org.objectweb.asm.ClassVisitor; diff --git a/src/main/java/org/to2mbn/authlibinjector/util/LoggingUtils.java b/src/main/java/org/to2mbn/authlibinjector/util/LoggingUtils.java new file mode 100644 index 0000000..d92e4e0 --- /dev/null +++ b/src/main/java/org/to2mbn/authlibinjector/util/LoggingUtils.java @@ -0,0 +1,24 @@ +package org.to2mbn.authlibinjector.util; + +import java.text.MessageFormat; + +public final class LoggingUtils { + + private static boolean debug = "true".equals(System.getProperty("org.to2mbn.authlibinjector.debug")); + + public static void info(String message, Object... args) { + System.err.println("[authlib-injector] " + MessageFormat.format(message, args)); + } + + public static void debug(String message, Object... args) { + if (debug) { + info(message, args); + } + } + + public static boolean isDebugOn() { + return debug; + } + + private LoggingUtils() {} +}