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