Skip to content

Commit

Permalink
Fix JENKINS-16269
Browse files Browse the repository at this point in the history
  • Loading branch information
slide committed Jan 7, 2013
1 parent 0b73ae4 commit 7bdb213
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -95,6 +95,10 @@ public class BuildLogRegexContent implements EmailContent {

private static final boolean ADD_NEWLINE_DEFAULT_VALUE = true;

private static final String NO_MATCH_DEFAULT_ARG_NAME = "defaultValue";

private static final String NO_MATCH_DEFAULT_VALUE = "";

public String getToken() {
return TOKEN;
}
Expand Down Expand Up @@ -252,6 +256,9 @@ String getContent(BufferedReader reader, Map<String, ?> args)
final boolean addNewline = Args.get(args,
ADD_NEWLINE_ARG_NAME,
ADD_NEWLINE_DEFAULT_VALUE);
final String defaultValue = Args.get(args,
NO_MATCH_DEFAULT_ARG_NAME,
NO_MATCH_DEFAULT_VALUE);

final Pattern pattern = Pattern.compile(regex);
final StringBuffer buffer = new StringBuffer();
Expand Down Expand Up @@ -338,6 +345,8 @@ String getContent(BufferedReader reader, Map<String, ?> args)
}
}
insidePre = stopPre(buffer, insidePre);
if(buffer.length() == 0)
return defaultValue;
return buffer.toString();
}

Expand Down
Expand Up @@ -241,4 +241,21 @@ public void testGetContent_addNewLineFalse()

assertEquals( "Firefox 15.0a2", result);
}

@Test
public void testGetContent_defaultValue()
throws Exception
{
// See JENKINS-16269
args.put( "defaultValue", "JENKINS" );
args.put( "regex", "^\\*{3} Blah Blah: (.*)$" );
args.put( "maxMatches", 1);
args.put( "showTruncatedLines", false );
args.put( "substText", "$1" );
final BufferedReader reader = new BufferedReader(
new StringReader( "*** Application: Firefox 15.0a2\n*** Platform: Mac OS X 10.7.4 64bit" ));
final String result = buildLogRegexContent.getContent( reader, args );

assertEquals( "JENKINS", result );
}
}

0 comments on commit 7bdb213

Please sign in to comment.