use of com.intellij.openapi.progress.impl.BackgroundableProcessIndicator in project intellij-community by JetBrains.
the class SearchForTestsTask method startSearch.
public void startSearch() {
if (ApplicationManager.getApplication().isUnitTestMode()) {
try {
search();
} catch (Throwable e) {
LOG.error(e);
}
onFound();
} else {
myProcessIndicator = new BackgroundableProcessIndicator(this);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(this, myProcessIndicator);
}
}
use of com.intellij.openapi.progress.impl.BackgroundableProcessIndicator in project intellij-community by JetBrains.
the class RefResolveServiceImpl method run.
@Override
public void run() {
while (!myDisposed) {
boolean isEmpty;
synchronized (filesToResolve) {
isEmpty = filesToResolve.isEmpty();
}
if (enableVetoes.get() > 0 || isEmpty || !resolveProcess.isDone() || HeavyProcessLatch.INSTANCE.isRunning() || PsiDocumentManager.getInstance(myProject).hasUncommitedDocuments()) {
try {
waitForQueue();
} catch (InterruptedException e) {
break;
}
continue;
}
final Set<VirtualFile> files = pollFilesToResolve();
if (files.isEmpty())
continue;
upToDate = false;
myApplication.invokeLater(() -> {
if (!resolveProcess.isDone())
return;
log("Started to resolve " + files.size() + " files");
Task.Backgroundable backgroundable = new Task.Backgroundable(myProject, "Resolving files...", false) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
if (!myApplication.isDisposed()) {
processBatch(indicator, files);
}
}
};
ProgressIndicator indicator;
if (files.size() > 1) {
//show progress
indicator = new BackgroundableProcessIndicator(backgroundable);
} else {
indicator = new MyProgress();
}
resolveProcess = ((ProgressManagerImpl) ProgressManager.getInstance()).runProcessWithProgressAsynchronously(backgroundable, indicator, null);
}, myProject.getDisposed());
flushLog();
}
}
use of com.intellij.openapi.progress.impl.BackgroundableProcessIndicator in project intellij-community by JetBrains.
the class GenerateBinaryStubsFix method applyFix.
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiFile file = descriptor.getPsiElement().getContainingFile();
final Backgroundable backgroundable = getFixTask(file);
ProgressManager.getInstance().runProcessWithProgressAsynchronously(backgroundable, new BackgroundableProcessIndicator(backgroundable));
}
use of com.intellij.openapi.progress.impl.BackgroundableProcessIndicator in project android by JetBrains.
the class AvdManagerConnection method startAvd.
/**
* Launch the given AVD in the emulator.
* @return a future with the device that was launched
*/
@NotNull
public ListenableFuture<IDevice> startAvd(@Nullable final Project project, @NotNull final AvdInfo info) {
if (!initIfNecessary()) {
return Futures.immediateFailedFuture(new RuntimeException("No Android SDK Found"));
}
AccelerationErrorCode error = checkAcceleration();
ListenableFuture<IDevice> errorResult = handleAccelerationError(project, info, error);
if (errorResult != null) {
return errorResult;
}
final File emulatorBinary = getEmulatorBinary();
if (!emulatorBinary.isFile()) {
IJ_LOG.error("No emulator binary found!");
return Futures.immediateFailedFuture(new RuntimeException("No emulator binary found"));
}
final String avdName = info.getName();
// perform the same action here. If it is not stale, then we should show this error and if possible, bring that window to the front.
if (myAvdManager.isAvdRunning(info, SDK_LOG)) {
String baseFolder;
try {
baseFolder = myAvdManager.getBaseAvdFolder().getAbsolutePath();
} catch (AndroidLocation.AndroidLocationException e) {
baseFolder = "$HOME";
}
String message = String.format("AVD %1$s is already running.\n" + "If that is not the case, delete the files at\n" + " %2$s/%1$s.avd/*.lock\n" + "and try again.", avdName, baseFolder);
Messages.showErrorDialog(project, message, "AVD Manager");
return Futures.immediateFailedFuture(new RuntimeException(message));
}
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath(emulatorBinary.getPath());
addParameters(info, commandLine);
EmulatorRunner runner = new EmulatorRunner(commandLine, info);
EmulatorRunner.ProcessOutputCollector collector = new EmulatorRunner.ProcessOutputCollector();
runner.addProcessListener(collector);
final ProcessHandler processHandler;
try {
processHandler = runner.start();
} catch (ExecutionException e) {
IJ_LOG.error("Error launching emulator", e);
return Futures.immediateFailedFuture(new RuntimeException(String.format("Error launching emulator %1$s ", avdName), e));
}
// If we're using qemu2, it has its own progress bar, so put ours in the background. Otherwise show it.
final ProgressWindow p = hasQEMU2Installed() ? new BackgroundableProcessIndicator(project, "Launching Emulator", PerformInBackgroundOption.ALWAYS_BACKGROUND, "", "", false) : new ProgressWindow(false, true, project);
p.setIndeterminate(false);
p.setDelayInMillis(0);
// It takes >= 8 seconds to start the Emulator. Display a small progress indicator otherwise it seems like
// the action wasn't invoked and users tend to click multiple times on it, ending up with several instances of the emulator
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
p.start();
p.setText("Starting AVD...");
for (double d = 0; d < 1; d += 1.0 / 80) {
p.setFraction(d);
//noinspection BusyWait
Thread.sleep(100);
if (processHandler.isProcessTerminated()) {
break;
}
}
} catch (InterruptedException ignore) {
} finally {
p.stop();
p.processFinish();
}
processHandler.removeProcessListener(collector);
String message = limitErrorMessage(collector.getText());
if (message.toLowerCase(Locale.ROOT).contains("error") || processHandler.isProcessTerminated() && !message.trim().isEmpty()) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(project, "Cannot launch AVD in emulator.\nOutput:\n" + message, avdName));
}
});
return EmulatorConnectionListener.getDeviceForEmulator(project, info.getName(), processHandler, 5, TimeUnit.MINUTES);
}
use of com.intellij.openapi.progress.impl.BackgroundableProcessIndicator in project android by JetBrains.
the class InstallSelectedPackagesStep method startSdkInstall.
private void startSdkInstall() {
CustomLogger customLogger = new CustomLogger();
synchronized (LOGGER_LOCK) {
myLogger = new ThrottledProgressWrapper(customLogger);
}
Function<List<RepoPackage>, Void> completeCallback = failures -> {
UIUtil.invokeLaterIfNeeded(() -> {
myProgressBar.setValue(100);
myProgressOverallLabel.setText("");
if (!failures.isEmpty()) {
myInstallFailed.set(true);
myProgressBar.setEnabled(false);
} else {
myProgressDetailLabel.setText("Done");
checkForUpgrades(myInstallRequests);
}
myInstallationFinished.set(true);
});
return null;
};
InstallerFactory factory = StudioSdkInstallerUtil.createInstallerFactory(mySdkHandler);
InstallTask task = new InstallTask(factory, mySdkHandler, StudioSettingsController.getInstance(), myLogger);
task.setInstallRequests(myInstallRequests);
task.setUninstallRequests(myUninstallRequests);
task.setCompleteCallback(completeCallback);
task.setPrepareCompleteCallback(() -> myBackgroundAction.setEnabled(false));
ProgressIndicator indicator;
boolean hasOpenProjects = ProjectManager.getInstance().getOpenProjects().length > 0;
if (hasOpenProjects) {
indicator = new BackgroundableProcessIndicator(task);
} else {
// If we don't have any open projects runProcessWithProgressAsynchronously will show a modal popup no matter what.
// Instead use an empty progress indicator to suppress that.
indicator = new EmptyProgressIndicator();
}
customLogger.setIndicator(indicator);
myLogger.logInfo("To install:");
for (UpdatablePackage p : myInstallRequests) {
myLogger.logInfo(String.format("- %1$s (%2$s)", p.getRemote().getDisplayName(), p.getRemote().getPath()));
}
myLogger.logInfo("");
ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, indicator);
}
Aggregations