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 @@ -351,7 +351,7 @@ public static List<Path> getClasspath(MavenSession session, MojoExecution mojoEx
MethodHandles methodHandles = new MethodHandles(pluginRealm);

MethodHandle generateTestClasspathMethod =
findMethod(methodHandles, mojo.getClass(), "generateTestClasspath");
findMethod(methodHandles, mojo.getClass(), "generateTestClasspath", true);
if (generateTestClasspathMethod == null) {
LOGGER.debug(
"Could not find generateTestClasspathMethod method in {} class",
Expand Down Expand Up @@ -485,13 +485,32 @@ private static String getEffectiveJvm(MojoExecution mojoExecution, Mojo mojo) {

private static MethodHandle findMethod(
MethodHandles methodHandles, Class<?> mojoClass, String methodName) {
do {
MethodHandle getEffectiveJvm = methodHandles.method(mojoClass, methodName);
if (getEffectiveJvm != null) {
return getEffectiveJvm;
return findMethod(methodHandles, mojoClass, methodName, false);
}

private static MethodHandle findMethod(
MethodHandles methodHandles, Class<?> mojoClass, String methodName, boolean acceptVarargs) {
for (Class<?> clazz = mojoClass; clazz != null; clazz = clazz.getSuperclass()) {
MethodHandle handle = methodHandles.method(clazz, methodName);
if (handle != null) {
return handle;
}
}
if (!acceptVarargs) {
return null;
}
// fallback to a varargs method of the same name, which can also be invoked without arguments:
// our MethodHandles#invoke delegates to MethodHandle#invokeWithArguments, which collects the
// missing trailing varargs into an empty array. Necessary for:
// - AbstractSurefireMojo#generateTestClasspath() in >= 3.6.0-M1: added "ArtifactFilter..."
// param
for (Class<?> clazz = mojoClass; clazz != null; clazz = clazz.getSuperclass()) {
MethodHandle handle =
methodHandles.method(clazz, m -> m.getName().equals(methodName) && m.isVarArgs());
if (handle != null) {
return handle;
}
mojoClass = mojoClass.getSuperclass();
} while (mojoClass != null);
}
return null;
}

Expand Down
Loading