Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java14
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java10
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java53
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilTest.java163
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java4
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtil.java243
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracRepositoryUi.java37
7 files changed, 428 insertions, 96 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java
index 9692e31d1..0cef2503f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java
@@ -25,29 +25,33 @@ public class TaskHyperlink implements IHyperlink {
private final TaskRepository repository;
- private final String key;
+ private final String taskId;
- public TaskHyperlink(IRegion region, TaskRepository repository, String key) {
+ public TaskHyperlink(IRegion region, TaskRepository repository, String taskId) {
this.region = region;
this.repository = repository;
- this.key = key;
+ this.taskId = taskId;
}
public IRegion getHyperlinkRegion() {
return region;
}
+ public String getTaskId() {
+ return taskId;
+ }
+
public String getTypeLabel() {
return null;
}
public String getHyperlinkText() {
- return "Open Task " + key;
+ return "Open Task " + taskId;
}
public void open() {
if (repository != null) {
- TasksUiUtil.openRepositoryTask(repository, key);
+ TasksUiUtil.openRepositoryTask(repository, taskId);
} else {
MessageDialog.openError(null, "Mylar", "Could not determine repository for report");
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java
index f0e8cae6b..365236f47 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracClient.java
@@ -81,6 +81,16 @@ public interface ITracClient {
public static final String WIKI_URL = "/wiki/";
+ public static final String REPORT_URL = "/report/";
+
+ public static final String CHANGESET_URL = "/changeset/";
+
+ public static final String REVISION_LOG_URL = "/log/";
+
+ public static final String MILESTONE_URL = "/milestone/";
+
+ public static final String BROWSER_URL = "/browser/";
+
/**
* Gets ticket with <code>id</code> from repository.
*
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java
deleted file mode 100644
index d255f96ae..000000000
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkDetectorTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.eclipse.mylar.internal.trac.ui;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jface.text.hyperlink.IHyperlink;
-import org.eclipse.mylar.internal.trac.core.TracCorePlugin;
-import org.eclipse.mylar.tasks.core.TaskRepository;
-import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
-import org.eclipse.mylar.tasks.ui.WebHyperlink;
-
-public class TracHyperlinkDetectorTest extends TestCase {
-
- // private TaskHyperlinkDetector detector;
- private TaskRepository repository;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- repository = new TaskRepository(TracCorePlugin.REPOSITORY_KIND, "http://localhost");
- // detector = new TaskHyperlinkDetector();
- }
-
- public void testFindHyperlinks1() {
- IHyperlink[] links = TasksUiPlugin.getRepositoryUi(TracCorePlugin.REPOSITORY_KIND).findHyperlinks(repository,
- "#11", 0, 0);
- // IHyperlink[] links = detector.findHyperlinks(repository, "#11", 0,
- // 0);
- assertNotNull(links);
- assertEquals(1, links.length);
- assertTrue(links[0].getHyperlinkText().endsWith(" 11"));
- }
-
- // public void testFindHyperlinks2() {
- // IHyperlink[] links = detector.findHyperlinks(repository, "#11, #1", 0,
- // 0);
- // assertNotNull(links);
- // assertEquals(2, links.length);
- // assertTrue(links[0].getHyperlinkText().endsWith(" 11"));
- // assertTrue(links[0].getHyperlinkText().endsWith(" 1"));
- // }
-
- public void testFindWikiHyperlinks1() {
- IHyperlink[] links = TasksUiPlugin.getRepositoryUi(TracCorePlugin.REPOSITORY_KIND).findHyperlinks(repository,
- "[wiki:page]", 0, 0);
- // IHyperlink[] links = detector.findHyperlinks(repository,
- // "[wiki:page]", 0, 0);
- assertNotNull(links);
- assertEquals(1, links.length);
- assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString());
- }
-
-}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilTest.java
new file mode 100644
index 000000000..dbc6ca874
--- /dev/null
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilTest.java
@@ -0,0 +1,163 @@
+package org.eclipse.mylar.internal.trac.ui;
+
+
+
+import junit.framework.TestCase;
+
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylar.internal.trac.core.TracCorePlugin;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TaskHyperlink;
+import org.eclipse.mylar.tasks.ui.WebHyperlink;
+
+public class TracHyperlinkUtilTest extends TestCase {
+
+ private TaskRepository repository;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ repository = new TaskRepository(TracCorePlugin.REPOSITORY_KIND, "http://localhost");
+ }
+
+ public void testFindHyperlinksTicket() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "#11", 0, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 3), links[0].getHyperlinkRegion());
+ assertEquals("11", ((TaskHyperlink)links[0]).getTaskId());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "#11, #234", 6, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("234", ((TaskHyperlink)links[0]).getTaskId());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, " ticket:123 ", 2, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals(new Region(2, 10), links[0].getHyperlinkRegion());
+ assertEquals("123", ((TaskHyperlink)links[0]).getTaskId());
+ }
+
+ public void testFindHyperlinksReport() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "report:123", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 10), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "{123}", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 5), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString());
+ }
+
+ public void testFindHyperlinksChangeset() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "r123", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 4), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "[123]", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 5), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "changeset:123", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 13), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "[123/trunk]", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 11), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/changeset/123/trunk", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "changeset:123/trunk", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 19), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/changeset/123/trunk", ((WebHyperlink) links[0]).getURLString());
+ }
+
+ public void testFindHyperlinksRevisionLog() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "r123:456", 0, 0);
+ assertEquals(2, links.length);
+ assertEquals(new Region(0, 8), links[1].getHyperlinkRegion());
+ assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[1]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "[123:456]", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 9), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "log:@123:456", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 12), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "log:trunk@123:456", 0, 0);
+ assertEquals(1, links.length);
+ assertEquals(new Region(0, 17), links[0].getHyperlinkRegion());
+ assertEquals("http://localhost/log/trunk?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
+ }
+
+ public void testFindHyperlinksWiki() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "[wiki:page]", 1, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "wiki:page", 0, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "Page", 0, 0);
+ assertNull(links);
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "ab Page dc", 0, 0);
+ assertNull(links);
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "paGe", 0, 0);
+ assertNull(links);
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "WikiPage", 0, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/wiki/WikiPage", ((WebHyperlink) links[0]).getURLString());
+ assertEquals(new Region(0, 8), links[0].getHyperlinkRegion());
+
+ }
+
+ public void testFindHyperlinksMilestone() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "milestone:1.0", 1, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/milestone/1.0", ((WebHyperlink) links[0]).getURLString());
+ }
+
+ public void testFindHyperlinksAttachment() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "attachment:ticket:123:foo.bar", 1, 0);
+ assertNotNull(links);
+ assertEquals("123", ((TaskHyperlink)links[0]).getTaskId());
+ }
+
+ public void testFindHyperlinksFiles() {
+ IHyperlink[] links = TracHyperlinkUtil.findHyperlinks(repository, "source:trunk/foo", 1, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/browser/trunk/foo", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "source:trunk/foo@123", 1, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/browser/trunk/foo?rev=123", ((WebHyperlink) links[0]).getURLString());
+
+ links = TracHyperlinkUtil.findHyperlinks(repository, "source:trunk/foo@123#L456", 1, 0);
+ assertNotNull(links);
+ assertEquals(1, links.length);
+ assertEquals("http://localhost/browser/trunk/foo?rev=123#L456", ((WebHyperlink) links[0]).getURLString());
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
index 1ad703b3f..62db2301a 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
@@ -14,7 +14,7 @@ package org.eclipse.mylar.trac.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.mylar.internal.trac.ui.TracHyperlinkDetectorTest;
+import org.eclipse.mylar.internal.trac.ui.TracHyperlinkUtilTest;
/**
* @author Mik Kersten
@@ -46,7 +46,7 @@ public class AllTracTests {
suite.addTestSuite(TracQueryHitTest.class);
suite.addTestSuite(TracRepositorySettingsPageTest.class);
suite.addTestSuite(TracClientProxyTest.class);
- suite.addTestSuite(TracHyperlinkDetectorTest.class);
+ suite.addTestSuite(TracHyperlinkUtilTest.class);
// $JUnit-END$
return suite;
}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtil.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtil.java
new file mode 100644
index 000000000..3dde4eb12
--- /dev/null
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtil.java
@@ -0,0 +1,243 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 Mylar committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.trac.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylar.internal.trac.core.ITracClient;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TaskHyperlink;
+import org.eclipse.mylar.tasks.ui.WebHyperlink;
+
+public class TracHyperlinkUtil {
+
+ static Pattern ticketPattern = Pattern.compile("(ticket:|#)(\\d+)");
+
+ static Pattern commentPattern = Pattern.compile("commen:ticket:(\\d+):(\\d+)");
+
+ static Pattern reportPattern1 = Pattern.compile("report:(\\d+)");
+
+ static Pattern reportPattern2 = Pattern.compile("\\{(\\d+)\\}");
+
+ static Pattern changesetPattern1 = Pattern.compile("(r|changeset:)(\\d+)(/\\w+)?");
+
+ static Pattern changesetPattern2 = Pattern.compile("\\[(\\d+)(/\\w+)?\\]");
+
+ static Pattern revisionLogPattern1 = Pattern.compile("r(\\d+):(\\d+)");
+
+ static Pattern revisionLogPattern2 = Pattern.compile("\\[(\\d+):(\\d+)\\]");
+
+ static Pattern revisionLogPattern3 = Pattern.compile("log:(\\w+)?@(\\d+):(\\d+)");
+
+ static Pattern wikiPattern1 = Pattern.compile("wiki:(\\w+)");
+
+ static Pattern wikiPattern2 = Pattern.compile("[A-Z][a-z0-9]+[A-Z]\\w*");
+
+ static Pattern milestonePattern = Pattern.compile("milestone:([\\w\\.]+)");
+
+ static Pattern attachmentPattern = Pattern.compile("attachment:ticket:(\\d+):([\\w\\.]+)");
+
+ static Pattern filesPattern = Pattern.compile("source:([\\w\\.\\/]+)(@(\\d+)(#L(\\d+))?)?");
+
+ /**
+ * <ul>
+ * <li>Tickets: #1 or ticket:1
+ * <li>Ticket comments: comment:ticket:1:2
+ * <li>Reports: {1} or report:1
+ * <li>Changesets: r1, [1], changeset:1 or (restricted) [1/trunk],
+ * changeset:1/trunk
+ * <li>Revision log: r1:3, [1:3] or log:@1:3, log:trunk@1:3
+ * <li>Diffs: diff:@1:3,
+ * diff:tags/trac-0.9.2/wiki-default//tags/trac-0.9.3/wiki-default or
+ * diff:trunk/trac@3538//sandbox/vc-refactoring@3539
+ * <li>Wiki pages: CamelCase or wiki:CamelCase
+ * <li>Milestones: milestone:1.0
+ * <li>Attachment: attachment:ticket:944:attachment.1073.diff
+ * <li>Files: source:trunk/COPYING
+ * <li>A specific file revision: source:/trunk/COPYING@200
+ * <li>A particular line of a specific file revision:
+ * source:/trunk/COPYING@200#L25
+ * </ul>
+ *
+ * @see http://trac.edgewall.org/wiki/TracLinks
+ */
+ public static IHyperlink[] findHyperlinks(TaskRepository repository, String text, int lineOffset, int regionOffset) {
+ List<IHyperlink> links = new ArrayList<IHyperlink>();
+
+ Matcher m = commentPattern.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String id = m.group(1);
+ // String comment = m.group(2);
+ links.add(new TaskHyperlink(determineRegion(regionOffset, m), repository, id));
+ }
+ }
+
+ m = ticketPattern.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String id = m.group(2);
+ links.add(new TaskHyperlink(determineRegion(regionOffset, m), repository, id));
+ }
+ }
+
+ m = reportPattern1.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String id = m.group(1);
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getUrl()
+ + ITracClient.REPORT_URL + id));
+ }
+ }
+
+ m = reportPattern2.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String id = m.group(1);
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getUrl()
+ + ITracClient.REPORT_URL + id));
+ }
+ }
+
+ m = changesetPattern1.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String rev = m.group(2);
+ String branch = m.group(3);
+ String url = repository.getUrl() + ITracClient.CHANGESET_URL + rev;
+ if (branch != null) {
+ url += branch;
+ }
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
+ }
+ }
+
+ m = changesetPattern2.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String rev = m.group(1);
+ String branch = m.group(2);
+ String url = repository.getUrl() + ITracClient.CHANGESET_URL + rev;
+ if (branch != null) {
+ url += branch;
+ }
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
+ }
+ }
+
+ m = revisionLogPattern1.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String rev = m.group(1);
+ String stopRev = m.group(2);
+ String url = repository.getUrl() + ITracClient.REVISION_LOG_URL + "?rev=" + rev + "&stop_rev="
+ + stopRev;
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
+ }
+ }
+
+ m = revisionLogPattern2.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String rev = m.group(1);
+ String stopRev = m.group(2);
+ String url = repository.getUrl() + ITracClient.REVISION_LOG_URL + "?rev=" + rev + "&stop_rev="
+ + stopRev;
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
+ }
+ }
+
+ m = revisionLogPattern3.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String branch = m.group(1);
+ String rev = m.group(2);
+ String stopRev = m.group(3);
+ String url = repository.getUrl() + ITracClient.REVISION_LOG_URL;
+ if (branch != null) {
+ url += branch;
+ }
+ url += "?rev=" + rev + "&stop_rev=" + stopRev;
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
+ }
+ }
+
+ // TODO diff pattern
+
+ m = wikiPattern1.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String page = m.group(1);
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getUrl() + ITracClient.WIKI_URL
+ + page));
+ }
+ }
+
+ m = wikiPattern2.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String page = m.group(0);
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getUrl() + ITracClient.WIKI_URL
+ + page));
+ }
+ }
+
+ m = milestonePattern.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String milestone = m.group(1);
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getUrl()
+ + ITracClient.MILESTONE_URL + milestone));
+ }
+ }
+
+ m = attachmentPattern.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String id = m.group(1);
+ // String attachment = m.group(2);
+ links.add(new TaskHyperlink(determineRegion(regionOffset, m), repository, id));
+ }
+ }
+
+ m = filesPattern.matcher(text);
+ while (m.find()) {
+ if (isInRegion(lineOffset, m)) {
+ String filename = m.group(1);
+ String rev = m.group(3);
+ String line = m.group(5);
+ String url = repository.getUrl() + ITracClient.BROWSER_URL + filename;
+ if (rev != null) {
+ url += "?rev=" + rev;
+ if (line != null) {
+ url += "#L" + line;
+ }
+ }
+ links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
+ }
+ }
+
+ return links.isEmpty() ? null : links.toArray(new IHyperlink[0]);
+ }
+
+ private static boolean isInRegion(int lineOffset, Matcher m) {
+ return (lineOffset >= m.start() && lineOffset <= m.end());
+ }
+
+ private static IRegion determineRegion(int regionOffset, Matcher m) {
+ return new Region(regionOffset + m.start(), m.end() - m.start());
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracRepositoryUi.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracRepositoryUi.java
index d3705114c..9f8512a18 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracRepositoryUi.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/ui/TracRepositoryUi.java
@@ -8,13 +8,6 @@
package org.eclipse.mylar.internal.trac.ui;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
@@ -31,8 +24,6 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
-import org.eclipse.mylar.tasks.ui.TaskHyperlink;
-import org.eclipse.mylar.tasks.ui.WebHyperlink;
import org.eclipse.mylar.tasks.ui.wizards.AbstractRepositorySettingsPage;
import org.eclipse.mylar.tasks.ui.wizards.NewTaskWizard;
import org.eclipse.mylar.tasks.ui.wizards.NewWebTaskWizard;
@@ -43,35 +34,9 @@ import org.eclipse.mylar.tasks.ui.wizards.NewWebTaskWizard;
*/
public class TracRepositoryUi extends AbstractRepositoryConnectorUi {
- Pattern taskPattern = Pattern.compile("#(\\d*)");
-
- Pattern wikiPattern = Pattern.compile("\\[wiki:([^\\]]*)\\]", Pattern.CASE_INSENSITIVE | Pattern.DOTALL
- | Pattern.MULTILINE);
-
-
@Override
public IHyperlink[] findHyperlinks(TaskRepository repository, String text, int lineOffset, int regionOffset) {
- List<IHyperlink> links = new ArrayList<IHyperlink>();
-
- Matcher m = taskPattern.matcher(text);
- while (m.find()) {
- String id = m.group(1);
- if (lineOffset >= m.start() && lineOffset <= m.end()) {
- IRegion linkRegion = new Region(regionOffset + m.start(), m.end() - m.start());
- links.add(new TaskHyperlink(linkRegion, repository, id));
- }
- }
-
- m = wikiPattern.matcher(text);
- while (m.find()) {
- String id = m.group(1);
- if (lineOffset >= m.start() && lineOffset <= m.end()) {
- IRegion linkRegion = new Region(regionOffset + m.start(), m.end() - m.start());
- links.add(new WebHyperlink(linkRegion, repository.getUrl() + ITracClient.WIKI_URL + id));
- }
- }
-
- return links.isEmpty() ? null : links.toArray(new IHyperlink[0]);
+ return TracHyperlinkUtil.findHyperlinks(repository, text, lineOffset, regionOffset);
}
public String getTaskKindLabel(AbstractRepositoryTask repositoryTask) {

Back to the top