Using ModifiableRootModel.addLibraryEntry still doesn't set the library dependency correctly

I appologize if its wrong to open a separate issue but I marked the previous one as answered: http://devnet.jetbrains.com/message/5509303

Turns out it was too soon, even though I added this call the behavior is exactly the same as if the dependency is undefined. This is what I'm doing:
    @Override
    void createProjectFolders(VirtualFile rootPath) throws IOException {
        super.createProjectFolders(rootPath);
        final VirtualFile libImplClasses = ProjectPaths.findOrCreateChildDirectory(rootPath, "lib/impl/cls");
        final VirtualFile libImplStubs = ProjectPaths.findOrCreateChildDirectory(rootPath, "lib/impl/stubs");
        new WriteAction<Library>() {
            protected void run(final Result<Library> result) throws IOException {
                final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(getProject());
                String libName = "library.cn1lib.name";
                Library library = libraryTable.getLibraryByName(MessageBundle.message(libName));
                if (library == null) {
                    library = libraryTable.createLibrary(libName);
                    final Library.ModifiableModel model = library.getModifiableModel();
                    model.addRoot(libImplClasses, OrderRootType.CLASSES);
                    model.addRoot(libImplStubs, OrderRootType.SOURCES);
                    model.commit();
                     ModifiableRootModel rmodel =  com.intellij.openapi.roots.ModuleRootManager.getInstance(getModule()).getModifiableModel();
                    rmodel.addLibraryEntry(library);
                    rmodel.commit();
                }
                result.setResult(library);
            }
        }.execute();
    }


Thanks.

2 comments
Comment actions Permalink

When 'createProjectFolders' method is called? If it's called from an implementation of ModuleBuilder#setupRootModel method (or similar method taking
ModifiableRootModel as a parameter) you need to use the provided ModifiableRootModel instance instead of calling ModuleRootManager#getModifiableModel
otherwise your changes will be overwritten when the original ModifiableRootModel is committed. Also you don't need to commit the provided model
instance yourself.

--
Nikolay Chashnikov
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

Thanks again! That finally did it!

0

Please sign in to leave a comment.