mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
extend current classloader instead of creating a classloader chain.
This commit is contained in:
parent
f69069c2f8
commit
ace47f7e67
@ -72,6 +72,7 @@ public abstract class MapperTestBase {
|
|||||||
|
|
||||||
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
|
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
|
||||||
private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator();
|
private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator();
|
||||||
|
private static volatile boolean enhancedClassloader = false;
|
||||||
|
|
||||||
private JavaCompiler compiler;
|
private JavaCompiler compiler;
|
||||||
private String sourceDir;
|
private String sourceDir;
|
||||||
@ -104,12 +105,16 @@ public abstract class MapperTestBase {
|
|||||||
|
|
||||||
createOutputDirs();
|
createOutputDirs();
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(
|
if ( !enhancedClassloader ) {
|
||||||
new URLClassLoader(
|
// we need to make sure that the the generated classes are loaded by the same classloader as the test has
|
||||||
new URL[] { new File( classOutputDir ).toURI().toURL() },
|
// been loaded already. Otherwise some tests won't work.
|
||||||
Thread.currentThread().getContextClassLoader()
|
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||||
)
|
Class<?> clazz = URLClassLoader.class;
|
||||||
);
|
Method method = clazz.getDeclaredMethod( "addURL", new Class[] { URL.class } );
|
||||||
|
method.setAccessible( true );
|
||||||
|
method.invoke( classLoader, new File( classOutputDir ).toURI().toURL() );
|
||||||
|
enhancedClassloader = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user