|
128 | 128 | import org.eclipse.jdt.debug.tests.core.LiteralTests17; |
129 | 129 | import org.eclipse.jdt.debug.tests.refactoring.MemberParser; |
130 | 130 | import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants; |
| 131 | +import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; |
131 | 132 | import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; |
132 | 133 | import org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine; |
133 | 134 | import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; |
134 | 135 | import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; |
135 | 136 | import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
136 | 137 | import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
137 | 138 | import org.eclipse.jdt.launching.IVMInstall; |
| 139 | +import org.eclipse.jdt.launching.IVMInstallChangedListener; |
138 | 140 | import org.eclipse.jdt.launching.JavaRuntime; |
| 141 | +import org.eclipse.jdt.launching.PropertyChangeEvent; |
139 | 142 | import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
| 143 | +import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
140 | 144 | import org.eclipse.jface.dialogs.ErrorDialog; |
141 | 145 | import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
142 | 146 | import org.eclipse.jface.preference.IPreferenceStore; |
|
170 | 174 | @SuppressWarnings("deprecation") |
171 | 175 | public abstract class AbstractDebugTest extends TestCase implements IEvaluationListener { |
172 | 176 |
|
| 177 | + private static boolean setupFirstTest = false; |
| 178 | + |
173 | 179 | public static final String MULTI_OUTPUT_PROJECT_NAME = "MultiOutput"; |
174 | 180 | public static final String BOUND_EE_PROJECT_NAME = "BoundEE"; |
175 | 181 | public static final String ONE_FOUR_PROJECT_NAME = "DebugTests"; |
@@ -264,6 +270,12 @@ public AbstractDebugTest(String name) { |
264 | 270 |
|
265 | 271 | @Override |
266 | 272 | 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 | + } |
267 | 279 | TestUtil.logInfo("SETUP " + getClass().getSimpleName() + "." + getName()); |
268 | 280 | super.setUp(); |
269 | 281 | setPreferences(); |
@@ -3090,4 +3102,56 @@ private static String toString(Collection<IMarker> markers) { |
3090 | 3102 | public interface StackFrameSupplier { |
3091 | 3103 | IJavaStackFrame get() throws Exception; |
3092 | 3104 | } |
| 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 | + } |
3093 | 3157 | } |
0 commit comments