FileDownloader reworked: allow to download in background, get rid of unnecessary VFS access

This commit is contained in:
nik
2013-10-25 11:00:55 +04:00
parent b95a17fcc1
commit c8bddaf645
7 changed files with 265 additions and 197 deletions
@@ -138,9 +138,9 @@ public class LibraryDownloadSettings {
}
List<Pair<VirtualFile,DownloadableFileDescription>> downloaded =
DownloadableFileService.getInstance().createDownloader(toDownload, null, parent, myLibraryName + " Library")
.toDirectory(myDirectoryForDownloadedLibrariesPath)
.downloadAndReturnWithDescriptions();
DownloadableFileService.getInstance()
.createDownloader(toDownload, myLibraryName + " Library")
.downloadWithProgress(myDirectoryForDownloadedLibrariesPath, null, parent);
if (downloaded == null) {
return null;
}
@@ -286,12 +286,13 @@ public abstract class FindJarFix<T extends PsiElement> implements IntentionActio
PropertiesComponent.getInstance(project).setValue("findjar.last.used.dir", file.getPath());
final DownloadableFileService downloader = DownloadableFileService.getInstance();
final DownloadableFileDescription description = downloader.createFileDescription(jarUrl, jarName);
final VirtualFile[] jars = downloader.createDownloader(Arrays.asList(description), project, myEditorComponent, jarName)
.toDirectory(file.getPath()).download();
if (jars != null && jars.length == 1) {
final List<VirtualFile> jars =
downloader.createDownloader(Arrays.asList(description), jarName)
.downloadFilesWithProgress(file.getPath(), project, myEditorComponent);
if (jars != null && jars.size() == 1) {
AccessToken token = WriteAction.start();
try {
OrderEntryFix.addJarToRoots(jars[0].getPresentableUrl(), myModule, myRef);
OrderEntryFix.addJarToRoots(jars.get(0).getPresentableUrl(), myModule, myRef);
}
finally {
token.finish();