From ba418cf57c8188cfa3948a5dbf5f6721d5557660 Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Tue, 12 Nov 2024 21:28:18 +0100 Subject: [PATCH] Fix printing logs of failed ant tasks Logs of failed ant tasks were supposed to be printed to stderr, but there was a bug preventing that. Related: #159 --- .../org/fedoraproject/mbi/tool/ToolUtils.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mbi/core/src/org/fedoraproject/mbi/tool/ToolUtils.java b/mbi/core/src/org/fedoraproject/mbi/tool/ToolUtils.java index d96fb50d..9aa32c47 100644 --- a/mbi/core/src/org/fedoraproject/mbi/tool/ToolUtils.java +++ b/mbi/core/src/org/fedoraproject/mbi/tool/ToolUtils.java @@ -73,6 +73,8 @@ public static void runToolOnProject( Reactor reactor, ModuleDescriptor toolModul Execution exec ) throws Exception { + boolean threadUnsafe = false; + Path logFile = reactor.getTargetDir( module ).resolve( exec.getToolName() + ".log" ); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try ( URLClassLoader cl = ToolUtils.newClassLoader( reactor, toolModule, module ) ) { @@ -80,8 +82,7 @@ public static void runToolOnProject( Reactor reactor, ModuleDescriptor toolModul var entryClassName = Tool.class.getPackage().getName() + "." + exec.getToolName() + "." + exec.getToolName().substring( 0, 1 ).toUpperCase() + exec.getToolName().substring( 1 ) + "Tool"; Class toolClass = cl.loadClass( entryClassName ); - boolean threadUnsafe = toolClass.isAnnotationPresent( ThreadUnsafe.class ); - Path logFile = reactor.getTargetDir( module ).resolve( exec.getToolName() + ".log" ); + threadUnsafe = toolClass.isAnnotationPresent( ThreadUnsafe.class ); Files.createDirectories( logFile.getParent() ); Lock lock = threadUnsafe ? EXCLUSIVE_LOCK : SHARED_LOCK; PrintStream out = null; @@ -112,14 +113,6 @@ public static void runToolOnProject( Reactor reactor, ModuleDescriptor toolModul } tool.execute(); } - catch ( Exception e ) - { - if ( threadUnsafe ) - { - System.err.print( Files.readString( logFile ) ); - } - throw e; - } finally { try @@ -136,6 +129,14 @@ public static void runToolOnProject( Reactor reactor, ModuleDescriptor toolModul } } } + catch ( Exception e ) + { + if ( threadUnsafe ) + { + System.err.print( Files.readString( logFile ) ); + } + throw e; + } finally { Thread.currentThread().setContextClassLoader( oldCl );