use of org.eclipse.jdt.launching.IVMInstallChangedListener in project eclipse.jdt.ls by eclipse.
the class JVMConfiguratorTest method testPreviewFeatureSettings.
@Test
public void testPreviewFeatureSettings() throws Exception {
IVMInstallChangedListener jvmConfigurator = new JVMConfigurator();
try {
JavaRuntime.addVMInstallChangedListener(jvmConfigurator);
IJavaProject defaultProject = newDefaultProject();
IProject invisibleProject = copyAndImportFolder("singlefile/java13", "foo/bar/Foo.java");
IJavaProject randomProject = JavaCore.create(invisibleProject);
assertComplianceAndPreviewSupport(defaultProject, "1.8", false);
assertComplianceAndPreviewSupport(randomProject, "1.8", false);
String latest = JavaCore.latestSupportedJavaVersion();
TestVMType.setTestJREAsDefault(latest);
assertComplianceAndPreviewSupport(defaultProject, latest, true);
assertComplianceAndPreviewSupport(randomProject, latest, true);
TestVMType.setTestJREAsDefault("12");
assertComplianceAndPreviewSupport(defaultProject, "12", false);
assertComplianceAndPreviewSupport(randomProject, "12", false);
TestVMType.setTestJREAsDefault("1.8");
assertComplianceAndPreviewSupport(defaultProject, "1.8", false);
assertComplianceAndPreviewSupport(randomProject, "1.8", false);
} finally {
JavaRuntime.removeVMInstallChangedListener(jvmConfigurator);
}
}
use of org.eclipse.jdt.launching.IVMInstallChangedListener in project eclipse.jdt.ls by eclipse.
the class InitHandlerTest method testConfigureJVMs.
@Test
public void testConfigureJVMs() throws Exception {
InitHandler handler = new InitHandler(projectsManager, preferenceManager, server.getClientConnection(), commandHandler);
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(IConstants.PLUGIN_ID);
boolean isWorkspaceInitialized = isWorkspaceInitialized(prefs);
boolean[] changed = new boolean[] { false };
IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
IVMInstallChangedListener listener = new IVMInstallChangedListener() {
@Override
public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
changed[0] = true;
}
@Override
public void vmChanged(PropertyChangeEvent event) {
}
@Override
public void vmAdded(IVMInstall vm) {
}
@Override
public void vmRemoved(IVMInstall vm) {
}
};
try {
prefs.putBoolean(IConstants.WORKSPACE_INITIALIZED, false);
InitializeParams params = new InitializeParams();
Map<String, Object> initializationOptions = new HashMap<>();
String javaHome = new File(TestVMType.getFakeJDKsLocation(), "9").getAbsolutePath();
HashMap<String, Object> homeMap = getMap("home", javaHome);
Map<String, Object> javaMap = getMap("java", homeMap);
initializationOptions.put(InitHandler.SETTINGS_KEY, javaMap);
params.setInitializationOptions(initializationOptions);
assertFalse(isWorkspaceInitialized(prefs));
JavaRuntime.addVMInstallChangedListener(listener);
handler.handleInitializationOptions(params);
assertTrue(isWorkspaceInitialized(prefs));
assertTrue(changed[0]);
changed[0] = false;
handler.handleInitializationOptions(params);
assertFalse(changed[0]);
} finally {
prefs.putBoolean(IConstants.WORKSPACE_INITIALIZED, isWorkspaceInitialized);
JavaRuntime.removeVMInstallChangedListener(listener);
JavaRuntime.setDefaultVMInstall(defaultVM, new NullProgressMonitor());
}
}
Aggregations