1 package org.apache.maven.scm.provider.hg.command.checkin;
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.ScmFileStatus;
26 import org.apache.maven.scm.ScmResult;
27 import org.apache.maven.scm.ScmVersion;
28 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
29 import org.apache.maven.scm.command.checkin.CheckInScmResult;
30 import org.apache.maven.scm.command.status.StatusScmResult;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.hg.HgUtils;
33 import org.apache.maven.scm.provider.hg.command.HgCommand;
34 import org.apache.maven.scm.provider.hg.command.HgConsumer;
35 import org.apache.maven.scm.provider.hg.command.status.HgStatusCommand;
36 import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
37 import org.codehaus.plexus.util.StringUtils;
38
39 import java.io.File;
40 import java.util.ArrayList;
41 import java.util.Iterator;
42 import java.util.List;
43
44
45
46
47 public class HgCheckInCommand
48 extends AbstractCheckInCommand
49 {
50
51 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
52 ScmVersion tag )
53 throws ScmException
54 {
55 if ( tag != null && !StringUtils.isEmpty( tag.getName() ) )
56 {
57 throw new ScmException( "This provider can't handle tags for this operation" );
58 }
59
60
61 List commitedFiles = new ArrayList();
62 File[] files = fileSet.getFiles();
63 if ( files.length == 0 )
64 {
65 HgStatusCommand statusCmd = new HgStatusCommand();
66 statusCmd.setLogger( getLogger() );
67 StatusScmResult status = statusCmd.executeStatusCommand( repo, fileSet );
68 List statusFiles = status.getChangedFiles();
69 for ( Iterator it = statusFiles.iterator(); it.hasNext(); )
70 {
71 ScmFile file = (ScmFile) it.next();
72 if ( file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED ||
73 file.getStatus() == ScmFileStatus.MODIFIED )
74 {
75 commitedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.CHECKED_IN ) );
76 }
77 }
78
79 }
80 else
81 {
82 for ( int i = 0; i < files.length; i++ )
83 {
84 commitedFiles.add( new ScmFile( files[i].getPath(), ScmFileStatus.CHECKED_IN ) );
85 }
86 }
87
88
89 String[] commitCmd = new String[]{HgCommand.COMMIT_CMD, HgCommand.MESSAGE_OPTION, message};
90 commitCmd = HgUtils.expandCommandLine( commitCmd, fileSet );
91 ScmResult result =
92 HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), commitCmd );
93
94
95 HgScmProviderRepository repository = (HgScmProviderRepository) repo;
96 if ( !repository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) )
97 {
98 String[] push_cmd = new String[]{HgCommand.PUSH_CMD, repository.getURI()};
99 result = HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(), push_cmd );
100 }
101
102 return new CheckInScmResult( commitedFiles, result );
103 }
104
105
106 }