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));
}
}
}
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;
}
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);
}
Aggregations