Search in sources :

Example 1 with DownloadableFileService

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

the class FindJarFix method downloadJar.

private void downloadJar(String jarUrl, String jarName) {
    final Project project = myModule.getProject();
    final String dirPath = PropertiesComponent.getInstance(project).getValue("findjar.last.used.dir");
    VirtualFile toSelect = dirPath == null ? null : LocalFileSystem.getInstance().findFileByIoFile(new File(dirPath));
    final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, toSelect);
    if (file != null) {
        PropertiesComponent.getInstance(project).setValue("findjar.last.used.dir", file.getPath());
        final DownloadableFileService downloader = DownloadableFileService.getInstance();
        final DownloadableFileDescription description = downloader.createFileDescription(jarUrl, jarName);
        final List<VirtualFile> jars = downloader.createDownloader(Arrays.asList(description), jarName).downloadFilesWithProgress(file.getPath(), project, myEditorComponent);
        if (jars != null && jars.size() == 1) {
            WriteAction.run(() -> OrderEntryFix.addJarToRoots(jars.get(0).getPresentableUrl(), myModule, myRef));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) DownloadableFileService(com.intellij.util.download.DownloadableFileService)

Example 2 with DownloadableFileService

use of com.intellij.util.download.DownloadableFileService in project intellij-plugins by JetBrains.

the class ErrorProneCompilerDownloadingTask method execute.

@Override
public boolean execute(CompileContext context) {
    if (!ErrorProneClasspathProvider.isErrorProneCompilerSelected(context.getProject())) {
        return true;
    }
    DownloadableFileService service = DownloadableFileService.getInstance();
    DownloadableFileSetVersions<DownloadableFileSetDescription> versions = service.createFileSetVersions(null, getClass().getResource("/library/error-prone.xml"));
    List<DownloadableFileSetDescription> descriptions = versions.fetchVersions();
    if (descriptions.isEmpty()) {
        context.addMessage(CompilerMessageCategory.ERROR, "No error-prone compiler versions loaded", null, -1, -1);
        return false;
    }
    DownloadableFileSetDescription latestVersion = descriptions.get(0);
    File cacheDir = ErrorProneClasspathProvider.getCompilerFilesDir(latestVersion.getVersionString());
    if (ErrorProneClasspathProvider.getJarFiles(cacheDir).length > 0) {
        return true;
    }
    try {
        List<Pair<File, DownloadableFileDescription>> pairs = service.createDownloader(latestVersion).download(cacheDir);
        if (pairs.isEmpty() || ErrorProneClasspathProvider.getJarFiles(cacheDir).length == 0) {
            context.addMessage(CompilerMessageCategory.ERROR, "No compiler JARs were downloaded", null, -1, -1);
            return false;
        }
    } catch (IOException e) {
        LOG.info(e);
        context.addMessage(CompilerMessageCategory.ERROR, "Failed to download error-prone compiler JARs: " + e.getMessage(), null, -1, -1);
        return false;
    }
    return true;
}
Also used : DownloadableFileSetDescription(com.intellij.util.download.DownloadableFileSetDescription) IOException(java.io.IOException) File(java.io.File) DownloadableFileService(com.intellij.util.download.DownloadableFileService) Pair(com.intellij.openapi.util.Pair)

Example 3 with DownloadableFileService

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

Aggregations

DownloadableFileService (com.intellij.util.download.DownloadableFileService)3 Pair (com.intellij.openapi.util.Pair)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DownloadableFileDescription (com.intellij.util.download.DownloadableFileDescription)2 File (java.io.File)2 ExecutionException (com.intellij.execution.ExecutionException)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 ActionLink (com.intellij.ui.components.labels.ActionLink)1 DownloadableFileSetDescription (com.intellij.util.download.DownloadableFileSetDescription)1 FileDownloader (com.intellij.util.download.FileDownloader)1 IOException (java.io.IOException)1 List (java.util.List)1