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