use of org.eclipse.jdt.launching.PropertyChangeEvent 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