001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.git.gitexe.command.update; 020 021import java.util.regex.Matcher; 022import java.util.regex.Pattern; 023 024import org.apache.maven.scm.util.AbstractConsumer; 025 026/** 027 * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a> 028 * 029 */ 030public class GitLatestRevisionCommandConsumer extends AbstractConsumer { 031 032 /** 033 * The pattern used to match git log latest revision lines 034 */ 035 private static final Pattern LATESTREV_PATTERN = Pattern.compile("^commit \\s*(.*)"); 036 037 private String latestRevision; 038 039 /** {@inheritDoc} */ 040 public void consumeLine(String line) { 041 if (logger.isDebugEnabled()) { 042 logger.debug("GitLatestRevisionCommandConsumer consumeLine : " + line); 043 } 044 if (line == null || (line == null || line.isEmpty())) { 045 return; 046 } 047 048 processGetLatestRevision(line); 049 } 050 051 public String getLatestRevision() { 052 return latestRevision; 053 } 054 055 /** 056 * Process the current input line for the latest revision 057 * 058 * @param line A line of text from the git log output 059 */ 060 private void processGetLatestRevision(String line) { 061 Matcher matcher = LATESTREV_PATTERN.matcher(line); 062 if (matcher.matches()) { 063 latestRevision = matcher.group(1); 064 } 065 } 066}