Update libraries during module open/close

Hello

I'd like to modify module dependencies during module open/close operations. (I need this to replace module dependencies with appropriate libraries if module removed).

I've created component with the following listener:

public class IdeaProject implements ProjectComponent, ModuleListener {
//...
    public void projectOpened() {
        //...
        project.getMessageBus().connect(project).subscribe(ProjectTopics.MODULES, this);
    }

    public void moduleAdded(Project project, final Module module) {
        // Replace libraries dependencies to this module
    }

    public void moduleRemoved(Project project, final Module module) {

        // Replace module dependencies to libraries
    }


But during modyfying project libraries I get the following error:
[ 120727]  ERROR - ts.impl.ProjectRootManagerImpl - Assertion failed: Merged rootsChanged not allowed inside rootsChanged, rootsChanged level == 1
java.lang.Throwable
    at com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:89)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.mergeRootsChangesDuring(ProjectRootManagerImpl.java:419)
...

I've tried to wrap library modification code into CommandProcessor.getInstance().executeCommand and ApplicationManager.getApplication().runWriteAction but this doesn't help.

Can somebody told me how is it possible to modify libraries during module open/close operation to prevent this assertion.



Attachment(s):
IdeaProject.java.zip
idea.log.zip
1 comment
Comment actions Permalink

Hello Pavel,

For consistency reasons, you cannot modify the libraries directly during
opening or closing of modules. You can use invokeLater() to perform the operations
asynchronously, but that won't work when the project is being closed - your
invokeLater() will be called when everything has been disposed already.

I'd like to modify module dependencies during module open/close
operations. (I need this to replace module dependencies with
appropriate libraries if module removed).

I've created component with the following listener:

 implements ProjectComponent, ModuleListener {
> //...
> public void projectOpened() {
> //...
> 
> project.getMessageBus().connect(project).subscribe(ProjectTopics.MODUL
> ES, this);
> }
> public void moduleAdded(Project project, final Module module) {
> // Replace libraries dependencies to this module
> }
> public void moduleRemoved(Project project, final Module module) {
> // Replace module dependencies to libraries
> }
> ]]>

But during modyfying project libraries I get the following error:
  ERROR - ts.impl.ProjectRootManagerImpl - Assertion failed:
Merged rootsChanged not allowed inside rootsChanged, rootsChanged
level == 1
java.lang.Throwable
at
com.intellij.openapi.diagnostic.Logger.assertTrue(Logger.java:89)
at
com.intellij.openapi.roots.impl.ProjectRootManagerImpl.mergeRootsChang
esDuring(ProjectRootManagerImpl.java:419)
..
I've tried to wrap library modification code into
CommandProcessor.getInstance().executeCommand and
ApplicationManager.getApplication().runWriteAction but this doesn't
help.

Can somebody told me how is it possible to modify libraries during
module open/close operation to prevent this assertion.

---
Original message URL:
http://www.jetbrains.net/devnet/message/5256770#5256770

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.