|
24 | 24 | import org.eclipse.jdt.core.IJavaProject; |
25 | 25 | import org.eclipse.jdt.core.JavaCore; |
26 | 26 | import org.eclipse.jdt.core.JavaModelException; |
| 27 | +import org.eclipse.jdt.debug.testplugin.JavaProjectHelper; |
27 | 28 | import org.eclipse.jdt.debug.tests.AbstractDebugTest; |
28 | | -import org.eclipse.jdt.debug.tests.TestUtil; |
29 | 29 | import org.eclipse.jdt.launching.IVMInstall; |
30 | 30 | import org.eclipse.jdt.launching.JavaRuntime; |
31 | | -import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
32 | | -import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
33 | 31 |
|
34 | 32 | public class ModuleOptionsTests extends AbstractDebugTest { |
35 | 33 |
|
36 | | - private static final String JAVASE_9 = "JavaSE-9"; |
37 | | - |
38 | 34 | private static final String ASSUMED_DEFAULT_MODULES_9 = "java.se," // |
39 | 35 | // + "javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web," REMOVED in 10 |
40 | 36 | + "jdk.accessibility,jdk.attach,jdk.compiler,jdk.dynalink,jdk.httpserver,"// |
@@ -78,13 +74,13 @@ public ModuleOptionsTests(String name) { |
78 | 74 | @Override |
79 | 75 | protected void setUp() throws Exception { |
80 | 76 | super.setUp(); |
81 | | - prepareExecutionEnvironment9(); |
| 77 | + defaultVM9 = prepareExecutionEnvironment(JavaProjectHelper.JAVA_SE_9_EE_NAME); |
82 | 78 | } |
83 | 79 |
|
84 | 80 | @Override |
85 | 81 | protected void tearDown() throws Exception { |
86 | 82 | try { |
87 | | - restoreExecutionEnvironment9(); |
| 83 | + setExecutionEnvironment(JavaProjectHelper.JAVA_SE_9_EE_NAME, defaultVM9); |
88 | 84 | } finally { |
89 | 85 | super.tearDown(); |
90 | 86 | } |
@@ -250,34 +246,4 @@ private void checkVMInstall(IJavaProject javaProject) throws CoreException { |
250 | 246 | IVMInstall vm = JavaRuntime.getVMInstall(javaProject); |
251 | 247 | assertEquals("Expected default VM but got: " + vm.getInstallLocation(), defaultVm.getName(), vm.getName()); |
252 | 248 | } |
253 | | - |
254 | | - /** |
255 | | - * JDT tests run in different environments where different major JVM installations might be selected as "default" JVM for a specific Execution Environment (EE). |
256 | | - * This test cases project requires JavaSE-9 EE, which can be resolved to e.g. Java 11, 17 or 21, depending on the installed JVMs. |
257 | | - * JVM modules vary between Java major versions, while we need a stable set of modules for the test case. |
258 | | - * Therefore we "pin" the JVM used for the JavaSE-9 EE to the JVM on which the tests are executed - to avoid tests failing in different test environments. |
259 | | - */ |
260 | | - private void prepareExecutionEnvironment9() { |
261 | | - IVMInstall vm = JavaRuntime.getDefaultVMInstall(); |
262 | | - IExecutionEnvironment environment9 = getExecutionEnvironment9(); |
263 | | - defaultVM9 = environment9.getDefaultVM(); |
264 | | - environment9.setDefaultVM(vm); |
265 | | - TestUtil.logInfo("Set VM \"" + vm.getName() + "\" for execution environments: " + environment9.getId()); |
266 | | - } |
267 | | - |
268 | | - private void restoreExecutionEnvironment9() { |
269 | | - IExecutionEnvironment environment9 = getExecutionEnvironment9(); |
270 | | - environment9.setDefaultVM(defaultVM9); |
271 | | - TestUtil.logInfo("Restored default VM for execution environment: " + environment9.getId()); |
272 | | - } |
273 | | - |
274 | | - private static IExecutionEnvironment getExecutionEnvironment9() { |
275 | | - IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); |
276 | | - IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); |
277 | | - return Arrays.stream(environments).filter(ModuleOptionsTests::isEnvironment9).findFirst().orElseThrow(); |
278 | | - } |
279 | | - |
280 | | - private static boolean isEnvironment9(IExecutionEnvironment environment) { |
281 | | - return JAVASE_9.equals(environment.getId()); |
282 | | - } |
283 | 249 | } |
0 commit comments