Library(path/url) doesn't get added to External Libraries

ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();

        LibraryTable.ModifiableModel modifiableModel = rootModel.getModuleLibraryTable().getModifiableModel();

        String libraryPath = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, src);
        VirtualFile url = VirtualFileManager.getInstance().findFileByUrl(libraryPath);

        if (url != null) {

          Library iceLibrary = modifiableModel.createLibrary("NME");

          Library.ModifiableModel libModel = iceLibrary.getModifiableModel();

          libModel.addRoot(libraryPath, OrderRootType.CLASSES);
          libModel.addRoot(libraryPath, OrderRootType.SOURCES);
          libModel.addJarDirectory(libraryPath, true);

          libModel.commit();

          modifiableModel.commit();

///* 115 */    rootModel.addLibraryEntry(iceLibrary);

          rootModel.commit();

        }
      }
    })
4 comments
Comment actions Permalink

This does runs on ProjectOptions.apply (but doesn't adds anything)

0
Comment actions Permalink

    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.PROJECT_LEVEL, myModule.getProject());

        LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();

        Library library = libraryTableModel.createLibrary("NME");

        Library.ModifiableModel libraryModel = library.getModifiableModel();

        VirtualFile file = LocalFileFinder.findFile("/usr/lib/haxe/lib/nme/5,1,8/");
        libraryModel.addRoot(file, OrderRootType.CLASSES);

        libraryModel.commit();

        libraryTableModel.commit();
      }
    });


Triggers on apply button click - no error, nothing changed.

0
Comment actions Permalink
ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        /*LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.PROJECT_LEVEL, myModule.getProject());

        LibraryTable.ModifiableModel libraryTableModel = libraryTable.getModifiableModel();

        Library library = libraryTableModel.createLibrary("NME");

        Library.ModifiableModel libraryModel = library.getModifiableModel();

        VirtualFile file = LocalFileFinder.findFile("/usr/lib/haxe/lib/nme/5,1,8/");
        libraryModel.addRoot(file, OrderRootType.CLASSES);

        libraryModel.commit();

        libraryTableModel.commit();*/

        ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
        LibraryTable.ModifiableModel tableModel = model.getModuleLibraryTable().getModifiableModel();

        Library library = tableModel.getLibraries()[0];  // for this example

        final Library.ModifiableModel libraryModel = library.getModifiableModel();

        String pathURL = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, "/usr/lib/haxe/lib/nme/5,1,8/");

        VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(pathURL);

        libraryModel.addRoot(file, OrderRootType.SOURCES);

        libraryModel.commit();

        tableModel.commit();


        ApplicationManager.getApplication().runWriteAction(new Runnable() {

          public void run() {

            rootModel.commit();
          }
        });
      }
    });


Doesn't works too.

0
Comment actions Permalink
/*ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {


        //ModuleRootModificationUtil.addModuleLibrary(myModule, libVirtFile.getUrl());
      }
    });*/

    final File libraryRoot = new File("/usr/lib/haxe/lib/nme/5,1,8");
    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libraryRoot);
    String urlForLibraryRoot = VfsUtil.getUrlForLibraryRoot(libraryRoot);
    VirtualFile libVirtFile = VirtualFileManager.getInstance().findFileByUrl(urlForLibraryRoot);

    ModuleRootModificationUtil.addModuleLibrary(myModule, "NME 5,1,8", Collections.singletonList(libVirtFile.getUrl()),
                                                Collections.singletonList(libVirtFile.getUrl()));


Doesn't works too.

0

Please sign in to leave a comment.