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 | 0 | 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 | 0 | CvsScmProviderRepository repository = (CvsScmProviderRepository) repo; |
55 | |
|
56 | 0 | Commandline cl = CvsCommandUtils.getBaseCommand( "commit", repository, fileSet, false ); |
57 | |
|
58 | 0 | if ( version != null && !StringUtils.isEmpty( version.getName() ) ) |
59 | |
{ |
60 | 0 | cl.createArg().setValue( "-r" + version.getName() ); |
61 | |
} |
62 | |
|
63 | 0 | cl.createArg().setValue( "-R" ); |
64 | |
|
65 | 0 | cl.createArg().setValue( "-F" ); |
66 | |
|
67 | |
File messageFile; |
68 | |
|
69 | |
try |
70 | |
{ |
71 | 0 | messageFile = File.createTempFile( "scm-commit-message", ".txt" ); |
72 | |
|
73 | 0 | FileUtils.fileWrite( messageFile.getAbsolutePath(), message ); |
74 | |
} |
75 | 0 | catch ( IOException ex ) |
76 | |
{ |
77 | 0 | throw new ScmException( "Error while making a temporary commit message file." ); |
78 | 0 | } |
79 | |
|
80 | 0 | cl.createArg().setValue( messageFile.getAbsolutePath() ); |
81 | |
|
82 | 0 | List<File> files = fileSet.getFileList(); |
83 | |
|
84 | 0 | for ( File f : files ) |
85 | |
{ |
86 | 0 | cl.createArg().setValue( f.getPath().replace( '\\', '/' ) ); |
87 | |
} |
88 | |
|
89 | 0 | if ( getLogger().isInfoEnabled() ) |
90 | |
{ |
91 | 0 | getLogger().info( "Executing: " + cl ); |
92 | 0 | getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); |
93 | |
} |
94 | |
|
95 | 0 | CheckInScmResult result = executeCvsCommand( cl, repository, messageFile ); |
96 | |
|
97 | |
try |
98 | |
{ |
99 | 0 | FileUtils.forceDelete( messageFile ); |
100 | |
} |
101 | 0 | catch ( IOException ex ) |
102 | |
{ |
103 | |
|
104 | 0 | } |
105 | |
|
106 | 0 | return result; |
107 | |
} |
108 | |
|
109 | |
protected abstract CheckInScmResult executeCvsCommand( Commandline cl, CvsScmProviderRepository repository, |
110 | |
File messageFile ) |
111 | |
throws ScmException; |
112 | |
} |