Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2007-05-07 23:00:36 +0000
committerrelves2007-05-07 23:00:36 +0000
commitd71b4023e571517c578a6bba45426aa11bcb8106 (patch)
tree5edcf37d63cffe14b38889d8f4bc81eb640bd452 /org.eclipse.mylyn.trac.core
parent8a14e86eeaba9a053f0ec797bf4624d3e7ce77bf (diff)
downloadorg.eclipse.mylyn.tasks-d71b4023e571517c578a6bba45426aa11bcb8106.tar.gz
org.eclipse.mylyn.tasks-d71b4023e571517c578a6bba45426aa11bcb8106.tar.xz
org.eclipse.mylyn.tasks-d71b4023e571517c578a6bba45426aa11bcb8106.zip
NEW - bug 170536: [api] unified error handling
https://bugs.eclipse.org/bugs/show_bug.cgi?id=170536
Diffstat (limited to 'org.eclipse.mylyn.trac.core')
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java22
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracCorePlugin.java33
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java4
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracStatus.java60
4 files changed, 44 insertions, 75 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java
index 3480a0eeb..38a3b2482 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java
@@ -23,7 +23,9 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylar.internal.trac.core.model.TracTicket;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.IAttachmentHandler;
+import org.eclipse.mylar.tasks.core.IMylarStatusConstants;
import org.eclipse.mylar.tasks.core.RepositoryAttachment;
+import org.eclipse.mylar.tasks.core.RepositoryStatus;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.TaskRepository;
@@ -38,7 +40,8 @@ public class TracAttachmentHandler implements IAttachmentHandler {
this.connector = connector;
}
- public void downloadAttachment(TaskRepository repository, RepositoryAttachment attachment, File file) throws CoreException {
+ public void downloadAttachment(TaskRepository repository, RepositoryAttachment attachment, File file)
+ throws CoreException {
byte[] data = getAttachmentData(repository, attachment);
try {
writeData(file, data);
@@ -56,15 +59,18 @@ public class TracAttachmentHandler implements IAttachmentHandler {
}
}
- public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, String comment, String description, File file, String contentType, boolean isPatch) throws CoreException {
+ public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, String comment,
+ String description, File file, String contentType, boolean isPatch) throws CoreException {
if (!TracRepositoryConnector.hasAttachmentSupport(repository, task)) {
- throw new CoreException(new TracStatus(IStatus.INFO, TracCorePlugin.PLUGIN_ID, TracStatus.INTERNAL_ERROR, "Attachments are not supported by this repository access type.", null));
+ throw new CoreException(new RepositoryStatus(repository.getUrl(), IStatus.INFO, TracCorePlugin.PLUGIN_ID,
+ IMylarStatusConstants.REPOSITORY_ERROR,
+ "Attachments are not supported by this repository access type"));
}
try {
ITracClient client = connector.getClientManager().getRepository(repository);
int id = Integer.parseInt(task.getTaskId());
- byte[] data = readData(file);
+ byte[] data = readData(file);
client.putAttachmentData(id, file.getName(), description, data);
if (comment != null && comment.length() > 0) {
TracTicket ticket = new TracTicket(id);
@@ -104,7 +110,7 @@ public class TracAttachmentHandler implements IAttachmentHandler {
return TracRepositoryConnector.hasAttachmentSupport(repository, task);
}
- public boolean canDeprecate(TaskRepository repository, RepositoryAttachment attachment) {
+ public boolean canDeprecate(TaskRepository repository, RepositoryAttachment attachment) {
return false;
}
@@ -115,7 +121,9 @@ public class TracAttachmentHandler implements IAttachmentHandler {
public byte[] getAttachmentData(TaskRepository repository, RepositoryAttachment attachment) throws CoreException {
String filename = attachment.getAttributeValue(RepositoryTaskAttribute.ATTACHMENT_FILENAME);
if (filename == null) {
- throw new CoreException(new TracStatus(IStatus.ERROR, TracCorePlugin.PLUGIN_ID, TracStatus.INTERNAL_ERROR, "Attachment download from " + repository.getUrl() + " failed, missing attachment filename.", null));
+ throw new CoreException(new RepositoryStatus(repository.getUrl(), IStatus.ERROR, TracCorePlugin.PLUGIN_ID,
+ IMylarStatusConstants.REPOSITORY_ERROR, "Attachment download from " + repository.getUrl()
+ + " failed, missing attachment filename."));
}
try {
@@ -126,5 +134,5 @@ public class TracAttachmentHandler implements IAttachmentHandler {
throw new CoreException(TracCorePlugin.toStatus(e));
}
}
-
+
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracCorePlugin.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracCorePlugin.java
index 1019f832b..f7deec769 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracCorePlugin.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracCorePlugin.java
@@ -17,6 +17,9 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylar.tasks.core.IMylarStatusConstants;
+import org.eclipse.mylar.tasks.core.MylarStatus;
+import org.eclipse.mylar.tasks.core.RepositoryStatus;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.osgi.framework.BundleContext;
@@ -78,25 +81,33 @@ public class TracCorePlugin extends Plugin {
return cacheFile;
}
- public static TracStatus toStatus(Throwable e, TaskRepository repository) {
- TracStatus status = toStatus(e);
- status.setRepositoryUrl(repository.getUrl());
- return status;
+ public static IStatus toStatus(Throwable e, TaskRepository repository) {
+ if (e instanceof TracLoginException) {
+ return RepositoryStatus.createLoginError(repository.getUrl(), PLUGIN_ID);
+ } else if (e instanceof TracPermissionDeniedException) {
+ return TracStatus.createPermissionDeniedError(repository.getUrl(), PLUGIN_ID);
+ }
+
+ return toStatus(e);
}
- public static TracStatus toStatus(Throwable e) {
+ public static IStatus toStatus(Throwable e) {
if (e instanceof TracLoginException) {
- return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.REPOSITORY_LOGIN_ERROR);
+ throw new RuntimeException("Invoke TracCorePlugin.toStatus(Throwable, TaskRepository)");
} else if (e instanceof TracPermissionDeniedException) {
- return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.PERMISSION_DENIED_ERROR);
+ throw new RuntimeException("Invoke TracCorePlugin.toStatus(Throwable, TaskRepository)");
} else if (e instanceof TracException) {
- return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.IO_ERROR, e.getMessage());
+ String message = e.getMessage();
+ if (message == null) {
+ message = "I/O error has occured";
+ }
+ return new MylarStatus(Status.ERROR, PLUGIN_ID, IMylarStatusConstants.IO_ERROR, message, e);
} else if (e instanceof ClassCastException) {
- return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.IO_ERROR, "Unexpected server response: " + e.getMessage(), e);
+ return new MylarStatus(Status.ERROR, PLUGIN_ID, IMylarStatusConstants.IO_ERROR, "Unexpected server response: " + e.getMessage(), e);
} else if (e instanceof MalformedURLException) {
- return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.IO_ERROR, "Repository URL is invalid", e);
+ return new MylarStatus(Status.ERROR, PLUGIN_ID, IMylarStatusConstants.IO_ERROR, "Repository URL is invalid", e);
} else {
- return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.INTERNAL_ERROR, "Unexpected error", e);
+ return new MylarStatus(Status.ERROR, PLUGIN_ID, IMylarStatusConstants.INTERNAL_ERROR, "Unexpected error", e);
}
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java
index 3f058965c..1b79b29b4 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java
@@ -37,6 +37,7 @@ import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.ITaskDataHandler;
import org.eclipse.mylar.tasks.core.QueryHitCollector;
import org.eclipse.mylar.tasks.core.RepositoryOperation;
+import org.eclipse.mylar.tasks.core.RepositoryStatus;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskRepository;
@@ -323,8 +324,7 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector {
ITracClient client = getClientManager().getRepository(repository);
client.updateAttributes(monitor, true);
} catch (Exception e) {
- throw new CoreException(new TracStatus(IStatus.INFO, TracCorePlugin.PLUGIN_ID, Status.WARNING,
- "Could not update attributes", null));
+ throw new CoreException(RepositoryStatus.createStatus(repository.getUrl(), IStatus.WARNING, TracCorePlugin.PLUGIN_ID, "Could not update attributes"));
}
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracStatus.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracStatus.java
index 752ef1c70..1afcfcea3 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracStatus.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracStatus.java
@@ -11,67 +11,17 @@
package org.eclipse.mylar.internal.trac.core;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylar.tasks.core.IMylarStatusConstants;
-import org.eclipse.osgi.util.NLS;
+import org.eclipse.mylar.tasks.core.RepositoryStatus;
/**
- * @author Rob Elves
* @author Steffen Pingel
*/
-public class TracStatus extends Status implements IMylarStatusConstants {
+public class TracStatus {
- public static final int PERMISSION_DENIED_ERROR = 1001;
-
- private String repositoryUrl;
-
- public TracStatus(int severity, String pluginId, int code) {
- super(severity, pluginId, code, null, null);
- }
-
- public TracStatus(int severity, String pluginId, int code, String message) {
- super(severity, pluginId, code, message, null);
+ public static IStatus createPermissionDeniedError(String repositoryUrl, String pluginId) {
+ return new RepositoryStatus(repositoryUrl, IStatus.ERROR, TracCorePlugin.PLUGIN_ID, IMylarStatusConstants.PERMISSION_DENIED_ERROR, "Permission denied.");
}
- public TracStatus(int severity, String pluginId, int code, String message, Throwable e) {
- super(severity, pluginId, code, message, e);
- }
-
- /**
- * Returns the message that is relevant to the code of this status.
- */
- public String getMessage() {
- String message = super.getMessage();
- if (message != null && !"".equals(message)) {
- return message;
- }
-
- Throwable exception = getException();
- if (exception != null) {
- if (exception.getMessage() != null) {
- return exception.getMessage();
- }
- return exception.toString();
- }
-
- switch (getCode()) {
- case REPOSITORY_LOGIN_ERROR:
- return NLS.bind("Unable to login to {0}. Please validate credentials via Task Repositories view.", getRepositoryUrl());
- case REPOSITORY_NOT_FOUND:
- return NLS.bind("Repository {0} could not be found.", getRepositoryUrl());
- case PERMISSION_DENIED_ERROR:
- return "Insufficient permissions.";
- default:
- return "";
- }
- }
-
- public String getRepositoryUrl() {
- return repositoryUrl;
- }
-
- public void setRepositoryUrl(String repsitoryUrl) {
- this.repositoryUrl = repsitoryUrl;
- }
-
}

Back to the top