1 | |
package org.apache.maven.scm.provider.jazz.command.update; |
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.apache.maven.scm.provider.ScmProviderRepository; |
26 | |
import org.apache.maven.scm.provider.jazz.command.consumer.AbstractRepositoryConsumer; |
27 | |
|
28 | |
import java.util.ArrayList; |
29 | |
import java.util.List; |
30 | |
import java.util.regex.Matcher; |
31 | |
import java.util.regex.Pattern; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class JazzUpdateConsumer |
39 | |
extends AbstractRepositoryConsumer |
40 | |
{ |
41 | |
|
42 | |
|
43 | |
|
44 | |
public static final String UPDATE_CMD_ADD_FLAG = "-a-"; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public static final String UPDATE_CMD_CHANGE_FLAG = "--c"; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public static final String UPDATE_CMD_DELETE_FLAG = "-d-"; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public static final String UPDATE_CMD_MOVED_FLAG = "-m-"; |
61 | |
|
62 | 0 | private List<ScmFile> fUpdatedFiles = new ArrayList<ScmFile>(); |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public JazzUpdateConsumer( ScmProviderRepository repository, ScmLogger logger ) |
71 | |
{ |
72 | 0 | super( repository, logger ); |
73 | 0 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public void consumeLine( String line ) |
82 | |
{ |
83 | 0 | super.consumeLine( line ); |
84 | 0 | if ( containsStatusFlag( line ) ) |
85 | |
{ |
86 | 0 | extractUpdatedFile( line ); |
87 | |
} |
88 | 0 | } |
89 | |
|
90 | |
private boolean containsStatusFlag( String line ) |
91 | |
{ |
92 | 0 | boolean containsStatusFlag = false; |
93 | |
|
94 | 0 | if ( line.trim().length() > 3 ) |
95 | |
{ |
96 | 0 | String flag = line.trim().substring( 0, 3 ); |
97 | 0 | if ( UPDATE_CMD_ADD_FLAG.equals( flag ) || |
98 | |
UPDATE_CMD_CHANGE_FLAG.equals( flag ) || |
99 | |
UPDATE_CMD_DELETE_FLAG.equals( flag ) || |
100 | |
UPDATE_CMD_MOVED_FLAG.equals( flag ) ) |
101 | |
{ |
102 | 0 | containsStatusFlag = true; |
103 | |
} |
104 | |
} |
105 | 0 | return containsStatusFlag; |
106 | |
} |
107 | |
|
108 | |
private void extractUpdatedFile( String line ) |
109 | |
{ |
110 | 0 | String filePath = ""; |
111 | 0 | String flag = line.trim().substring( 0, 3 ); |
112 | 0 | ScmFileStatus status = ScmFileStatus.UNKNOWN; |
113 | |
|
114 | 0 | if ( UPDATE_CMD_ADD_FLAG.equals( flag ) ) |
115 | |
{ |
116 | 0 | status = ScmFileStatus.ADDED; |
117 | 0 | filePath = line.trim().substring( 4 ); |
118 | |
} |
119 | |
|
120 | 0 | if ( UPDATE_CMD_CHANGE_FLAG.equals( flag ) ) |
121 | |
{ |
122 | 0 | status = ScmFileStatus.UPDATED; |
123 | 0 | filePath = line.trim().substring( 4 ); |
124 | |
} |
125 | |
|
126 | 0 | if ( UPDATE_CMD_DELETE_FLAG.equals( flag ) ) |
127 | |
{ |
128 | 0 | status = ScmFileStatus.DELETED; |
129 | 0 | filePath = line.trim().substring( 4 ); |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 0 | if ( UPDATE_CMD_MOVED_FLAG.equals( flag ) ) |
136 | |
{ |
137 | 0 | status = ScmFileStatus.ADDED; |
138 | 0 | String pattern = "^" + UPDATE_CMD_MOVED_FLAG + "\\s(.*)\\s\\(moved\\sfrom\\s.*$"; |
139 | 0 | Pattern r = Pattern.compile( pattern ); |
140 | 0 | Matcher m = r.matcher( line.trim() ); |
141 | 0 | if ( m.find() ) |
142 | |
{ |
143 | 0 | filePath = m.group( 1 ); |
144 | |
} |
145 | |
} |
146 | |
|
147 | 0 | fUpdatedFiles.add( new ScmFile( filePath, status ) ); |
148 | 0 | } |
149 | |
|
150 | |
public List<ScmFile> getUpdatedFiles() |
151 | |
{ |
152 | 0 | return fUpdatedFiles; |
153 | |
} |
154 | |
|
155 | |
} |