Line data Source code
1 : // Copyright (C) 2010 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.config; 16 : 17 : import com.google.common.collect.ListMultimap; 18 : import com.google.common.collect.MultimapBuilder; 19 : import java.util.List; 20 : import java.util.regex.Matcher; 21 : import org.eclipse.jgit.revwalk.FooterLine; 22 : 23 : public class TrackingFooters { 24 : protected List<TrackingFooter> trackingFooters; 25 : 26 150 : public TrackingFooters(List<TrackingFooter> trFooters) { 27 150 : trackingFooters = trFooters; 28 150 : } 29 : 30 : public List<TrackingFooter> getTrackingFooters() { 31 0 : return trackingFooters; 32 : } 33 : 34 : public boolean isEmpty() { 35 3 : return trackingFooters.isEmpty(); 36 : } 37 : 38 : public ListMultimap<String, String> extract(List<FooterLine> lines) { 39 103 : ListMultimap<String, String> r = MultimapBuilder.hashKeys().arrayListValues().build(); 40 : 41 103 : for (FooterLine footer : lines) { 42 103 : for (TrackingFooter config : trackingFooters) { 43 7 : if (footer.matches(config.footerKey())) { 44 5 : Matcher m = config.match().matcher(footer.getValue()); 45 5 : while (m.find()) { 46 5 : String id = m.groupCount() > 0 ? m.group(1) : m.group(); 47 5 : if (!id.isEmpty()) { 48 5 : r.put(config.system(), id); 49 : } 50 5 : } 51 : } 52 7 : } 53 103 : } 54 103 : return r; 55 : } 56 : }