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 | 0 | 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 | 0 | HgScmProviderRepository repository = (HgScmProviderRepository) repo; |
59 | 0 | String url = repository.getURI(); |
60 | |
|
61 | 0 | File checkoutDir = fileSet.getBasedir(); |
62 | |
try |
63 | |
{ |
64 | 0 | if ( getLogger().isInfoEnabled() ) |
65 | |
{ |
66 | 0 | getLogger().info( "Removing " + checkoutDir ); |
67 | |
} |
68 | 0 | FileUtils.deleteDirectory( checkoutDir ); |
69 | |
} |
70 | 0 | catch ( IOException e ) |
71 | |
{ |
72 | 0 | throw new ScmException( "Cannot remove " + checkoutDir ); |
73 | 0 | } |
74 | |
|
75 | |
|
76 | 0 | List<String> cmdList = new ArrayList<String>(); |
77 | 0 | if ( repo.isPushChanges() ) |
78 | |
{ |
79 | 0 | cmdList.add( HgCommandConstants.CLONE_CMD ); |
80 | |
} |
81 | |
else |
82 | |
{ |
83 | 0 | cmdList.add( HgCommandConstants.UPDATE_CMD ); |
84 | |
} |
85 | 0 | if ( scmVersion != null && !StringUtils.isEmpty( scmVersion.getName() ) ) |
86 | |
{ |
87 | 0 | cmdList.add( HgCommandConstants.REVISION_OPTION ); |
88 | 0 | cmdList.add( scmVersion.getName() ); |
89 | |
} |
90 | 0 | if ( !repo.isPushChanges() ) |
91 | |
{ |
92 | 0 | cmdList.add( HgCommandConstants.CLEAN_OPTION ); |
93 | |
} |
94 | 0 | cmdList.add( url ); |
95 | 0 | cmdList.add( checkoutDir.getAbsolutePath() ); |
96 | 0 | String[] checkoutCmd = cmdList.toArray( new String[0] ); |
97 | 0 | HgConsumer checkoutConsumer = new HgConsumer( getLogger() ); |
98 | 0 | HgUtils.execute( checkoutConsumer, getLogger(), checkoutDir.getParentFile(), checkoutCmd ); |
99 | |
|
100 | |
|
101 | 0 | String[] inventoryCmd = new String[]{ HgCommandConstants.INVENTORY_CMD }; |
102 | 0 | HgCheckOutConsumer consumer = new HgCheckOutConsumer( getLogger(), checkoutDir ); |
103 | 0 | ScmResult result = HgUtils.execute( consumer, getLogger(), checkoutDir, inventoryCmd ); |
104 | |
|
105 | 0 | return new CheckOutScmResult( consumer.getCheckedOutFiles(), result ); |
106 | |
} |
107 | |
} |