break; if (indicator.isCanceled()) { cancelledByUser = true; OSProcessManager.getInstance().killProcessTree(processHandler.getProcess());
/** * Returns true if the task should be cancelled as soon as possible. */ @Override public boolean isCanceled() { return indicator.isCanceled(); }
@Override public void run() { if (indicator.isCanceled()) { thread.interrupt(); } } });
@Override public boolean shouldContinue(final File t) { if (this.progressIndicator.isCanceled()) { return false; } this.progressIndicator.setText2(t.getAbsolutePath()); return true; } }
@VisibleForTesting boolean checkIfCancelled() { return ProgressManager.getInstance().getProgressIndicator().isCanceled(); }
private static void checkCanceled(ProgressIndicator indicator, Project project) { if (indicator.isCanceled() || project.isDisposed()) { throw new CanceledException(); } }
private void streamProcessOutputToSonarConsole(ProgressIndicator indicator, Process process) { final StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(),sonarConsole,ERROR); final StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(),sonarConsole,INFO); errorGobbler.start(); outputGobbler.start(); while (outputGobbler.isAlive()) { if (indicator.isCanceled()) { process.destroy(); break; } } }
private void createIssuesIndex() { for (Map.Entry<String, ImmutableList<Issue>> entry : downloadedIssuesByResourceKey.entrySet()) { if (ProgressManager.getInstance().getProgressIndicator().isCanceled()) break; sonarConsole.info(String.format("Creating index for SonarQube resource %s",entry.getKey())); long indexCreationStartTime = System.currentTimeMillis(); final ImmutableList<Issue> issues = entry.getValue(); final Map<String, Set<SonarIssue>> index = new IssuesByFileIndexer(psiFiles) .withSonarServerIssues(issues) .withSonarConsole(sonarConsole) .create(); final Optional<IssuesByFileIndexProjectComponent> indexComponent = IssuesByFileIndexProjectComponent.getInstance(enrichedSettings.project); indexComponent.ifPresent(issuesByFileIndexProjectComponent -> issuesByFileIndexProjectComponent.getIndex().putAll(index)); final int issuesCountInIndex = (int) index.values().stream() .mapToLong(Set::size) .sum(); sonarConsole.info( String.format( "Finished creating index with %d issues for SonarQube resource %s in %s", issuesCountInIndex, entry.getKey(), DurationUtil.getDurationBreakdown(System.currentTimeMillis()-indexCreationStartTime) ) ); } }
@Override public void offer(E item, int estimatedRemainingItems) throws CancellationException { if (progress != null && progress.isCanceled()) { throw new CancellationException();
public List<Resource> getAllProjectsAndModules() { List<Resource> allResources = new LinkedList<>(); final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); indicator.setText("Downloading SonarQube projects"); List<Component> projects = getAllProjects(sonarClient); projects = projects.stream().sorted(comparing(Component::getName)).collect(toList()); indicator.setText("Downloading SonarQube modules"); int i = 0; for (Component project : projects) { if (indicator.isCanceled()) break; i++; indicator.setFraction(1.0 * i / projects.size()); indicator.setText2(project.getName()); allResources.add(new Resource(project.getKey(), project.getName(), project.getQualifier())); List<Component> modules = getAllModules(sonarClient, project.getId()); modules = modules.stream().sorted(comparing(Component::getName)).collect(toList()); for (Component module : modules) { allResources.add(new Resource(module.getKey(), module.getName(), module.getQualifier())); } } return allResources; }
private void createIndexFor(List<PsiFile> psiFiles) { for (PsiFile psiFile : psiFiles) { if (indicator.isCanceled()) break; final int currentFileIndex = fileIndex.incrementAndGet(); ProgressIndicatorUtil.setFraction(indicator,1.0 * currentFileIndex / filesCount); ProgressIndicatorUtil.setText2(indicator,psiFile.getName()); final String filesProgressMessage = String.format("%d / %d files processed",currentFileIndex, filesCount); ProgressIndicatorUtil.setText(indicator,filesProgressMessage); if (filesCount % currentFileIndex == 20) { info(filesProgressMessage); } String fullFilePath = psiFile.getVirtualFile().getPath(); final Settings settings = Settings.getSettingsFor(psiFile); if (settings == null) continue; final Collection<Resource> resources = settings.getResources(); final Set<SonarIssue> sonarIssues = buildSonarIssues(fullFilePath, resources); if (!sonarIssues.isEmpty()) index.put(fullFilePath,sonarIssues); } }
ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (progress.isCanceled()) { LOG.info("API enablement canceled by user"); notifyApiEnableSkipped(Sets.difference(libraries, enabledApis), project);
public ImmutableList<Issue> getAllIssuesFor(String resourceKey) { final ImmutableList.Builder<Issue> builder = ImmutableList.builder(); SearchWsRequest query = new SearchWsRequest(); query.setComponentRoots(singletonList(resourceKey)) .setResolved(false) .setPageSize(-1); IssuesService issuesService = sonarClient.issues(); SearchWsResponse response = issuesService.search(query); builder.addAll(response.getIssuesList()); Common.Paging paging = response.getPaging(); Integer total = paging.getTotal(); Integer pageSize = paging.getPageSize(); Integer pages = total / pageSize + (total % pageSize > 0 ? 1 : 0); for (int pageIndex = 2; pageIndex <= pages; pageIndex++) { final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); if (progressIndicator.isCanceled()) break; final String pagesProgressMessage = String.format("%d / %d pages downloaded", pageIndex, pages); ProgressIndicatorUtil.setText(progressIndicator, pagesProgressMessage); ProgressIndicatorUtil.setFraction(progressIndicator, pageIndex * 1.0 / pages); query.setPage(pageIndex); builder.addAll(issuesService.search(query).getIssuesList()); } return builder.build(); } }
@Before public void prepare() { MockitoAnnotations.initMocks(this); files = new HashSet<>(); VirtualFile testFile = mock(VirtualFile.class); files.add(testFile); job = createJob(); when(progress.isCanceled()).thenReturn(false); when(analysisResults.failedAnalysisFiles()).thenReturn(Collections.emptyList()); when(sonarLintAnalyzer.analyzeModule(eq(module), eq(files), any(IssueListener.class), any(ProgressMonitor.class))).thenReturn(analysisResults); super.register(SonarLintStatus.class, new SonarLintStatus(getProject())); super.register(SonarLintAnalyzer.class, sonarLintAnalyzer); super.register(SonarLintConsole.class, mock(SonarLintConsole.class)); super.register(ServerIssueUpdater.class, mock(ServerIssueUpdater.class)); super.register(IssueManager.class, mock(IssueManager.class)); task = new SonarLintTask(processor, job, false, true); //IntelliJ light test fixtures appear to reuse the same project container, so we need to ensure that status is stopped. SonarLintStatus.get(getProject()).stopRun(); }
private void handleError(Throwable e, ProgressIndicator indicator) { // if cancelled, ignore any errors since they were most likely caused by the interrupt if (!indicator.isCanceled()) { String msg = "Error running SonarLint analysis"; console.error(msg, e); LOGGER.warn(msg, e); if (indicator.isShowing()) { String dialogMsg = "SonarLint analysis failed: " + e.getMessage(); ApplicationManager.getApplication().invokeAndWait( () -> Messages.showErrorDialog(dialogMsg, "Error Running SonarLint Analysis"), ModalityState.defaultModalityState()); } AnalysisCallback callback = job.callback(); if (callback != null) { callback.onError(e); } } }
Set<VirtualFile> allXSFiles = getAllXSFiles(myProject); for (VirtualFile virtualFile : allXSFiles) { if (indicator.isCanceled()) { return;
@Test public void should_wrap() { monitor.finishNonCancelableSection(); verify(wrapped).finishNonCancelableSection(); monitor.isCanceled(); verify(wrapped).isCanceled(); monitor.setFraction(0.5f); verify(wrapped).setFraction(0.5f); monitor.setIndeterminate(true); verify(wrapped).setIndeterminate(true); monitor.setMessage("message"); verify(wrapped).setText("message"); monitor.startNonCancelableSection(); verify(wrapped).startNonCancelableSection(); } }