Obtaining module content roots

How do I get a list of a module's content roots in a module component? Calling Module.getPom().getContentRoots() is throwing an assertion failure (see below). I need to search the content roots of each module on startup to look for pom.xml files. Is there another way I can do that, without calling getContentRoots(), maybe?

L.

ERROR - .roots.impl.DirectoryIndexImpl - Assertion failed
ERROR - .roots.impl.DirectoryIndexImpl - IntelliJ IDEA 5.1 Build #4155
ERROR - .roots.impl.DirectoryIndexImpl - JDK: 1.5.0_05
ERROR - .roots.impl.DirectoryIndexImpl - VM: Java HotSpot(TM) Client VM
ERROR - .roots.impl.DirectoryIndexImpl - Vendor: Apple Computer, Inc.
ERROR - .roots.impl.DirectoryIndexImpl - OS: Mac OS X
ERROR - .roots.impl.DirectoryIndexImpl - Last Action:
ERROR - .roots.impl.DirectoryIndexImpl - Assertion failed
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:78)
at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:86)
at com.intellij.openapi.roots.impl.DirectoryIndexImpl.getInfoForDirectory(DirectoryIndexImpl.java:213)
at com.intellij.openapi.roots.impl.ModuleFileIndexImpl.isInContent(ModuleFileIndexImpl.java:57)
at com.intellij.pom.core.impl.PomModuleImpl.findDirectory(PomModuleImpl.java:36)
at com.intellij.pom.core.impl.PomModuleImpl.a(PomModuleImpl.java:21)
at com.intellij.pom.core.impl.PomModuleImpl.getContentRoots(PomModuleImpl.java:11)
at org.mevenide.idea.plugin.components.module.MvnPomLocator.projectOpened(MvnPomLocator.java:89)
at com.intellij.openapi.module.impl.ModuleImpl.projectOpened(ModuleImpl.java:50)
at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.projectOpened(ModuleManagerImpl.java:21)
at com.intellij.openapi.module.impl.ModuleManagerImpl.projectOpened(ModuleManagerImpl.java:65)
at com.intellij.openapi.project.impl.ProjectImpl.c(ProjectImpl.java:142)
at com.intellij.openapi.project.impl.ProjectImpl.access$200(ProjectImpl.java:147)
at com.intellij.openapi.project.impl.ProjectImpl$MyProjectManagerListener.projectOpened(ProjectImpl.java:0)
at com.intellij.openapi.project.impl.ProjectManagerImpl$1.projectOpened(ProjectManagerImpl.java:5)
at com.intellij.openapi.project.impl.ProjectManagerImpl.d(ProjectManagerImpl.java:148)
at com.intellij.openapi.project.impl.ProjectManagerImpl.openProject(ProjectManagerImpl.java:73)
at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(ProjectManagerImpl.java:4)
at com.intellij.ide.impl.ProjectUtil.openProject(ProjectUtil.java:69)
at com.intellij.idea.IdeaApplication.c(IdeaApplication.java:17)
at com.intellij.idea.IdeaApplication.access$400(IdeaApplication.java:18)
at com.intellij.idea.IdeaApplication$IdeStarter$2.run(IdeaApplication.java:0)
at com.intellij.openapi.application.impl.LaterInvocatorEx$FlushQueue.run(LaterInvocatorEx.java:13)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:94)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:119)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

2 comments

I think you're not supposed to call any methods on (Project|Module)FileIndex from the projectOpened() method. Use com.intellij.openapi.startup.StartupManager#registerPostStartupActivity() to defer this until those indexes are properly initialized.

Sascha

0

I would have thought that by the time projectOpened() was called, the module loading would have finished -- meaning the indexes should be built. I guess not. Using ModuleRootManager.getInstance(module).getContentRoots(), however, does seem to work, from projectOpened() or from moduleAdded(). If the problem is uninitialized indexes I'm not sure why this works and what I had before didn't?

0

Please sign in to leave a comment.