Search in sources :

Example 1 with InheritedJdkOrderEntry

use of com.intellij.openapi.roots.InheritedJdkOrderEntry in project intellij-community by JetBrains.

the class InheritedJdkTest method test2.

public void test2() throws Exception {
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
    ModuleRootModificationUtil.setSdkInherited(myModule);
    assertTrue("JDK is inherited after inheritSdk()", rootManager.isSdkInherited());
    assertNull("No JDK assigned", rootManager.getSdk());
    final Sdk mockJdk = IdeaTestUtil.getMockJdk17("mock 1.4");
    ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(mockJdk));
    final ProjectRootManagerEx projectRootManager = ProjectRootManagerEx.getInstanceEx(myProject);
    ApplicationManager.getApplication().runWriteAction(() -> projectRootManager.setProjectSdk(mockJdk));
    assertTrue(rootManager.isSdkInherited());
    assertEquals("mockJdk inherited", mockJdk, rootManager.getSdk());
    ApplicationManager.getApplication().runWriteAction(() -> projectRootManager.setProjectSdkName("jdk1"));
    assertTrue(rootManager.isSdkInherited());
    Assert.assertEquals("Correct non-existing JDK inherited", "jdk1", rootManager.orderEntries().process(new RootPolicy<String>() {

        @Override
        public String visitInheritedJdkOrderEntry(InheritedJdkOrderEntry inheritedJdkOrderEntry, String s) {
            return inheritedJdkOrderEntry.getJdkName();
        }
    }, null));
    assertNull("Non-existing JDK", rootManager.getSdk());
    final Sdk jdk1 = IdeaTestUtil.getMockJdk17("jdk1");
    ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(jdk1));
    assertTrue(rootManager.isSdkInherited());
    assertNotNull("JDK appeared", rootManager.getSdk());
    assertEquals("jdk1 found", jdk1, rootManager.getSdk());
}
Also used : ProjectRootManagerEx(com.intellij.openapi.roots.ex.ProjectRootManagerEx) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Sdk(com.intellij.openapi.projectRoots.Sdk) RootPolicy(com.intellij.openapi.roots.RootPolicy) InheritedJdkOrderEntry(com.intellij.openapi.roots.InheritedJdkOrderEntry)

Aggregations

Sdk (com.intellij.openapi.projectRoots.Sdk)1 InheritedJdkOrderEntry (com.intellij.openapi.roots.InheritedJdkOrderEntry)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 RootPolicy (com.intellij.openapi.roots.RootPolicy)1 ProjectRootManagerEx (com.intellij.openapi.roots.ex.ProjectRootManagerEx)1