From ce7f68675b3e407a0127f7da33d758c96dade0a7 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 19 Feb 2015 14:52:45 +0900 Subject: [PATCH] Allow to specify multiple 'footer' tags per trackingid entry The documentation says: "A single trackingid entry can have multiple footer tags" However the implementation was only considering the first one that was listed. So for a configuration like: [trackingid "jira-bug"] footer = Bugfix: footer = Bug: match = JRA\\d{2,8} system = JIRA only "Bugfix:" would be considered, and "Bug:" would be ignored. Fix it so that all footer tags are recognized. Change-Id: Ib6706d0743bb9a2fd116cb260c8e4270e765c91a --- Documentation/config-gerrit.txt | 15 ++++++++++----- .../server/config/TrackingFootersProvider.java | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 901c1a3890..bd82a92d69 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -3363,6 +3363,7 @@ bug:. ---- [trackingid "jira-bug"] footer = Bugfix: + footer = Bug: match = JRA\\d{2,8} system = JIRA @@ -3374,11 +3375,15 @@ bug:. [[trackingid.name.footer]]trackingid..footer:: + -A prefix tag that identify the footer line to parse for tracking ids. -Several trackingid entries can have the same footer tag. A single -trackingid entry can have multiple footer tags. If multiple footer -tags are specified, each tag will be parsed separately. -(the trailing ":" is optional) +A prefix tag that identifies the footer line to parse for tracking ids. ++ +Several trackingid entries can have the same footer tag, and a single trackingid +entry can have multiple footer tags. ++ +If multiple footer tags are specified, each tag will be parsed separately and +duplicates will be ignored. ++ +The trailing ":" is optional. [[trackingid.name.match]]trackingid..match:: + diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/TrackingFootersProvider.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/TrackingFootersProvider.java index 2554781901..4c1bde9774 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/TrackingFootersProvider.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/TrackingFootersProvider.java @@ -24,7 +24,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.regex.PatternSyntaxException; /** Provides a list of all configured {@link TrackingFooter}s. */ @@ -43,8 +47,11 @@ public class TrackingFootersProvider implements Provider { for (String name : cfg.getSubsections(TRACKING_ID_TAG)) { boolean configValid = true; - String footer = cfg.getString(TRACKING_ID_TAG, name, FOOTER_TAG); - if (footer == null || footer.isEmpty()) { + Set footers = new HashSet<>( + Arrays.asList(cfg.getStringList(TRACKING_ID_TAG, name, FOOTER_TAG))); + footers.removeAll(Collections.singleton(null)); + + if (footers.isEmpty()) { configValid = false; log.error("Missing " + TRACKING_ID_TAG + "." + name + "." + FOOTER_TAG + " in gerrit.config"); @@ -71,7 +78,9 @@ public class TrackingFootersProvider implements Provider { if (configValid) { try { - trackingFooters.add(new TrackingFooter(footer, match, system)); + for (String footer : footers) { + trackingFooters.add(new TrackingFooter(footer, match, system)); + } } catch (PatternSyntaxException e) { log.error("Invalid pattern \"" + match + "\" in gerrit.config " + TRACKING_ID_TAG + "." + name + "." + REGEX_TAG + ": "