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 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 BazaarScmProviderRepository repository = (BazaarScmProviderRepository) repo;
55 String url = repository.getURI();
56
57 File checkoutDir = fileSet.getBasedir();
58 try
59 {
60 if ( getLogger().isInfoEnabled() )
61 {
62 getLogger().info( "Removing " + checkoutDir );
63 }
64 FileUtils.deleteDirectory( checkoutDir );
65 }
66 catch ( IOException e )
67 {
68 throw new ScmException( "Cannot remove " + checkoutDir );
69 }
70
71
72 List<String> checkoutCmd = new ArrayList<String>();
73 checkoutCmd.add( BazaarConstants.BRANCH_CMD );
74 checkoutCmd.add( url );
75 checkoutCmd.add( checkoutDir.getAbsolutePath() );
76 if ( version != null && StringUtils.isNotEmpty( version.getName() ) ) {
77 checkoutCmd.add( BazaarConstants.REVISION_OPTION );
78 checkoutCmd.add( "tag:" + version.getName() );
79 }
80 BazaarConsumer checkoutConsumer = new BazaarConsumer( getLogger() );
81 BazaarUtils.execute( checkoutConsumer, getLogger(), checkoutDir.getParentFile(),
82 (String[]) checkoutCmd.toArray( new String[0] ) );
83
84
85 String[] inventoryCmd = new String[]{BazaarConstants.INVENTORY_CMD};
86 BazaarCheckOutConsumer consumer = new BazaarCheckOutConsumer( getLogger(), checkoutDir );
87 ScmResult result = BazaarUtils.execute( consumer, getLogger(), checkoutDir, inventoryCmd );
88 if ( !result.isSuccess() )
89 {
90 throw new ScmException( result.getProviderMessage() );
91 }
92 return new CheckOutScmResult( consumer.getCheckedOutFiles(), result );
93 }
94 }