Search in sources :

Example 11 with ProgressIndicator

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

the class RepositoryAttachHandler method searchArtifacts.

public static void searchArtifacts(final Project project, String coord, final PairProcessor<Collection<Pair<MavenArtifactInfo, MavenRepositoryInfo>>, Boolean> resultProcessor) {
    if (coord == null || coord.length() == 0)
        return;
    final MavenArtifactInfo template;
    if (coord.indexOf(':') == -1 && Character.isUpperCase(coord.charAt(0))) {
        template = new MavenArtifactInfo(null, null, null, "jar", null, coord, null);
    } else {
        template = new MavenArtifactInfo(getMavenId(coord), "jar", null);
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Maven", false) {

        public void run(@NotNull ProgressIndicator indicator) {
            String[] urls = MavenRepositoryServicesManager.getServiceUrls();
            boolean tooManyResults = false;
            final AtomicBoolean proceedFlag = new AtomicBoolean(true);
            for (int i = 0, length = urls.length; i < length; i++) {
                if (!proceedFlag.get())
                    break;
                final List<Pair<MavenArtifactInfo, MavenRepositoryInfo>> resultList = new ArrayList<>();
                try {
                    String serviceUrl = urls[i];
                    final List<MavenArtifactInfo> artifacts;
                    artifacts = MavenRepositoryServicesManager.findArtifacts(template, serviceUrl);
                    if (!artifacts.isEmpty()) {
                        if (!proceedFlag.get()) {
                            break;
                        }
                        List<MavenRepositoryInfo> repositories = MavenRepositoryServicesManager.getRepositories(serviceUrl);
                        Map<String, MavenRepositoryInfo> map = new THashMap<>();
                        for (MavenRepositoryInfo repository : repositories) {
                            map.put(repository.getId(), repository);
                        }
                        for (MavenArtifactInfo artifact : artifacts) {
                            if (artifact == null) {
                                tooManyResults = true;
                            } else {
                                MavenRepositoryInfo repository = map.get(artifact.getRepositoryId());
                                // because it won't be resolved anyway
                                if (repository == null)
                                    continue;
                                resultList.add(Pair.create(artifact, repository));
                            }
                        }
                    }
                } catch (Exception e) {
                    MavenLog.LOG.error(e);
                } finally {
                    if (!proceedFlag.get())
                        break;
                    final Boolean aBoolean = i == length - 1 ? tooManyResults : null;
                    ApplicationManager.getApplication().invokeLater(() -> proceedFlag.set(resultProcessor.process(resultList, aBoolean)), o -> !proceedFlag.get());
                }
            }
        }
    });
}
Also used : MavenRepositoryServicesManager(org.jetbrains.idea.maven.services.MavenRepositoryServicesManager) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PairProcessor(com.intellij.util.PairProcessor) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) Task(com.intellij.openapi.progress.Task) SmartList(com.intellij.util.SmartList) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) ProjectBundle(org.jetbrains.idea.maven.project.ProjectBundle) RepositoryAttachDialog(org.jetbrains.idea.maven.utils.RepositoryAttachDialog) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) NotificationType(com.intellij.notification.NotificationType) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) MavenLog(org.jetbrains.idea.maven.utils.MavenLog) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) org.jetbrains.idea.maven.model(org.jetbrains.idea.maven.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) File(java.io.File) Pair(com.intellij.openapi.util.Pair) MavenDependenciesRemoteManager(org.jetbrains.idea.maven.utils.library.remote.MavenDependenciesRemoteManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) javax.swing(javax.swing) Task(com.intellij.openapi.progress.Task) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SmartList(com.intellij.util.SmartList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) THashMap(gnu.trove.THashMap)

Example 12 with ProgressIndicator

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

the class MavenUtil method runInBackground.

