View Javadoc
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.log.ScmLogger;
28  import org.apache.maven.scm.util.AbstractConsumer;
29  import org.codehaus.plexus.util.StringUtils;
30  
31  /**
32   * @author Olivier Lamy
33   * @since 1.5
34   */
35  public class GitInfoConsumer
36      extends AbstractConsumer
37  {
38  
39      //$ git show
40      //commit cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767
41  
42      private List<InfoItem> infoItems = new ArrayList<InfoItem>( 1 );
43  
44      private ScmFileSet scmFileSet;
45      public GitInfoConsumer( ScmLogger logger, ScmFileSet scmFileSet )
46      {
47          super( logger );
48          this.scmFileSet = scmFileSet;
49      }
50      
51      /**
52       * @see org.codehaus.plexus.util.cli.StreamConsumer#consumeLine(java.lang.String)
53       */
54      public void consumeLine( String line )
55      {
56          if ( getLogger().isDebugEnabled() )
57          {
58              getLogger().debug( "consume line " + line );
59          }
60          
61          if ( infoItems.isEmpty() )
62          {
63              if ( !StringUtils.isEmpty( line ) )
64              {
65                  InfoItem infoItem = new InfoItem();
66                  infoItem.setRevision( StringUtils.trim( line ) );
67                  infoItem.setURL( scmFileSet.getBasedir().getPath() );
68                  infoItems.add( infoItem );
69              }
70          }
71  
72      }
73  
74      public List<InfoItem> getInfoItems()
75      {
76          return infoItems;
77      }
78  
79  }