1 package org.apache.maven.scm.provider.hg.command.checkout;
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.ScmFileSet;
24 import org.apache.maven.scm.ScmResult;
25 import org.apache.maven.scm.ScmVersion;
26 import org.apache.maven.scm.command.Command;
27 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
28 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
29 import org.apache.maven.scm.provider.ScmProviderRepository;
30 import org.apache.maven.scm.provider.hg.HgUtils;
31 import org.apache.maven.scm.provider.hg.command.HgCommandConstants;
32 import org.apache.maven.scm.provider.hg.command.HgConsumer;
33 import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
34 import org.codehaus.plexus.util.FileUtils;
35 import org.codehaus.plexus.util.StringUtils;
36
37 import java.io.File;
38 import java.io.IOException;
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46
47 public class HgCheckOutCommand
48 extends AbstractCheckOutCommand
49 implements Command
50 {
51
52
53
54 protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
55 ScmVersion scmVersion, boolean recursive )
56 throws ScmException
57 {
58 HgScmProviderRepository repository = (HgScmProviderRepository) repo;
59 String url = repository.getURI();
60
61 File checkoutDir = fileSet.getBasedir();
62 try
63 {
64 if ( getLogger().isInfoEnabled() )
65 {
66 getLogger().info( "Removing " + checkoutDir );
67 }
68 FileUtils.deleteDirectory( checkoutDir );
69 }
70 catch ( IOException e )
71 {
72 throw new ScmException( "Cannot remove " + checkoutDir );
73 }
74
75
76 List<String> cmdList = new ArrayList<String>();
77 if ( repo.isPushChanges() )
78 {
79 cmdList.add( HgCommandConstants.CLONE_CMD );
80 }
81 else
82 {
83 cmdList.add( HgCommandConstants.UPDATE_CMD );
84 }
85 if ( scmVersion != null && !StringUtils.isEmpty( scmVersion.getName() ) )
86 {
87 cmdList.add( HgCommandConstants.REVISION_OPTION );
88 cmdList.add( scmVersion.getName() );
89 }
90 if ( !repo.isPushChanges() )
91 {
92 cmdList.add( HgCommandConstants.CLEAN_OPTION );
93 }
94 cmdList.add( url );
95 cmdList.add( checkoutDir.getAbsolutePath() );
96 String[] checkoutCmd = cmdList.toArray( new String[0] );
97 HgConsumer checkoutConsumer = new HgConsumer( getLogger() );
98 HgUtils.execute( checkoutConsumer, getLogger(), checkoutDir.getParentFile(), checkoutCmd );
99
100
101 String[] inventoryCmd = new String[]{ HgCommandConstants.INVENTORY_CMD };
102 HgCheckOutConsumer consumer = new HgCheckOutConsumer( getLogger(), checkoutDir );
103 ScmResult result = HgUtils.execute( consumer, getLogger(), checkoutDir, inventoryCmd );
104
105 return new CheckOutScmResult( consumer.getCheckedOutFiles(), result );
106 }
107 }