1 package org.apache.maven.scm.provider.git.gitexe.command;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmFile;
23 import org.apache.maven.scm.log.ScmLogger;
24 import org.codehaus.plexus.util.cli.StreamConsumer;
25
26 import java.io.File;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30
31
32
33
34
35
36 public abstract class AbstractFileCheckingConsumer
37 implements StreamConsumer
38 {
39 protected ScmLogger logger;
40
41 protected File workingDirectory;
42
43 private List<ScmFile> files = new ArrayList<ScmFile>();
44
45 protected int revision;
46
47 private boolean filtered;
48
49 public AbstractFileCheckingConsumer( ScmLogger logger, File workingDirectory )
50 {
51 this.logger = logger;
52 this.workingDirectory = workingDirectory;
53 }
54
55
56 public final void consumeLine( String line )
57 {
58 if ( line.length() <= 3 )
59 {
60 return;
61 }
62
63 if ( logger.isDebugEnabled() )
64 {
65 logger.debug( line );
66 }
67
68 parseLine( line );
69 }
70
71 protected abstract void parseLine( String line );
72
73 protected List<ScmFile> getFiles()
74 {
75 if ( !filtered )
76 {
77 for ( Iterator<ScmFile> it = files.iterator(); it.hasNext(); )
78 {
79 if ( !new File( workingDirectory, it.next().getPath() ).isFile() )
80 {
81 it.remove();
82 }
83 }
84
85 filtered = true;
86 }
87
88 return files;
89 }
90
91 protected final int parseInt( String revisionString )
92 {
93 try
94 {
95 return Integer.parseInt( revisionString );
96 }
97 catch ( NumberFormatException ex )
98 {
99 return 0;
100 }
101 }
102
103 protected void addFile( ScmFile file )
104 {
105 files.add( file );
106 }
107
108 public final int getRevision()
109 {
110 return revision;
111 }
112
113 }