View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe.command.diff;
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.ScmFile;
26  import org.apache.maven.scm.ScmFileStatus;
27  import org.apache.maven.scm.log.ScmLogger;
28  import org.codehaus.plexus.util.StringUtils;
29  import org.codehaus.plexus.util.cli.StreamConsumer;
30  
31  /**
32   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
33   *
34   */
35  public class GitDiffRawConsumer
36      implements StreamConsumer
37  {
38      private ScmLogger logger;
39  
40      private List<ScmFile> changedFiles = new ArrayList<ScmFile>();
41  
42      // ----------------------------------------------------------------------
43      //
44      // ----------------------------------------------------------------------
45  
46      public GitDiffRawConsumer(ScmLogger logger)
47      {
48          this.logger = logger;
49      }
50  
51      // ----------------------------------------------------------------------
52      // StreamConsumer Implementation
53      // ----------------------------------------------------------------------
54  
55      /**
56       * {@inheritDoc}
57       */
58      public void consumeLine( String line )
59      {
60          if ( logger.isDebugEnabled() )
61          {
62              logger.debug( line );
63          }
64          if ( StringUtils.isEmpty( line ) )
65          {
66              return;
67          }
68  
69          ScmFileStatus status = null;
70  
71          String[] parts = line.split( "\\s", 6 );
72          if ( parts.length != 6 )
73          {
74              logger.warn( "Skipping line because it doesn't contain the right status parameters: " + line );
75              return;
76          }
77          
78          String modus = parts[4];
79          String file = parts[5];
80  
81          if ( "A".equals( modus ) )
82          {
83              status = ScmFileStatus.ADDED;
84          }
85          else if ( "M".equals( modus ) )
86          {
87              // attention! 'M' is 'updated', and _not_ ScmFileStatus.MODIFIED (which is for 'modified locally')
88              status = ScmFileStatus.UPDATED;
89          }
90          else if ( "D".equals( modus ) )
91          {
92              status = ScmFileStatus.DELETED;
93          }
94          else
95          {
96              logger.warn( "unknown status detected in line: " + line );
97              return;
98          }
99  
100         changedFiles.add( new ScmFile( file, status ) );
101     }
102 
103     public List<ScmFile> getChangedFiles()
104     {
105         return changedFiles;
106     }
107 }