Search in sources :

Example 1 with ModuleRootManagerImpl

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;
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) ModuleEx(com.intellij.openapi.module.impl.ModuleEx) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ModuleRootManagerImpl

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);
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with ModuleRootManagerImpl

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);
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) Element(org.jdom.Element) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 4 with ModuleRootManagerImpl

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) Element(org.jdom.Element) Iterator(java.util.Iterator) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 5 with ModuleRootManagerImpl

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);
    }
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) Element(org.jdom.Element) IOException(java.io.IOException)

Aggregations

ModuleRootManagerImpl (com.intellij.openapi.roots.impl.ModuleRootManagerImpl)7 Element (org.jdom.Element)5 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 IOException (java.io.IOException)3 ModuleEx (com.intellij.openapi.module.impl.ModuleEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 Iterator (java.util.Iterator)1 JDOMException (org.jdom.JDOMException)1 NotNull (org.jetbrains.annotations.NotNull)1 EclipseClasspathWriter (org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter)1