1 package org.apache.maven.scm.provider.svn.svnexe.command;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.List;
26
27 import org.apache.maven.scm.ScmFile;
28 import org.apache.maven.scm.ScmFileStatus;
29 import org.apache.maven.scm.log.ScmLogger;
30 import org.codehaus.plexus.util.cli.StreamConsumer;
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 try
69 {
70 parseLine( line );
71 }
72 catch ( RuntimeException re )
73 {
74 logger.warn( "RuntimeException while parsing: " + line , re );
75 throw re;
76 }
77 }
78
79 protected abstract void parseLine( String line );
80
81 protected List<ScmFile> getFiles()
82 {
83
84 if ( !filtered )
85 {
86 for ( Iterator<ScmFile> ite = files.iterator(); ite.hasNext(); )
87 {
88 ScmFile file = ite.next();
89 if ( !file.getStatus().equals( ScmFileStatus.DELETED )
90 && !new File( workingDirectory, file.getPath() ).isFile() )
91 {
92 ite.remove();
93 }
94 }
95
96 filtered = true;
97 }
98
99 return files;
100 }
101
102 protected final int parseInt( String revisionString )
103 {
104 try
105 {
106 return Integer.parseInt( revisionString );
107 }
108 catch ( NumberFormatException ex )
109 {
110 return 0;
111 }
112 }
113
114 protected void addFile( ScmFile file )
115 {
116 files.add( file );
117 }
118
119 public final int getRevision()
120 {
121 return revision;
122 }
123
124 public File getWorkingDirectory()
125 {
126 return workingDirectory;
127 }
128
129 }