Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java76
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java12
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java12
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaConnectorUi.java128
4 files changed, 186 insertions, 42 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
index 945c66643..c17d569bb 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
@@ -67,17 +67,17 @@ import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer;
+import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.Token;
import org.eclipse.mylyn.commons.net.HtmlTag;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.commons.net.WebUtil;
-import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.Token;
import org.eclipse.mylyn.internal.bugzilla.core.history.BugzillaTaskHistoryParser;
import org.eclipse.mylyn.internal.bugzilla.core.history.TaskHistory;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
+import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource;
@@ -524,7 +524,7 @@ public class BugzillaClient {
}
}
}
-
+ // because html is not a valid config content type it is save to get the response here
parseHtmlError(getResponseStream(postMethod, monitor));
} finally {
if (postMethod != null) {
@@ -661,7 +661,7 @@ public class BugzillaClient {
try {
int status = WebUtil.execute(httpClient, hostConfiguration, method, monitor);
if (status == HttpStatus.SC_OK) {
-// ignore the response
+ //copy the response
InputStream instream = method.getResponseBodyAsStream();
byte[] buffer = new byte[4096];
int len;
@@ -866,26 +866,25 @@ public class BugzillaClient {
postMethod.setRequestBody(formData);
postMethod.setDoAuthentication(true);
- try {
- int status = WebUtil.execute(httpClient, hostConfiguration, postMethod, monitor);
- if (status == HttpStatus.SC_OK) {
- return postMethod;
- } else if (status == HttpStatus.SC_MOVED_TEMPORARILY) {
- String redirectLocation;
- Header locationHeader = postMethod.getResponseHeader("location"); //$NON-NLS-1$
- if (locationHeader != null) {
- redirectLocation = locationHeader.getValue();
- throw new RedirectException(redirectLocation);
- }
-
+ int status = WebUtil.execute(httpClient, hostConfiguration, postMethod, monitor);
+ if (status == HttpStatus.SC_OK) {
+ return postMethod;
+ } else if (status == HttpStatus.SC_MOVED_TEMPORARILY) {
+ String redirectLocation;
+ Header locationHeader = postMethod.getResponseHeader("location"); //$NON-NLS-1$
+ if (locationHeader != null) {
+ redirectLocation = locationHeader.getValue();
+ postMethod.getResponseBodyNoop();
+ postMethod.releaseConnection();
+ throw new RedirectException(redirectLocation);
}
- throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
- RepositoryStatus.ERROR_IO, repositoryUrl.toString(), new IOException(
- "Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status)))); //$NON-NLS-1$
- } finally {
- postMethod.getResponseBodyNoop();
- postMethod.releaseConnection();
+
}
+ postMethod.getResponseBodyNoop();
+ postMethod.releaseConnection();
+ throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
+ RepositoryStatus.ERROR_IO, repositoryUrl.toString(), new IOException(
+ "Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status)))); //$NON-NLS-1$
}
public void postUpdateAttachment(TaskAttribute taskAttribute, String action, IProgressMonitor monitor)
@@ -1818,6 +1817,7 @@ public class BugzillaClient {
}
if (!parseable) {
+ // because html is not a valid config content type it is save to get the response here
parseHtmlError(getResponseStream(method, monitor));
break;
}
@@ -1898,10 +1898,7 @@ public class BugzillaClient {
code = WebUtil.execute(httpClient, hostConfiguration, headMethod, monitor);
} catch (IOException e) {
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
headMethod.releaseConnection();
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_IO, repositoryUrl.toString(), e));
@@ -1911,10 +1908,7 @@ public class BugzillaClient {
return headMethod;
} else if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
// login or reauthenticate due to an expired session
headMethod.releaseConnection();
loggedIn = false;
@@ -1922,20 +1916,14 @@ public class BugzillaClient {
} else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
loggedIn = false;
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
headMethod.releaseConnection();
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_REPOSITORY_LOGIN, repositoryUrl.toString(),
"Proxy authentication required")); //$NON-NLS-1$
} else {
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
headMethod.releaseConnection();
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_NETWORK, "Http error: " + HttpStatus.getStatusText(code))); //$NON-NLS-1$
@@ -2096,4 +2084,16 @@ public class BugzillaClient {
RepositoryStatus.ERROR_INTERNAL, "Unable to parse response from " + repositoryUrl.toString() + ".")); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
+ private void consumeResponse(HttpMethodBase method) {
+ InputStream instream;
+ try {
+ instream = method.getResponseBodyAsStream();
+ byte[] buffer = new byte[4096];
+ while (instream.read(buffer) > 0) {
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java
index bf6dfbcc8..648d2221b 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java
@@ -12,6 +12,7 @@
package org.eclipse.mylyn.internal.bugzilla.core;
import java.io.IOException;
+import java.io.InputStream;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
@@ -63,8 +64,15 @@ public class GzipGetMethod extends GetMethod {
* @throws IOException
*/
public void getResponseBodyNoop() throws IOException {
- // result is ignored
- super.getResponseBody();
+ InputStream instream;
+ try {
+ instream = getResponseBodyAsStream();
+ byte[] buffer = new byte[4096];
+ while (instream.read(buffer) > 0) {
+ }
+ } catch (IOException e) {
+ // ignore
+ }
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java
index d85e002e1..84fad071f 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java
@@ -12,6 +12,7 @@
package org.eclipse.mylyn.internal.bugzilla.core;
import java.io.IOException;
+import java.io.InputStream;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
@@ -63,7 +64,14 @@ public class GzipPostMethod extends PostMethod {
* @throws IOException
*/
public void getResponseBodyNoop() throws IOException {
- // result is ignored
- super.getResponseBody();
+ InputStream instream;
+ try {
+ instream = getResponseBodyAsStream();
+ byte[] buffer = new byte[4096];
+ while (instream.read(buffer) > 0) {
+ }
+ } catch (IOException e) {
+ // ignore
+ }
}
}
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