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