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