|
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.compiler.impl.CompilerOptions; |
| 132 | +import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; |
131 | 133 | import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; |
132 | 134 | import org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine; |
133 | 135 | import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; |
134 | 136 | import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; |
135 | 137 | import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
136 | 138 | import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
137 | 139 | import org.eclipse.jdt.launching.IVMInstall; |
| 140 | +import org.eclipse.jdt.launching.IVMInstallChangedListener; |
138 | 141 | import org.eclipse.jdt.launching.JavaRuntime; |
| 142 | +import org.eclipse.jdt.launching.PropertyChangeEvent; |
139 | 143 | import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
| 144 | +import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
140 | 145 | import org.eclipse.jface.dialogs.ErrorDialog; |
141 | 146 | import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
142 | 147 | import org.eclipse.jface.preference.IPreferenceStore; |
|
170 | 175 | @SuppressWarnings("deprecation") |
171 | 176 | public abstract class AbstractDebugTest extends TestCase implements IEvaluationListener { |
172 | 177 |
|
| 178 | + private static boolean setupFirstTest = false; |
| 179 | + |
173 | 180 | public static final String MULTI_OUTPUT_PROJECT_NAME = "MultiOutput"; |
174 | 181 | public static final String BOUND_EE_PROJECT_NAME = "BoundEE"; |
175 | 182 | public static final String ONE_FOUR_PROJECT_NAME = "DebugTests"; |
@@ -264,6 +271,12 @@ public AbstractDebugTest(String name) { |
264 | 271 |
|
265 | 272 | @Override |
266 | 273 | protected void setUp() throws Exception { |
| 274 | + if (!setupFirstTest) { |
| 275 | + TestUtil.logInfo("SETTING UP TESTS"); |
| 276 | + JavaRuntime.addVMInstallChangedListener(new LogVMInstallChanges()); |
| 277 | + setExecutionEnvironments(); |
| 278 | + setupFirstTest = true; |
| 279 | + } |
267 | 280 | TestUtil.logInfo("SETUP " + getClass().getSimpleName() + "." + getName()); |
268 | 281 | super.setUp(); |
269 | 282 | setPreferences(); |
@@ -3090,4 +3103,58 @@ private static String toString(Collection<IMarker> markers) { |
3090 | 3103 | public interface StackFrameSupplier { |
3091 | 3104 | IJavaStackFrame get() throws Exception; |
3092 | 3105 | } |
| 3106 | + |
| 3107 | + private static void setExecutionEnvironments() { |
| 3108 | + IVMInstall vm = JavaRuntime.getDefaultVMInstall(); |
| 3109 | + TestUtil.logInfo("Default VM is \"" + vm.getName() + "\""); |
| 3110 | + String javaSEPrefix = "JavaSE-"; |
| 3111 | + IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); |
| 3112 | + IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); |
| 3113 | + List<String> versions = new ArrayList<>(); |
| 3114 | + for (IExecutionEnvironment environment : environments) { |
| 3115 | + String id = environment.getId(); |
| 3116 | + if (id.startsWith(javaSEPrefix)) { |
| 3117 | + String version = id.substring(javaSEPrefix.length()); |
| 3118 | + long jdkLevel = CompilerOptions.versionToJdkLevel(version, false); |
| 3119 | + if (jdkLevel != 0 && JavaRuntime.compareJavaVersions(vm, version) >= 0) { |
| 3120 | + environment.setDefaultVM(vm); |
| 3121 | + versions.add(environment.getId()); |
| 3122 | + } |
| 3123 | + } |
| 3124 | + } |
| 3125 | + if (!versions.isEmpty()) { |
| 3126 | + TestUtil.logInfo("Set VM \"" + vm.getName() + "\" for execution environments: " + versions); |
| 3127 | + } |
| 3128 | + } |
| 3129 | + |
| 3130 | + private static void logVMChange(String message, IVMInstall vm) { |
| 3131 | + IStatus status = new Status(IStatus.INFO, JDIDebugPlugin.getUniqueIdentifier(), |
| 3132 | + message + " " + vm.getName() + ", location: " + vm.getInstallLocation(), |
| 3133 | + new RuntimeException("strack trace info")); |
| 3134 | + JDIDebugPlugin.log(status); |
| 3135 | + } |
| 3136 | + |
| 3137 | + private static class LogVMInstallChanges implements IVMInstallChangedListener { |
| 3138 | + |
| 3139 | + @Override |
| 3140 | + public void vmRemoved(IVMInstall vm) { |
| 3141 | + logVMChange("VM removed", vm); |
| 3142 | + } |
| 3143 | + |
| 3144 | + @Override |
| 3145 | + public void vmChanged(PropertyChangeEvent event) { |
| 3146 | + } |
| 3147 | + |
| 3148 | + @Override |
| 3149 | + public void vmAdded(IVMInstall vm) { |
| 3150 | + logVMChange("VM added", vm); |
| 3151 | + |
| 3152 | + } |
| 3153 | + |
| 3154 | + @Override |
| 3155 | + public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) { |
| 3156 | + logVMChange("Default VM changed", current); |
| 3157 | + } |
| 3158 | + |
| 3159 | + } |
3093 | 3160 | } |
0 commit comments