Skip to content

Commit e879943

Browse files
committed
Log VM install changes during JDT debug tests, set default VM for execution environments
See: #782
1 parent 9ba1b48 commit e879943

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,19 @@
128128
import org.eclipse.jdt.debug.tests.core.LiteralTests17;
129129
import org.eclipse.jdt.debug.tests.refactoring.MemberParser;
130130
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
131+
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
131132
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
132133
import org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine;
133134
import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
134135
import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
135136
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
136137
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
137138
import org.eclipse.jdt.launching.IVMInstall;
139+
import org.eclipse.jdt.launching.IVMInstallChangedListener;
138140
import org.eclipse.jdt.launching.JavaRuntime;
141+
import org.eclipse.jdt.launching.PropertyChangeEvent;
139142
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
143+
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
140144
import org.eclipse.jface.dialogs.ErrorDialog;
141145
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
142146
import org.eclipse.jface.preference.IPreferenceStore;
@@ -170,6 +174,8 @@
170174
@SuppressWarnings("deprecation")
171175
public abstract class AbstractDebugTest extends TestCase implements IEvaluationListener {
172176

177+
private static boolean setupFirstTest = false;
178+
173179
public static final String MULTI_OUTPUT_PROJECT_NAME = "MultiOutput";
174180
public static final String BOUND_EE_PROJECT_NAME = "BoundEE";
175181
public static final String ONE_FOUR_PROJECT_NAME = "DebugTests";
@@ -264,6 +270,12 @@ public AbstractDebugTest(String name) {
264270

265271
@Override
266272
protected void setUp() throws Exception {
273+
if (!setupFirstTest) {
274+
TestUtil.logInfo("SETTING UP TESTS");
275+
setExecutionEnvironments();
276+
JavaRuntime.addVMInstallChangedListener(new LogVMInstallChanges());
277+
setupFirstTest = true;
278+
}
267279
TestUtil.logInfo("SETUP " + getClass().getSimpleName() + "." + getName());
268280
super.setUp();
269281
setPreferences();
@@ -3090,4 +3102,56 @@ private static String toString(Collection<IMarker> markers) {
30903102
public interface StackFrameSupplier {
30913103
IJavaStackFrame get() throws Exception;
30923104
}
3105+
3106+
private static void setExecutionEnvironments() {
3107+
IVMInstall vm = JavaRuntime.getDefaultVMInstall();
3108+
String javaSEPrefix = "JavaSE-";
3109+
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
3110+
IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
3111+
List<String> versions = new ArrayList<>();
3112+
for (IExecutionEnvironment environment : environments) {
3113+
String id = environment.getId();
3114+
if (id.startsWith(javaSEPrefix)) {
3115+
String version = id.substring(javaSEPrefix.length());
3116+
if (JavaRuntime.compareJavaVersions(vm, version) >= 0) {
3117+
environment.setDefaultVM(vm);
3118+
versions.add(environment.getId());
3119+
}
3120+
}
3121+
}
3122+
if (!versions.isEmpty()) {
3123+
TestUtil.logInfo("Set VM \"" + vm.getName() + "\" for execution environments: " + versions);
3124+
}
3125+
}
3126+
3127+
private static void logVMChange(String message, IVMInstall vm) {
3128+
IStatus status = new Status(IStatus.INFO, JDIDebugPlugin.getUniqueIdentifier(),
3129+
message + " " + vm.getName() + ", location: " + vm.getInstallLocation(),
3130+
new RuntimeException("strack trace info"));
3131+
JDIDebugPlugin.log(status);
3132+
}
3133+
3134+
private static class LogVMInstallChanges implements IVMInstallChangedListener {
3135+
3136+
@Override
3137+
public void vmRemoved(IVMInstall vm) {
3138+
logVMChange("VM removed", vm);
3139+
}
3140+
3141+
@Override
3142+
public void vmChanged(PropertyChangeEvent event) {
3143+
}
3144+
3145+
@Override
3146+
public void vmAdded(IVMInstall vm) {
3147+
logVMChange("VM added", vm);
3148+
3149+
}
3150+
3151+
@Override
3152+
public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
3153+
logVMChange("Default VM changed", current);
3154+
}
3155+
3156+
}
30933157
}

0 commit comments

Comments
 (0)