Skip to content

Commit

Permalink
Revert e628f09..37d0cbd
Browse files Browse the repository at this point in the history
This rolls back to commit e628f09.
  • Loading branch information
rompic committed Jan 4, 2015
1 parent 37d0cbd commit bc98634
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 68 deletions.
38 changes: 14 additions & 24 deletions src/main/java/hudson/plugins/redmine/RedmineLinkAnnotator.java
Expand Up @@ -7,7 +7,6 @@
import hudson.scm.ChangeLogAnnotator;
import hudson.scm.ChangeLogSet.Entry;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -48,30 +47,18 @@ static final class LinkMarkup {
private final String href;

LinkMarkup(String pattern, String href) {
pattern = NUM_PATTERN.matcher(pattern).replaceAll("([\\\\d|,| |&|#]+(?<!\\\\s))"); // \\\\d becomes \\d when in the expanded text.
pattern = NUM_PATTERN.matcher(pattern).replaceAll("([\\\\d|,| |&|#]+)"); // \\\\d becomes \\d when in the expanded text.
pattern = ANYWORD_PATTERN.matcher(pattern).replaceAll("((?:\\\\w|[._-])+)");
this.pattern = Pattern.compile(pattern);
this.href = href;
}

void process(MarkupText text, String url) {

for(SubText st : text.findTokens(pattern)) {
String[] message;
int splitOffset=1;
if (st.getText().trim().startsWith("#")) //to support #10, #11 or #10 text
{
message=new String[]{"",st.getText().substring(1)};
}
else{
message = st.getText().split("[: ]+", 2);
Pattern pattern = Pattern.compile("[: ]+");
Matcher matcher = pattern.matcher(st.getText());
// Get Index of First occurence
if(matcher.find()){
splitOffset=matcher.end()-matcher.start();
}
}
if (message.length>1) {
String[] message = st.getText().split(" ", 2);

if (message.length > 1) {
String[] nums = message[1].split(",|&| ");
String splitValue = ",";
if(message[1].indexOf("&") != -1) {
Expand All @@ -82,11 +69,12 @@ void process(MarkupText text, String url) {
splitValue = " ";
}

int startpos = 0;
int endpos = message[0].length() + nums[0].length() + splitOffset;
nums[0] = nums[0].replace("#", "");
st.addMarkup(startpos, endpos, getIssuesUrl(url, nums[0]), "</a>");
if(nums.length > 1) {
int startpos = 0;
int endpos = message[0].length() + nums[0].length() + 1;
nums[0] = nums[0].replace("#", "");
st.addMarkup(startpos, endpos, getIssuesUrl(url, nums[0]), "</a>");

startpos = endpos + splitValue.length();
endpos = startpos;

Expand All @@ -105,6 +93,8 @@ void process(MarkupText text, String url) {
startpos = endpos + splitValue.length();

}
} else {
st.surroundWith("<a href='"+url+href+"'>","</a>");
}
} else {
st.surroundWith("<a href='"+url+href+"'>","</a>");
Expand All @@ -126,15 +116,15 @@ private String getIssuesUrl(String url, String num) {

static final LinkMarkup[] MARKUPS = new LinkMarkup[] {
new LinkMarkup(
"(?i)(?:#|(?:refs|references|IssueID|fixes|closes)[: ]+#?)NUM",
"(?:#|refs |references |IssueID |fixes |closes )#?NUM",
"issues/$1"),
new LinkMarkup(
"((?:[A-Z][a-z]+){2,})|wiki:ANYWORD",
"wiki/$1$2"),
};
static final LinkMarkup[] MARKUPS_OLD = new LinkMarkup[] {
new LinkMarkup(
"(?i)(?:#|(?:refs|references|IssueID|fixes|closes)[: ]+#?)NUM",
"(?:#|refs |references |IssueID |fixes |closes )#?NUM",
"issues/show/$1"),
new LinkMarkup(
"((?:[A-Z][a-z]+){2,})|wiki:ANYWORD",
Expand Down
44 changes: 0 additions & 44 deletions src/test/java/hudson/plugins/redmine/RedmineLinkAnnotatorTest.java
Expand Up @@ -62,50 +62,6 @@ public void testWikiLinkSyntax() {
assertAnnotatedTextEquals("IssueID #1 #11",
"<a href='" + REDMINE_URL + "issues/1'>IssueID #1</a> " +
"<a href='" + REDMINE_URL + "issues/11'>#11</a>");
assertAnnotatedTextEquals("#1, #11",
"<a href='" + REDMINE_URL + "issues/1'>#1</a>, " +
"<a href='" + REDMINE_URL + "issues/11'>#11</a>");
assertAnnotatedTextEquals("refs #13 fixes #12",
"<a href='" + REDMINE_URL + "issues/13'>refs #13</a> " +
"<a href='" + REDMINE_URL + "issues/12'>fixes #12</a>");
assertAnnotatedTextEquals("#7753 Text",
"<a href='" + REDMINE_URL + "issues/7753'>#7753</a>" +
" Text");

//examples from http://www.redmine.org/projects/redmine/wiki/RedmineSettings
assertAnnotatedTextEquals("This commit refs #1, #2 and fixes #3",
"This commit <a href='" + REDMINE_URL + "issues/1'>refs #1</a>, " +
"<a href='" + REDMINE_URL + "issues/2'>#2</a> and " +
"<a href='" + REDMINE_URL + "issues/3'>fixes #3</a>");

assertAnnotatedTextEquals("This commit refs:#1, #2 and fixes #3",
"This commit <a href='" + REDMINE_URL + "issues/1'>refs:#1</a>, " +
"<a href='" + REDMINE_URL + "issues/2'>#2</a> and " +
"<a href='" + REDMINE_URL + "issues/3'>fixes #3</a>");


assertAnnotatedTextEquals("This commit Refs #1, #2 and fixes #3",
"This commit <a href='" + REDMINE_URL + "issues/1'>Refs #1</a>, " +
"<a href='" + REDMINE_URL + "issues/2'>#2</a> and " +
"<a href='" + REDMINE_URL + "issues/3'>fixes #3</a>");

assertAnnotatedTextEquals("This commit REFS: #1, #2 and fixes #3",
"This commit <a href='" + REDMINE_URL + "issues/1'>REFS: #1</a>, " +
"<a href='" + REDMINE_URL + "issues/2'>#2</a> and " +
"<a href='" + REDMINE_URL + "issues/3'>fixes #3</a>");

assertAnnotatedTextEquals("This commit Refs: #1, #2 and fixes: #3",
"This commit <a href='" + REDMINE_URL + "issues/1'>Refs: #1</a>, " +
"<a href='" + REDMINE_URL + "issues/2'>#2</a> and " +
"<a href='" + REDMINE_URL + "issues/3'>fixes: #3</a>");

//multi-line tests
assertAnnotatedTextEquals("refs #1\n comment",
"<a href='" + REDMINE_URL + "issues/1'>refs #1</a>\n comment");

assertAnnotatedTextEquals("refs #1\n refs #12 comment",
"<a href='" + REDMINE_URL + "issues/1'>refs #1</a>\n <a href='" + REDMINE_URL + "issues/12'>refs #12</a> comment");

}

private void assertAnnotatedTextEquals(String originalText, String expectedAnnotatedText) {
Expand Down

0 comments on commit bc98634

Please sign in to comment.