Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions mbi/core/src/org/fedoraproject/mbi/tool/ToolUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ 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 ) )
{
Thread.currentThread().setContextClassLoader( cl );
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;
Expand Down Expand Up @@ -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
Expand All @@ -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 );
Expand Down