Search in sources :

Example 1 with PropertyChangeEvent

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());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) PropertyChangeEvent(org.eclipse.jdt.launching.PropertyChangeEvent) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) HashMap(java.util.HashMap) IVMInstallChangedListener(org.eclipse.jdt.launching.IVMInstallChangedListener) InitializeParams(org.eclipse.lsp4j.InitializeParams) IVMInstall(org.eclipse.jdt.launching.IVMInstall) File(java.io.File) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

File (java.io.File)1 HashMap (java.util.HashMap)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 IVMInstall (org.eclipse.jdt.launching.IVMInstall)1 IVMInstallChangedListener (org.eclipse.jdt.launching.IVMInstallChangedListener)1 PropertyChangeEvent (org.eclipse.jdt.launching.PropertyChangeEvent)1 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)1 InitializeParams (org.eclipse.lsp4j.InitializeParams)1 Test (org.junit.Test)1