Update logback conditional to replace logback usage with reflection

This commit is contained in:
Michael Simacek 2017-06-08 12:46:42 +02:00
parent a747b6d9f7
commit fb99c98382
5 changed files with 67 additions and 8 deletions

View File

@ -1,7 +1,7 @@
From 8ef7cdcdc1c40742fb091177afe17f771a518f90 Mon Sep 17 00:00:00 2001
From: Michael Simacek <msimacek@redhat.com>
Date: Wed, 1 Feb 2017 14:54:26 +0100
Subject: [PATCH 1/3] Adapt mvn script
Subject: [PATCH 1/4] Adapt mvn script
---
apache-maven/src/bin/mvn | 19 ++++++++++++++++---
@ -65,5 +65,5 @@ index 623b5f2..e486b34 100755
# For Cygwin, switch paths to Windows format before running java
--
2.9.3
2.9.4

View File

@ -1,7 +1,7 @@
From 3dce15a3da21f5817a1b0193664312ffc8a5345c Mon Sep 17 00:00:00 2001
From: Michael Simacek <msimacek@redhat.com>
Date: Tue, 18 Apr 2017 16:30:58 +0200
Subject: [PATCH 2/3] Update to current slf4j
Subject: [PATCH 2/4] Update to current slf4j
---
.../src/main/java/org/slf4j/impl/MavenSimpleLogger.java | 7 ++++++-
@ -27,5 +27,5 @@ index 17f1f48..c4acb92 100644
if ( t.getMessage() != null )
{
--
2.9.3
2.9.4

View File

@ -1,7 +1,7 @@
From b54789188f2a61b5d58ff53986a5efe042d84fdf Mon Sep 17 00:00:00 2001
From: Michael Simacek <msimacek@redhat.com>
Date: Tue, 18 Apr 2017 16:51:34 +0200
Subject: [PATCH 3/3] Replace groovy invocation with antrun
Subject: [PATCH 3/4] Replace groovy invocation with antrun
---
maven-slf4j-provider/pom.xml | 23 ++++++++++++++---------
@ -50,5 +50,5 @@ index 363e00d..9be251b 100644
\ No newline at end of file
+</project>
--
2.9.3
2.9.4

View File

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

View File

@ -5,7 +5,7 @@
Name: maven
Epoch: 1
Version: 3.5.0
Release: 3%{?dist}
Release: 4%{?dist}
Summary: Java project management and project comprehension tool
License: ASL 2.0
URL: http://maven.apache.org/
@ -20,6 +20,9 @@ Patch1: 0001-Adapt-mvn-script.patch
Patch2: 0002-Update-to-current-slf4j.patch
# Fedora specific, avoids usage of unpackaged groovy-maven-plugin
Patch3: 0003-Replace-groovy-invocation-with-antrun.patch
# Downstream-specific, avoids dependency on logback
# Used only when %without logback is in effect
Patch4: 0004-Invoke-logback-via-reflection.patch
BuildRequires: maven-local
BuildRequires: mvn(com.google.guava:guava)
@ -169,7 +172,7 @@ sed -i 's:\r::' apache-maven/src/conf/settings.xml
%if %{without logback}
%pom_remove_dep -r :logback-classic
rm maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java
%patch4 -p1
%endif
%mvn_alias :maven-resolver-provider :maven-aether-provider
@ -238,6 +241,9 @@ ln -sf %{_sysconfdir}/%{name}/logging %{buildroot}%{_datadir}/%{name}/conf
%changelog
* Thu Jun 08 2017 Michael Simacek <msimacek@redhat.com> - 1:3.5.0-4
- Update logback conditional to replace logback usage with reflection
* Wed Apr 26 2017 Mikolaj Izdebski <mizdebsk@redhat.com> - 1:3.5.0-3
- Add apache-commons-codec to plexus.core
- Resolves: rhbz#1445738