1 package org.apache.maven.scm.provider.starteam.command.checkin;
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.ScmFileStatus;
24 import org.apache.maven.scm.log.ScmLogger;
25 import org.codehaus.plexus.util.cli.StreamConsumer;
26
27 import java.io.File;
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34
35
36 public class StarteamCheckInConsumer
37 implements StreamConsumer
38 {
39 private String workingDirectory;
40
41 private ScmLogger logger;
42
43 private List<ScmFile> files = new ArrayList<ScmFile>();
44
45
46
47
48 private String currentDir = "";
49
50
51
52
53 private static final String DIR_MARKER = "(working dir: ";
54
55
56
57
58 private static final String CHECKIN_MARKER = ": checked in";
59
60
61
62
63 private static final String SKIPPED_MARKER = ": skipped";
64
65
66
67
68 private static final String LINKTO_MARKER = ": linked to";
69
70 public StarteamCheckInConsumer( ScmLogger logger, File basedir )
71 {
72 this.logger = logger;
73 this.workingDirectory = basedir.getPath().replace( '\\', '/' );
74 }
75
76
77 public void consumeLine( String line )
78 {
79 if ( logger.isDebugEnabled() )
80 {
81 logger.debug( line );
82 }
83
84 int pos = 0;
85
86 if ( ( pos = line.indexOf( DIR_MARKER ) ) != -1 )
87 {
88 processDirectory( line, pos );
89 }
90 else if ( ( pos = line.indexOf( CHECKIN_MARKER ) ) != -1 )
91 {
92 processCheckedInFile( line, pos );
93 }
94 else if ( ( pos = line.indexOf( SKIPPED_MARKER ) ) != -1 )
95 {
96 processSkippedFile( line, pos );
97 }
98 else if ( ( pos = line.indexOf( LINKTO_MARKER ) ) != -1 )
99 {
100
101 }
102 else
103 {
104 if ( logger.isWarnEnabled() )
105 {
106 logger.warn( "Unknown checkin ouput: " + line );
107 }
108 }
109
110 }
111
112 public List<ScmFile> getCheckedInFiles()
113 {
114 return files;
115 }
116
117 private void processDirectory( String line, int pos )
118 {
119 String dirPath = line.substring( pos + DIR_MARKER.length(), line.length() - 1 ).replace( '\\', '/' );
120
121 if ( !dirPath.startsWith( workingDirectory ) )
122 {
123 if ( logger.isInfoEnabled() )
124 {
125 logger.info( "Working directory: " + workingDirectory );
126 logger.info( "Checkin directory: " + dirPath );
127 }
128
129 throw new IllegalStateException( "Working and checkin directories are not on the same tree" );
130 }
131
132 this.currentDir = "." + dirPath.substring( workingDirectory.length() );
133 }
134
135 private void processCheckedInFile( String line, int pos )
136 {
137 String checkedInFilePath = this.currentDir + "/" + line.substring( 0, pos );
138
139 this.files.add( new ScmFile( checkedInFilePath, ScmFileStatus.CHECKED_OUT ) );
140
141 if ( logger.isInfoEnabled() )
142 {
143 logger.info( "Checked in: " + checkedInFilePath );
144 }
145 }
146
147 private void processSkippedFile( String line, int pos )
148 {
149 String skippedFilePath = this.currentDir + "/" + line.substring( 0, pos );
150
151 if ( logger.isInfoEnabled() )
152 {
153 logger.info( "Skipped: " + skippedFilePath );
154 }
155 }
156 }