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