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