public static MavenTaskHandler runInBackground(final Project project, final String title, final boolean cancellable, final MavenTask task) {
    final MavenProgressIndicator indicator = new MavenProgressIndicator();
    Runnable runnable = () -> {
        if (project.isDisposed())
            return;
        try {
            task.run(indicator);
        } catch (MavenProcessCanceledException | ProcessCanceledException ignore) {
            indicator.cancel();
        }
    };
    if (isNoBackgroundMode()) {
        runnable.run();
        return new MavenTaskHandler() {

            public void waitFor() {
            }
        };
    } else {
        final Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(runnable);
        final MavenTaskHandler handler = new MavenTaskHandler() {

            public void waitFor() {
                try {
                    future.get();
                } catch (InterruptedException | ExecutionException e) {
                    MavenLog.LOG.error(e);
                }
            }
        };
        invokeLater(project, () -> {
            if (future.isDone())
                return;
            new Task.Backgroundable(project, title, cancellable) {

                public void run(@NotNull ProgressIndicator i) {
                    indicator.setIndicator(i);
                    handler.waitFor();
                }
            }.queue();
        });
        return handler;
    }
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with ProgressIndicator

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

the class GrabDependencies method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
    assert vfile != null;
    if (JavaPsiFacade.getInstance(project).findClass("org.apache.ivy.core.report.ResolveReport", file.getResolveScope()) == null) {
        Messages.showErrorDialog("Sorry, but IDEA cannot @Grab the dependencies without Ivy. Please add Ivy to your module dependencies and re-run the action.", "Ivy Missing");
        return;
    }
    Map<String, String> queries = prepareQueries(file);
    final Map<String, GeneralCommandLine> lines = new HashMap<>();
    for (String grabText : queries.keySet()) {
        final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
        try {
            DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module, GRAPE_RUNNER, false, true);
            javaParameters.getClassPath().add(PathUtil.getJarPathForClass(GrapeRunner.class));
            javaParameters.getProgramParametersList().add(queries.get(grabText));
            javaParameters.setUseDynamicClasspath(true);
            lines.put(grabText, javaParameters.toCommandLine());
        } catch (CantRunException e) {
            String title = "Can't run @Grab: " + ExceptionUtil.getMessage(e);
            NOTIFICATION_GROUP.createNotification(title, ExceptionUtil.getThrowableText(e), NotificationType.ERROR, null).notify(project);
            return;
        }
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab Annotations") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            int jarCount = 0;
            String messages = "";
            for (Map.Entry<String, GeneralCommandLine> entry : lines.entrySet()) {
                String grabText = entry.getKey();
                indicator.setText2(grabText);
                try {
                    final GrapeProcessHandler handler = new GrapeProcessHandler(entry.getValue(), module);
                    handler.startNotify();
                    handler.waitFor();
                    jarCount += handler.jarCount;
                    messages += "<b>" + grabText + "</b>: " + handler.messages + "<p>";
                } catch (ExecutionException e) {
                    LOG.error(e);
                }
            }
            final String finalMessages = messages;
            final String title = jarCount + " Grape dependency jar" + (jarCount == 1 ? "" : "s") + " added";
            NOTIFICATION_GROUP.createNotification(title, finalMessages, NotificationType.INFORMATION, null).notify(project);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) CantRunException(com.intellij.execution.CantRunException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException)

Example 14 with ProgressIndicator

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

the class SvnHistoryProvider method reportAppendableHistory.

