Search in sources :

Example 1 with LocateLibraryDialog

use of com.intellij.codeInsight.daemon.impl.quickfix.LocateLibraryDialog in project intellij-community by JetBrains.

the class IdeaProjectModelModifier method addExternalLibraryDependency.

@Override
public Promise<Void> addExternalLibraryDependency(@NotNull final Collection<Module> modules, @NotNull final ExternalLibraryDescriptor descriptor, @NotNull final DependencyScope scope) {
    List<String> defaultRoots = descriptor.getLibraryClassesRoots();
    Module firstModule = ContainerUtil.getFirstItem(modules);
    LOG.assertTrue(firstModule != null);
    LocateLibraryDialog dialog = new LocateLibraryDialog(firstModule, defaultRoots, descriptor.getPresentableName());
    List<String> classesRoots = dialog.showAndGetResult();
    if (!classesRoots.isEmpty()) {
        String libraryName = classesRoots.size() > 1 ? descriptor.getPresentableName() : null;
        final List<String> urls = OrderEntryFix.refreshAndConvertToUrls(classesRoots);
        if (modules.size() == 1) {
            ModuleRootModificationUtil.addModuleLibrary(firstModule, libraryName, urls, Collections.emptyList(), scope);
        } else {
            new WriteAction() {

                protected void run(@NotNull Result result) {
                    Library library = LibraryUtil.createLibrary(LibraryTablesRegistrar.getInstance().getLibraryTable(myProject), descriptor.getPresentableName());
                    Library.ModifiableModel model = library.getModifiableModel();
                    for (String url : urls) {
                        model.addRoot(url, OrderRootType.CLASSES);
                    }
                    model.commit();
                    for (Module module : modules) {
                        ModuleRootModificationUtil.addDependency(module, library, scope, false);
                    }
                }
            }.execute();
        }
    }
    return Promises.resolvedPromise(null);
}
Also used : LocateLibraryDialog(com.intellij.codeInsight.daemon.impl.quickfix.LocateLibraryDialog) WriteAction(com.intellij.openapi.application.WriteAction) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result)

Aggregations

LocateLibraryDialog (com.intellij.codeInsight.daemon.impl.quickfix.LocateLibraryDialog)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 Module (com.intellij.openapi.module.Module)1 Library (com.intellij.openapi.roots.libraries.Library)1