public synchronized void stop() { if (myOriginal.isRunning()) { myOriginal.stop(); } else { myStartupAlarm.cancelAllRequests(); } // needed only for correct assertion of !progress.isRunning() in // ApplicationImpl.runProcessWithProgressSynchroniously final Semaphore semaphore = new Semaphore(); semaphore.down(); SwingUtilities.invokeLater( new Runnable() { public void run() { semaphore.waitFor(); if (myDialog != null) { // System.out.println("myDialog.destroyProcess()"); myDialog.close(DialogWrapper.OK_EXIT_CODE); myDialog = null; } } }); super.stop(); // should be last to not leaveModal before closing the dialog semaphore.up(); }
static void log( ProgressIndicator progressIndicator, TextEditorHighlightingPass pass, @NonNls @NotNull Object... info) { if (LOG.isDebugEnabled()) { CharSequence docText = pass == null || pass.getDocument() == null ? "" : ": '" + StringUtil.first(pass.getDocument().getCharsSequence(), 10, true) + "'"; synchronized (PassExecutorService.class) { String infos = StringUtil.join(info, Functions.TO_STRING(), " "); String message = StringUtil.repeatSymbol(' ', getThreadNum() * 4) + " " + pass + " " + infos + "; progress=" + (progressIndicator == null ? null : progressIndicator.hashCode()) + " " + (progressIndicator == null ? "?" : progressIndicator.isCanceled() ? "X" : "V") + docText; LOG.debug(message); // System.out.println(message); } } }
private void updateIndicatorText(@NotNull String upperLabel, @NotNull String downLabel) { ProgressIndicator indicator = myCompositeTask.getIndicator(); if (indicator != null) { indicator.setText(upperLabel); indicator.setText2(downLabel); } }
@Nullable public static PsiClass[] getAllTestClasses(final TestClassFilter filter, boolean sync) { final PsiClass[][] holder = new PsiClass[1][]; final Runnable process = () -> { final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); final Collection<PsiClass> set = new LinkedHashSet<>(); final PsiManager manager = PsiManager.getInstance(filter.getProject()); final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject()); final GlobalSearchScope scope = projectScope.intersectWith(filter.getScope()); for (final PsiClass psiClass : AllClassesSearch.search(scope, manager.getProject())) { if (filter.isAccepted(psiClass)) { if (indicator != null) { indicator.setText2( "Found test class " + ReadAction.compute(psiClass::getQualifiedName)); } set.add(psiClass); } } holder[0] = set.toArray(new PsiClass[set.size()]); }; if (sync) { ProgressManager.getInstance() .runProcessWithProgressSynchronously( process, "Searching For Tests...", true, filter.getProject()); } else { process.run(); } return holder[0]; }
private boolean doQueue( @NotNull Document document, @NotNull Project project, CommitStage start, @NonNls @NotNull Object reason) { synchronized (documentsToCommit) { if (!changeCommitStage(document, start, CommitStage.QUEUED_TO_COMMIT, false)) return false; Object[] documentTasks = documentsToCommit.toArray(); for (Object o : documentTasks) { assert o != null : "Null element in:" + documentsToCommit; CommitTask task = (CommitTask) o; if (task.document == document) { ProgressIndicator current = document.getUserData(COMMIT_PROGRESS); if (current == null) { // already queued, not started yet return true; } else { // cancel current commit process to re-queue current.cancel(); removeCommitFromQueue(document); break; } } } ProgressIndicator indicator = new ProgressIndicatorBase(); indicator.start(); documentsToCommit.addLast(new CommitTask(document, project, indicator, reason)); log("Queued", document, false, reason); wakeUpQueue(); return true; } }
public static void writeFileImpl(String folder, @NonNls String fileName, CharSequence buf) throws IOException { ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); final String fullPath = folder + File.separator + fileName; if (indicator != null) { ProgressManager.checkCanceled(); indicator.setText( InspectionsBundle.message("inspection.export.generating.html.for", fullPath)); } FileWriter writer = null; try { File folderFile = new File(folder); folderFile.mkdirs(); new File(fullPath).getParentFile().mkdirs(); writer = new FileWriter(fullPath); writer.write(buf.toString().toCharArray()); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { // Cannot do anything in case of exception } } } }
@Override public synchronized void setText2(String text) { super.setText2(text); if (myOriginal.isRunning()) { myOriginal.setText2(text); } }
@CalledInAwt @Nullable public static <T> T tryComputeFast( @NotNull final Function<ProgressIndicator, T> backgroundTask, final int waitMillis) { final Ref<T> resultRef = new Ref<T>(); ProgressIndicator indicator = executeAndTryWait( new Function<ProgressIndicator, Runnable>() { @Override public Runnable fun(final ProgressIndicator indicator) { final T result = backgroundTask.fun(indicator); return new Runnable() { @Override public void run() { resultRef.set(result); } }; } }, null, waitMillis, false); indicator.cancel(); return resultRef.get(); }
private void initProject(@NotNull ProjectImpl project, @Nullable ProjectImpl template) throws IOException { final ProgressIndicator indicator = myProgressManager.getProgressIndicator(); if (indicator != null && !project.isDefault()) { indicator.setText(ProjectBundle.message("loading.components.for", project.getName())); indicator.setIndeterminate(true); } ApplicationManager.getApplication() .getMessageBus() .syncPublisher(ProjectLifecycleListener.TOPIC) .beforeProjectLoaded(project); try { if (template != null) { project.getStateStore().loadProjectFromTemplate(template); } else { project.getStateStore().load(); } project.loadProjectComponents(); project.init(); } catch (IOException e) { scheduleDispose(project); throw e; } catch (ProcessCanceledException e) { scheduleDispose(project); throw e; } }
@Override public synchronized void setFraction(double fraction) { super.setFraction(fraction); if (myOriginal.isRunning()) { myOriginal.setFraction(fraction); } }
private void updateProgress(final ProgressIndicator indicator, final String text) { LOG.info("PAX output: " + text.replace("\n", "")); Matcher matcher = errorMessagePattern.matcher(text.trim()); // save error message for later.. if (matcher.matches()) { String message = matcher.group(1).trim(); if (!StringUtil.isEmpty(message) && !message.contains("--log=debug") && !message.contains("Oops")) { myErrorMessage = (myErrorMessage != null ? myErrorMessage : "") + message + "\n"; } } if (indicator != null) { if (indicator.isCanceled()) { if (!myIsCancelled) { ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { cancel(); } }); } } indicator.setText2(text); } }
private void perform(final ProgressIndicator indicator) { indicator.setText("Downloading OSGi framework"); indicator.setIndeterminate(true); try { myProcessHandler = new DefaultJavaProcessHandler(createJavaParameters()) { public void notifyTextAvailable(String text, Key outputType) { updateProgress(indicator, text); } }; } catch (ExecutionException e) { myIsSuccessful = false; myErrorMessage = "Error when starting pax runner: " + e.getMessage(); return; } start(); readProcessOutput(); stop(); int i = myProcessHandler.getProcess().exitValue(); if (i != 0) { myIsSuccessful = false; } else { myIsSuccessful = true; } }
public static void deleteFile(Project project, final VirtualFile file) throws ExecutionException { final Ref<IOException> error = new Ref<IOException>(); final Runnable runnable = new Runnable() { public void run() { ApplicationManager.getApplication() .runWriteAction( new Runnable() { public void run() { try { if (file.isValid()) { file.delete(this); } } catch (IOException e) { error.set(e); } } }); } }; if (ApplicationManager.getApplication().isDispatchThread()) { runnable.run(); } else { ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator(); ApplicationManager.getApplication() .invokeAndWait(runnable, pi != null ? pi.getModalityState() : ModalityState.NON_MODAL); } if (!error.isNull()) { //noinspection ThrowableResultOfMethodCallIgnored throw new ExecutionException(error.get().getMessage()); } }
public static boolean prepareToInstall( List<PluginNode> pluginsToInstall, List<IdeaPluginDescriptor> allPlugins) { ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator(); final List<PluginId> pluginIds = new ArrayList<PluginId>(); for (PluginNode pluginNode : pluginsToInstall) { pluginIds.add(pluginNode.getPluginId()); } boolean result = false; for (final PluginNode pluginNode : pluginsToInstall) { if (pi != null) pi.setText(pluginNode.getName()); try { result |= prepareToInstall(pluginNode, pluginIds, allPlugins); } catch (final IOException e) { SwingUtilities.invokeLater( new Runnable() { public void run() { Messages.showErrorDialog( pluginNode.getName() + ": " + e.getMessage(), CommonBundle.message("title.error")); } }); } } return result; }
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (myProgress.isCanceled()) { return Printable.NO_SUCH_PAGE; } while (myFileIndex < myFilesList.size()) { if (myTextPainter == null) { myTextPainter = PrintManager.initTextPainter((PsiFile) myFilesList.get(myFileIndex), myProject); } if (myTextPainter != null) { ((TextPainter) myTextPainter).setProgress(myProgress); int ret = 0; try { ret = myTextPainter.print(g, pageFormat, pageIndex - myStartPageIndex); } catch (ProcessCanceledException e) { } if (myProgress.isCanceled()) { return Printable.NO_SUCH_PAGE; } if (ret == Printable.PAGE_EXISTS) { return Printable.PAGE_EXISTS; } myTextPainter = null; myStartPageIndex = pageIndex; } myFileIndex++; } return Printable.NO_SUCH_PAGE; }
private void doIndexing( @NotNull final VirtualFile virtualFile, @NotNull final ProgressIndicator indicator) { final int fileId = FileBasedIndex.getFileId(virtualFile); indicator.setText("IntelliJence Advisor plugin indexing..."); indicator.setText2(virtualFile.getCanonicalPath()); final Long timestamp = getTimestamp(fileId); ProgressManager.checkCanceled(); final long currentTimeStamp = virtualFile.getModificationStamp(); if (timestamp == null || timestamp != currentTimeStamp) { putTimestamp(fileId, currentTimeStamp); final ClassReader reader; try { reader = new ClassReader(virtualFile.contentsToByteArray()); } catch (IOException e) { removeTimestamp(fileId); return; } try { for (final AdvisorBaseIndex index : indexes) { index.update(fileId, reader); } } catch (RuntimeException e) { log.error(String.format("can't index file: %s", virtualFile.getCanonicalPath())); // TODO delete it e.printStackTrace(); throw e; } } }
/** * Checks if update is possible, saves local changes and updates all roots. In case of error shows * notification and returns false. If update completes without errors, returns true. * * <p>Perform update on all roots. 0. Blocks reloading project on external change, saving/syncing * on frame deactivation. 1. Checks if update is possible (rebase/merge in progress, no tracked * branches...) and provides merge dialog to solve problems. 2. Finds updaters to use (merge or * rebase). 3. Preserves local changes if needed (not needed for merge sometimes). 4. Updates via * 'git pull' or equivalent. 5. Restores local changes if update completed or failed with error. * If update is incomplete, i.e. some unmerged files remain, local changes are not restored. */ @NotNull public GitUpdateResult update(final UpdateMethod updateMethod) { LOG.info("update started|" + updateMethod); String oldText = myProgressIndicator.getText(); myProgressIndicator.setText("Updating..."); for (GitRepository repository : myRepositories) { repository.update(); } // check if update is possible if (checkRebaseInProgress() || isMergeInProgress() || areUnmergedFiles() || !checkTrackedBranchesConfigured()) { return GitUpdateResult.NOT_READY; } if (!fetchAndNotify()) { return GitUpdateResult.NOT_READY; } AccessToken token = DvcsUtil.workingTreeChangeStarted(myProject); GitUpdateResult result; try { result = updateImpl(updateMethod); } finally { DvcsUtil.workingTreeChangeFinished(myProject, token); } myProgressIndicator.setText(oldText); return result; }
public SmoothProgressAdapter(ProgressIndicator original, Project project) { myOriginal = original; myProject = project; if (myOriginal.isModal()) { myOriginal.setModalityProgress(this); this.setModalityProgress(this); } }
private static void runIndeterminateProgress(ProgressIndicator indicator) { indicator.setIndeterminate(true); indicator.setText("Indeterminate"); for (int i = 0; i < 200; i++) { TimeoutUtil.sleep(10); indicator.checkCanceled(); } }
public boolean isInModalProgressThread() { if (myExceptionalThreadWithReadAccessRunnable == null || !isExceptionalThreadWithReadAccess()) { return false; } ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); return progressIndicator.isModal() && ((ProgressIndicatorEx) progressIndicator).isModalityEntered(); }
public SmoothProgressAdapter(@NotNull ProgressIndicator original, @NotNull Project project) { myOriginal = original; myProject = project; if (myOriginal.isModal()) { myOriginal.setModalityProgress(this); setModalityProgress(this); } ProgressManager.assertNotCircular(original); }
private static void runDeterminateProgress(ProgressIndicator indicator) { int iterations = 3000; for (int i = 0; i < iterations; i++) { TimeoutUtil.sleep(1); indicator.setFraction(((double) i + 1) / ((double) iterations)); indicator.setText(String.valueOf(i)); ProgressManager.checkCanceled(); } }
@NotNull public ModalityState getDefaultModalityState() { if (EventQueue.isDispatchThread()) { return getCurrentModalityState(); } else { ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); return progress == null ? getNoneModalityState() : progress.getModalityState(); } }
protected void showProgressMessage(final ProgressIndicator progress, final File root) { if (SvnConfiguration.getInstance(myVcs.getProject()).MERGE_DRY_RUN) { progress.setText( SvnBundle.message("progress.text.merging.dry.run.changes", root.getAbsolutePath())); } else { progress.setText( SvnBundle.message("progress.text.merging.changes", root.getAbsolutePath())); } }
void displayProgress() { final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { indicator.setText( MessageFormat.format( "{0} {1}", myAction != null ? myAction : RunnerBundle.message("maven.running"), myParameters.getWorkingDirPath())); indicator.setText2(myParameters.getGoals().toString()); } }
public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); indicator.setText2(VcsBundle.message("commit.wait.util.synched.text")); if (!myStarted.compareAndSet(false, true)) { LOG.error("Waiter running under progress being started again."); } else { while (!mySemaphore.waitFor(500)) { indicator.checkCanceled(); } } }
private void removeCommitFromQueue(@NotNull Document document) { synchronized (documentsToCommit) { ProgressIndicator indicator = document.getUserData(COMMIT_PROGRESS); if (indicator != null && indicator.isRunning()) { indicator.stop(); // mark document as removed log("Removed from queue", document, false); } // let our thread know that queue must be polled again wakeUpQueue(); } }
private static void updateIndicator(@NotNull final String text, final double progressFraction) { final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator != null) { final ProgressIndicator progressIndicator = ProgressWrapper.unwrap(indicator); progressIndicator.setText(text); if (progressFraction == -1) { progressIndicator.setIndeterminate(true); } else { progressIndicator.setIndeterminate(false); progressIndicator.setFraction(progressFraction); } } }
private void doRun() { myIndicator = ProgressManager.getInstance().getProgressIndicator(); final List<Change> changesToRefresh = new ArrayList<Change>(); try { ChangesUtil.processChangesByVcs( myProject, myChanges, new ChangesUtil.PerVcsProcessor<Change>() { public void process(AbstractVcs vcs, List<Change> changes) { final RollbackEnvironment environment = vcs.getRollbackEnvironment(); if (environment != null) { changesToRefresh.addAll(changes); if (myIndicator != null) { myIndicator.setText(vcs.getDisplayName() + ": performing rollback..."); myIndicator.setIndeterminate(false); myIndicator.checkCanceled(); } environment.rollbackChanges( changes, myExceptions, new RollbackProgressModifier(changes.size(), myIndicator)); if (myIndicator != null) { myIndicator.setText2(""); myIndicator.checkCanceled(); } if (myExceptions.isEmpty() && myDeleteLocallyAddedFiles) { deleteAddedFilesLocally(changes); } } } }); } catch (ProcessCanceledException e) { // still do refresh } if (myIndicator != null) { myIndicator.startNonCancelableSection(); myIndicator.setIndeterminate(true); myIndicator.setText2(""); myIndicator.setText(VcsBundle.message("progress.text.synchronizing.files")); } doRefresh(myProject, changesToRefresh); AbstractVcsHelper.getInstance(myProject) .showErrors(myExceptions, VcsBundle.message("changes.action.rollback.text")); }
public void loadCommittedChanges( ChangeBrowserSettings settings, RepositoryLocation location, int maxCount, final AsynchConsumer<CommittedChangeList> consumer) throws VcsException { try { final SvnRepositoryLocation svnLocation = (SvnRepositoryLocation) location; final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator(); if (progress != null) { progress.setText(SvnBundle.message("progress.text.changes.collecting.changes")); progress.setText2( SvnBundle.message("progress.text2.changes.establishing.connection", location)); } final String repositoryRoot; SVNRepository repository = null; try { repository = myVcs.createRepository(svnLocation.getURL()); repositoryRoot = repository.getRepositoryRoot(true).toString(); } catch (SVNException e) { throw new VcsException(e); } finally { if (repository != null) { repository.closeSession(); } } final ChangeBrowserSettings.Filter filter = settings.createFilter(); getCommittedChangesImpl( settings, svnLocation.getURL(), new String[] {""}, maxCount, new Consumer<SVNLogEntry>() { public void consume(final SVNLogEntry svnLogEntry) { final SvnChangeList cl = new SvnChangeList(myVcs, svnLocation, svnLogEntry, repositoryRoot); if (filter.accepts(cl)) { consumer.consume(cl); } } }, false, true); } finally { consumer.finished(); } }