Bug 244442 - [api] TaskHyperlinkDetector does not detect hyperlinks correctly for regions of non-zero length
Summary: [api] TaskHyperlinkDetector does not detect hyperlinks correctly for regions ...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: dev   Edit
Hardware: All All
: P2 major (vote)
Target Milestone: 3.1   Edit
Assignee: Steffen Pingel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 182839 (view as bug list)
Depends on: 248798 248800 248801
Blocks: 167941
  Show dependency tree
 
Reported: 2008-08-18 11:49 EDT by David Green CLA
Modified: 2008-10-01 00:06 EDT (History)
1 user (show)

See Also:


Attachments
patch that adds new API for detection of hyperlinks covering a region (7.87 KB, patch)
2008-08-18 12:41 EDT, David Green CLA
no flags Details | Diff
mylyn/context/zip (42.17 KB, application/octet-stream)
2008-08-18 12:41 EDT, David Green CLA
no flags Details
re-cut the patch avoiding document.get() (8.59 KB, patch)
2008-08-19 11:49 EDT, David Green CLA
no flags Details | Diff
mylyn/context/zip (3.75 KB, application/octet-stream)
2008-08-19 11:49 EDT, David Green CLA
no flags Details
updated patch (8.55 KB, text/plain)
2008-09-26 16:35 EDT, Steffen Pingel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Green CLA 2008-08-18 11:49:23 EDT
TaskHyperlinkDetector currently only detects hyperlinks correctly for regions of 0-length.  This is due to the API of java class AbstractRepositoryConnectorUi:
@public IHyperlink[] findHyperlinks(TaskRepository repository, String text, int textOffset, int lineOffset)@

Note that the method takes a textOffset, with no length.  The implementation of this method in BugzillaConnectorUi only returns hyperlinks that overlap the provided @textOffset@.
This blocks bug 167941, which should be able to reuse the TaskHyperlinkDetector to find TaskHyperlinks.  It also fails to fulfill the contract specified by IHyperlinkDetector, which takes a region as an argument.
Comment 1 David Green CLA 2008-08-18 12:41:31 EDT
Created attachment 110251 [details]
patch that adds new API for detection of hyperlinks covering a region

This patch adds new API for detection of hyperlinks in a region of text.
The old findHyperlinks API is deprecated, and the new API calls the old one so that subclasses still work.
The new API is implemented in BugzillaConnectorUi

With this patch applied patch on bug 167941 works
Comment 2 David Green CLA 2008-08-18 12:41:33 EDT
Created attachment 110252 [details]
mylyn/context/zip
Comment 3 Steffen Pingel CLA 2008-08-19 04:35:49 EDT
I agree that the current hyperlink detection API is not generic enough to be reused to resolve bug 167941. I am a bit concerned about the performance impact of the changes proposed in the patch though.

Invoking document.get() creates a copy of the whole document each time hyperlink detection is triggered. Considering that task hyperlinking works in any textual editor this could potentially lead to significant temporary memory allocation for large documents. 

There are also performance considerations when matching regular expressions on the whole document. This could be slow for complex regular expressions (e.g. JIRA) or large documents.

I'm not sure what the best abstraction for the hyperlink detection is. The intention of the current API is to avoid code duplication between connectors but I find the method signature difficult to understand and to implement.

Maybe it would be better to encapsulate the common code in a utility method  and change the API to resemble IHyperlinkDetector more closely?  
Comment 4 David Green CLA 2008-08-19 11:49:16 EDT
Created attachment 110354 [details]
re-cut the patch avoiding document.get()

I understand your performance concerns.  
Here's a re-do of the patch that avoids the no-arg document.get().  See TaskHyperlinkDetector for changes
Comment 5 David Green CLA 2008-08-19 11:49:18 EDT
Created attachment 110355 [details]
mylyn/context/zip
Comment 6 Steffen Pingel CLA 2008-08-20 02:38:31 EDT
Great! I'll merge the patch once 3.0.2 is released. We'll also need to implement a few test cases for finding multiple hyperlinks for the various connectors.
Comment 7 David Green CLA 2008-08-20 11:58:35 EDT
(In reply to comment #6)
> Great! I'll merge the patch once 3.0.2 is released. We'll also need to implement
> a few test cases for finding multiple hyperlinks for the various connectors.

Agreed regarding test cases.  The attached patch has no test cases, and only alters the BugzillaConnectorUi implementation: I left Trac, JIRA and all of the others alone.  Let me know if you'll take care of these, otherwise I'll try to set aside some time.
Comment 8 Steffen Pingel CLA 2008-08-20 15:47:50 EDT
Thanks for offering help with the tests. I'll have a better sense of  the priorities once we take a pass at the next release planning. I think we can hold off on this for now. 
Comment 9 Steffen Pingel CLA 2008-09-24 01:28:34 EDT
*** Bug 182839 has been marked as a duplicate of this bug. ***
Comment 10 Steffen Pingel CLA 2008-09-26 16:35:57 EDT
Created attachment 113631 [details]
updated patch
Comment 11 Steffen Pingel CLA 2008-09-26 18:46:17 EDT
Patch applied and updated BugzillaTaskHyperlinkTest. Before resolving this bug we'll need more tests for Bugzilla. I have created subtasks to track the implementation for Trac, XPlanner and JIRA.
Comment 12 David Green CLA 2008-09-26 19:16:23 EDT
thanks for getting this one in!
Comment 13 Steffen Pingel CLA 2008-09-26 19:26:51 EDT
During testing I noticed a problem where the hyperlink detector will return hyperlinks that don't match the region in case the region length is 0. I think we need to validate the hyperlinks returned by connectors against the originial region. I'll try to create a test case.
Comment 14 Steffen Pingel CLA 2008-09-26 19:29:59 EDT
Added testMatchMultipleEmptyRegion() to BugzillaTaskHyperlinkDetectorTest.
Comment 15 Steffen Pingel CLA 2008-09-29 14:47:22 EDT
I have committed a fix for the failing test but still need to add additional tests.
Comment 16 Steffen Pingel CLA 2008-10-01 00:06:52 EDT
While reviewing the new API I decided to revert the changes to AbstractRepositoryConnectorUi and to use the existing method for detecting hyperlinks instead of adding an additional method. The main reason being that I found it impossible to specify the new method in a way that provided full backwards compatibility while maintaining a simple signature. 

The default implementation of the proposed findHyperlinks() method would always pass 0 as the index into text when invoking the existing implementation of findHyperlinks(). This would cause most existing implementations to return an empty list (unless the hyperlink was actually at the beginning of the text).

Clients are now expected to return all matching hyperlinks when the passed offset into text is -1. It is likely that existing implementations will return an empty list in that case but that is acceptable as detecting multiple hyperlinks will require changes to existing implementations at any rate.