public void reportAppendableHistory(FilePath path, final VcsAppendableHistorySessionPartner partner, @Nullable final SVNRevision from, @Nullable final SVNRevision to, final int limit, SVNRevision peg, final boolean forceBackwards) throws VcsException {
    FilePath committedPath = path;
    Change change = ChangeListManager.getInstance(myVcs.getProject()).getChange(path);
    if (change != null) {
        final ContentRevision beforeRevision = change.getBeforeRevision();
        final ContentRevision afterRevision = change.getAfterRevision();
        if (beforeRevision != null && afterRevision != null && !beforeRevision.getFile().equals(afterRevision.getFile()) && afterRevision.getFile().equals(path)) {
            committedPath = beforeRevision.getFile();
        }
        // revision can be VcsRevisionNumber.NULL
        if (peg == null && change.getBeforeRevision() != null && change.getBeforeRevision().getRevisionNumber() instanceof SvnRevisionNumber) {
            peg = ((SvnRevisionNumber) change.getBeforeRevision().getRevisionNumber()).getRevision();
        }
    }
    boolean showMergeSources = myVcs.getSvnConfiguration().isShowMergeSourcesInAnnotate();
    final LogLoader logLoader;
    if (path.isNonLocal()) {
        logLoader = new RepositoryLoader(myVcs, committedPath, from, to, limit, peg, forceBackwards, showMergeSources);
    } else {
        logLoader = new LocalLoader(myVcs, committedPath, from, to, limit, peg, showMergeSources);
    }
    try {
        logLoader.preliminary();
    } catch (SVNException e) {
        throw new VcsException(e);
    }
    logLoader.check();
    if (showMergeSources) {
        logLoader.initSupports15();
    }
    final SvnHistorySession historySession = new SvnHistorySession(myVcs, Collections.emptyList(), committedPath, showMergeSources && Boolean.TRUE.equals(logLoader.mySupport15), null, false, !path.isNonLocal());
    final Ref<Boolean> sessionReported = new Ref<>();
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        indicator.setText(SvnBundle.message("progress.text2.collecting.history", path.getName()));
    }
    final Consumer<VcsFileRevision> consumer = vcsFileRevision -> {
        if (!Boolean.TRUE.equals(sessionReported.get())) {
            partner.reportCreatedEmptySession(historySession);
            sessionReported.set(true);
        }
        partner.acceptRevision(vcsFileRevision);
    };
    logLoader.setConsumer(consumer);
    logLoader.load();
    logLoader.check();
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) UIUtil(com.intellij.util.ui.UIUtil) SvnBindException(org.jetbrains.idea.svn.commandLine.SvnBindException) SvnRevisionNumber(org.jetbrains.idea.svn.SvnRevisionNumber) Change(com.intellij.openapi.vcs.changes.Change) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Date(java.util.Date) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) ThrowableConsumer(com.intellij.util.ThrowableConsumer) ColumnInfo(com.intellij.util.ui.ColumnInfo) TableCellRenderer(javax.swing.table.TableCellRenderer) ActionManager(com.intellij.openapi.actionSystem.ActionManager) ShowAllAffectedGenericAction(com.intellij.openapi.vcs.annotate.ShowAllAffectedGenericAction) SVNErrorManager(org.tmatesoft.svn.core.internal.wc.SVNErrorManager) VcsConfiguration(com.intellij.openapi.vcs.VcsConfiguration) SvnUtil(org.jetbrains.idea.svn.SvnUtil) Charset(java.nio.charset.Charset) StatusText(com.intellij.util.ui.StatusText) SvnVcs(org.jetbrains.idea.svn.SvnVcs) VcsException(com.intellij.openapi.vcs.VcsException) FilePath(com.intellij.openapi.vcs.FilePath) PlatformIcons(com.intellij.util.PlatformIcons) ProgressManager(com.intellij.openapi.progress.ProgressManager) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) SVNException(org.tmatesoft.svn.core.SVNException) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) Info(org.jetbrains.idea.svn.info.Info) com.intellij.openapi.vcs.history(com.intellij.openapi.vcs.history) com.intellij.ui(com.intellij.ui) MouseEvent(java.awt.event.MouseEvent) SvnBundle(org.jetbrains.idea.svn.SvnBundle) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsActions(com.intellij.openapi.vcs.VcsActions) List(java.util.List) TableLinkMouseListener(com.intellij.openapi.vcs.changes.issueLinks.TableLinkMouseListener) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) SVNLogType(org.tmatesoft.svn.util.SVNLogType) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNPathUtil(org.tmatesoft.svn.core.internal.util.SVNPathUtil) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) SVNException(org.tmatesoft.svn.core.SVNException) SvnRevisionNumber(org.jetbrains.idea.svn.SvnRevisionNumber) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException)

