Search in sources :

Example 6 with ModuleRootManagerImpl

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

the class ClasspathSaveSession method setState.

@Override
public void setState(Object component, @NotNull String componentName, @NotNull Object state) {
    try {
        CachedXmlDocumentSet fileSet = EclipseClasspathStorageProvider.getFileCache(module);
        Element oldClassPath;
        try {
            oldClassPath = fileSet.load(EclipseXml.CLASSPATH_FILE, true);
        } catch (Exception e) {
            EclipseClasspathWriter.LOG.warn(e);
            oldClassPath = null;
        }
        ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) component;
        if (oldClassPath != null || moduleRootManager.getSourceRoots().length > 0 || moduleRootManager.getOrderEntries().length > 2) {
            Element newClassPathElement = new EclipseClasspathWriter().writeClasspath(oldClassPath, moduleRootManager);
            if (oldClassPath == null || !JDOMUtil.areElementsEqual(newClassPathElement, oldClassPath)) {
                update(newClassPathElement, EclipseXml.CLASSPATH_FILE);
            }
        }
        if (fileSet.getFile(EclipseXml.PROJECT_FILE, true) == null) {
            DotProjectFileHelper.saveDotProjectFile(module, fileSet.getParent(EclipseXml.PROJECT_FILE));
        }
        Element ideaSpecific = new Element(IdeaXml.COMPONENT_TAG);
        String emlFilename = moduleRootManager.getModule().getName() + EclipseXml.IDEA_SETTINGS_POSTFIX;
        if (IdeaSpecificSettings.writeIdeaSpecificClasspath(ideaSpecific, moduleRootManager)) {
            update(ideaSpecific, emlFilename);
        } else {
            delete(emlFilename);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) Element(org.jdom.Element) EclipseClasspathWriter(org.jetbrains.idea.eclipse.conversion.EclipseClasspathWriter) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with ModuleRootManagerImpl

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

the class ModuleRootsExternalizationTest method testContentWrite.

public void testContentWrite() throws Exception {
    File content = getTestRoot();
    File source = new File(content, "source");
    File testSource = new File(content, "testSource");
    File exclude = new File(content, "exclude");
    File classes = new File(content, "classes");
    File testClasses = new File(content, "testClasses");
    final VirtualFile contentFile = LocalFileSystem.getInstance().findFileByIoFile(content);
    assertNotNull(contentFile);
    final VirtualFile sourceFile = LocalFileSystem.getInstance().findFileByIoFile(source);
    assertNotNull(sourceFile);
    final VirtualFile testSourceFile = LocalFileSystem.getInstance().findFileByIoFile(testSource);
    assertNotNull(testSourceFile);
    final VirtualFile excludeFile = LocalFileSystem.getInstance().findFileByIoFile(exclude);
    assertNotNull(excludeFile);
    final VirtualFile classesFile = LocalFileSystem.getInstance().findFileByIoFile(classes);
    assertNotNull(classesFile);
    final VirtualFile testClassesFile = LocalFileSystem.getInstance().findFileByIoFile(testClasses);
    assertNotNull(testClassesFile);
    final File moduleFile = new File(content, "test.iml");
    final Module module = createModule(moduleFile);
    final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);
    PsiTestUtil.addContentRoot(module, contentFile);
    PsiTestUtil.addSourceRoot(module, sourceFile);
    PsiTestUtil.addSourceRoot(module, testSourceFile, true);
    ModuleRootModificationUtil.setModuleSdk(module, IdeaTestUtil.getMockJdk17());
    PsiTestUtil.addExcludedRoot(module, excludeFile);
    PsiTestUtil.setCompilerOutputPath(module, classesFile.getUrl(), false);
    PsiTestUtil.setCompilerOutputPath(module, testClassesFile.getUrl(), true);
    final Element element = new Element("root");
    moduleRootManager.getState().writeExternal(element);
    assertElementEquals(element, "<root>" + "<output url=\"file://$MODULE_DIR$/classes\" />" + "<output-test url=\"file://$MODULE_DIR$/testClasses\" />" + "<exclude-output />" + "<content url=\"file://$MODULE_DIR$\">" + "<sourceFolder url=\"file://$MODULE_DIR$/source\" isTestSource=\"false\" />" + "<sourceFolder url=\"file://$MODULE_DIR$/testSource\" isTestSource=\"true\" />" + "<excludeFolder url=\"file://$MODULE_DIR$/exclude\" />" + "</content>" + "<orderEntry type=\"jdk\" jdkName=\"java 1.7\" jdkType=\"JavaSDK\" />" + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />" + "</root>", module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) 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)

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