Can't create more than one library in project

It seems that i can create a project or application level library just fine only if there's still no other library at the same level. If there's at least already one library at the same level where i'm trying to create the new one it just doesn't get created. No error though.

The code i'm using to create the library is something like this:

LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.PROJECT_LEVEL, facet.getModule().getProject());
LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();

Library library = libraryTableModel.createLibrary(JAXWS_LIBRARY_NAME);
Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(myJarVirtualFile, OrderRootType.CLASSES);
libraryModel.commit();
libraryTableModel.commit();

When i debug this, i can see that at the end both libraryTable.getLibraries() and libraryTableModel.getLibraries() return the new library. But still, it doesn't show up in IDEA.

Any ideas of what might be wrong would be great.
Thanks.

5 comments
Comment actions Permalink

Is the code in your post executed inside a write action?
If you want to change anything in IDEA, you need to wrap it into a write action like so

0
Comment actions Permalink

http://svn.jetbrains.org/idea/Trunk/bundled/WebServices/src/com/advancedtools/webservices/utils/LibUtils.java#addRequiredLibraryIfNeeded

Hugo Palma wrote:

It seems that i can create a project or application level library just fine only if there's still no other library at the same level. If there's at least already one library at the same level where i'm trying to create the new one it just doesn't get created. No error though.

The code i'm using to create the library is something like this:

LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.PROJECT_LEVEL, facet.getModule().getProject());
LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();

Library library = libraryTableModel.createLibrary(JAXWS_LIBRARY_NAME);
Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addRoot(myJarVirtualFile, OrderRootType.CLASSES);
libraryModel.commit();
libraryTableModel.commit();

When i debug this, i can see that at the end both libraryTable.getLibraries() and libraryTableModel.getLibraries() return the new library. But still, it doesn't show up in IDEA.

Any ideas of what might be wrong would be great.
Thanks.



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Yep, i'm already executing inside a write action.

0
Comment actions Permalink

Thanks, this really helped.

It seems that this problem only happens when it's executed from within the onFacetInitialized method on my FacetEditor. I need this because a change in a configuration of the facet can result in libraries being added or removed.
If i execute it from any other event it works just fine.

Also, i saw that when i execute this code from onFacetInitialized, although the library doesn't show up in the project libraries list it's in the .ipr file. But when i save the library declaration in the .ipr just disappears.

0
Comment actions Permalink

I found the answer.
If in the onFacetInitialized method put the code that adds the library inside an Application.invokeLater block then everything works fine.

0

Please sign in to leave a comment.