Skip to content
Merged
Show file tree
Hide file tree
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 @@ -140,6 +140,7 @@
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.PropertyChangeEvent;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
Expand Down Expand Up @@ -3097,6 +3098,42 @@ private static String toString(Collection<IMarker> markers) {
return markersInfo.toString();
}

/**
* JDT tests run in different environments where different major JVM installations might be selected as "default" JVM for a specific Execution
* Environment (EE). Some test cases projects requires JavaSE-N EE, which can be resolved to e.g. Java 11, 17 or 21, depending on the installed
* JVMs. JVM modules vary between Java major versions, while we need a stable set of modules for the test case. Therefore we "pin" the JVM used
* for the JavaSE-N EE to the JVM on which the tests are executed - to avoid tests failing in different test environments.
*
* @param environmentId The ID of the EE, e.g.: "JavaSE-9"
* @return The default VM install for the EE, before we change it.
*/
protected static IVMInstall prepareExecutionEnvironment(String environmentId) {
IVMInstall vm = JavaRuntime.getDefaultVMInstall();
IExecutionEnvironment environment = getExecutionEnvironment(environmentId);
IVMInstall defaultVM = environment.getDefaultVM();
environment.setDefaultVM(vm);
TestUtil.logInfo("Set VM \"" + vm.getName() + "\" for execution environments: " + environment.getId());
return defaultVM;
}

/**
* Set the default VM of an EE.
*
* @param environmentId The ID of the EE, e.g.: "JavaSE-9"
* @param defaultVM The default VM to set.
*/
protected static void setExecutionEnvironment(String environmentId, IVMInstall defaultVM) {
IExecutionEnvironment environment = getExecutionEnvironment(environmentId);
environment.setDefaultVM(defaultVM);
TestUtil.logInfo("Set default VM for execution environment: " + environment.getId());
}

private static IExecutionEnvironment getExecutionEnvironment(String environmentId) {
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
return Arrays.stream(environments).filter(e -> environmentId.equals(e.getId())).findFirst().orElseThrow();
}

public interface StackFrameSupplier {
IJavaStackFrame get() throws Exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.debug.testplugin.JavaProjectHelper;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestUtil;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;

public class ModuleOptionsTests extends AbstractDebugTest {

private static final String JAVASE_9 = "JavaSE-9";

private static final String ASSUMED_DEFAULT_MODULES_9 = "java.se," //
// + "javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web," REMOVED in 10
+ "jdk.accessibility,jdk.attach,jdk.compiler,jdk.dynalink,jdk.httpserver,"//
Expand Down Expand Up @@ -78,13 +74,13 @@ public ModuleOptionsTests(String name) {
@Override
protected void setUp() throws Exception {
super.setUp();
prepareExecutionEnvironment9();
defaultVM9 = prepareExecutionEnvironment(JavaProjectHelper.JAVA_SE_9_EE_NAME);
}

@Override
protected void tearDown() throws Exception {
try {
restoreExecutionEnvironment9();
setExecutionEnvironment(JavaProjectHelper.JAVA_SE_9_EE_NAME, defaultVM9);
} finally {
super.tearDown();
}
Expand Down Expand Up @@ -250,34 +246,4 @@ private void checkVMInstall(IJavaProject javaProject) throws CoreException {
IVMInstall vm = JavaRuntime.getVMInstall(javaProject);
assertEquals("Expected default VM but got: " + vm.getInstallLocation(), defaultVm.getName(), vm.getName());
}

/**
* JDT tests run in different environments where different major JVM installations might be selected as "default" JVM for a specific Execution Environment (EE).
* 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.
* JVM modules vary between Java major versions, while we need a stable set of modules for the test case.
* 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.
*/
private void prepareExecutionEnvironment9() {
IVMInstall vm = JavaRuntime.getDefaultVMInstall();
IExecutionEnvironment environment9 = getExecutionEnvironment9();
defaultVM9 = environment9.getDefaultVM();
environment9.setDefaultVM(vm);
TestUtil.logInfo("Set VM \"" + vm.getName() + "\" for execution environments: " + environment9.getId());
}

private void restoreExecutionEnvironment9() {
IExecutionEnvironment environment9 = getExecutionEnvironment9();
environment9.setDefaultVM(defaultVM9);
TestUtil.logInfo("Restored default VM for execution environment: " + environment9.getId());
}

private static IExecutionEnvironment getExecutionEnvironment9() {
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
return Arrays.stream(environments).filter(ModuleOptionsTests::isEnvironment9).findFirst().orElseThrow();
}

private static boolean isEnvironment9(IExecutionEnvironment environment) {
return JAVASE_9.equals(environment.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.jdt.debug.tests.launching;

import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import java.io.File;
Expand Down Expand Up @@ -60,12 +59,16 @@
* version and OS.
*/
public class LongClassPathTests extends AbstractDebugTest {

protected static final String MAIN_TYPE_NAME = "test.classpath.Main";
protected static final IPath CLASSPATH_PROJECT_CONTENT_PATH = new Path("testresources/classpathProject");
protected IJavaProject javaProject;
protected ILaunchConfiguration launchConfiguration;
protected IJavaThread thread;

private IVMInstall defaultVM1_6;
private IVMInstall defaultVM9;

public LongClassPathTests(String name) {
super(name);
}
Expand All @@ -81,6 +84,13 @@ public static Test suite() {
return suite;
}

@Override
protected void setUp() throws Exception {
super.setUp();
defaultVM1_6 = prepareExecutionEnvironment(JavaProjectHelper.JAVA_SE_1_6_EE_NAME);
defaultVM9 = prepareExecutionEnvironment(JavaProjectHelper.JAVA_SE_9_EE_NAME);
}

@Override
protected void tearDown() throws Exception {
try {
Expand All @@ -93,6 +103,8 @@ protected void tearDown() throws Exception {
if (launchConfiguration != null) {
launchConfiguration.delete();
}
setExecutionEnvironment(JavaProjectHelper.JAVA_SE_1_6_EE_NAME, defaultVM1_6);
setExecutionEnvironment(JavaProjectHelper.JAVA_SE_9_EE_NAME, defaultVM9);
} catch (CoreException ce) {
// ignore
} finally {
Expand Down Expand Up @@ -145,7 +157,7 @@ public void testVeryLongClasspathWithArgumentFile() throws Exception {
}
javaProject = createJavaProjectClone("testVeryLongClasspathWithArgumentFile", CLASSPATH_PROJECT_CONTENT_PATH.toString(), JavaProjectHelper.JAVA_SE_9_EE_NAME, true);
launchConfiguration = createLaunchConfigurationStopInMain(javaProject, MAIN_TYPE_NAME);
assumeTrue(isArgumentFileSupported(launchConfiguration));
assertTrue(isArgumentFileSupported(launchConfiguration));
int minClasspathLength = 300000;

// Given
Expand Down Expand Up @@ -180,7 +192,7 @@ public void testVeryLongClasspathWithEnvironmentVariable() throws Exception {
// Given
javaProject = createJavaProjectClone("testVeryLongClasspath", CLASSPATH_PROJECT_CONTENT_PATH.toString(), JavaProjectHelper.JAVA_SE_1_6_EE_NAME, true);
launchConfiguration = createLaunchConfigurationStopInMain(javaProject, MAIN_TYPE_NAME);
assumeFalse(isArgumentFileSupported(launchConfiguration));
assertFalse(isArgumentFileSupported(launchConfiguration));
int minClasspathLength = 300000;
setLongClasspath(javaProject, minClasspathLength);
waitForBuild();
Expand Down
Loading