Search in sources :

Example 91 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class JobUtilTest method testProcessorReturningFalseDoesNotCrashTheOtherThread.

public void testProcessorReturningFalseDoesNotCrashTheOtherThread() {
    final AtomicInteger delay = new AtomicInteger(0);
    final Runnable checkCanceled = ProgressManager::checkCanceled;
    Processor<String> processor = s -> {
        busySleep(delay.incrementAndGet() % 10 + 10, checkCanceled);
        return delay.get() % 100 != 0;
    };
    for (int i = 0; i < 100; i++) {
        ProgressIndicator indicator = new EmptyProgressIndicator();
        boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(10000, ""), indicator, false, false, processor);
        assertFalse(indicator.isCanceled());
        assertFalse(result);
    }
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) UIUtil(com.intellij.util.ui.UIUtil) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) java.util.concurrent(java.util.concurrent) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ThreadDumper(com.intellij.diagnostic.ThreadDumper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BigDecimal(java.math.BigDecimal) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutUtil(com.intellij.util.TimeoutUtil) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) javax.swing(javax.swing) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)

Example 92 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class JobUtilTest method checkProgressAndReadAction.

private static void checkProgressAndReadAction(final List<Object> objects, final DaemonProgressIndicator progress, final boolean runInReadAction) throws Throwable {
    final AtomicReference<Throwable> exception = new AtomicReference<>();
    JobLauncher.getInstance().invokeConcurrentlyUnderProgress(objects, progress, runInReadAction, o -> {
        try {
            if (objects.size() <= 1 || JobSchedulerImpl.CORES_COUNT <= JobLauncherImpl.CORES_FORK_THRESHOLD) {
                assertTrue(ApplicationManager.getApplication().isDispatchThread());
            } else {
            }
            ProgressIndicator actualIndicator = ProgressManager.getInstance().getProgressIndicator();
            if (progress == null) {
                assertNotNull(actualIndicator);
                assertTrue(actualIndicator instanceof AbstractProgressIndicatorBase);
            } else {
                assertTrue(actualIndicator instanceof SensitiveProgressWrapper);
                ProgressIndicator original = ((SensitiveProgressWrapper) actualIndicator).getOriginalProgressIndicator();
                assertSame(progress, original);
            }
            assertTrue(!runInReadAction || ApplicationManager.getApplication().isReadAccessAllowed());
        } catch (Throwable e) {
            exception.set(e);
        }
        return true;
    });
    if (exception.get() != null)
        throw exception.get();
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 93 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-community by JetBrains.

the class ModuleManagerImpl method loadModules.

protected void loadModules(@NotNull ModuleModelImpl moduleModel) {
    myFailedModulePaths.clear();
    if (myModulePathsToLoad == null || myModulePathsToLoad.isEmpty()) {
        return;
    }
    myFailedModulePaths.addAll(myModulePathsToLoad);
    ProgressIndicator globalIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
    ProgressIndicator progressIndicator = myProject.isDefault() || globalIndicator == null ? new EmptyProgressIndicator() : globalIndicator;
    progressIndicator.setText("Loading modules...");
    progressIndicator.setText2("");
    List<Module> modulesWithUnknownTypes = new SmartList<>();
    List<ModuleLoadingErrorDescription> errors = Collections.synchronizedList(new ArrayList<>());
    ModuleGroupInterner groupInterner = new ModuleGroupInterner();
    ExecutorService service = AppExecutorUtil.createBoundedApplicationPoolExecutor("modules loader", JobSchedulerImpl.CORES_COUNT);
    List<Pair<Future<Module>, ModulePath>> tasks = new ArrayList<>();
    Set<String> paths = new THashSet<>();
    boolean parallel = Registry.is("parallel.modules.loading");
    for (ModulePath modulePath : myModulePathsToLoad) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            String path = modulePath.getPath();
            if (!paths.add(path))
                continue;
            if (!parallel) {
                tasks.add(Pair.create(null, modulePath));
                continue;
            }
            ThrowableComputable<Module, IOException> computable = moduleModel.loadModuleInternal(path);
            Future<Module> future = service.submit(() -> {
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
                try {
                    return computable.compute();
                } catch (IOException e) {
                    reportError(errors, modulePath, e);
                } catch (Exception e) {
                    LOG.error(e);
                }
                return null;
            });
            tasks.add(Pair.create(future, modulePath));
        } catch (IOException e) {
            reportError(errors, modulePath, e);
        }
    }
    for (Pair<Future<Module>, ModulePath> task : tasks) {
        if (progressIndicator.isCanceled()) {
            break;
        }
        try {
            Module module;
            if (parallel) {
                module = task.first.get();
            } else {
                module = moduleModel.loadModuleInternal(task.second.getPath()).compute();
                progressIndicator.setFraction(progressIndicator.getFraction() + myProgressStep);
            }
            if (module == null)
                continue;
            if (isUnknownModuleType(module)) {
                modulesWithUnknownTypes.add(module);
            }
            ModulePath modulePath = task.second;
            final String groupPathString = modulePath.getGroup();
            if (groupPathString != null) {
                // model should be updated too
                groupInterner.setModuleGroupPath(moduleModel, module, groupPathString.split(MODULE_GROUP_SEPARATOR));
            }
            myFailedModulePaths.remove(modulePath);
        } catch (IOException e) {
            reportError(errors, task.second, e);
        } catch (Exception e) {
            LOG.error(e);
        }
    }
    service.shutdown();
    progressIndicator.checkCanceled();
    Application app = ApplicationManager.getApplication();
    if (app.isInternal() || app.isEAP() || ApplicationInfo.getInstance().getBuild().isSnapshot()) {
        Map<String, Module> track = new THashMap<>();
        for (Module module : moduleModel.getModules()) {
            for (String url : ModuleRootManager.getInstance(module).getContentRootUrls()) {
                Module oldModule = track.put(url, module);
                if (oldModule != null) {
                    //Map<String, VirtualFilePointer> track1 = ContentEntryImpl.track;
                    //VirtualFilePointer pointer = track1.get(url);
                    LOG.error("duplicated content url: " + url);
                }
            }
        }
    }
    onModuleLoadErrors(moduleModel, errors);
    showUnknownModuleTypeNotification(modulesWithUnknownTypes);
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) THashMap(gnu.trove.THashMap) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SmartList(com.intellij.util.SmartList) Application(com.intellij.openapi.application.Application)

