use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class KShortestPathsFinderTest method doTest.
private static void doTest(Map<String, String> graph, final String start, final String finish, final int k, String... expectedPaths) {
Graph<String> generator = initGraph(graph);
List<List<String>> paths = getAlgorithmsInstance().findKShortestPaths(generator, start, finish, k, new EmptyProgressIndicator(ModalityState.NON_MODAL));
List<String> pathStrings = new ArrayList<>();
Set<Integer> sizes = new HashSet<>();
for (List<String> path : paths) {
pathStrings.add(StringUtil.join(path, ""));
sizes.add(path.size());
}
if (sizes.size() != paths.size()) {
UsefulTestCase.assertSameElements(pathStrings, expectedPaths);
} else {
UsefulTestCase.assertOrderedEquals(pathStrings, expectedPaths);
}
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class PersistenceStressTest method testReadWrite.
public void testReadWrite() throws Exception {
List<Future<Boolean>> futures = new ArrayList<>();
for (PersistentHashMap<String, Record> map : myMaps) {
Future<Boolean> submit = submit(map);
futures.add(submit);
}
Future<?> waitFuture = myThreadPool.submit(() -> {
try {
while (ContainerUtil.find(futures, STILL_RUNNING) != null) {
Thread.sleep(100);
myMaps.forEach(PersistentHashMap::dropMemoryCaches);
}
} catch (InterruptedException ignore) {
}
});
List<VirtualFile> files = new ArrayList<>();
for (int i = 0; i < 100; i++) {
File file = FileUtil.createTempFile("", ".txt");
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
assertNotNull(virtualFile);
PlatformTestCase.setFileText(virtualFile, "foo bar");
files.add(virtualFile);
}
FileBasedIndexImpl index = (FileBasedIndexImpl) FileBasedIndex.getInstance();
while (ContainerUtil.find(futures, STILL_RUNNING) != null) {
Thread.sleep(100);
CacheUpdateRunner.processFiles(new EmptyProgressIndicator(), true, files, getProject(), content -> index.indexFileContent(getProject(), content));
}
for (Future<Boolean> future : futures) {
assertTrue(future.get());
}
waitFuture.get();
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class PluginManagerMain method loadPluginsFromHostInBackground.
/**
* Start a new thread which downloads new list of plugins from the site in
* the background and updates a list of plugins in the table.
*/
protected void loadPluginsFromHostInBackground() {
setDownloadStatus(true);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final List<IdeaPluginDescriptor> list = ContainerUtil.newArrayList();
final Map<String, String> errors = ContainerUtil.newLinkedHashMap();
ProgressIndicator indicator = new EmptyProgressIndicator();
List<String> hosts = RepositoryHelper.getPluginHosts();
Set<PluginId> unique = ContainerUtil.newHashSet();
for (String host : hosts) {
try {
if (host == null || acceptHost(host)) {
List<IdeaPluginDescriptor> plugins = RepositoryHelper.loadPlugins(host, indicator);
for (IdeaPluginDescriptor plugin : plugins) {
if (unique.add(plugin.getPluginId())) {
list.add(plugin);
}
}
}
} catch (FileNotFoundException e) {
LOG.info(host, e);
} catch (IOException e) {
LOG.info(host, e);
if (host != ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl()) {
errors.put(host, String.format("'%s' for '%s'", e.getMessage(), host));
}
}
}
UIUtil.invokeLaterIfNeeded(() -> {
setDownloadStatus(false);
if (!list.isEmpty()) {
InstalledPluginsState state = InstalledPluginsState.getInstance();
for (IdeaPluginDescriptor descriptor : list) {
state.onDescriptorDownload(descriptor);
}
modifyPluginsList(list);
propagateUpdates(list);
}
if (!errors.isEmpty()) {
String message = IdeBundle.message("error.list.of.plugins.was.not.loaded", StringUtil.join(errors.keySet(), ", "), StringUtil.join(errors.values(), ",\n"));
String title = IdeBundle.message("title.plugins");
String ok = CommonBundle.message("button.retry"), cancel = CommonBundle.getCancelButtonText();
if (Messages.showOkCancelDialog(message, title, ok, cancel, Messages.getErrorIcon()) == Messages.OK) {
loadPluginsFromHostInBackground();
}
}
});
});
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class BackgroundTaskUtil method executeOnPooledThread.
@NotNull
@CalledInAny
public static ProgressIndicator executeOnPooledThread(@NotNull Consumer<ProgressIndicator> task, @NotNull Disposable parent, @NotNull ModalityState modalityState) {
ProgressIndicator indicator = new EmptyProgressIndicator(modalityState);
Disposable disposable = new Disposable() {
@Override
public void dispose() {
if (indicator.isRunning())
indicator.cancel();
}
};
Disposer.register(parent, disposable);
indicator.start();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
try {
task.consume(indicator);
} finally {
indicator.stop();
Disposer.dispose(disposable);
}
}, indicator);
});
return indicator;
}
use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.
the class CommitSelectionListener method processEvent.
public void processEvent() {
int rows = myGraphTable.getSelectedRowCount();
if (rows < 1) {
stopLoading();
onEmptySelection();
} else {
onSelection(myGraphTable.getSelectedRows());
startLoading();
final EmptyProgressIndicator indicator = new EmptyProgressIndicator();
myLastRequest = indicator;
List<Integer> selectionToLoad = getSelectionToLoad();
myLogData.getCommitDetailsGetter().loadCommitsData(myGraphTable.getModel().convertToCommitIds(selectionToLoad), detailsList -> {
if (myLastRequest == indicator && !(indicator.isCanceled())) {
LOG.assertTrue(selectionToLoad.size() == detailsList.size(), "Loaded incorrect number of details " + detailsList + " for selection " + selectionToLoad);
myLastRequest = null;
onDetailsLoaded(detailsList);
stopLoading();
}
}, indicator);
}
}
Aggregations