private void initListeners() { testConnectionButton.addActionListener(actionEvent -> { ServerConfiguration configuration = createServerConfigurationForTesting(); final Ref<Exception> excRef = new Ref<>(); final ProgressManager progressManager = ProgressManager.getInstance(); progressManager.runProcessWithProgressSynchronously(() -> { final ProgressIndicator progressIndicator = progressManager.getProgressIndicator(); if (progressIndicator != null) { progressIndicator.setText("Connecting to Mongo server..."); } try { mongoManager.connect(configuration); } catch (Exception ex) { excRef.set(ex); } }, "Testing Connection", true, ServerConfigurationPanel.this.project); if (!excRef.isNull()) { Messages.showErrorDialog(rootPanel, excRef.get().getMessage(), "Connection Test Failed"); } else { Messages.showInfoMessage(rootPanel, "Connection test successful", "Connection Test Successful"); } }); }
@VisibleForTesting boolean checkIfCancelled() { return ProgressManager.getInstance().getProgressIndicator().isCanceled(); }
@Override public Boolean compute() throws Exception { ProgressManager.getInstance().getProgressIndicator().setText("Trying to login to Gerrit"); return testConnection(gerritAuthData); } });
/** * Sets {@code newText} to the progress indicator if available. * * @return old indicator text */ @Nullable public static String setProgressText(@Nullable String newText) { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { String oldText = indicator.getText(); indicator.setText(newText); return oldText; } return null; }
/** * Sets {@code newText} to the progress indicator secondary text, if indicator is available * * @return old indicator text */ @Nullable public static String setProgressText2(@Nullable String newText) { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { String oldText = indicator.getText2(); indicator.setText2(newText); return oldText; } return null; }
public SonarIssuesIndexBuilder buildIndex() { filesCount = files.size(); fileIndex = new AtomicInteger(0); indicator = ProgressManager.getInstance().getProgressIndicator(); final int availableProcessors = Runtime.getRuntime().availableProcessors(); info( String.format( "Start processing %d files and %d issues with %d threads", filesCount, issues.size(), availableProcessors ) ); final ExecutorService executorService = Executors.newFixedThreadPool(availableProcessors); final Iterable<List<PsiFile>> filePartitions = Iterables.partition(files,availableProcessors); index = Maps.newConcurrentMap(); for (final List<PsiFile> partition : filePartitions) { executorService.execute(() -> createIndexFor(partition)); } executorService.shutdown(); try { executorService.awaitTermination(Long.MAX_VALUE,TimeUnit.NANOSECONDS); } catch (InterruptedException e) { sonarConsole.error(Throwables.getStackTraceAsString(e)); } return this; }
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) ) ); } }
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; }
@Override public List<ProjectInfo> compute() throws Exception { ProgressManager.getInstance().getProgressIndicator().setText("Extracting info about available repositories"); return gerritClient.projects().list().get(); } });
private void execute() { // init indicator final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); ProgressIndicatorUtil.setText(indicator,"Executing SonarQube local analysis"); ProgressIndicatorUtil.setText2(indicator,sourceCode); ProgressIndicatorUtil.setIndeterminate(indicator,true); final Optional<SonarServerConfig> sonarServerConfig = SonarServers.get(enrichedSettings.settings.getServerName()); if (sonarServerConfig.isPresent() && useLoginPassword(sonarServerConfig.get())) { final String password = sonarServerConfig.get().loadPassword(); sonarConsole.withPasswordFilter(password); } if (sonarServerConfig.isPresent() && useToken(sonarServerConfig.get())) { final String token = sonarServerConfig.get().getToken(); sonarConsole.withPasswordFilter(token); } // execute user defined local analysis script final long startTime = System.currentTimeMillis(); sonarConsole.info("working dir: " + this.workingDir.getPath()); sonarConsole.info("executing: " + this.sourceCode); final Process process; try { process = Runtime.getRuntime().exec(this.sourceCode.split("[\\s]+"),null,this.workingDir); } catch (IOException e) { sonarConsole.error(Throwables.getStackTraceAsString(e)); return; } streamProcessOutputToSonarConsole(indicator, process); waitForProcessEnd(process); logAnalysisResultToConsole(startTime, process); }
@Before public void setUp() throws VcsException { MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(CommandUtils.class, ConflictsEnvironment.class, ProgressManager.class, VcsUtil.class, TFSVcs.class, TfsFileUtil.class, TFSContentRevision.class, CurrentContentRevision.class, VersionControlPath.class); when(mockFile.isFile()).thenReturn(true); when(mockFile.isDirectory()).thenReturn(false); when(mockUpdatedFiles.getGroupById(anyString())).thenReturn(mockFileGroup); when(mockTFSVcs.getServerContext(anyBoolean())).thenReturn(mockServerContext); when(mockResolveConflictsModel.getConflictsTableModel()).thenReturn(mockConflictsTableModel); when(mockProgressManager.getProgressIndicator()).thenReturn(mockProgressIndicator); when(ProgressManager.getInstance()).thenReturn(mockProgressManager); when(TFSVcs.getInstance(mockProject)).thenReturn(mockTFSVcs); when(ConflictsEnvironment.getNameMerger()).thenReturn(mockNameMerger); when(ConflictsEnvironment.getContentMerger()).thenReturn(mockContentMerger); helper = new ResolveConflictHelper(mockProject, mockUpdatedFiles, updateRoots); }
ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
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 setUp() throws IOException { when(googleLoginService.getLoggedInUser("user")).thenReturn(Optional.of(user)); when(progressManager.getProgressIndicator()).thenReturn(progressIndicator); when(apiClientFactory.getIamClient(any())).thenReturn(iam); when(apiClientFactory.getCloudResourceManagerClient(any())).thenReturn(resourceManager); setupFakeServiceAccount(); setupFakeServiceAccountKey(); setupFakePolicy(); setupMockIamClient(); setupMockResourceManagerClient(); testFixture .getProject() .getMessageBus() .connect() .subscribe(Notifications.TOPIC, notifications); // TODO: consider shutting down timer instead when clear what is creating the timer. ThreadTracker.longRunningThreadCreated(ApplicationManager.getApplication(), "Timer-0"); }
ServiceManager.getService(ProgressManager.class).getProgressIndicator();
final ProgressIndicator indicator = progressManager.getProgressIndicator(); if (indicator != null) { indicator.setIndeterminate(true);