1 package org.apache.maven.scm.provider.git.gitexe.command.info;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.maven.scm.ScmFileSet;
26 import org.apache.maven.scm.command.info.InfoItem;
27 import org.apache.maven.scm.util.AbstractConsumer;
28 import org.codehaus.plexus.util.StringUtils;
29
30 /**
31 * @author Olivier Lamy
32 * @since 1.5
33 */
34 public class GitInfoConsumer
35 extends AbstractConsumer
36 {
37
38 //$ git show
39 //commit cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767
40
41 private final List<InfoItem> infoItems = new ArrayList<>( 1 );
42
43 private final ScmFileSet scmFileSet;
44
45 public GitInfoConsumer( ScmFileSet scmFileSet )
46 {
47 this.scmFileSet = scmFileSet;
48 }
49
50 /**
51 * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
52 */
53 public void consumeLine( String line )
54 {
55 if ( logger.isDebugEnabled() )
56 {
57 logger.debug( "consume line " + line );
58 }
59
60 if ( infoItems.isEmpty() )
61 {
62 if ( !StringUtils.isEmpty( line ) )
63 {
64 InfoItem infoItem = new InfoItem();
65 infoItem.setRevision( StringUtils.trim( line ) );
66 infoItem.setURL( scmFileSet.getBasedir().toPath().toUri().toASCIIString() );
67 infoItems.add( infoItem );
68 }
69 }
70
71 }
72
73 public List<InfoItem> getInfoItems()
74 {
75 return infoItems;
76 }
77
78 }