Bug 296445 - [api] provide extension point for task hyperlink detectors
Summary: [api] provide extension point for task hyperlink detectors
Status: CLOSED MOVED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL: http://sourceforge.net/apps/mantisbt/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-30 05:25 EST by Andreas Höhmann CLA
Modified: 2009-12-09 14:09 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Höhmann CLA 2009-11-30 05:25:40 EST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Build Identifier: 

org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi
define a abstract method "findHyperlinks". 

I think a default implementation for that would help all connectors.

For example in the qc-mylyn (https://sourceforge.net/projects/qcmylyn/) 
I copied the code from googlecode-connector:

private static final String ISSUE = "Issue";
private static final String SPACE = " ?#? ?";
private static final String INTEGER = "\\d+";
private static final Pattern ISSUE_PATTERN = Pattern.compile("(" + ISSUE + ")(" + SPACE + ")(" + INTEGER + ")", Pattern.CASE_INSENSITIVE);

@Override
public IHyperlink[] findHyperlinks(final TaskRepository pRepository, final 
                                   String pText, final int pIndex, 
                                   final int pTextOffset) {
  final List<IHyperlink> links = new ArrayList<IHyperlink>();
  final Matcher matcher = ISSUE_PATTERN.matcher(pText);
  while (matcher.find()) {
  if (pIndex == -1 || (pIndex >= matcher.start() && pIndex <= matcher.end())) {
    try {
      final IHyperlink link = 
         extractHyperlink(pRepository, pTextOffset, matcher);
      links.add(link);
    }
    catch (final NumberFormatException e) {
     // ignore
     // should happen only on long overflow which should happen
    }
  }
 }
 return links.toArray(new IHyperlink[links.size()]);
}

private static IHyperlink extractHyperlink(final TaskRepository pRepository, 
                                           final int pRegionOffset, 
                                           final Matcher pMatcher)
            throws NumberFormatException {
  int start = pMatcher.start();
  int end = pMatcher.end();
  start += pRegionOffset;
  end += pRegionOffset;
  final String issueId = pMatcher.group(ISSUE_ID_GROUP).trim();
  final IRegion region = new Region(start, end - start);
  return new TaskHyperlink(region, pRepository, issueId);
}

I think the code to detect such a "issue" is always the same?!
1. The only difference is (maybe) the prefix. 
2. Each connector define a different prefix.
3. It should be possible to define more than one prefix.

Open questions:
1. What happend if a prefix is defined by different connectors?
2. How could it be possible to map a simple text "Bug #12234" to
   the correct bug-repository?

Reproducible: Always
Comment 1 Steffen Pingel CLA 2009-11-30 13:39:20 EST
> I think the code to detect such a "issue" is always the same?!
> 1. The only difference is (maybe) the prefix.
> 2. Each connector define a different prefix.
> 3. It should be possible to define more than one prefix.

The connector prefix usually corresponds to what the repository uses internally, e.g. Bugzilla uses "bug" whereas Trac uses "#". Some connectors do not use a prefix at all or have separate rules for linking and highlighting. While we could consider a simple default implementation I currently don't see an obvious overlap looking at the implementations for Trac, JIRA and Bugzilla.  What did you have in mind for that in terms of API?

> Open questions:
> 1. What happend if a prefix is defined by different connectors?

Input fields are usually specific to a repository. If not, a popup with links to all matching repositories is provided.

> 2. How could it be possible to map a simple text "Bug #12234" to
> the correct bug-repository?

The mapping is done based on the repository associated with the input field (e.g. the repository of the task in case of the task editor).
Comment 2 Andreas Höhmann CLA 2009-11-30 14:08:15 EST
> The connector prefix usually corresponds to what the repository uses
> internally, e.g. Bugzilla uses "bug" whereas Trac uses "#". Some connectors do
> not use a prefix at all or have separate rules for linking and highlighting.
> While we could consider a simple default implementation I currently don't see
> an obvious overlap looking at the implementations for Trac, JIRA and Bugzilla. 
> What did you have in mind for that in terms of API?

Ok. I think I described the "problem" not exactly enough. Let my try again :)

I'm talking about the eclipse "editor support" for task-detection (i.e. in a javadoc comments). I don't mean the task-editor page or any input field in the mylyn plugins. I mean the "enduser" behavior. Do you understand my point of view? :D

I ask myself ... if I open a java-file (for example the file is part of a active bug context) and the file contains a comment like this: "Fix for Bug 1234" how can our qc-connector-plugin (or better the mylyn core) detect the correct repository where this bug can be found? If I press ctrl and click on the text "Bug 1234" then the bug editor with task 1234 should be open. What happens if more than one repository-connector-plugin return a TaskHyperlink (because the prefix "Bug" is very common) to the mylyn core? Which content shows the TaskEditor?

> 
> > Open questions:
> > 1. What happend if a prefix is defined by different connectors?
> 
> Input fields are usually specific to a repository. If not, a popup with links
> to all matching repositories is provided.
> 
> > 2. How could it be possible to map a simple text "Bug #12234" to
> > the correct bug-repository?
> 
> The mapping is done based on the repository associated with the input field
> (e.g. the repository of the task in case of the task editor).

You talking about "input fields". Is the same correct for text pieces in editors?

I'm searching for a extension point (from mylyn core) where connector developers can register "prefixes" for there bugtracking-system-plugin.
Mylyn core "TaskHyperlinkDetector" should contain the code to search the prefixes via regexpr and should create TaskHyperlink objects etc. I think this code is very universal.
Comment 3 Steffen Pingel CLA 2009-11-30 14:21:38 EST
As I said the detection code varies between connectors and while it might be feasible to generalize this in an extension point I find the current solution that delegates to the connector UI more flexible. If you have a concrete proposal how to design the API we can consider adding that.

Task hyperlink detection in the Java editor is controlled through associating projects with task repositories. You can set this in the project properties under Task Repository.
Comment 4 Eclipse Webmaster CLA 2022-11-15 11:45:08 EST
Mylyn has been restructured, and our issue tracking has moved to GitHub [1].

We are closing ~14K Bugzilla issues to give the new team a fresh start. If you feel that this issue is still relevant, please create a new one on GitHub.

[1] https://github.com/orgs/eclipse-mylyn