Search in sources :

Example 31 with OrderRootType

use of com.intellij.openapi.roots.OrderRootType in project intellij-community by JetBrains.

the class LibraryDownloadSettings method download.

@Nullable
public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) {
    final List<DownloadableFileDescription> toDownload = new ArrayList<>(mySelectedDownloads);
    Map<DownloadableFileDescription, OrderRootType> rootTypes = new HashMap<>();
    for (DownloadableLibraryFileDescription description : mySelectedDownloads) {
        final DownloadableFileDescription sources = description.getSourcesDescription();
        if (myDownloadSources && sources != null) {
            toDownload.add(sources);
            rootTypes.put(sources, OrderRootType.SOURCES);
        }
        final DownloadableFileDescription docs = description.getDocumentationDescription();
        if (myDownloadJavaDocs && docs != null) {
            toDownload.add(docs);
            rootTypes.put(docs, JavadocOrderRootType.getInstance());
        }
    }
    String path = rootPath != null && !FileUtil.isAbsolute(myLibrariesPath) ? new File(rootPath, myLibrariesPath).getPath() : myLibrariesPath;
    List<Pair<VirtualFile, DownloadableFileDescription>> downloaded = DownloadableFileService.getInstance().createDownloader(toDownload, myLibraryName + " Library").downloadWithProgress(path, null, parent);
    if (downloaded == null) {
        return null;
    }
    final NewLibraryEditor libraryEditor;
    if (myLibraryType != null) {
        libraryEditor = new NewLibraryEditor(myLibraryType, new LibraryVersionProperties(myVersion.getVersionString()));
    } else {
        libraryEditor = new NewLibraryEditor();
    }
    libraryEditor.setName(myLibraryName);
    for (Pair<VirtualFile, DownloadableFileDescription> pair : downloaded) {
        final OrderRootType rootType = rootTypes.containsKey(pair.getSecond()) ? rootTypes.get(pair.getSecond()) : OrderRootType.CLASSES;
        libraryEditor.addRoot(pair.getFirst(), rootType);
    }
    return libraryEditor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DownloadableLibraryFileDescription(com.intellij.framework.library.DownloadableLibraryFileDescription) LibraryVersionProperties(com.intellij.framework.library.LibraryVersionProperties) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) OrderRootType(com.intellij.openapi.roots.OrderRootType) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OrderRootType (com.intellij.openapi.roots.OrderRootType)31 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 File (java.io.File)7 Element (org.jdom.Element)7 PersistentOrderRootType (com.intellij.openapi.roots.PersistentOrderRootType)6 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)5 Library (com.intellij.openapi.roots.libraries.Library)4 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)4 NotNull (org.jetbrains.annotations.NotNull)4 AnnotationOrderRootType (com.intellij.openapi.roots.AnnotationOrderRootType)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 Disposable (com.intellij.openapi.Disposable)2 LibraryPathType (com.intellij.openapi.externalSystem.model.project.LibraryPathType)2 RootProvider (com.intellij.openapi.roots.RootProvider)2 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 Pair (com.intellij.openapi.util.Pair)2 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)2 HashMap (com.intellij.util.containers.HashMap)2 HashMap (java.util.HashMap)2