4dbac3
From 4d0c432cf88f2f70e6f793569d3dedace062fdef Mon Sep 17 00:00:00 2001
4dbac3
From: Michael Simacek <msimacek@redhat.com>
4dbac3
Date: Tue, 6 Jun 2017 13:47:43 +0200
4dbac3
Subject: [PATCH 2/6] Invoke logback via reflection
4dbac3
4dbac3
---
4dbac3
 .../logging/impl/LogbackConfiguration.java    | 19 ++++++++++++++-----
4dbac3
 1 file changed, 14 insertions(+), 5 deletions(-)
4dbac3
4dbac3
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java
4dbac3
index 5d9fab744..ced38cb5a 100644
4dbac3
--- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java
4dbac3
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java
4dbac3
@@ -35,22 +35,31 @@
4dbac3
     @Override
4dbac3
     public void setRootLoggerLevel( Level level )
4dbac3
     {
4dbac3
-        ch.qos.logback.classic.Level value;
4dbac3
+        String value;
4dbac3
         switch ( level )
4dbac3
         {
4dbac3
             case DEBUG:
4dbac3
-                value = ch.qos.logback.classic.Level.DEBUG;
4dbac3
+                value = "DEBUG";
4dbac3
                 break;
4dbac3
 
4dbac3
             case INFO:
4dbac3
-                value = ch.qos.logback.classic.Level.INFO;
4dbac3
+                value = "INFO";
4dbac3
                 break;
4dbac3
 
4dbac3
             default:
4dbac3
-                value = ch.qos.logback.classic.Level.ERROR;
4dbac3
+                value = "ERROR";
4dbac3
                 break;
4dbac3
         }
4dbac3
-        ( (ch.qos.logback.classic.Logger) LoggerFactory.getLogger( Logger.ROOT_LOGGER_NAME ) ).setLevel( value );
4dbac3
+        Logger logger = LoggerFactory.getLogger( Logger.ROOT_LOGGER_NAME );
4dbac3
+        try {
4dbac3
+            Class levelClass = Class.forName("ch.qos.logback.classic.Level");
4dbac3
+            Object logbackLevel = levelClass.getField(value).get(null);
4dbac3
+            Class loggerClass = Class.forName("ch.qos.logback.classic.Logger");
4dbac3
+            loggerClass.getMethod("setLevel", new Class[] {levelClass})
4dbac3
+                .invoke(logger, new Object[] {logbackLevel});
4dbac3
+        } catch (Exception e) {
4dbac3
+            throw new RuntimeException("Failed to initialize logback configuration", e);
4dbac3
+        }
4dbac3
     }
4dbac3
 
4dbac3
     @Override
4dbac3
-- 
4dbac3
2.35.1
4dbac3