1 | |
package org.apache.maven.scm.provider.svn; |
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.List; |
25 | |
|
26 | |
import org.apache.maven.scm.CommandParameters; |
27 | |
import org.apache.maven.scm.ScmException; |
28 | |
import org.apache.maven.scm.ScmFileSet; |
29 | |
import org.apache.maven.scm.ScmResult; |
30 | |
import org.apache.maven.scm.command.add.AddScmResult; |
31 | |
import org.apache.maven.scm.command.blame.BlameScmResult; |
32 | |
import org.apache.maven.scm.command.branch.BranchScmResult; |
33 | |
import org.apache.maven.scm.command.changelog.ChangeLogScmResult; |
34 | |
import org.apache.maven.scm.command.checkin.CheckInScmResult; |
35 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
36 | |
import org.apache.maven.scm.command.diff.DiffScmResult; |
37 | |
import org.apache.maven.scm.command.export.ExportScmResult; |
38 | |
import org.apache.maven.scm.command.info.InfoScmResult; |
39 | |
import org.apache.maven.scm.command.list.ListScmResult; |
40 | |
import org.apache.maven.scm.command.mkdir.MkdirScmResult; |
41 | |
import org.apache.maven.scm.command.remove.RemoveScmResult; |
42 | |
import org.apache.maven.scm.command.status.StatusScmResult; |
43 | |
import org.apache.maven.scm.command.tag.TagScmResult; |
44 | |
import org.apache.maven.scm.command.update.UpdateScmResult; |
45 | |
import org.apache.maven.scm.provider.AbstractScmProvider; |
46 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
47 | |
import org.apache.maven.scm.provider.svn.command.SvnCommand; |
48 | |
import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository; |
49 | |
import org.apache.maven.scm.provider.svn.util.SvnUtil; |
50 | |
import org.apache.maven.scm.repository.ScmRepositoryException; |
51 | |
import org.apache.maven.scm.repository.UnknownRepositoryStructure; |
52 | |
import org.codehaus.plexus.util.StringUtils; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | 31 | public abstract class AbstractSvnScmProvider |
61 | |
extends AbstractScmProvider |
62 | |
{ |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 31 | private static class ScmUrlParserResult |
68 | |
{ |
69 | 61 | private List<String> messages = new ArrayList<String>(); |
70 | |
|
71 | |
private ScmProviderRepository repository; |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public String getScmSpecificFilename() |
80 | |
{ |
81 | 0 | return ".svn"; |
82 | |
} |
83 | |
|
84 | |
|
85 | |
public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter ) |
86 | |
throws ScmRepositoryException |
87 | |
{ |
88 | 61 | ScmUrlParserResult result = parseScmUrl( scmSpecificUrl ); |
89 | |
|
90 | 61 | if ( result.messages.size() > 0 ) |
91 | |
{ |
92 | 1 | throw new ScmRepositoryException( "The scm url is invalid.", result.messages ); |
93 | |
} |
94 | |
|
95 | 60 | return result.repository; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
public ScmProviderRepository makeProviderScmRepository( File path ) |
100 | |
throws ScmRepositoryException, UnknownRepositoryStructure |
101 | |
{ |
102 | 0 | if ( path == null ) |
103 | |
{ |
104 | 0 | throw new NullPointerException( "Path argument is null" ); |
105 | |
} |
106 | |
|
107 | 0 | if ( !path.isDirectory() ) |
108 | |
{ |
109 | 0 | throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a valid directory." ); |
110 | |
} |
111 | |
|
112 | 0 | if ( !new File( path, ".svn" ).exists() ) |
113 | |
{ |
114 | 0 | throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a svn checkout directory." ); |
115 | |
} |
116 | |
|
117 | |
try |
118 | |
{ |
119 | 0 | return makeProviderScmRepository( getRepositoryURL( path ), ':' ); |
120 | |
} |
121 | 0 | catch ( ScmException e ) |
122 | |
{ |
123 | |
|
124 | 0 | throw new ScmRepositoryException( "Error executing info command", e ); |
125 | |
} |
126 | |
} |
127 | |
|
128 | |
protected abstract String getRepositoryURL( File path ) |
129 | |
throws ScmException; |
130 | |
|
131 | |
|
132 | |
public List<String> validateScmUrl( String scmSpecificUrl, char delimiter ) |
133 | |
{ |
134 | 0 | List<String> messages = new ArrayList<String>(); |
135 | |
try |
136 | |
{ |
137 | 0 | makeProviderScmRepository( scmSpecificUrl, delimiter ); |
138 | |
} |
139 | 0 | catch ( ScmRepositoryException e ) |
140 | |
{ |
141 | 0 | messages = e.getValidationMessages(); |
142 | 0 | } |
143 | 0 | return messages; |
144 | |
} |
145 | |
|
146 | |
|
147 | |
public String getScmType() |
148 | |
{ |
149 | 0 | return "svn"; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
private ScmUrlParserResult parseScmUrl( String scmSpecificUrl ) |
157 | |
{ |
158 | 61 | ScmUrlParserResult result = new ScmUrlParserResult(); |
159 | |
|
160 | 61 | String url = scmSpecificUrl; |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | 61 | if ( url.startsWith( "file" ) ) |
167 | |
{ |
168 | 5 | if ( !url.startsWith( "file://" ) ) |
169 | |
{ |
170 | 1 | result.messages.add( "A svn 'file' url must be on the form 'file://[hostname]/'." ); |
171 | |
|
172 | 1 | return result; |
173 | |
} |
174 | |
} |
175 | 56 | else if ( url.startsWith( "https" ) ) |
176 | |
{ |
177 | 4 | if ( !url.startsWith( "https://" ) ) |
178 | |
{ |
179 | 0 | result.messages.add( "A svn 'http' url must be on the form 'https://'." ); |
180 | |
|
181 | 0 | return result; |
182 | |
} |
183 | |
} |
184 | 52 | else if ( url.startsWith( "http" ) ) |
185 | |
{ |
186 | 41 | if ( !url.startsWith( "http://" ) ) |
187 | |
{ |
188 | 0 | result.messages.add( "A svn 'http' url must be on the form 'http://'." ); |
189 | |
|
190 | 0 | return result; |
191 | |
} |
192 | |
} |
193 | |
|
194 | 11 | else if ( url.startsWith( "svn+" ) ) |
195 | |
{ |
196 | 7 | if ( url.indexOf( "://" ) < 0 ) |
197 | |
{ |
198 | 0 | result.messages.add( "A svn 'svn+xxx' url must be on the form 'svn+xxx://'." ); |
199 | |
|
200 | 0 | return result; |
201 | |
} |
202 | |
else |
203 | |
{ |
204 | 7 | String tunnel = url.substring( "svn+".length(), url.indexOf( "://" ) ); |
205 | |
|
206 | |
|
207 | 7 | if ( !"ssh".equals( tunnel ) ) |
208 | |
{ |
209 | 0 | SvnConfigFileReader reader = new SvnConfigFileReader(); |
210 | 0 | if ( SvnUtil.getSettings().getConfigDirectory() != null ) |
211 | |
{ |
212 | 0 | reader.setConfigDirectory( new File( SvnUtil.getSettings().getConfigDirectory() ) ); |
213 | |
} |
214 | |
|
215 | 0 | if ( StringUtils.isEmpty( reader.getProperty( "tunnels", tunnel ) ) ) |
216 | |
{ |
217 | 0 | result.messages.add( |
218 | |
"The tunnel '" + tunnel + "' isn't defined in your subversion configuration file." ); |
219 | |
|
220 | 0 | return result; |
221 | |
} |
222 | |
} |
223 | 7 | } |
224 | |
} |
225 | 4 | else if ( url.startsWith( "svn" ) ) |
226 | |
{ |
227 | 4 | if ( !url.startsWith( "svn://" ) ) |
228 | |
{ |
229 | 0 | result.messages.add( "A svn 'svn' url must be on the form 'svn://'." ); |
230 | |
|
231 | 0 | return result; |
232 | |
} |
233 | |
} |
234 | |
else |
235 | |
{ |
236 | 0 | result.messages.add( url + " url isn't a valid svn URL." ); |
237 | |
|
238 | 0 | return result; |
239 | |
} |
240 | |
|
241 | 60 | result.repository = new SvnScmProviderRepository( url ); |
242 | |
|
243 | 60 | return result; |
244 | |
} |
245 | |
|
246 | |
protected abstract SvnCommand getAddCommand(); |
247 | |
|
248 | |
|
249 | |
public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
250 | |
throws ScmException |
251 | |
{ |
252 | 0 | return (AddScmResult) executeCommand( getAddCommand(), repository, fileSet, parameters ); |
253 | |
} |
254 | |
|
255 | |
protected abstract SvnCommand getBranchCommand(); |
256 | |
|
257 | |
|
258 | |
protected BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet, |
259 | |
CommandParameters parameters ) |
260 | |
throws ScmException |
261 | |
{ |
262 | 0 | return (BranchScmResult) executeCommand( getBranchCommand(), repository, fileSet, parameters ); |
263 | |
} |
264 | |
|
265 | |
protected abstract SvnCommand getChangeLogCommand(); |
266 | |
|
267 | |
|
268 | |
public ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet, |
269 | |
CommandParameters parameters ) |
270 | |
throws ScmException |
271 | |
{ |
272 | 0 | return (ChangeLogScmResult) executeCommand( getChangeLogCommand(), repository, fileSet, parameters ); |
273 | |
} |
274 | |
|
275 | |
protected abstract SvnCommand getCheckInCommand(); |
276 | |
|
277 | |
|
278 | |
public CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet, |
279 | |
CommandParameters parameters ) |
280 | |
throws ScmException |
281 | |
{ |
282 | 0 | return (CheckInScmResult) executeCommand( getCheckInCommand(), repository, fileSet, parameters ); |
283 | |
} |
284 | |
|
285 | |
protected abstract SvnCommand getCheckOutCommand(); |
286 | |
|
287 | |
|
288 | |
public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet, |
289 | |
CommandParameters parameters ) |
290 | |
throws ScmException |
291 | |
{ |
292 | 0 | return (CheckOutScmResult) executeCommand( getCheckOutCommand(), repository, fileSet, parameters ); |
293 | |
} |
294 | |
|
295 | |
protected abstract SvnCommand getDiffCommand(); |
296 | |
|
297 | |
|
298 | |
public DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
299 | |
throws ScmException |
300 | |
{ |
301 | 0 | return (DiffScmResult) executeCommand( getDiffCommand(), repository, fileSet, parameters ); |
302 | |
} |
303 | |
|
304 | |
protected abstract SvnCommand getExportCommand(); |
305 | |
|
306 | |
|
307 | |
protected ExportScmResult export( ScmProviderRepository repository, ScmFileSet fileSet, |
308 | |
CommandParameters parameters ) |
309 | |
throws ScmException |
310 | |
{ |
311 | 0 | return (ExportScmResult) executeCommand( getExportCommand(), repository, fileSet, parameters ); |
312 | |
} |
313 | |
|
314 | |
protected abstract SvnCommand getRemoveCommand(); |
315 | |
|
316 | |
|
317 | |
public RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
318 | |
throws ScmException |
319 | |
{ |
320 | 0 | return (RemoveScmResult) executeCommand( getRemoveCommand(), repository, fileSet, parameters ); |
321 | |
} |
322 | |
|
323 | |
protected abstract SvnCommand getStatusCommand(); |
324 | |
|
325 | |
|
326 | |
public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
327 | |
throws ScmException |
328 | |
{ |
329 | 0 | return (StatusScmResult) executeCommand( getStatusCommand(), repository, fileSet, parameters ); |
330 | |
} |
331 | |
|
332 | |
protected abstract SvnCommand getTagCommand(); |
333 | |
|
334 | |
|
335 | |
public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
336 | |
throws ScmException |
337 | |
{ |
338 | 0 | return (TagScmResult) executeCommand( getTagCommand(), repository, fileSet, parameters ); |
339 | |
} |
340 | |
|
341 | |
protected abstract SvnCommand getUpdateCommand(); |
342 | |
|
343 | |
|
344 | |
public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
345 | |
throws ScmException |
346 | |
{ |
347 | 0 | return (UpdateScmResult) executeCommand( getUpdateCommand(), repository, fileSet, parameters ); |
348 | |
} |
349 | |
|
350 | |
protected ScmResult executeCommand( SvnCommand command, ScmProviderRepository repository, ScmFileSet fileSet, |
351 | |
CommandParameters parameters ) |
352 | |
throws ScmException |
353 | |
{ |
354 | 0 | command.setLogger( getLogger() ); |
355 | |
|
356 | 0 | return command.execute( repository, fileSet, parameters ); |
357 | |
} |
358 | |
|
359 | |
protected abstract SvnCommand getListCommand(); |
360 | |
|
361 | |
|
362 | |
public ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
363 | |
throws ScmException |
364 | |
{ |
365 | 0 | SvnCommand cmd = getListCommand(); |
366 | |
|
367 | 0 | return (ListScmResult) executeCommand( cmd, repository, fileSet, parameters ); |
368 | |
} |
369 | |
|
370 | |
protected abstract SvnCommand getInfoCommand(); |
371 | |
|
372 | |
public InfoScmResult info( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
373 | |
throws ScmException |
374 | |
{ |
375 | 0 | SvnCommand cmd = getInfoCommand(); |
376 | |
|
377 | 0 | return (InfoScmResult) executeCommand( cmd, repository, fileSet, parameters ); |
378 | |
} |
379 | |
|
380 | |
|
381 | |
protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
382 | |
throws ScmException |
383 | |
{ |
384 | 0 | SvnCommand cmd = getBlameCommand(); |
385 | |
|
386 | 0 | return (BlameScmResult) executeCommand( cmd, repository, fileSet, parameters ); |
387 | |
} |
388 | |
|
389 | |
protected abstract SvnCommand getBlameCommand(); |
390 | |
|
391 | |
|
392 | |
public MkdirScmResult mkdir( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) |
393 | |
throws ScmException |
394 | |
{ |
395 | 0 | SvnCommand cmd = getMkdirCommand(); |
396 | |
|
397 | 0 | return (MkdirScmResult) executeCommand( cmd, repository, fileSet, parameters ); |
398 | |
} |
399 | |
|
400 | |
protected abstract SvnCommand getMkdirCommand(); |
401 | |
} |