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);
}
}
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);
}
Aggregations