use of com.intellij.openapi.roots.impl.ModuleRootManagerImpl in project intellij-community by JetBrains.
the class CoreModuleManager method createAndLoadModule.
@NotNull
@Override
protected ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) throws IOException {
final ModuleEx module = createModule(filePath);
try {
ModuleRootManagerImpl.ModuleRootManagerState state = new ModuleRootManagerImpl.ModuleRootManagerState();
state.readExternal(CoreProjectLoader.loadStorageFile(module, file).get("NewModuleRootManager"));
((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).loadState(state);
} catch (JDOMException e) {
throw new IOException(e);
}
return module;
}
use of com.intellij.openapi.roots.impl.ModuleRootManagerImpl in project intellij-community by JetBrains.
the class ModuleRootsExternalizationTest method createTempModuleRootManager.
private ModuleRootManagerImpl createTempModuleRootManager() throws IOException {
File tmpModule = FileUtil.createTempFile("tst", ModuleFileType.DOT_DEFAULT_EXTENSION);
myFilesToDelete.add(tmpModule);
final Module module = createModule(tmpModule);
return (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);
}
use of com.intellij.openapi.roots.impl.ModuleRootManagerImpl in project intellij-community by JetBrains.
the class ModuleRootsExternalizationTest method testCompilerOutputInheritance.
public void testCompilerOutputInheritance() throws Exception {
File moduleFile = new File(getTestRoot(), "test.iml");
Module module = createModule(moduleFile);
final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);
final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
rootModel.getModuleExtension(CompilerModuleExtension.class).inheritCompilerOutputPath(true);
ApplicationManager.getApplication().runWriteAction(rootModel::commit);
Element element = new Element("root");
moduleRootManager.getState().writeExternal(element);
assertElementEquals(element, "<root inherit-compiler-output=\"true\">" + "<exclude-output />" + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />" + "</root>", module);
}
use of com.intellij.openapi.roots.impl.ModuleRootManagerImpl in project intellij-community by JetBrains.
the class ModuleRootsExternalizationTest method testModuleLibraries.
public void testModuleLibraries() throws Exception {
File moduleFile = new File(getTestRoot(), "test.iml");
Module module = createModule(moduleFile);
final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);
final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
final Library unnamedLibrary = moduleLibraryTable.createLibrary();
final File unnamedLibClasses = new File(getTestRoot(), "unnamedLibClasses");
final VirtualFile unnamedLibClassesRoot = LocalFileSystem.getInstance().findFileByIoFile(unnamedLibClasses);
final Library.ModifiableModel libraryModifyableModel = unnamedLibrary.getModifiableModel();
libraryModifyableModel.addRoot(unnamedLibClassesRoot.getUrl(), OrderRootType.CLASSES);
final Library namedLibrary = moduleLibraryTable.createLibrary("namedLibrary");
final File namedLibClasses = new File(getTestRoot(), "namedLibClasses");
final VirtualFile namedLibClassesRoot = LocalFileSystem.getInstance().findFileByIoFile(namedLibClasses);
final Library.ModifiableModel namedLibraryModel = namedLibrary.getModifiableModel();
namedLibraryModel.addRoot(namedLibClassesRoot.getUrl(), OrderRootType.CLASSES);
ApplicationManager.getApplication().runWriteAction(() -> {
libraryModifyableModel.commit();
namedLibraryModel.commit();
});
final Iterator libraryIterator = moduleLibraryTable.getLibraryIterator();
assertEquals(libraryIterator.next(), unnamedLibrary);
assertEquals(libraryIterator.next(), namedLibrary);
ApplicationManager.getApplication().runWriteAction(rootModel::commit);
final Element element = new Element("root");
moduleRootManager.getState().writeExternal(element);
assertElementEquals(element, "<root inherit-compiler-output=\"true\">" + "<exclude-output />" + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />" + "<orderEntry type=\"module-library\">" + "<library>" + "<CLASSES><root url=\"file://$MODULE_DIR$/unnamedLibClasses\" /></CLASSES>" + "<JAVADOC />" + "<SOURCES />" + "</library>" + "</orderEntry>" + "<orderEntry type=\"module-library\">" + "<library name=\"namedLibrary\">" + "<CLASSES><root url=\"file://$MODULE_DIR$/namedLibClasses\" /></CLASSES>" + "<JAVADOC />" + "<SOURCES />" + "</library>" + "</orderEntry>" + "</root>", module);
}
use of com.intellij.openapi.roots.impl.ModuleRootManagerImpl in project intellij-community by JetBrains.
the class ModuleRootsExternalizationTest method testEmptyModuleWrite.
public void testEmptyModuleWrite() throws Exception {
try {
ModuleRootManagerImpl moduleRootManager = createTempModuleRootManager();
Element root = new Element("root");
moduleRootManager.getState().writeExternal(root);
assertEquals(root.getText(), "");
} catch (IOException e) {
LOG.error(e);
}
}
Aggregations