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 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 if ( getLogger().isDebugEnabled() )
55 {
56 getLogger().debug( "executing checkin command..." );
57 }
58 Commandline cl = createCommandLine( fileSet, message );
59
60 ClearCaseCheckInConsumer consumer = new ClearCaseCheckInConsumer( getLogger() );
61
62 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
63
64 int exitCode;
65
66 try
67 {
68 if ( getLogger().isDebugEnabled() )
69 {
70 getLogger().debug(
71 "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
72 + cl.toString() );
73 }
74 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
75 }
76 catch ( CommandLineException ex )
77 {
78 throw new ScmException( "Error while executing clearcase command.", ex );
79 }
80
81 if ( exitCode != 0 )
82 {
83 return new CheckInScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
84 }
85
86 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 Commandline command = new Commandline();
97
98 File workingDirectory = scmFileSet.getBasedir();
99
100 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
101
102 command.setExecutable( "cleartool" );
103
104 command.createArg().setValue( "ci" );
105
106 if ( message != null )
107 {
108 command.createArg().setValue( "-c" );
109 command.createArg().setLine( "\"" + message + "\"" );
110 }
111 else
112 {
113 command.createArg().setValue( "-nc" );
114 }
115
116 List<File> files = scmFileSet.getFileList();
117 if ( files.isEmpty() )
118 {
119 throw new ScmException( "There are no files in the fileset to check in!" );
120 }
121 for ( File file : files )
122 {
123 command.createArg().setValue( file.getAbsolutePath() );
124 }
125
126 return command;
127 }
128 }