1 package org.apache.maven.scm.provider.svn.svnexe.command.update;
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.Arrays;
25 import java.util.List;
26
27 import org.apache.maven.scm.ChangeFile;
28 import org.apache.maven.scm.ChangeSet;
29 import org.apache.maven.scm.ScmFile;
30 import org.apache.maven.scm.ScmFileStatus;
31 import org.apache.maven.scm.log.ScmLogger;
32 import org.apache.maven.scm.provider.svn.svnexe.command.AbstractFileCheckingConsumer;
33
34
35
36
37
38 public class SvnUpdateConsumer
39 extends AbstractFileCheckingConsumer
40 {
41 private static final String UPDATED_TO_REVISION_TOKEN = "Updated to revision";
42
43 private static final String AT_REVISION_TOKEN = "At revision";
44
45 private static final String EXPORTED_REVISION_TOKEN = "Exported revision";
46
47 private static final String RESTORED_TOKEN = "Restored";
48
49 private List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
50
51
52
53
54
55 public SvnUpdateConsumer( ScmLogger logger, File workingDirectory )
56 {
57 super( logger, workingDirectory );
58 }
59
60
61
62
63
64
65 protected void parseLine( String line )
66 {
67 line = line.trim();
68
69 String statusString = line.substring( 0, 1 );
70
71 String file = line.substring( 3 ).trim();
72
73 if ( file.startsWith( workingDirectory.getAbsolutePath() ) )
74 {
75 if ( file.length() == workingDirectory.getAbsolutePath().length() )
76 {
77 file = ".";
78 }
79 else
80 {
81 file = file.substring( this.workingDirectory.getAbsolutePath().length() + 1 );
82 }
83 }
84
85 ScmFileStatus status;
86
87 if ( line.startsWith( UPDATED_TO_REVISION_TOKEN ) )
88 {
89 String revisionString = line.substring( UPDATED_TO_REVISION_TOKEN.length() + 1, line.length() - 1 );
90
91 revision = parseInt( revisionString );
92
93 return;
94 }
95 else if ( line.startsWith( AT_REVISION_TOKEN ) )
96 {
97 String revisionString = line.substring( AT_REVISION_TOKEN.length() + 1, line.length() - 1 );
98
99 revision = parseInt( revisionString );
100
101 return;
102 }
103 else if ( line.startsWith( EXPORTED_REVISION_TOKEN ) )
104 {
105 String revisionString = line.substring( EXPORTED_REVISION_TOKEN.length() + 1, line.length() - 1 );
106
107 revision = parseInt( revisionString );
108
109 return;
110 }
111 else if ( line.startsWith( RESTORED_TOKEN ) )
112 {
113 return;
114 }
115 else if ( statusString.equals( "A" ) )
116 {
117 status = ScmFileStatus.ADDED;
118 }
119 else if ( statusString.equals( "U" ) || statusString.equals( "M" ) )
120 {
121 status = ScmFileStatus.UPDATED;
122 }
123 else if ( statusString.equals( "D" ) )
124 {
125 status = ScmFileStatus.DELETED;
126 }
127 else
128 {
129
130
131 return;
132 }
133
134 addFile( new ScmFile( file, status ) );
135
136 List<ChangeFile>
137 changeFiles =
138 Arrays.asList( new ChangeFile[] { new ChangeFile( line, Integer.valueOf( revision ).toString() ) } );
139
140 ChangeSet changeSet = new ChangeSet( null, null, null, changeFiles );
141 changeSets.add( changeSet );
142 }
143
144 public List<ScmFile> getUpdatedFiles()
145 {
146 return getFiles();
147 }
148
149 public List<ChangeSet> getChangeSets()
150 {
151 return changeSets;
152 }
153
154 public void setChangeSets( List<ChangeSet> changeSets )
155 {
156 this.changeSets = changeSets;
157 }
158 }