use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class TextFieldWithAutoCompletionListProvider method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull String prefix, @NotNull CompletionResultSet result) {
Collection<T> items = getItems(prefix, true, parameters);
addCompletionElements(result, this, items, -10000);
final ProgressManager progressManager = ProgressManager.getInstance();
ProgressIndicator mainIndicator = progressManager.getProgressIndicator();
final ProgressIndicator indicator = mainIndicator != null ? new SensitiveProgressWrapper(mainIndicator) : new EmptyProgressIndicator();
Future<Collection<T>> future = ApplicationManager.getApplication().executeOnPooledThread(() -> progressManager.runProcess(() -> getItems(prefix, false, parameters), indicator));
while (true) {
try {
Collection<T> tasks = future.get(100, TimeUnit.MILLISECONDS);
if (tasks != null) {
addCompletionElements(result, this, tasks, 0);
return;
}
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception ignore) {
}
ProgressManager.checkCanceled();
}
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class FileDownloaderImpl method download.
@NotNull
@Override
public List<Pair<File, DownloadableFileDescription>> download(@NotNull final File targetDir) throws IOException {
List<Pair<File, DownloadableFileDescription>> downloadedFiles = Collections.synchronizedList(new ArrayList<>());
List<Pair<File, DownloadableFileDescription>> existingFiles = Collections.synchronizedList(new ArrayList<>());
ProgressIndicator parentIndicator = ProgressManager.getInstance().getProgressIndicator();
if (parentIndicator == null) {
parentIndicator = new EmptyProgressIndicator();
}
try {
final ConcurrentTasksProgressManager progressManager = new ConcurrentTasksProgressManager(parentIndicator, myFileDescriptions.size());
parentIndicator.setText(IdeBundle.message("progress.downloading.0.files.text", myFileDescriptions.size()));
int maxParallelDownloads = Runtime.getRuntime().availableProcessors();
LOG.debug("Downloading " + myFileDescriptions.size() + " files using " + maxParallelDownloads + " threads");
long start = System.currentTimeMillis();
ExecutorService executor = AppExecutorUtil.createBoundedApplicationPoolExecutor("FileDownloaderImpl pool", maxParallelDownloads);
List<Future<Void>> results = new ArrayList<>();
final AtomicLong totalSize = new AtomicLong();
for (final DownloadableFileDescription description : myFileDescriptions) {
results.add(executor.submit(() -> {
SubTaskProgressIndicator indicator = progressManager.createSubTaskIndicator();
indicator.checkCanceled();
final File existing = new File(targetDir, description.getDefaultFileName());
final String url = description.getDownloadUrl();
if (url.startsWith(LIB_SCHEMA)) {
final String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LIB_SCHEMA));
final File file = PathManager.findFileInLibDirectory(path);
existingFiles.add(Pair.create(file, description));
} else if (url.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LocalFileSystem.PROTOCOL_PREFIX));
File file = new File(path);
if (file.exists()) {
existingFiles.add(Pair.create(file, description));
}
} else {
File downloaded;
try {
downloaded = downloadFile(description, existing, indicator);
} catch (IOException e) {
throw new IOException(IdeBundle.message("error.file.download.failed", description.getDownloadUrl(), e.getMessage()), e);
}
if (FileUtil.filesEqual(downloaded, existing)) {
existingFiles.add(Pair.create(existing, description));
} else {
totalSize.addAndGet(downloaded.length());
downloadedFiles.add(Pair.create(downloaded, description));
}
}
indicator.finished();
return null;
}));
}
for (Future<Void> result : results) {
try {
result.get();
} catch (InterruptedException e) {
throw new ProcessCanceledException();
} catch (ExecutionException e) {
Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
Throwables.propagateIfInstanceOf(e.getCause(), ProcessCanceledException.class);
LOG.error(e);
}
}
long duration = System.currentTimeMillis() - start;
LOG.debug("Downloaded " + StringUtil.formatFileSize(totalSize.get()) + " in " + StringUtil.formatDuration(duration) + "(" + duration + "ms)");
List<Pair<File, DownloadableFileDescription>> localFiles = new ArrayList<>();
localFiles.addAll(moveToDir(downloadedFiles, targetDir));
localFiles.addAll(existingFiles);
return localFiles;
} catch (ProcessCanceledException | IOException e) {
deleteFiles(downloadedFiles);
throw e;
}
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class JavaModuleInsight method scanModuleInfoFiles.
private void scanModuleInfoFiles() {
final List<DetectedSourceRoot> allRoots = super.getSourceRootsToScan();
final List<JavaModuleSourceRoot> moduleInfoRoots = StreamEx.of(allRoots).select(JavaModuleSourceRoot.class).filter(JavaModuleSourceRoot::isWithModuleInfoFile).filter(root -> !isIgnoredName(root.getDirectory())).toList();
if (moduleInfoRoots.isEmpty()) {
return;
}
myProgress.setIndeterminate(true);
myProgress.pushState();
try {
Map<String, ModuleInfo> moduleInfos = new HashMap<>();
for (JavaModuleSourceRoot moduleInfoRoot : moduleInfoRoots) {
final File sourceRoot = moduleInfoRoot.getDirectory();
myProgress.setText("Scanning " + sourceRoot.getPath());
final ModuleInfo moduleInfo = scanModuleInfoFile(sourceRoot);
if (moduleInfo != null) {
moduleInfo.descriptor = createModuleDescriptor(moduleInfo.directory, Collections.singletonList(moduleInfoRoot));
moduleInfos.put(moduleInfo.name, moduleInfo);
addExportedPackages(sourceRoot, moduleInfo.exportsPackages);
}
}
myProgress.setText("Building modules layout...");
for (ModuleInfo moduleInfo : moduleInfos.values()) {
for (String requiresModule : moduleInfo.requiresModules) {
ModuleInfo requiredModuleInfo = moduleInfos.get(requiresModule);
if (requiredModuleInfo != null) {
moduleInfo.descriptor.addDependencyOn(requiredModuleInfo.descriptor);
}
}
}
addModules(StreamEx.of(moduleInfos.values()).map(info -> info.descriptor).toList());
} catch (ProcessCanceledException ignored) {
} finally {
myProgress.popState();
}
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class ModuleInsight method scanModules.
public void scanModules() {
myProgress.setIndeterminate(true);
final Map<File, ModuleDescriptor> contentRootToModules = new HashMap<>();
try {
myProgress.pushState();
List<DetectedSourceRoot> processedRoots = new ArrayList<>();
for (DetectedSourceRoot root : getSourceRootsToScan()) {
final File sourceRoot = root.getDirectory();
if (isIgnoredName(sourceRoot)) {
continue;
}
myProgress.setText("Scanning " + sourceRoot.getPath());
final HashSet<String> usedPackages = new HashSet<>();
mySourceRootToReferencedPackagesMap.put(sourceRoot, usedPackages);
final HashSet<String> selfPackages = new HashSet<>();
addExportedPackages(sourceRoot, selfPackages);
scanSources(sourceRoot, ProjectFromSourcesBuilderImpl.getPackagePrefix(root), usedPackages, selfPackages);
usedPackages.removeAll(selfPackages);
processedRoots.add(root);
}
myProgress.popState();
myProgress.pushState();
myProgress.setText("Building modules layout...");
for (DetectedSourceRoot sourceRoot : processedRoots) {
final File srcRoot = sourceRoot.getDirectory();
final File moduleContentRoot = isEntryPointRoot(srcRoot) ? srcRoot : srcRoot.getParentFile();
ModuleDescriptor moduleDescriptor = contentRootToModules.get(moduleContentRoot);
if (moduleDescriptor != null) {
moduleDescriptor.addSourceRoot(moduleContentRoot, sourceRoot);
} else {
moduleDescriptor = createModuleDescriptor(moduleContentRoot, Collections.singletonList(sourceRoot));
contentRootToModules.put(moduleContentRoot, moduleDescriptor);
}
}
buildModuleDependencies(contentRootToModules);
myProgress.popState();
} catch (ProcessCanceledException ignored) {
}
addModules(contentRootToModules.values());
}
use of com.intellij.openapi.progress.ProcessCanceledException in project intellij-community by JetBrains.
the class DocumentImpl method changedUpdate.
private void changedUpdate(@NotNull DocumentEvent event, long newModificationStamp, @NotNull CharSequence prevText) {
try {
if (LOG.isDebugEnabled())
LOG.debug(event.toString());
assert event.getOldFragment().length() == event.getOldLength() : "event.getOldFragment().length() = " + event.getOldFragment().length() + "; event.getOldLength() = " + event.getOldLength();
assert event.getNewFragment().length() == event.getNewLength() : "event.getNewFragment().length() = " + event.getNewFragment().length() + "; event.getNewLength() = " + event.getNewLength();
assert prevText.length() + event.getNewLength() - event.getOldLength() == getTextLength() : "prevText.length() = " + prevText.length() + "; event.getNewLength() = " + event.getNewLength() + "; event.getOldLength() = " + event.getOldLength() + "; getTextLength() = " + getTextLength();
myLineSet = getLineSet().update(prevText, event.getOffset(), event.getOffset() + event.getOldLength(), event.getNewFragment(), event.isWholeTextReplaced());
assert getTextLength() == myLineSet.getLength() : "getTextLength() = " + getTextLength() + "; myLineSet.getLength() = " + myLineSet.getLength();
myFrozen = null;
setModificationStamp(newModificationStamp);
if (!ShutDownTracker.isShutdownHookRunning()) {
DocumentListener[] listeners = getListeners();
for (DocumentListener listener : listeners) {
try {
listener.documentChanged(event);
} catch (ProcessCanceledException e) {
if (!myAssertThreading) {
throw e;
} else {
LOG.error("ProcessCanceledException must not be thrown from document listeners for real document", new Throwable(e));
}
} catch (Throwable e) {
LOG.error(e);
}
}
}
} finally {
myEventsHandling = false;
}
}
Aggregations