1 package org.apache.maven.scm.provider.git.gitexe.command.diff;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
53
54
55
56
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
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 }