mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-81400: Annoying 'Can't connect to YouTrack message' from task plugin
This commit is contained in:
@@ -67,22 +67,29 @@ public interface Notifications {
|
||||
}
|
||||
|
||||
public static void notify(@NotNull final Notification notification, @Nullable final Project project) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
//noinspection SSBasedInspection
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (project != null && !project.isDisposed()) {
|
||||
project.getMessageBus().syncPublisher(TOPIC).notify(notification);
|
||||
} else {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (!app.isDisposed()) {
|
||||
app.getMessageBus().syncPublisher(TOPIC).notify(notification);
|
||||
}
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
doNotify(notification, project);
|
||||
}
|
||||
else {
|
||||
//noinspection SSBasedInspection
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doNotify(notification, project);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void doNotify(Notification notification, Project project) {
|
||||
if (project != null && !project.isDisposed()) {
|
||||
project.getMessageBus().syncPublisher(TOPIC).notify(notification);
|
||||
} else {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (!app.isDisposed()) {
|
||||
app.getMessageBus().syncPublisher(TOPIC).notify(notification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
return o.getId();
|
||||
}
|
||||
};
|
||||
private static final String TASKS_NOTIFICATION_GROUP = "Task Group";
|
||||
static final String TASKS_NOTIFICATION_GROUP = "Task Group";
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
@@ -647,40 +647,49 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
return;
|
||||
}
|
||||
myUpdating = true;
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
List<Task> issues = getIssuesFromRepositories(null, myConfig.updateIssuesCount, 0, false);
|
||||
|
||||
synchronized (myIssueCache) {
|
||||
myIssueCache.clear();
|
||||
for (Task issue : issues) {
|
||||
myIssueCache.put(issue.getId(), issue);
|
||||
}
|
||||
}
|
||||
// update local tasks
|
||||
synchronized (myTasks) {
|
||||
for (Iterator<Map.Entry<String,LocalTaskImpl>> it = myTasks.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<String,LocalTaskImpl> entry = it.next();
|
||||
Task issue = myIssueCache.get(entry.getKey());
|
||||
if (issue != null) {
|
||||
if (issue.isClosed()) {
|
||||
it.remove();
|
||||
} else {
|
||||
entry.getValue().updateFromIssue(issue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
doUpdate(onComplete);
|
||||
}
|
||||
else {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
public void run() {
|
||||
doUpdate(onComplete);
|
||||
}
|
||||
finally {
|
||||
if (onComplete != null) {
|
||||
onComplete.run();
|
||||
}
|
||||
myUpdating = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void doUpdate(Runnable onComplete) {
|
||||
try {
|
||||
List<Task> issues = getIssuesFromRepositories(null, myConfig.updateIssuesCount, 0, false);
|
||||
|
||||
synchronized (myIssueCache) {
|
||||
myIssueCache.clear();
|
||||
for (Task issue : issues) {
|
||||
myIssueCache.put(issue.getId(), issue);
|
||||
}
|
||||
}
|
||||
});
|
||||
// update local tasks
|
||||
synchronized (myTasks) {
|
||||
for (Iterator<Map.Entry<String,LocalTaskImpl>> it = myTasks.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<String,LocalTaskImpl> entry = it.next();
|
||||
Task issue = myIssueCache.get(entry.getKey());
|
||||
if (issue != null) {
|
||||
if (issue.isClosed()) {
|
||||
it.remove();
|
||||
} else {
|
||||
entry.getValue().updateFromIssue(issue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (onComplete != null) {
|
||||
onComplete.run();
|
||||
}
|
||||
myUpdating = false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Task> getIssuesFromRepositories(@Nullable String request, int max, long since, boolean forceRequest) {
|
||||
@@ -696,25 +705,31 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
|
||||
}
|
||||
catch (Exception e) {
|
||||
myBadRepositories.add(repository);
|
||||
Notifications.Bus.register(TASKS_NOTIFICATION_GROUP, NotificationDisplayType.BALLOON);
|
||||
Notifications.Bus.notify(new Notification(TASKS_NOTIFICATION_GROUP, "Cannot connect to " + repository.getUrl(),
|
||||
"<p><a href=\"\">Configure server...</a></p>", NotificationType.WARNING,
|
||||
new NotificationListener() {
|
||||
public void hyperlinkUpdate(@NotNull Notification notification,
|
||||
@NotNull HyperlinkEvent event) {
|
||||
TaskRepositoriesConfigurable configurable =
|
||||
new TaskRepositoriesConfigurable(myProject);
|
||||
ShowSettingsUtil.getInstance().editConfigurable(myProject, configurable);
|
||||
if (!ArrayUtil.contains(repository, getAllRepositories())) {
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
}), myProject);
|
||||
if (forceRequest) {
|
||||
notifyAboutConnectionFailure(repository);
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues;
|
||||
}
|
||||
|
||||
private void notifyAboutConnectionFailure(final TaskRepository repository) {
|
||||
Notifications.Bus.register(TASKS_NOTIFICATION_GROUP, NotificationDisplayType.BALLOON);
|
||||
Notifications.Bus.notify(new Notification(TASKS_NOTIFICATION_GROUP, "Cannot connect to " + repository.getUrl(),
|
||||
"<p><a href=\"\">Configure server...</a></p>", NotificationType.WARNING,
|
||||
new NotificationListener() {
|
||||
public void hyperlinkUpdate(@NotNull Notification notification,
|
||||
@NotNull HyperlinkEvent event) {
|
||||
TaskRepositoriesConfigurable configurable =
|
||||
new TaskRepositoriesConfigurable(myProject);
|
||||
ShowSettingsUtil.getInstance().editConfigurable(myProject, configurable);
|
||||
if (!ArrayUtil.contains(repository, getAllRepositories())) {
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
}), myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVcsEnabled() {
|
||||
return ProjectLevelVcsManager.getInstance(myProject).getAllActiveVcss().length > 0;
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package com.intellij.tasks;
|
||||
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationDisplayType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -40,4 +47,42 @@ public class TaskManagerTest extends TaskManagerTestCase {
|
||||
myManager.removeTaskListener(listener);
|
||||
}
|
||||
|
||||
public void testNotifications() throws Exception {
|
||||
|
||||
final Ref<Notification> notificationRef = new Ref<Notification>();
|
||||
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(Notifications.TOPIC, new Notifications() {
|
||||
@Override
|
||||
public void notify(@NotNull Notification notification) {
|
||||
notificationRef.set(notification);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(@NotNull String groupDisplayName, @NotNull NotificationDisplayType defaultDisplayType) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(@NotNull String groupDisplayName,
|
||||
@NotNull NotificationDisplayType defaultDisplayType,
|
||||
boolean shouldLog) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
TestRepository repository = new TestRepository() {
|
||||
@Override
|
||||
public Task[] getIssues(@Nullable String query, int max, long since) throws Exception {
|
||||
throw new Exception();
|
||||
}
|
||||
};
|
||||
myManager.setRepositories(Collections.singletonList(repository));
|
||||
|
||||
myManager.updateIssues(null);
|
||||
|
||||
assertNull(notificationRef.get());
|
||||
|
||||
myManager.getIssues("");
|
||||
|
||||
assertNotNull(notificationRef.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.tasks;
|
||||
|
||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
@@ -12,11 +13,11 @@ public abstract class TaskManagerTestCase extends LightCodeInsightFixtureTestCas
|
||||
super(UsefulTestCase.IDEA_MARKER_CLASS, "PlatformLangXml");
|
||||
}
|
||||
|
||||
protected TaskManager myManager;
|
||||
protected TaskManagerImpl myManager;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myManager = TaskManager.getManager(getProject());
|
||||
myManager = (TaskManagerImpl)TaskManager.getManager(getProject());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user