diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javafx/JavaFXTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javafx/JavaFXTest.java index 7eadeda96d..70bf3808d3 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javafx/JavaFXTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/javafx/JavaFXTest.java @@ -37,21 +37,20 @@ public class JavaFXTest extends AbstractProjectsManagerBasedTest { - private static final String VERSION_1_8 = "1.8"; private static final String JAVA_SE_8 = "JavaSE-1.8"; private static final String JAVA_SE_17 = "JavaSE-17"; /** - * Test musts run with the -Djdkfx8.home=/path/to/jdk8+fx System property, or it - * will be skipped. + * Test requires Java 8 in toolchains.xml */ @Test public void testJavaFX() throws Exception { IVMInstall defaultJRE = JavaRuntime.getDefaultVMInstall(); String name = "java8fx"; IProject project = null; + IExecutionEnvironment java8env = JVMConfigurator.getExecutionEnvironment(JAVA_SE_8); + IVMInstall oldJavaVm = java8env.getDefaultVM(); try { - IExecutionEnvironment java8env = JVMConfigurator.getExecutionEnvironment(JAVA_SE_8); IVMInstall java8vm = null; IVMInstall java8DefaultVm = null; if (java8env != null) { @@ -89,6 +88,7 @@ public void testJavaFX() throws Exception { if (environment != null) { environment.setDefaultVM(defaultJRE); } + java8env.setDefaultVM(oldJavaVm); } } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java index 20dc988d73..badc112160 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java @@ -67,6 +67,11 @@ import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.jdt.core.manipulation.CoreASTProvider; +import org.eclipse.jdt.launching.IVMInstall; +import org.eclipse.jdt.launching.IVMInstallType; +import org.eclipse.jdt.launching.JavaRuntime; +import org.eclipse.jdt.launching.environments.IExecutionEnvironment; +import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; import org.eclipse.jdt.ls.core.internal.DocumentAdapter; import org.eclipse.jdt.ls.core.internal.JDTUtils; import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient; @@ -76,6 +81,7 @@ import org.eclipse.jdt.ls.core.internal.ProjectUtils; import org.eclipse.jdt.ls.core.internal.ResourceUtils; import org.eclipse.jdt.ls.core.internal.SimpleLogListener; +import org.eclipse.jdt.ls.core.internal.TestVMType; import org.eclipse.jdt.ls.core.internal.WorkspaceHelper; import org.eclipse.jdt.ls.core.internal.handlers.BundleUtils; import org.eclipse.jdt.ls.core.internal.handlers.ProgressReporterManager; @@ -173,6 +179,21 @@ public IBuffer createBuffer(ICompilationUnit workingCopy) { return DocumentAdapter.Null; } }); + IVMInstallType[] vmInstallTypes = JavaRuntime.getVMInstallTypes(); + for (IVMInstallType vmInstallType : vmInstallTypes) { + if (vmInstallType instanceof TestVMType) { + for (IVMInstall vm : vmInstallType.getVMInstalls()) { + IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); + IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); + for (IExecutionEnvironment environment : environments) { + if (environment.isStrictlyCompatible(vm)) { + environment.setDefaultVM(vm); + break; + } + } + } + } + } } protected void initPreferences(Preferences preferences) throws IOException {