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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class FacadeClassLoader extends ClassLoader implements Closeable {
private static final Map<String, CuratedApplication> curatedApplications = new HashMap<>();

// JUnit discovery is single threaded, so no need for concurrency on this map
private final Map<String, StartupAction> runtimeClassLoaders = new HashMap<>();
private final Map<String, QuarkusClassLoader> runtimeClassLoaders = new HashMap<>();
private static final String NO_PROFILE = "no-profile";

/*
Expand Down Expand Up @@ -439,8 +439,8 @@ private QuarkusClassLoader getQuarkusClassLoader(Class<?> requiredTestClass, Cla
String profileKey = getProfileKey(profile);

try {
StartupAction startupAction;
String key;
QuarkusClassLoader classLoader;

// We cannot directly access TestResourceUtil as long as we're in the core module, but the app classloaders can.
// But, chicken-and-egg, we may not have an app classloader yet. However, if we don't, we won't need to worry about restarts, but this instance clearly cannot need a restart
Expand All @@ -450,8 +450,8 @@ private QuarkusClassLoader getQuarkusClassLoader(Class<?> requiredTestClass, Cla
// If we make a classloader with a null profile, we get the problem of starting dev services multiple times, which is very bad (if temporary) - once that issue is fixed, could reconsider
if (keyMakerClassLoader == null) {
// Making a classloader uses the profile key to look up a curated application
startupAction = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
keyMakerClassLoader = startupAction.getClassLoader();
classLoader = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
keyMakerClassLoader = classLoader;

// We cannot use the startup action one because it's a base runtime classloader and so will not have the right access to application classes (they're in its banned list)
final String resourceKey = requiredTestClass != null ? getResourceKey(requiredTestClass, profile) : null;
Expand All @@ -463,18 +463,15 @@ private QuarkusClassLoader getQuarkusClassLoader(Class<?> requiredTestClass, Cla

// The resource key might be null, and that's ok
key = profileKey + resourceKey;
startupAction = runtimeClassLoaders.get(key);
if (startupAction == null) {
classLoader = runtimeClassLoaders.get(key);
if (classLoader == null) {
// Making a classloader uses the profile key to look up a curated application
startupAction = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
classLoader = getOrCreateRuntimeClassLoader(profileKey, requiredTestClass, profile);
}

}

// If we didn't have a classloader and didn't get a resource key
runtimeClassLoaders.put(key, startupAction);

return startupAction.getClassLoader();
runtimeClassLoaders.put(key, classLoader);
return classLoader;
} catch (RuntimeException e) {
// Exceptions here get swallowed by the JUnit framework and we don't get any debug information unless we print it ourself
e.printStackTrace();
Expand Down Expand Up @@ -543,13 +540,12 @@ private QuarkusClassLoader getOrCreateBaseClassLoader(String key, Class<?> requi
return curatedApplication.getOrCreateBaseRuntimeClassLoader();
}

private StartupAction getOrCreateRuntimeClassLoader(String key, Class<?> requiredTestClass, Class<?> profile)
private QuarkusClassLoader getOrCreateRuntimeClassLoader(String key, Class<?> requiredTestClass, Class<?> profile)
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException,
IllegalAccessException, AppModelResolverException, BootstrapException, IOException {
CuratedApplication curatedApplication = getOrCreateCuratedApplication(key, requiredTestClass);
StartupAction startupAction = AppMakerHelper.getStartupAction(requiredTestClass,
curatedApplication, profile);

QuarkusClassLoader loader = startupAction.getClassLoader();

Class<?> configProviderResolverClass = loader.loadClass(ConfigProviderResolver.class.getName());
Expand All @@ -561,7 +557,7 @@ private StartupAction getOrCreateRuntimeClassLoader(String key, Class<?> require
configProviderResolverClass.getDeclaredMethod("setInstance", configProviderResolverClass)
.invoke(null, testConfigProviderResolver);

return startupAction;
return loader;

}

Expand Down
Loading