|
22 | 22 | import org.junit.platform.commons.JUnitException;
|
23 | 23 | import org.junit.platform.commons.util.ClassLoaderUtils;
|
24 | 24 | import org.junit.platform.commons.util.ReflectionUtils;
|
| 25 | +import org.junit.platform.engine.EngineExecutionListener; |
| 26 | +import org.junit.platform.engine.ExecutionRequest; |
25 | 27 | import org.junit.platform.engine.TestDescriptor;
|
26 | 28 | import org.junit.platform.engine.TestEngine;
|
27 | 29 | import org.junit.platform.engine.TestSource;
|
@@ -105,6 +107,74 @@ private JUnitPlatformUtils() {}
|
105 | 107 | private static final MethodHandle GET_JAVA_METHOD =
|
106 | 108 | METHOD_HANDLES.method(MethodSource.class, "getJavaMethod");
|
107 | 109 |
|
| 110 | + /* |
| 111 | + * From 5.13.0-RC1 onwards ExecutionRequest requires two additional arguments on creation. |
| 112 | + * - OutputDirectoryProvider outputDirectoryProvider |
| 113 | + * - NamespacedHierarchicalStore<Namespace> requestLevelStore |
| 114 | + */ |
| 115 | + private static final MethodHandle GET_OUTPUT_DIRECTORY_PROVIDER = |
| 116 | + METHOD_HANDLES.method(ExecutionRequest.class, "getOutputDirectoryProvider"); |
| 117 | + private static final MethodHandle GET_STORE = |
| 118 | + METHOD_HANDLES.method(ExecutionRequest.class, "getStore"); |
| 119 | + private static final String[] CREATE_FALLBACK_PARAMETER_TYPES = |
| 120 | + new String[] { |
| 121 | + "org.junit.platform.engine.TestDescriptor", |
| 122 | + "org.junit.platform.engine.EngineExecutionListener", |
| 123 | + "org.junit.platform.engine.ConfigurationParameters" |
| 124 | + }; |
| 125 | + private static final String[] CREATE_PARAMETER_TYPES = |
| 126 | + new String[] { |
| 127 | + "org.junit.platform.engine.TestDescriptor", |
| 128 | + "org.junit.platform.engine.EngineExecutionListener", |
| 129 | + "org.junit.platform.engine.ConfigurationParameters", |
| 130 | + "org.junit.platform.engine.reporting.OutputDirectoryProvider", |
| 131 | + "org.junit.platform.engine.support.store.NamespacedHierarchicalStore" |
| 132 | + }; |
| 133 | + private static final MethodHandle EXECUTION_REQUEST_CREATE = createExecutionRequestHandle(); |
| 134 | + |
| 135 | + private static MethodHandle createExecutionRequestHandle() { |
| 136 | + if (GET_STORE != null && GET_OUTPUT_DIRECTORY_PROVIDER != null) { |
| 137 | + return METHOD_HANDLES.method( |
| 138 | + ExecutionRequest.class, |
| 139 | + m -> |
| 140 | + "create".equals(m.getName()) |
| 141 | + && m.getParameterCount() == 5 |
| 142 | + && Arrays.equals( |
| 143 | + Arrays.stream(m.getParameterTypes()).map(Class::getName).toArray(), |
| 144 | + CREATE_PARAMETER_TYPES)); |
| 145 | + } else { |
| 146 | + return METHOD_HANDLES.method( |
| 147 | + ExecutionRequest.class, |
| 148 | + m -> |
| 149 | + "create".equals(m.getName()) |
| 150 | + && m.getParameterCount() == 3 |
| 151 | + && Arrays.equals( |
| 152 | + Arrays.stream(m.getParameterTypes()).map(Class::getName).toArray(), |
| 153 | + CREATE_FALLBACK_PARAMETER_TYPES)); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + public static ExecutionRequest createExecutionRequest( |
| 158 | + ExecutionRequest request, EngineExecutionListener listener) { |
| 159 | + if (GET_STORE != null && GET_OUTPUT_DIRECTORY_PROVIDER != null) { |
| 160 | + Object provider = METHOD_HANDLES.invoke(GET_OUTPUT_DIRECTORY_PROVIDER, request); |
| 161 | + Object store = METHOD_HANDLES.invoke(GET_STORE, request); |
| 162 | + return METHOD_HANDLES.invoke( |
| 163 | + EXECUTION_REQUEST_CREATE, |
| 164 | + request.getRootTestDescriptor(), |
| 165 | + listener, |
| 166 | + request.getConfigurationParameters(), |
| 167 | + provider, |
| 168 | + store); |
| 169 | + } else { |
| 170 | + return METHOD_HANDLES.invoke( |
| 171 | + EXECUTION_REQUEST_CREATE, |
| 172 | + request.getRootTestDescriptor(), |
| 173 | + listener, |
| 174 | + request.getConfigurationParameters()); |
| 175 | + } |
| 176 | + } |
| 177 | + |
108 | 178 | private static Class<?> getTestClass(MethodSource methodSource) {
|
109 | 179 | Class<?> javaClass = METHOD_HANDLES.invoke(GET_JAVA_CLASS, methodSource);
|
110 | 180 | if (javaClass != null) {
|
|
0 commit comments