use of com.intellij.openapi.roots.ex.ProjectRootManagerEx in project intellij-elixir by KronicDeth.
the class MixProjectImportBuilder method fixProjectSdk.
@Nullable
private static Sdk fixProjectSdk(@NotNull Project project) {
final ProjectRootManagerEx projectRootMgr = ProjectRootManagerEx.getInstanceEx(project);
Sdk selectedSdk = projectRootMgr.getProjectSdk();
if (selectedSdk == null || selectedSdk.getSdkType() != ElixirSdkType.getInstance()) {
final Sdk moreSuitableSdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(ElixirSdkType.getInstance());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
projectRootMgr.setProjectSdk(moreSuitableSdk);
}
});
return moreSuitableSdk;
}
return selectedSdk;
}
use of com.intellij.openapi.roots.ex.ProjectRootManagerEx in project intellij-community by JetBrains.
the class NewProjectUtil method applyJdkToProject.
public static void applyJdkToProject(@NotNull Project project, @NotNull Sdk jdk) {
ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project);
rootManager.setProjectSdk(jdk);
JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
if (version != null) {
LanguageLevel maxLevel = version.getMaxLanguageLevel();
LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject());
LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project);
if (extension.isDefault() || maxLevel.compareTo(ext.getLanguageLevel()) < 0) {
ext.setLanguageLevel(maxLevel);
}
}
}
use of com.intellij.openapi.roots.ex.ProjectRootManagerEx in project intellij-leiningen-plugin by derkork.
the class ModuleCreationUtils method importModule.
/**
* This method imports a leiningen module from a leiningen project file and imports it into the idea project.
* <p/>
* Notes:
* <p/>
* Each of the IDEA components has a getModifiableModel on it. This method returns a new instance each time you
* invoke it. Once you have a modifiable model of the component you wish to update, you mutate it to the state
* you wish. Once you're done, you call commit() on the modifiable model and it updates the component it came from.
* <p/>
* Since a lot of the components are persisted in files, commit() updates these files as well. Therefore you need
* to make any calls to commit() from within a WriteAction.
*
* @param ideaProject The IDEA project to add the leiningen module to.
* @param leinProjectFile The leiningen project file
* @return The leiningen project map.
*/
public Map importModule(Project ideaProject, VirtualFile leinProjectFile) {
ClassPathUtils.getInstance().switchToPluginClassLoader();
Map projectMap = LeiningenAPI.loadProject(leinProjectFile.getPath());
String name = (String) projectMap.get(LEIN_PROJECT_NAME);
final ModifiableModuleModel moduleManager = createModuleManager(ideaProject);
final ModifiableRootModel module = createModule(moduleManager, leinProjectFile.getParent().getPath(), name);
initializeModulePaths(projectMap, module, leinProjectFile.getParent());
ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(ideaProject);
module.setSdk(rootManager.getProjectSdk());
//Setup the dependencies
// Based loosely on org.jetbrains.idea.maven.importing.MavenRootModelAdapter#addLibraryDependency
//We could use the module table here, but then the libraries wouldn't be shared across modules.
final LibraryTable.ModifiableModel projectLibraries = ProjectLibraryTable.getInstance(ideaProject).getModifiableModel();
//Load all the dependencies from the project file
List dependencyMaps = LeiningenAPI.loadDependencies(leinProjectFile.getCanonicalPath());
final List<LibraryInfo> dependencies = initializeDependencies(module, projectLibraries, dependencyMaps);
new WriteAction() {
@Override
protected void run(Result result) throws Throwable {
for (LibraryInfo library : dependencies) {
library.modifiableModel.commit();
}
//Save the project libraries
projectLibraries.commit();
//Save the module itself to the module file.
module.commit();
//Save the list of modules that are in this project to the IDEA project file
moduleManager.commit();
}
}.execute();
return projectMap;
}
use of com.intellij.openapi.roots.ex.ProjectRootManagerEx in project intellij-community by JetBrains.
the class InheritedJdkTest method test1.
public void test1() throws Exception {
final Sdk jdk = IdeaTestUtil.getMockJdk17("java 1.4");
ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(jdk));
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
ApplicationManager.getApplication().runWriteAction(() -> {
final ProjectRootManagerEx rootManagerEx = ProjectRootManagerEx.getInstanceEx(myProject);
rootManagerEx.setProjectSdkName(jdk.getName());
ModuleRootModificationUtil.setSdkInherited(myModule);
});
assertTrue("JDK is inherited after explicit inheritSdk()", rootManager.isSdkInherited());
assertEquals("Correct jdk inherited", jdk, rootManager.getSdk());
ModuleRootModificationUtil.setModuleSdk(myModule, null);
assertFalse("JDK is not inherited after setJdk(null)", rootManager.isSdkInherited());
assertNull("No JDK assigned", rootManager.getSdk());
final Sdk jdk1 = IdeaTestUtil.getMockJdk17("jjj");
ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(jdk1));
ModuleRootModificationUtil.setModuleSdk(myModule, jdk1);
assertFalse("JDK is not inherited after setJdk(jdk1)", rootManager.isSdkInherited());
assertEquals("jdk1 is assigned", jdk1, rootManager.getSdk());
}
use of com.intellij.openapi.roots.ex.ProjectRootManagerEx 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());
}
Aggregations