Search in sources :

Example 1 with IVMInstallChangedListener

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);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IVMInstallChangedListener(org.eclipse.jdt.launching.IVMInstallChangedListener) IProject(org.eclipse.core.resources.IProject) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest) Test(org.junit.Test)

Example 2 with IVMInstallChangedListener

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());
    }
}
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

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