Java Code Examples for com.intellij.openapi.roots.impl.libraries.LibraryEx#ModifiableModelEx

The following examples show how to use com.intellij.openapi.roots.impl.libraries.LibraryEx#ModifiableModelEx . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaxeProjectConfigurationUpdater.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private void setupLibraries(Project project, ModifiableModelsProvider modelsProvider, ModulesProvider modulesProvider, List<LibraryData> libraries) {
  LibraryTable.ModifiableModel librariesModel = modelsProvider.getLibraryTableModifiableModel(project);

  for(LibraryData lib:libraries) {
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(lib.getClasspath());
    if(root != null) {
      LibraryImpl library = (LibraryImpl)librariesModel.createLibrary(lib.getName());
      LibraryEx.ModifiableModelEx model = library.getModifiableModel();
      model.setKind(HaxeLibraryType.HAXE_LIBRARY);
      model.addRoot(root, OrderRootType.CLASSES);
      model.addRoot(root, OrderRootType.SOURCES);
      model.commit();

      for(Module module:modulesProvider.getModules()) {
        ModifiableRootModel moduleModel = modelsProvider.getModuleModifiableModel(module);
        moduleModel.addLibraryEntry(library);
        moduleModel.commit();
      }
    }
  }

  librariesModel.commit();
}
 
Example 2
Source File: FileOrDirectoryDependencyTabContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Library createLibraryFromRoots(ModifiableModuleRootLayer layer, List<OrderRoot> roots, @Nullable final LibraryType libraryType) {
  final LibraryTable.ModifiableModel moduleLibraryModel = layer.getModuleLibraryTable().getModifiableModel();

  final PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
  final Library library = ((LibraryTableBase.ModifiableModelEx)moduleLibraryModel).createLibrary(null, kind);
  final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx)library.getModifiableModel();

  for (OrderRoot root : roots) {
    if (root.isJarDirectory()) {
      libModel.addJarDirectory(root.getFile(), false, root.getType());
    }
    else {
      libModel.addRoot(root.getFile(), root.getType());
    }
  }
  libModel.commit();
  return library;
}
 
Example 3
Source File: BaseLibrariesConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent e) {
  final Object o = getSelectedObject();
  if (o instanceof LibraryEx) {
    final LibraryEx selected = (LibraryEx)o;
    final String newName = Messages.showInputDialog("Enter library name:", "Copy Library", null, selected.getName() + "2", new NonEmptyInputValidator());
    if (newName == null) return;

    BaseLibrariesConfigurable configurable = BaseLibrariesConfigurable.this;
    final LibraryEx library = (LibraryEx)myContext.getLibrary(selected.getName(), myLevel);
    LOG.assertTrue(library != null);

    final LibrariesModifiableModel libsModel = configurable.getModelProvider().getModifiableModel();
    final Library lib = libsModel.createLibrary(newName, library.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)libsModel.getLibraryEditor(lib).getModel();
    LibraryEditingUtil.copyLibrary(library, Collections.<String, String>emptyMap(), model);
  }
}
 
Example 4
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Library createLibraryInTable(final @Nonnull NewLibraryEditor editor, final LibraryTable table) {
  LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx) table.getModifiableModel();
  final String name = StringUtil.isEmpty(editor.getName()) ? null : getUniqueLibraryName(editor.getName(), modifiableModel);
  final LibraryType<?> type = editor.getType();
  Library library = modifiableModel.createLibrary(name, type == null ? null : type.getKind());
  final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
  editor.applyTo(model);
  model.commit();
  modifiableModel.commit();
  return library;
}
 
Example 5
Source File: LibraryEditingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void copyLibrary(LibraryEx from, Map<String, String> rootMapping, LibraryEx.ModifiableModelEx target) {
  target.setProperties(from.getProperties());
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    final String[] urls = from.getUrls(type);
    for (String url : urls) {
      final String protocol = VirtualFileManager.extractProtocol(url);
      if (protocol == null) continue;
      final String fullPath = VirtualFileManager.extractPath(url);
      final int sep = fullPath.indexOf(ArchiveFileSystem.ARCHIVE_SEPARATOR);
      String localPath;
      String pathInJar;
      if (sep != -1) {
        localPath = fullPath.substring(0, sep);
        pathInJar = fullPath.substring(sep);
      }
      else {
        localPath = fullPath;
        pathInJar = "";
      }
      final String targetPath = rootMapping.get(localPath);
      String targetUrl = targetPath != null ? VirtualFileManager.constructUrl(protocol, targetPath + pathInJar) : url;

      if (from.isJarDirectory(url, type)) {
        target.addJarDirectory(targetUrl, false, type);
      }
      else {
        target.addRoot(targetUrl, type);
      }
    }
  }
}
 
Example 6
Source File: CreateNewLibraryDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Library createLibrary() {
  final LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx)getTableModifiableModel();
  final LibraryType<?> type = myLibraryEditor.getType();
  final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), type != null ? type.getKind() : null);
  final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
  myLibraryEditor.applyTo(model);
  WriteAction.run(model::commit);
  return library;
}
 
Example 7
Source File: ModuleEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object object, Method method, Object[] params) throws Throwable {
  try {
    final Object result = method.invoke(myDelegateLibrary, unwrapParams(params));
    if (result instanceof LibraryEx.ModifiableModelEx) {
      return Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{LibraryEx.ModifiableModelEx.class},
                                    new LibraryModifiableModelInvocationHandler((LibraryEx.ModifiableModelEx)result));
    }
    return result;
  }
  catch (InvocationTargetException e) {
    throw e.getCause();
  }
}
 
Example 8
Source File: ExistingLibraryEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LibraryEx.ModifiableModelEx getModel() {
  if (myModel == null) {
    myModel = myLibrary.getModifiableModel();
  }
  return myModel;
}
 
Example 9
Source File: NewLibraryEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void applyTo(@Nonnull LibraryEx.ModifiableModelEx model) {
  model.setProperties(myProperties);
  exportRoots(model::getUrls, model::isValid, model::removeRoot, model::addRoot, model::addJarDirectory, model::addExcludedRoot);
}