1 | |
package org.apache.maven.scm.provider.bazaar.command.checkout; |
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.io.IOException; |
24 | |
import java.util.ArrayList; |
25 | |
import java.util.List; |
26 | |
|
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.ScmVersion; |
31 | |
import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand; |
32 | |
import org.apache.maven.scm.command.checkout.CheckOutScmResult; |
33 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
34 | |
import org.apache.maven.scm.provider.bazaar.BazaarUtils; |
35 | |
import org.apache.maven.scm.provider.bazaar.command.BazaarConstants; |
36 | |
import org.apache.maven.scm.provider.bazaar.command.BazaarConsumer; |
37 | |
import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository; |
38 | |
import org.codehaus.plexus.util.FileUtils; |
39 | |
import org.codehaus.plexus.util.StringUtils; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class BazaarCheckOutCommand |
47 | |
extends AbstractCheckOutCommand |
48 | |
{ |
49 | |
|
50 | |
protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet, |
51 | |
ScmVersion version, boolean recursive ) |
52 | |
throws ScmException |
53 | |
{ |
54 | 0 | BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo; |
55 | 0 | String url = repository.getURI(); |
56 | |
|
57 | 0 | File checkoutDir = fileSet.getBasedir(); |
58 | |
try |
59 | |
{ |
60 | 0 | if ( getLogger().isInfoEnabled() ) |
61 | |
{ |
62 | 0 | getLogger().info( "Removing " + checkoutDir ); |
63 | |
} |
64 | 0 | FileUtils.deleteDirectory( checkoutDir ); |
65 | |
} |
66 | 0 | catch ( IOException e ) |
67 | |
{ |
68 | 0 | throw new ScmException( "Cannot remove " + checkoutDir ); |
69 | 0 | } |
70 | |
|
71 | |
|
72 | 0 | List<String> checkoutCmd = new ArrayList<String>(); |
73 | 0 | checkoutCmd.add( BazaarConstants.BRANCH_CMD ); |
74 | 0 | checkoutCmd.add( url ); |
75 | 0 | checkoutCmd.add( checkoutDir.getAbsolutePath() ); |
76 | 0 | if ( version != null && StringUtils.isNotEmpty( version.getName() ) ) { |
77 | 0 | checkoutCmd.add( BazaarConstants.REVISION_OPTION ); |
78 | 0 | checkoutCmd.add( "tag:" + version.getName() ); |
79 | |
} |
80 | 0 | BazaarConsumer checkoutConsumer = new BazaarConsumer( getLogger() ); |
81 | 0 | BazaarUtils.execute( checkoutConsumer, getLogger(), checkoutDir.getParentFile(), |
82 | |
(String[]) checkoutCmd.toArray( new String[0] ) ); |
83 | |
|
84 | |
|
85 | 0 | String[] inventoryCmd = new String[]{BazaarConstants.INVENTORY_CMD}; |
86 | 0 | BazaarCheckOutConsumer consumer = new BazaarCheckOutConsumer( getLogger(), checkoutDir ); |
87 | 0 | ScmResult result = BazaarUtils.execute( consumer, getLogger(), checkoutDir, inventoryCmd ); |
88 | 0 | if ( !result.isSuccess() ) |
89 | |
{ |
90 | 0 | throw new ScmException( result.getProviderMessage() ); |
91 | |
} |
92 | 0 | return new CheckOutScmResult( consumer.getCheckedOutFiles(), result ); |
93 | |
} |
94 | |
} |