Example 15 with ProgressIndicator

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

the class LiveProvider method getEarliestBunchInIntervalImpl.

private Fragment getEarliestBunchInIntervalImpl(long earliestRevision, final long oldestRevision, final int desirableSize, final boolean includeYoungest, final boolean includeOldest, final long earliestToTake) throws VcsException {
    if ((myEarliestRevisionWasAccessed) || ((oldestRevision == myYoungestRevision) && ((!includeYoungest) || (!includeOldest)))) {
        return null;
    }
    final SVNRevision youngRevision = (earliestRevision == -1) ? SVNRevision.HEAD : SVNRevision.create(earliestRevision);
    final Ref<List<CommittedChangeList>> refToList = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    final Runnable loader = () -> {
        try {
            refToList.set(myLoader.loadInterval(youngRevision, SVNRevision.create(oldestRevision), desirableSize, includeYoungest, includeOldest));
        } catch (VcsException e) {
            exceptionRef.set(e);
        }
    };
    final Application application = ApplicationManager.getApplication();
    if (application.isUnitTestMode() || !application.isDispatchThread()) {
        loader.run();
    } else {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ProgressIndicator ind = ProgressManager.getInstance().getProgressIndicator();
            if (ind != null) {
                ind.setText(SvnBundle.message("progress.live.provider.loading.revisions.details.text"));
            }
            loader.run();
        }, SvnBundle.message("progress.live.provider.loading.revisions.text"), false, myVcs.getProject());
    }
    if (!exceptionRef.isNull()) {
        final VcsException e = exceptionRef.get();
        if (isElementNotFound(e)) {
            // occurs when target URL is deleted in repository
            // try to find latest existent revision. expensive ...
            final LatestExistentSearcher searcher = new LatestExistentSearcher(oldestRevision, myYoungestRevision, (oldestRevision != 0), myVcs, myLocation.toSvnUrl(), myRepositoryUrl);
            final long existent = searcher.getLatestExistent();
            if ((existent == -1) || (existent == earliestRevision)) {
                myEarliestRevisionWasAccessed = true;
                return null;
            }
            return getEarliestBunchInIntervalImpl(existent, oldestRevision, includeYoungest ? desirableSize : (desirableSize + 1), true, includeOldest, Math.min(existent, earliestRevision));
        }
        throw e;
    }
    final List<CommittedChangeList> list = refToList.get();
    if (list.isEmpty()) {
        myEarliestRevisionWasAccessed = (oldestRevision == 0);
        return null;
    }
    if (earliestToTake > 0) {
        for (Iterator<CommittedChangeList> iterator = list.iterator(); iterator.hasNext(); ) {
            final CommittedChangeList changeList = iterator.next();
            if (changeList.getNumber() > earliestToTake)
                iterator.remove();
        }
    }
    myEarliestRevisionWasAccessed = (oldestRevision == 0) && ((list.size() + ((!includeOldest) ? 1 : 0) + ((!includeYoungest) ? 1 : 0)) < desirableSize);
    return new Fragment(Origin.LIVE, list, true, true, null);
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) List(java.util.List) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) Application(com.intellij.openapi.application.Application)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)400 Task (com.intellij.openapi.progress.Task)151 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 NotNull (org.jetbrains.annotations.NotNull)101 Project (com.intellij.openapi.project.Project)88 File (java.io.File)59 IOException (java.io.IOException)58 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)47 Nullable (org.jetbrains.annotations.Nullable)46 ProgressManager (com.intellij.openapi.progress.ProgressManager)39 List (java.util.List)36 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)31 Ref (com.intellij.openapi.util.Ref)27 Module (com.intellij.openapi.module.Module)26 VcsException (com.intellij.openapi.vcs.VcsException)26 ArrayList (java.util.ArrayList)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 Logger (com.intellij.openapi.diagnostic.Logger)23 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)22 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)22