1 package org.apache.maven.scm.provider.cvslib.command.checkin;
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.List;
25
26 import org.apache.maven.scm.ScmException;
27 import org.apache.maven.scm.ScmFileSet;
28 import org.apache.maven.scm.ScmVersion;
29 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
30 import org.apache.maven.scm.command.checkin.CheckInScmResult;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
33 import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
34 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
35 import org.codehaus.plexus.util.FileUtils;
36 import org.codehaus.plexus.util.StringUtils;
37 import org.codehaus.plexus.util.cli.Commandline;
38
39
40
41
42
43
44
45 public abstract class AbstractCvsCheckInCommand
46 extends AbstractCheckInCommand
47 implements CvsCommand
48 {
49
50 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
51 ScmVersion version )
52 throws ScmException
53 {
54 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
55
56 Commandline cl = CvsCommandUtils.getBaseCommand( "commit", repository, fileSet, false );
57
58 if ( version != null && !StringUtils.isEmpty( version.getName() ) )
59 {
60 cl.createArg().setValue( "-r" + version.getName() );
61 }
62
63 cl.createArg().setValue( "-R" );
64
65 cl.createArg().setValue( "-F" );
66
67 File messageFile;
68
69 try
70 {
71 messageFile = File.createTempFile( "scm-commit-message", ".txt" );
72
73 FileUtils.fileWrite( messageFile.getAbsolutePath(), message );
74 }
75 catch ( IOException ex )
76 {
77 throw new ScmException( "Error while making a temporary commit message file." );
78 }
79
80 cl.createArg().setValue( messageFile.getAbsolutePath() );
81
82 List<File> files = fileSet.getFileList();
83
84 for ( File f : files )
85 {
86 cl.createArg().setValue( f.getPath().replace( '\\', '/' ) );
87 }
88
89 if ( getLogger().isInfoEnabled() )
90 {
91 getLogger().info( "Executing: " + cl );
92 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
93 }
94
95 CheckInScmResult result = executeCvsCommand( cl, repository, messageFile );
96
97 try
98 {
99 FileUtils.forceDelete( messageFile );
100 }
101 catch ( IOException ex )
102 {
103
104 }
105
106 return result;
107 }
108
109 protected abstract CheckInScmResult executeCvsCommand( Commandline cl, CvsScmProviderRepository repository,
110 File messageFile )
111 throws ScmException;
112 }