Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfbecker2010-04-02 08:15:56 +0000
committerfbecker2010-04-02 08:15:56 +0000
commitdd00fd827cb494016f2975fbed6188d9cd7b3c6c (patch)
treebd15328abb64b6338b1dc023051e3a4fa728889f /org.eclipse.mylyn.bugzilla.ui/src
parent9baf3b6ab656241205751a4522e412a0e582b143 (diff)
downloadorg.eclipse.mylyn.tasks-dd00fd827cb494016f2975fbed6188d9cd7b3c6c.tar.gz
org.eclipse.mylyn.tasks-dd00fd827cb494016f2975fbed6188d9cd7b3c6c.tar.xz
org.eclipse.mylyn.tasks-dd00fd827cb494016f2975fbed6188d9cd7b3c6c.zip
ASSIGNED - bug 299555: Bugzilla connector should not invoke getResponseBody()
https://bugs.eclipse.org/bugs/show_bug.cgi?id=299555
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.ui/src')
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java128
1 files changed, 128 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java
index ec6468170..3579bf5b8 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java
@@ -32,6 +32,7 @@ import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaImages;
import org.eclipse.mylyn.internal.bugzilla.ui.TaskAttachmentHyperlink;
import org.eclipse.mylyn.internal.bugzilla.ui.search.BugzillaSearchPage;
import org.eclipse.mylyn.internal.bugzilla.ui.wizard.NewBugzillaTaskWizard;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskComment;
@@ -61,6 +62,20 @@ public class BugzillaConnectorUi extends AbstractRepositoryConnectorUi {
private static final Pattern PATTERN = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
+ private static final int GET_TASK_NUM_GROUP = 8;
+
+ private static final int GET_COMMENT_NUM_GROUP = 13;
+
+ private static final int GET_ATTACHMENT_NUM_GROUP = 3;
+
+ private static final String regexp_bug = "(((duplicate of|((\\W||^)+(bug|task)))( ?#? ?)(\\d+))?((\\W||\\s)*(comment|c)??(\\s*#\\s*)(\\d+))?)"; //$NON-NLS-1$
+
+ private static final String regexp_attachment = "Created (an )?attachment\\s*(\\(id=)?(\\d+)"; //$NON-NLS-1$
+
+ private static final Pattern PATTERN_BUG = Pattern.compile(regexp_bug, Pattern.CASE_INSENSITIVE);
+
+ private static final Pattern PATTERN_ATTACHMENT = Pattern.compile(regexp_attachment, Pattern.CASE_INSENSITIVE);
+
@Override
public String getAccountCreationUrl(TaskRepository taskRepository) {
return taskRepository.getRepositoryUrl() + "/createaccount.cgi"; //$NON-NLS-1$
@@ -245,4 +260,117 @@ public class BugzillaConnectorUi extends AbstractRepositoryConnectorUi {
return new BugzillaTaskAttachmentPage(model);
}
+ @Override
+ public boolean supportGetHyperlinks() {
+ return true;
+ }
+
+ @Override
+ public IHyperlink[] getHyperlinks(TaskRepository repository, AbstractTask task, String text, int index,
+ int textOffset) {
+ ArrayList<IHyperlink> hyperlinksFound = null;
+ Matcher mb = PATTERN_BUG.matcher(text);
+ while (mb.find()) {
+ if (index == -1 || (index >= mb.start() && index <= mb.end())) {
+ IHyperlink link = extractHyperlinkBug(repository, task, textOffset, mb);
+ if (link != null) {
+ if (hyperlinksFound == null) {
+ hyperlinksFound = new ArrayList<IHyperlink>();
+ }
+ hyperlinksFound.add(link);
+ }
+ }
+ }
+ Matcher ma = PATTERN_ATTACHMENT.matcher(text);
+ while (ma.find()) {
+ if (index == -1 || (index >= ma.start() && index <= ma.end())) {
+ IHyperlink link = extractHyperlinkAttachment(repository, textOffset, ma);
+ if (link != null) {
+ if (hyperlinksFound == null) {
+ hyperlinksFound = new ArrayList<IHyperlink>();
+ }
+ hyperlinksFound.add(link);
+ }
+ }
+ }
+
+ return (hyperlinksFound != null) ? hyperlinksFound.toArray(new IHyperlink[0]) : null;
+ }
+
+ private static IHyperlink extractHyperlinkBug(TaskRepository repository, AbstractTask task, int regionOffset,
+ Matcher m) {
+
+ int start = m.start();
+ if (m.group().startsWith("duplicate")) { //$NON-NLS-1$
+ start = m.start() + m.group().indexOf(m.group(GET_TASK_NUM_GROUP));
+ } else {
+ start = m.start();
+ for (int index = 0; index < m.group().length() && !Character.isLetter(m.group().charAt(index)); index++, start++) {
+ }
+ }
+
+ int end = m.end();
+
+ if (end == -1) {
+ end = m.group().length();
+ }
+
+ start += regionOffset;
+ end += regionOffset;
+ String bugId = m.group(GET_TASK_NUM_GROUP);
+ if (bugId == null) {
+ String commentId = m.group(GET_COMMENT_NUM_GROUP);
+ IRegion sregion = new Region(start, end - start);
+ if (commentId != null) {
+ String taskID;
+ if (task != null) {
+ taskID = task.getTaskId();
+ } else {
+ taskID = ""; //$NON-NLS-1$
+ }
+ TaskHyperlink taskHyperLink = new TaskHyperlink(sregion, repository, taskID);
+ if (commentId != null) {
+ taskHyperLink.setSelection(TaskAttribute.PREFIX_COMMENT + commentId);
+ }
+ return taskHyperLink;
+
+ }
+ } else {
+ bugId.trim();
+ IRegion sregion = new Region(start, end - start);
+ TaskHyperlink taskHyperLink = new TaskHyperlink(sregion, repository, bugId);
+ String commentId = m.group(GET_COMMENT_NUM_GROUP);
+ if (commentId != null) {
+ taskHyperLink.setSelection(TaskAttribute.PREFIX_COMMENT + commentId);
+ }
+ return taskHyperLink;
+ }
+ return null;
+ }
+
+ private static IHyperlink extractHyperlinkAttachment(TaskRepository repository, int regionOffset, Matcher m) {
+
+ int start = -1;
+ start = m.start();
+ for (int index = 0; index < m.group().length() && !Character.isLetter(m.group().charAt(index)); index++, start++) {
+ }
+
+ int end = m.end();
+
+ if (end == -1) {
+ end = m.group().length();
+ }
+
+ start += regionOffset;
+ end += regionOffset;
+
+ String attachmentId = m.group(GET_ATTACHMENT_NUM_GROUP);
+ if (attachmentId != null) {
+ start = start + m.group().indexOf(m.group(GET_ATTACHMENT_NUM_GROUP));
+
+ IRegion sregion = new Region(start, end - start);
+ return new TaskAttachmentHyperlink(sregion, repository, attachmentId);
+ }
+ return null;
+ }
}

Back to the top