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