Search in sources :

Example 6 with DownloadableFileDescription

use of com.intellij.util.download.DownloadableFileDescription in project android by JetBrains.

the class DistributionServiceTest method testAsync.

/**
   * Test that refresh will run asynchronously.
   */
public void testAsync() throws Exception {
    final FileDownloader downloader = Mockito.mock(FileDownloader.class);
    final Semaphore s = new Semaphore();
    s.down();
    Mockito.when(downloader.download(Matchers.any(File.class))).thenAnswer(new Answer<List<Pair<File, DownloadableFileDescription>>>() {

        @Override
        public List<Pair<File, DownloadableFileDescription>> answer(InvocationOnMock invocation) throws Throwable {
            assertTrue(s.waitFor(5000));
            return ImmutableList.of(Pair.create(myDistributionFile, myDescription));
        }
    });
    final DistributionService service = new DistributionService(downloader, CACHE_PATH, myDistributionFileUrl);
    service.refresh(() -> {
        service.getSupportedDistributionForApiLevel(19);
        service.getDistributionForApiLevel(21);
        try {
            Mockito.verify(downloader).download(Matchers.any(File.class));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }, null);
    s.up();
}
Also used : DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FileDownloader(com.intellij.util.download.FileDownloader) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Semaphore(com.intellij.util.concurrency.Semaphore) IOException(java.io.IOException) File(java.io.File)

Example 7 with DownloadableFileDescription

use of com.intellij.util.download.DownloadableFileDescription in project intellij-elixir by KronicDeth.

the class MixConfigurationForm method createUIComponents.

private void createUIComponents() {
    myLinkContainer = new JPanel(new BorderLayout());
    ActionLink link = new ActionLink("Download the latest Mix version", new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            DownloadableFileService service = DownloadableFileService.getInstance();
            DownloadableFileDescription mix = service.createFileDescription("http://s3.hex.pm/builds/mix/mix", "mix");
            FileDownloader downloader = service.createDownloader(ContainerUtil.list(mix), "mix");
            List<Pair<VirtualFile, DownloadableFileDescription>> pairs = downloader.downloadWithProgress(null, getEventProject(anActionEvent), myLinkContainer);
            if (pairs != null) {
                for (Pair<VirtualFile, DownloadableFileDescription> pair : pairs) {
                    try {
                        String path = pair.first.getCanonicalPath();
                        if (path != null) {
                            FileUtilRt.setExecutableAttribute(path, true);
                            myMixPathSelector.setText(path);
                            validateMixPath();
                        }
                    } catch (Exception e) {
                    // Ignore
                    }
                }
            }
        }
    });
    myLinkContainer.add(link, BorderLayout.NORTH);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) ExecutionException(com.intellij.execution.ExecutionException) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) FileDownloader(com.intellij.util.download.FileDownloader) List(java.util.List) ActionLink(com.intellij.ui.components.labels.ActionLink) DownloadableFileService(com.intellij.util.download.DownloadableFileService) Pair(com.intellij.openapi.util.Pair)

Example 8 with DownloadableFileDescription

use of com.intellij.util.download.DownloadableFileDescription 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)

Example 9 with DownloadableFileDescription

use of com.intellij.util.download.DownloadableFileDescription in project intellij-community by JetBrains.

the class FileDownloaderImpl method findVirtualFiles.

@NotNull
private static List<Pair<VirtualFile, DownloadableFileDescription>> findVirtualFiles(List<Pair<File, DownloadableFileDescription>> ioFiles) {
    List<Pair<VirtualFile, DownloadableFileDescription>> result = new ArrayList<>();
    for (final Pair<File, DownloadableFileDescription> pair : ioFiles) {
        final File ioFile = pair.getFirst();
        VirtualFile libraryRootFile = new WriteAction<VirtualFile>() {

            @Override
            protected void run(@NotNull Result<VirtualFile> result) {
                final String url = VfsUtil.getUrlForLibraryRoot(ioFile);
                LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
                result.setResult(VirtualFileManager.getInstance().refreshAndFindFileByUrl(url));
            }
        }.execute().getResultObject();
        if (libraryRootFile != null) {
            result.add(Pair.create(libraryRootFile, pair.getSecond()));
        }
    }
    return result;
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Pair(com.intellij.openapi.util.Pair) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DownloadableFileDescription

use of com.intellij.util.download.DownloadableFileDescription in project android by JetBrains.

the class DistributionServiceTest method testAsync2.

/**
   * Test that if we get another call to refresh while one is in progress, it's callbacks will be queued.
   */
public void testAsync2() throws Exception {
    final FileDownloader downloader = Mockito.mock(FileDownloader.class);
    final Semaphore s = new Semaphore();
    s.down();
    final Semaphore s2 = new Semaphore();
    s2.down();
    Mockito.when(downloader.download(Matchers.any(File.class))).thenAnswer(new Answer<List<Pair<File, DownloadableFileDescription>>>() {

        @Override
        public List<Pair<File, DownloadableFileDescription>> answer(InvocationOnMock invocation) throws Throwable {
            assertTrue(s.waitFor(5000));
            return ImmutableList.of(Pair.create(myDistributionFile, myDescription));
        }
    });
    DistributionService service = new DistributionService(downloader, CACHE_PATH, myDistributionFileUrl);
    final AtomicBoolean check = new AtomicBoolean(false);
    service.refresh(() -> check.set(true), null);
    service.refresh(() -> {
        assertTrue(check.get());
        s2.up();
    }, null);
    s.up();
    assertTrue(s2.waitFor(5000));
    service.getSupportedDistributionForApiLevel(19);
    try {
        Mockito.verify(downloader).download(Matchers.any(File.class));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FileDownloader(com.intellij.util.download.FileDownloader) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) File(java.io.File)

Aggregations

DownloadableFileDescription (com.intellij.util.download.DownloadableFileDescription)10 File (java.io.File)8 Pair (com.intellij.openapi.util.Pair)5 ArrayList (java.util.ArrayList)5 FileDownloader (com.intellij.util.download.FileDownloader)4 IOException (java.io.IOException)4 List (java.util.List)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ImmutableList (com.google.common.collect.ImmutableList)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Semaphore (com.intellij.util.concurrency.Semaphore)2 DownloadableFileService (com.intellij.util.download.DownloadableFileService)2 ExecutionException (java.util.concurrent.ExecutionException)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ExecutionException (com.intellij.execution.ExecutionException)1 DownloadableLibraryFileDescription (com.intellij.framework.library.DownloadableLibraryFileDescription)1 LibraryVersionProperties (com.intellij.framework.library.LibraryVersionProperties)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1