1 | |
package org.apache.maven.wagon.providers.scm; |
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.ScmException; |
23 | |
import org.apache.maven.scm.ScmFile; |
24 | |
import org.apache.maven.scm.ScmFileSet; |
25 | |
import org.apache.maven.scm.ScmResult; |
26 | |
import org.apache.maven.scm.ScmVersion; |
27 | |
import org.apache.maven.scm.command.add.AddScmResult; |
28 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
29 | |
import org.apache.maven.scm.command.list.ListScmResult; |
30 | |
import org.apache.maven.scm.manager.NoSuchScmProviderException; |
31 | |
import org.apache.maven.scm.manager.ScmManager; |
32 | |
import org.apache.maven.scm.provider.ScmProvider; |
33 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
34 | |
import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; |
35 | |
import org.apache.maven.scm.repository.ScmRepository; |
36 | |
import org.apache.maven.scm.repository.ScmRepositoryException; |
37 | |
import org.apache.maven.wagon.AbstractWagon; |
38 | |
import org.apache.maven.wagon.ConnectionException; |
39 | |
import org.apache.maven.wagon.ResourceDoesNotExistException; |
40 | |
import org.apache.maven.wagon.TransferFailedException; |
41 | |
import org.apache.maven.wagon.authorization.AuthorizationException; |
42 | |
import org.apache.maven.wagon.events.TransferEvent; |
43 | |
import org.apache.maven.wagon.resource.Resource; |
44 | |
import org.codehaus.plexus.util.FileUtils; |
45 | |
import org.codehaus.plexus.util.StringUtils; |
46 | |
|
47 | |
import java.io.File; |
48 | |
import java.io.IOException; |
49 | |
import java.text.DecimalFormat; |
50 | |
import java.util.ArrayList; |
51 | |
import java.util.Iterator; |
52 | |
import java.util.List; |
53 | |
import java.util.Random; |
54 | |
import java.util.Stack; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 14 | public class ScmWagon |
74 | |
extends AbstractWagon |
75 | |
{ |
76 | |
|
77 | |
|
78 | |
|
79 | |
private ScmManager scmManager; |
80 | |
|
81 | |
private File checkoutDirectory; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public ScmManager getScmManager() |
89 | |
{ |
90 | 97 | return scmManager; |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
public void setScmManager( ScmManager scmManager ) |
99 | |
{ |
100 | 0 | this.scmManager = scmManager; |
101 | 0 | } |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public File getCheckoutDirectory() |
109 | |
{ |
110 | 0 | return checkoutDirectory; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
public void setCheckoutDirectory( File checkoutDirectory ) |
119 | |
{ |
120 | 14 | this.checkoutDirectory = checkoutDirectory; |
121 | 14 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public ScmProvider getScmProvider( String scmType ) |
131 | |
throws NoSuchScmProviderException |
132 | |
{ |
133 | 36 | return getScmManager().getProviderByType( scmType ); |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public void openConnectionInternal() |
140 | |
throws ConnectionException |
141 | |
{ |
142 | 17 | if ( checkoutDirectory == null ) |
143 | |
{ |
144 | 0 | checkoutDirectory = createCheckoutDirectory(); |
145 | |
} |
146 | |
|
147 | 17 | if ( checkoutDirectory.exists() ) |
148 | |
{ |
149 | 4 | removeCheckoutDirectory(); |
150 | |
} |
151 | |
|
152 | 17 | checkoutDirectory.mkdirs(); |
153 | 17 | } |
154 | |
|
155 | |
private File createCheckoutDirectory() |
156 | |
{ |
157 | |
File checkoutDirectory; |
158 | |
|
159 | 11 | DecimalFormat fmt = new DecimalFormat( "#####" ); |
160 | |
|
161 | 11 | Random rand = new Random( System.currentTimeMillis() + Runtime.getRuntime().freeMemory() ); |
162 | |
|
163 | 11 | synchronized ( rand ) |
164 | |
{ |
165 | |
do |
166 | |
{ |
167 | 11 | checkoutDirectory = new File( System.getProperty( "java.io.tmpdir" ), |
168 | |
"wagon-scm" + fmt.format( Math.abs( rand.nextInt() ) ) + ".checkout" ); |
169 | |
} |
170 | 11 | while ( checkoutDirectory.exists() ); |
171 | 11 | } |
172 | |
|
173 | 11 | return checkoutDirectory; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
private void removeCheckoutDirectory() |
178 | |
throws ConnectionException |
179 | |
{ |
180 | 21 | if( checkoutDirectory == null ) |
181 | |
{ |
182 | 0 | return; |
183 | |
} |
184 | |
|
185 | |
try |
186 | |
{ |
187 | 21 | FileUtils.deleteDirectory( checkoutDirectory ); |
188 | |
} |
189 | 0 | catch ( IOException e ) |
190 | |
{ |
191 | 0 | throw new ConnectionException( "Unable to cleanup checkout directory", e ); |
192 | 21 | } |
193 | 21 | } |
194 | |
|
195 | |
private ScmRepository getScmRepository( String url ) |
196 | |
throws ScmRepositoryException, NoSuchScmProviderException |
197 | |
{ |
198 | 47 | String username = null; |
199 | |
|
200 | 47 | String password = null; |
201 | |
|
202 | 47 | String privateKey = null; |
203 | |
|
204 | 47 | String passphrase = null; |
205 | |
|
206 | 47 | if ( authenticationInfo != null ) |
207 | |
{ |
208 | 47 | username = authenticationInfo.getUserName(); |
209 | |
|
210 | 47 | password = authenticationInfo.getPassword(); |
211 | |
|
212 | 47 | privateKey = authenticationInfo.getPrivateKey(); |
213 | |
|
214 | 47 | passphrase = authenticationInfo.getPassphrase(); |
215 | |
} |
216 | |
|
217 | 47 | ScmRepository scmRepository = getScmManager().makeScmRepository( url ); |
218 | |
|
219 | 47 | ScmProviderRepository providerRepository = scmRepository.getProviderRepository(); |
220 | |
|
221 | 47 | if ( StringUtils.isNotEmpty( username ) ) |
222 | |
{ |
223 | 0 | providerRepository.setUser( username ); |
224 | |
} |
225 | |
|
226 | 47 | if ( StringUtils.isNotEmpty( password ) ) |
227 | |
{ |
228 | 0 | providerRepository.setPassword( password ); |
229 | |
} |
230 | |
|
231 | 47 | if ( providerRepository instanceof ScmProviderRepositoryWithHost ) |
232 | |
{ |
233 | 47 | ScmProviderRepositoryWithHost providerRepo = (ScmProviderRepositoryWithHost) providerRepository; |
234 | |
|
235 | 47 | if ( StringUtils.isNotEmpty( privateKey ) ) |
236 | |
{ |
237 | 0 | providerRepo.setPrivateKey( privateKey ); |
238 | |
} |
239 | |
|
240 | 47 | if ( StringUtils.isNotEmpty( passphrase ) ) |
241 | |
{ |
242 | 0 | providerRepo.setPassphrase( passphrase ); |
243 | |
} |
244 | |
} |
245 | |
|
246 | 47 | return scmRepository; |
247 | |
} |
248 | |
|
249 | |
public void put( File source, String targetName ) |
250 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
251 | |
{ |
252 | 7 | if ( source.isDirectory() ) |
253 | |
{ |
254 | 0 | throw new IllegalArgumentException( "Source is a directory: " + source ); |
255 | |
} |
256 | 7 | putInternal( source, targetName ); |
257 | 7 | } |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
private void putInternal( File source, String targetName ) |
267 | |
throws TransferFailedException |
268 | |
{ |
269 | 11 | Resource target = new Resource( targetName ); |
270 | |
|
271 | 11 | firePutInitiated( target, source ); |
272 | |
|
273 | |
try |
274 | |
{ |
275 | 11 | ScmRepository scmRepository = getScmRepository( getRepository().getUrl() ); |
276 | |
|
277 | 11 | target.setContentLength( source.length() ); |
278 | 11 | target.setLastModified( source.lastModified() ); |
279 | |
|
280 | 11 | firePutStarted( target, source ); |
281 | |
|
282 | 11 | String msg = "Wagon: Adding " + source.getName() + " to repository"; |
283 | |
|
284 | 11 | ScmProvider scmProvider = getScmProvider( scmRepository.getProvider() ); |
285 | |
|
286 | 11 | String checkoutTargetName = source.isDirectory() ? targetName : getDirname( targetName ); |
287 | 11 | String relPath = checkOut( scmProvider, scmRepository, checkoutTargetName, target ); |
288 | |
|
289 | 11 | File newCheckoutDirectory = new File( checkoutDirectory, relPath ); |
290 | |
|
291 | 11 | File scmFile = |
292 | |
new File( newCheckoutDirectory, source.isDirectory() ? "" : getFilename( targetName ) ); |
293 | |
|
294 | 11 | boolean fileAlreadyInScm = scmFile.exists(); |
295 | |
|
296 | 11 | if ( !scmFile.equals( source ) ) |
297 | |
{ |
298 | 11 | if ( source.isDirectory() ) |
299 | |
{ |
300 | 4 | FileUtils.copyDirectoryStructure( source, scmFile ); |
301 | |
} |
302 | |
else |
303 | |
{ |
304 | 7 | FileUtils.copyFile( source, scmFile ); |
305 | |
} |
306 | |
} |
307 | |
|
308 | 11 | if ( !fileAlreadyInScm || scmFile.isDirectory() ) |
309 | |
{ |
310 | 11 | int addedFiles = addFiles( scmProvider, scmRepository, newCheckoutDirectory, |
311 | |
source.isDirectory() ? "" : scmFile.getName() ); |
312 | |
|
313 | 11 | if ( !fileAlreadyInScm && addedFiles == 0 ) |
314 | |
{ |
315 | 0 | throw new ScmException( |
316 | |
"Unable to add file to SCM: " + scmFile + "; see error messages above for more information" ); |
317 | |
} |
318 | |
} |
319 | |
|
320 | 11 | ScmResult result = scmProvider.checkIn( scmRepository, new ScmFileSet( checkoutDirectory ), |
321 | |
(ScmVersion) null, msg ); |
322 | |
|
323 | 11 | checkScmResult( result ); |
324 | |
} |
325 | 0 | catch ( ScmException e ) |
326 | |
{ |
327 | 0 | fireTransferError( target, e, TransferEvent.REQUEST_GET ); |
328 | |
|
329 | 0 | throw new TransferFailedException( "Error interacting with SCM: " + e.getMessage(), e ); |
330 | |
} |
331 | 0 | catch ( IOException e ) |
332 | |
{ |
333 | 0 | fireTransferError( target, e, TransferEvent.REQUEST_GET ); |
334 | |
|
335 | 0 | throw new TransferFailedException( "Error interacting with SCM: " + e.getMessage(), e ); |
336 | 11 | } |
337 | |
|
338 | 11 | if ( source.isFile() ) |
339 | |
{ |
340 | 7 | postProcessListeners( target, source, TransferEvent.REQUEST_PUT ); |
341 | |
} |
342 | |
|
343 | 11 | firePutCompleted( target, source ); |
344 | 11 | } |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
private String checkOut( ScmProvider scmProvider, ScmRepository scmRepository, String targetName, |
357 | |
Resource resource ) |
358 | |
throws TransferFailedException |
359 | |
{ |
360 | 11 | checkoutDirectory = createCheckoutDirectory(); |
361 | |
|
362 | 11 | Stack stack = new Stack(); |
363 | |
|
364 | 11 | String target = targetName; |
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
try |
372 | |
{ |
373 | 17 | while ( target.length() > 0 && !scmProvider |
374 | |
.list( scmRepository, new ScmFileSet( new File( "." ), new File( target ) ), false, (ScmVersion) null ) |
375 | |
.isSuccess() ) |
376 | |
{ |
377 | 6 | stack.push( getFilename( target ) ); |
378 | 6 | target = getDirname( target ); |
379 | |
} |
380 | |
} |
381 | 0 | catch ( ScmException e ) |
382 | |
{ |
383 | 0 | fireTransferError( resource, e, TransferEvent.REQUEST_PUT ); |
384 | |
|
385 | 0 | throw new TransferFailedException( "Error listing repository: " + e.getMessage(), e ); |
386 | 11 | } |
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
try |
394 | |
{ |
395 | 11 | scmRepository = getScmRepository( getRepository().getUrl() + "/" + target.replace( '\\', '/' ) ); |
396 | |
|
397 | 11 | CheckOutScmResult ret = scmProvider.checkOut( scmRepository, |
398 | |
new ScmFileSet( new File( checkoutDirectory, "" ) ), |
399 | |
(ScmVersion) null, false ); |
400 | |
|
401 | 11 | checkScmResult( ret ); |
402 | |
} |
403 | 0 | catch ( ScmException e ) |
404 | |
{ |
405 | 0 | fireTransferError( resource, e, TransferEvent.REQUEST_PUT ); |
406 | |
|
407 | 0 | throw new TransferFailedException( "Error checking out: " + e.getMessage(), e ); |
408 | 11 | } |
409 | |
|
410 | |
|
411 | |
|
412 | 11 | String relPath = ""; |
413 | |
|
414 | 17 | while ( !stack.isEmpty() ) |
415 | |
{ |
416 | 6 | String p = (String) stack.pop(); |
417 | 6 | relPath += p + "/"; |
418 | |
|
419 | 6 | File newDir = new File( checkoutDirectory, relPath ); |
420 | 6 | if ( !newDir.mkdirs() ) |
421 | |
{ |
422 | 0 | throw new TransferFailedException( "Failed to create directory " + newDir.getAbsolutePath() |
423 | |
+ "; parent should exist: " + checkoutDirectory ); |
424 | |
} |
425 | |
|
426 | |
try |
427 | |
{ |
428 | 6 | addFiles( scmProvider, scmRepository, checkoutDirectory, relPath ); |
429 | |
} |
430 | 0 | catch ( ScmException e ) |
431 | |
{ |
432 | 0 | fireTransferError( resource, e, TransferEvent.REQUEST_PUT ); |
433 | |
|
434 | 0 | throw new TransferFailedException( "Failed to add directory " + newDir + " to working copy", e ); |
435 | 6 | } |
436 | 6 | } |
437 | |
|
438 | 11 | return relPath; |
439 | |
} |
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
private int addFiles( ScmProvider scmProvider, ScmRepository scmRepository, File basedir, String scmFilePath ) |
454 | |
throws ScmException |
455 | |
{ |
456 | 54 | int addedFiles = 0; |
457 | |
|
458 | 54 | File scmFile = new File( basedir, scmFilePath ); |
459 | |
|
460 | 54 | if ( scmFilePath.length() != 0 ) |
461 | |
{ |
462 | 50 | AddScmResult result = scmProvider.add( scmRepository, new ScmFileSet( basedir, new File( scmFilePath ) ) ); |
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | 50 | if ( !result.isSuccess() ) |
470 | |
{ |
471 | 0 | result = scmProvider.add( scmRepository, new ScmFileSet( basedir, new File( scmFilePath ) ) ); |
472 | |
} |
473 | |
|
474 | 50 | addedFiles = result.getAddedFiles().size(); |
475 | |
} |
476 | |
|
477 | 54 | String reservedScmFile = scmProvider.getScmSpecificFilename(); |
478 | |
|
479 | 54 | if ( scmFile.isDirectory() ) |
480 | |
{ |
481 | 28 | File[] files = scmFile.listFiles(); |
482 | |
|
483 | 93 | for ( int i = 0; i < files.length; i++ ) |
484 | |
{ |
485 | 65 | if ( reservedScmFile != null && !reservedScmFile.equals( files[i].getName() ) ) |
486 | |
{ |
487 | 37 | addedFiles += addFiles( scmProvider, scmRepository, basedir, ( scmFilePath.length() == 0 ? "" |
488 | |
: scmFilePath + "/" ) + files[i].getName() ); |
489 | |
} |
490 | |
} |
491 | |
} |
492 | |
|
493 | 54 | return addedFiles; |
494 | |
} |
495 | |
|
496 | |
|
497 | |
|
498 | |
|
499 | |
public boolean supportsDirectoryCopy() |
500 | |
{ |
501 | 4 | return true; |
502 | |
} |
503 | |
|
504 | |
public void putDirectory( File sourceDirectory, String destinationDirectory ) |
505 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
506 | |
{ |
507 | 4 | if ( !sourceDirectory.isDirectory() ) |
508 | |
{ |
509 | 0 | throw new IllegalArgumentException( "Source is not a directory: " + sourceDirectory ); |
510 | |
} |
511 | |
|
512 | 4 | putInternal( sourceDirectory, destinationDirectory ); |
513 | 4 | } |
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
private void checkScmResult( ScmResult result ) |
523 | |
throws ScmException |
524 | |
{ |
525 | 22 | if ( !result.isSuccess() ) |
526 | |
{ |
527 | 0 | throw new ScmException( "Unable to commit file. " + result.getProviderMessage() + " " |
528 | |
+ ( result.getCommandOutput() == null ? "" : result.getCommandOutput() ) ); |
529 | |
} |
530 | 22 | } |
531 | |
|
532 | |
public void closeConnection() |
533 | |
throws ConnectionException |
534 | |
{ |
535 | 17 | removeCheckoutDirectory(); |
536 | 17 | } |
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
public boolean getIfNewer( String resourceName, File destination, long timestamp ) |
544 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
545 | |
{ |
546 | 0 | throw new UnsupportedOperationException( "Not currently supported: getIfNewer" ); |
547 | |
} |
548 | |
|
549 | |
public void get( String resourceName, File destination ) |
550 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
551 | |
{ |
552 | 20 | Resource resource = new Resource( resourceName ); |
553 | |
|
554 | 20 | fireGetInitiated( resource, destination ); |
555 | |
|
556 | 20 | String url = getRepository().getUrl() + "/" + resourceName; |
557 | |
|
558 | |
|
559 | 20 | url = url.substring( 0, url.lastIndexOf( '/' ) ); |
560 | |
|
561 | |
try |
562 | |
{ |
563 | 20 | ScmRepository scmRepository = getScmRepository( url ); |
564 | |
|
565 | 20 | fireGetStarted( resource, destination ); |
566 | |
|
567 | |
|
568 | |
|
569 | |
|
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | 20 | File scmFile = new File( checkoutDirectory, resourceName ); |
575 | |
|
576 | 20 | File basedir = scmFile.getParentFile(); |
577 | |
|
578 | 20 | ScmProvider scmProvider = getScmProvider( scmRepository.getProvider() ); |
579 | |
|
580 | 20 | String reservedScmFile = scmProvider.getScmSpecificFilename(); |
581 | |
|
582 | 20 | if ( reservedScmFile != null && new File( basedir, reservedScmFile ).exists() ) |
583 | |
{ |
584 | 18 | scmProvider.update( scmRepository, new ScmFileSet( basedir ), (ScmVersion) null ); |
585 | |
} |
586 | |
else |
587 | |
{ |
588 | |
|
589 | 2 | basedir.mkdirs(); |
590 | |
|
591 | 2 | scmProvider.checkOut( scmRepository, new ScmFileSet( basedir ), (ScmVersion) null ); |
592 | |
} |
593 | |
|
594 | 20 | if ( !scmFile.exists() ) |
595 | |
{ |
596 | 1 | throw new ResourceDoesNotExistException( "Unable to find resource " + destination + " after checkout" ); |
597 | |
} |
598 | |
|
599 | 19 | if ( !scmFile.equals( destination ) ) |
600 | |
{ |
601 | 19 | FileUtils.copyFile( scmFile, destination ); |
602 | |
} |
603 | |
} |
604 | 0 | catch ( ScmException e ) |
605 | |
{ |
606 | 0 | fireTransferError( resource, e, TransferEvent.REQUEST_GET ); |
607 | |
|
608 | 0 | throw new TransferFailedException( "Error getting file from SCM", e ); |
609 | |
} |
610 | 0 | catch ( IOException e ) |
611 | |
{ |
612 | 0 | fireTransferError( resource, e, TransferEvent.REQUEST_GET ); |
613 | |
|
614 | 0 | throw new TransferFailedException( "Error getting file from SCM", e ); |
615 | 19 | } |
616 | |
|
617 | 19 | postProcessListeners( resource, destination, TransferEvent.REQUEST_GET ); |
618 | |
|
619 | 19 | fireGetCompleted( resource, destination ); |
620 | 19 | } |
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
public List getFileList( String resourcePath ) |
627 | |
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException |
628 | |
{ |
629 | |
try |
630 | |
{ |
631 | 5 | ScmRepository repository = getScmRepository( getRepository().getUrl() ); |
632 | |
|
633 | 5 | ScmProvider provider = getScmProvider( repository.getProvider() ); |
634 | |
|
635 | 5 | ListScmResult result = provider.list( repository, |
636 | |
new ScmFileSet( new File( "." ), new File( resourcePath ) ), false, |
637 | |
(ScmVersion) null ); |
638 | |
|
639 | 5 | if ( !result.isSuccess() ) |
640 | |
{ |
641 | 2 | throw new ResourceDoesNotExistException( result.getProviderMessage() ); |
642 | |
} |
643 | |
|
644 | |
|
645 | 3 | List files = new ArrayList(); |
646 | |
|
647 | 3 | for ( Iterator it = result.getFiles().iterator(); it.hasNext(); ) |
648 | |
{ |
649 | 8 | ScmFile f = (ScmFile) it.next(); |
650 | 8 | files.add( f.getPath() ); |
651 | 8 | System.out.println( "LIST FILE: " + f + " (path=" + f.getPath() + ")" ); |
652 | 8 | } |
653 | |
|
654 | 3 | return files; |
655 | |
} |
656 | 0 | catch ( ScmException e ) |
657 | |
{ |
658 | 0 | throw new TransferFailedException( "Error getting filelist from SCM", e ); |
659 | |
} |
660 | |
} |
661 | |
|
662 | |
public boolean resourceExists( String resourceName ) |
663 | |
throws TransferFailedException, AuthorizationException |
664 | |
{ |
665 | |
try |
666 | |
{ |
667 | 2 | getFileList( resourceName ); |
668 | |
|
669 | 1 | return true; |
670 | |
} |
671 | 1 | catch ( ResourceDoesNotExistException e ) |
672 | |
{ |
673 | 1 | return false; |
674 | |
} |
675 | |
} |
676 | |
|
677 | |
private String getFilename( String filename ) |
678 | |
{ |
679 | 13 | String fname = StringUtils.replace( filename, "/", File.separator ); |
680 | 13 | return FileUtils.filename( fname ); |
681 | |
} |
682 | |
|
683 | |
private String getDirname( String filename ) |
684 | |
{ |
685 | 13 | String fname = StringUtils.replace( filename, "/", File.separator ); |
686 | 13 | return FileUtils.dirname( fname ); |
687 | |
} |
688 | |
} |