Skip to content
Permalink
Browse files
[JENKINS-27733] Handle gracefully history entries with no version
information (only ucm activity metadata)
  • Loading branch information
Vlatombe committed Apr 3, 2015
1 parent 07259db commit f8984fb7b5669d269e9488337e1bd25148a4f932
@@ -33,10 +33,10 @@

@Override
public boolean accept(HistoryEntry entry) {
if (entry.getVersionId().endsWith("/0"))
if (entry.doesVersionIdEndWith("/0"))
return false;

if (entry.getVersionId().endsWith("\\0"))
if (entry.doesVersionIdEndWith("\\0"))
return false;
if (entry.getEvent().equalsIgnoreCase("create branch"))
return false;
@@ -33,6 +33,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
* @author hlyh
*/
@@ -79,38 +81,37 @@ public FieldFilter(FieldFilter.Type type, String patternText) {
}

public boolean accept(String value) {

switch (type) {
case Equals:
return value.equals(patternText);
return StringUtils.equals(value, patternText);
case EqualsIgnoreCase:
return value.toLowerCase().equals(patternText);
return StringUtils.equalsIgnoreCase(value, patternText);
case NotEquals:
return !(value.equals(patternText));
return !StringUtils.equals(value, patternText);
case NotEqualsIgnoreCase:
return !(value.toLowerCase().equals(patternText));
return !StringUtils.equalsIgnoreCase(value, patternText);
case StartsWith:
return value.startsWith(patternText);
return value != null && value.startsWith(patternText);
case StartsWithIgnoreCase:
return value.toLowerCase().startsWith(patternText);
return value != null && value.toLowerCase().startsWith(patternText);
case EndsWith:
return value.endsWith(patternText);
return value != null && value.endsWith(patternText);
case EndsWithIgnoreCase:
return value.toLowerCase().endsWith(patternText);
return value != null && value.toLowerCase().endsWith(patternText);
case Contains:
return value.contains(patternText);
return StringUtils.contains(value, patternText);
case ContainsIgnoreCase:
return value.toLowerCase().contains(patternText);
return StringUtils.contains(StringUtils.lowerCase(value), patternText);
case DoesNotContain:
return !(value.contains(patternText));
return !StringUtils.contains(value, patternText);
case DoesNotContainIgnoreCase:
LOGGER.fine(value.toLowerCase() + " <>" + patternText);
return !(value.toLowerCase().contains(patternText));
LOGGER.fine(StringUtils.lowerCase(value) + " <>" + patternText);
return !StringUtils.contains(StringUtils.lowerCase(value), patternText);
case ContainsRegxp:
Matcher m = pattern.matcher(value);
Matcher m = pattern.matcher(StringUtils.defaultString(value));
return m.find();
case DoesNotContainRegxp:
Matcher m2 = pattern.matcher(value);
Matcher m2 = pattern.matcher(StringUtils.defaultString(value));
return !m2.find();
}
return true;
@@ -114,6 +114,12 @@ public String getVersionId() {
return versionId;
}

public boolean doesVersionIdEndWith(String suffix) {
if (versionId == null)
return false;
return versionId.endsWith(suffix);
}

@Override
public int hashCode() {
int hash = 5;
@@ -38,6 +38,7 @@
HistoryEntry historyEntry = new HistoryEntry();
historyEntry.setActivityHeadline(activity.getHeadline());
historyEntry.setActivityName(activity.getSelector());
historyEntry.setEvent("ucm activity");
historyEntries.add(historyEntry);
}
return historyEntries;
@@ -57,6 +57,17 @@ public boolean requiresMinorEvents() {
private static final String PATTERN_REGXP = "F[a-z]*";

private static final String PATTERN_UC = "FilterTest";

/**
* Make sure that each criteria is able to handle null gracefully
*/
@Test
public void testNullSafety() {
for (FieldFilter.Type type : FieldFilter.Type.values()) {
FieldFilter filter = new FieldFilterDummy(type, PATTERN);
filter.accept((String) null);
}
}

@Test
public void testContainsFiltered() {

0 comments on commit f8984fb

Please sign in to comment.