1 | |
package org.apache.maven.scm.provider.clearcase.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.util.List; |
24 | |
|
25 | |
import org.apache.maven.scm.ScmException; |
26 | |
import org.apache.maven.scm.ScmFileSet; |
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.provider.ScmProviderRepository; |
31 | |
import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand; |
32 | |
import org.codehaus.plexus.util.cli.CommandLineException; |
33 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
34 | |
import org.codehaus.plexus.util.cli.Commandline; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class ClearCaseCheckInCommand |
42 | |
extends AbstractCheckInCommand |
43 | |
implements ClearCaseCommand |
44 | |
{ |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
protected CheckInScmResult executeCheckInCommand( ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, |
51 | |
String message, ScmVersion version ) |
52 | |
throws ScmException |
53 | |
{ |
54 | 0 | if ( getLogger().isDebugEnabled() ) |
55 | |
{ |
56 | 0 | getLogger().debug( "executing checkin command..." ); |
57 | |
} |
58 | 0 | Commandline cl = createCommandLine( fileSet, message ); |
59 | |
|
60 | 0 | ClearCaseCheckInConsumer consumer = new ClearCaseCheckInConsumer( getLogger() ); |
61 | |
|
62 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
63 | |
|
64 | |
int exitCode; |
65 | |
|
66 | |
try |
67 | |
{ |
68 | 0 | if ( getLogger().isDebugEnabled() ) |
69 | |
{ |
70 | 0 | getLogger().debug( |
71 | |
"Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" |
72 | |
+ cl.toString() ); |
73 | |
} |
74 | 0 | exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
75 | |
} |
76 | 0 | catch ( CommandLineException ex ) |
77 | |
{ |
78 | 0 | throw new ScmException( "Error while executing clearcase command.", ex ); |
79 | 0 | } |
80 | |
|
81 | 0 | if ( exitCode != 0 ) |
82 | |
{ |
83 | 0 | return new CheckInScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false ); |
84 | |
} |
85 | |
|
86 | 0 | return new CheckInScmResult( cl.toString(), consumer.getCheckedInFiles() ); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public static Commandline createCommandLine( ScmFileSet scmFileSet, String message ) |
94 | |
throws ScmException |
95 | |
{ |
96 | 1 | Commandline command = new Commandline(); |
97 | |
|
98 | 1 | File workingDirectory = scmFileSet.getBasedir(); |
99 | |
|
100 | 1 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
101 | |
|
102 | 1 | command.setExecutable( "cleartool" ); |
103 | |
|
104 | 1 | command.createArg().setValue( "ci" ); |
105 | |
|
106 | 1 | if ( message != null ) |
107 | |
{ |
108 | 1 | command.createArg().setValue( "-c" ); |
109 | 1 | command.createArg().setLine( "\"" + message + "\"" ); |
110 | |
} |
111 | |
else |
112 | |
{ |
113 | 0 | command.createArg().setValue( "-nc" ); |
114 | |
} |
115 | |
|
116 | 1 | List<File> files = scmFileSet.getFileList(); |
117 | 1 | if ( files.isEmpty() ) |
118 | |
{ |
119 | 0 | throw new ScmException( "There are no files in the fileset to check in!" ); |
120 | |
} |
121 | 1 | for ( File file : files ) |
122 | |
{ |
123 | 1 | command.createArg().setValue( file.getAbsolutePath() ); |
124 | |
} |
125 | |
|
126 | 1 | return command; |
127 | |
} |
128 | |
} |