Example 94 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project intellij-plugins by JetBrains.

the class DartCoverageProgramRunner method activateCoverage.

private boolean activateCoverage(@NotNull final Project project, @NotNull final String dartPubPath) {
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
            indicator.setIndeterminate(true);
        }
        try {
            // 'pub global list' is fast, let's run it first to find out if coverage package is already activated.
            // Following 'pub global activate' is long and may be cancelled by user
            checkIfCoverageActivated(dartPubPath);
            // run 'pub global activate' regardless of activation status, because it checks for the coverage package update
            final ProcessOutput activateOutput = new CapturingProcessHandler(new GeneralCommandLine().withExePath(dartPubPath).withParameters("global", "activate", "coverage").withRedirectErrorStream(true)).runProcessWithProgressIndicator(ProgressManager.getInstance().getProgressIndicator());
            if (activateOutput.getExitCode() != 0) {
                LOG.warn("'pub global activate coverage' exit code: " + activateOutput.getExitCode() + ", stdout:\n" + activateOutput.getStdout());
            }
            if (!myCoveragePackageActivated) {
                checkIfCoverageActivated(dartPubPath);
            }
        } catch (ExecutionException e) {
            LOG.warn(e);
        }
    }, "Activating Coverage Package...", true, project);
    // Even if 'pub global activate' process has been cancelled we can proceed if coverage already activated
    return myCoveragePackageActivated;
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ExecutionException(com.intellij.execution.ExecutionException)

Example 95 with ProgressIndicator

use of com.intellij.openapi.progress.ProgressIndicator in project android by JetBrains.

the class BuildStopperTest method stopBuildWithStoredTokenAndRunningProgressIndicator.

@Test
public void stopBuildWithStoredTokenAndRunningProgressIndicator() {
    ProgressIndicator progressIndicator = mock(ProgressIndicator.class);
    when(progressIndicator.isRunning()).thenReturn(true);
    myMapping.register(myId, myTokenSource);
    myMapping.attemptToStopBuild(myId, progressIndicator);
    verify(myTokenSource, times(1)).cancel();
    verify(progressIndicator, times(1)).setText("Stopping Gradle build...");
    verify(progressIndicator, times(1)).cancel();
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Test(org.junit.Test)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)352 Task (com.intellij.openapi.progress.Task)139 NotNull (org.jetbrains.annotations.NotNull)98 VirtualFile (com.intellij.openapi.vfs.VirtualFile)96 Project (com.intellij.openapi.project.Project)78 File (java.io.File)52 IOException (java.io.IOException)48 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)44 Nullable (org.jetbrains.annotations.Nullable)43 ProgressManager (com.intellij.openapi.progress.ProgressManager)35 List (java.util.List)30 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)28 Ref (com.intellij.openapi.util.Ref)27 VcsException (com.intellij.openapi.vcs.VcsException)25 ArrayList (java.util.ArrayList)23 ApplicationManager (com.intellij.openapi.application.ApplicationManager)22 Module (com.intellij.openapi.module.Module)21 Logger (com.intellij.openapi.diagnostic.Logger)20 java.util (java.util)20 Processor (com.intellij.util.Processor)18