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