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);
}
}
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();
}
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);
}
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;
}
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();
}
Aggregations