Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 244017 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtil.java (-9 / +10 lines)
Lines 28-33 Link Here
28
 * Utility class for detecting Trac hyperlinks.
28
 * Utility class for detecting Trac hyperlinks.
29
 * 
29
 * 
30
 * @author Steffen Pingel
30
 * @author Steffen Pingel
31
 * @author David Green fix for bug 244017
31
 */
32
 */
32
public class TracHyperlinkUtil {
33
public class TracHyperlinkUtil {
33
34
Lines 55-61 Link Here
55
56
56
	static Pattern wikiPattern1 = Pattern.compile("wiki:(\\w+)");
57
	static Pattern wikiPattern1 = Pattern.compile("wiki:(\\w+)");
57
58
58
	static Pattern wikiPattern2 = Pattern.compile("[A-Z][a-z0-9]+[A-Z]\\w*");
59
	static Pattern wikiPattern2 = Pattern.compile("(?<=[^\\!])[A-Z][a-z0-9]+[A-Z]\\w*");
59
60
60
	static Pattern milestonePattern = Pattern.compile("milestone:([\\w\\.]+)");
61
	static Pattern milestonePattern = Pattern.compile("milestone:([\\w\\.]+)");
61
62
Lines 146-153 Link Here
146
			if (isInRegion(lineOffset, m)) {
147
			if (isInRegion(lineOffset, m)) {
147
				String rev = m.group(1);
148
				String rev = m.group(1);
148
				String stopRev = m.group(2);
149
				String stopRev = m.group(2);
149
				String url = repository.getRepositoryUrl() + ITracClient.REVISION_LOG_URL + "?rev=" + rev + "&stop_rev="
150
				String url = repository.getRepositoryUrl() + ITracClient.REVISION_LOG_URL + "?rev=" + rev
150
						+ stopRev;
151
						+ "&stop_rev=" + stopRev;
151
				links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
152
				links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
152
			}
153
			}
153
		}
154
		}
Lines 157-164 Link Here
157
			if (isInRegion(lineOffset, m)) {
158
			if (isInRegion(lineOffset, m)) {
158
				String rev = m.group(1);
159
				String rev = m.group(1);
159
				String stopRev = m.group(2);
160
				String stopRev = m.group(2);
160
				String url = repository.getRepositoryUrl() + ITracClient.REVISION_LOG_URL + "?rev=" + rev + "&stop_rev="
161
				String url = repository.getRepositoryUrl() + ITracClient.REVISION_LOG_URL + "?rev=" + rev
161
						+ stopRev;
162
						+ "&stop_rev=" + stopRev;
162
				links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
163
				links.add(new WebHyperlink(determineRegion(regionOffset, m), url));
163
			}
164
			}
164
		}
165
		}
Lines 244-251 Link Here
244
		while (m.find()) {
245
		while (m.find()) {
245
			if (isInRegion(lineOffset, m)) {
246
			if (isInRegion(lineOffset, m)) {
246
				String page = m.group(1);
247
				String page = m.group(1);
247
				links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getRepositoryUrl() + ITracClient.WIKI_URL
248
				links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getRepositoryUrl()
248
						+ page));
249
						+ ITracClient.WIKI_URL + page));
249
			}
250
			}
250
		}
251
		}
251
252
Lines 253-260 Link Here
253
		while (m.find()) {
254
		while (m.find()) {
254
			if (isInRegion(lineOffset, m)) {
255
			if (isInRegion(lineOffset, m)) {
255
				String page = m.group(0);
256
				String page = m.group(0);
256
				links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getRepositoryUrl() + ITracClient.WIKI_URL
257
				links.add(new WebHyperlink(determineRegion(regionOffset, m), repository.getRepositoryUrl()
257
						+ page));
258
						+ ITracClient.WIKI_URL + page));
258
			}
259
			}
259
		}
260
		}
260
261
(-)src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilTest.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.trac.ui;
10
11
import java.util.regex.Matcher;
12
13
import junit.framework.TestCase;
14
15
/**
16
 * 
17
 * @author David Green
18
 */
19
public class TracHyperlinkUtilTest extends TestCase {
20
	public void testWikiPattern2SinglePositiveMatch() {
21
		Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("a HyperLink there");
22
		assertTrue(matcher.find());
23
		assertEquals(matcher.group(0), "HyperLink");
24
		assertFalse(matcher.find());
25
	}
26
27
	public void testWikiPattern2MultiplePositiveMatch() {
28
		Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("a HyperLink there and ThereIsAnother");
29
		assertTrue(matcher.find());
30
		assertEquals(matcher.group(0), "HyperLink");
31
		assertTrue(matcher.find());
32
		assertEquals(matcher.group(0), "ThereIsAnother");
33
		assertFalse(matcher.find());
34
	}
35
36
	public void testWikiPattern2SingleNegativeMatch() {
37
		Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("no !HyperLink there");
38
		assertFalse(matcher.find());
39
	}
40
41
	public void testWikiPattern2MixedPositiveNegativeMatch() {
42
		Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("a HyperLink there and ThereIsAnother but !NotHere");
43
		assertTrue(matcher.find());
44
		assertEquals(matcher.group(0), "HyperLink");
45
		assertTrue(matcher.find());
46
		assertEquals(matcher.group(0), "ThereIsAnother");
47
		assertFalse(matcher.find());
48
	}
49
}

Return to bug 244017