Search in sources :

Example 6 with BackgroundableProcessIndicator

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);
    }
}
Also used : BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)

Example 7 with BackgroundableProcessIndicator

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();
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Task(com.intellij.openapi.progress.Task) FutureTask(java.util.concurrent.FutureTask) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with BackgroundableProcessIndicator

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));
}
Also used : BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) PsiFile(com.intellij.psi.PsiFile) Backgroundable(com.intellij.openapi.progress.Task.Backgroundable)

Example 9 with BackgroundableProcessIndicator

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);
}
Also used : IDevice(com.android.ddmlib.IDevice) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) AndroidLocation(com.android.prefs.AndroidLocation) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with BackgroundableProcessIndicator

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);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) StudioSdkInstallerUtil(com.android.tools.idea.sdk.install.StudioSdkInstallerUtil) FalseValidator(com.android.tools.idea.ui.validation.validators.FalseValidator) StudioWizardStepPanel(com.android.tools.idea.ui.wizard.StudioWizardStepPanel) com.android.repository.api(com.android.repository.api) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) WizardConstants(com.android.tools.idea.wizard.WizardConstants) JBLabel(com.intellij.ui.components.JBLabel) Function(java.util.function.Function) ObservableBool(com.android.tools.idea.ui.properties.core.ObservableBool) Validator(com.android.tools.idea.ui.validation.Validator) ProjectManager(com.intellij.openapi.project.ProjectManager) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Logger(com.intellij.openapi.diagnostic.Logger) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) ProgressManager(com.intellij.openapi.progress.ProgressManager) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) TrueValidator(com.android.tools.idea.ui.validation.validators.TrueValidator) Collection(java.util.Collection) ModelWizardStep(com.android.tools.idea.wizard.model.ModelWizardStep) ActionEvent(java.awt.event.ActionEvent) ValidatorPanel(com.android.tools.idea.ui.validation.ValidatorPanel) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) TypeDetails(com.android.repository.impl.meta.TypeDetails) ThrottledProgressWrapper(com.android.tools.idea.sdk.progress.ThrottledProgressWrapper) BoolProperty(com.android.tools.idea.ui.properties.core.BoolProperty) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ThrottledProgressWrapper(com.android.tools.idea.sdk.progress.ThrottledProgressWrapper) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator) List(java.util.List)

Aggregations

BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)10 NotNull (org.jetbrains.annotations.NotNull)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 Task (com.intellij.openapi.progress.Task)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)2 StudioSdkInstallerUtil (com.android.tools.idea.sdk.install.StudioSdkInstallerUtil)2 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)2 Disposable (com.intellij.openapi.Disposable)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IDevice (com.android.ddmlib.IDevice)1 AndroidLocation (com.android.prefs.AndroidLocation)1 com.android.repository.api (com.android.repository.api)1 Installer (com.android.repository.api.Installer)1 InstallerFactory (com.android.repository.api.InstallerFactory)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoManager (com.android.repository.api.RepoManager)1 TypeDetails (com.android.repository.impl.meta.TypeDetails)1 FileOp (com.android.repository.io.FileOp)1 FileOpUtils (com.android.repository.io.FileOpUtils)1