1 package org.apache.maven.scm.provider.clearcase.command.status;
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.ScmFileSet;
24 import org.apache.maven.scm.command.status.AbstractStatusCommand;
25 import org.apache.maven.scm.command.status.StatusScmResult;
26 import org.apache.maven.scm.provider.ScmProviderRepository;
27 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
28 import org.codehaus.plexus.util.cli.CommandLineException;
29 import org.codehaus.plexus.util.cli.CommandLineUtils;
30 import org.codehaus.plexus.util.cli.Commandline;
31
32 import java.io.File;
33
34
35
36
37
38 public class ClearCaseStatusCommand
39 extends AbstractStatusCommand
40 implements ClearCaseCommand
41 {
42
43 protected StatusScmResult executeStatusCommand( ScmProviderRepository scmProviderRepository, ScmFileSet scmFileSet )
44 throws ScmException
45 {
46 if ( getLogger().isDebugEnabled() )
47 {
48 getLogger().debug( "executing status command..." );
49 }
50 Commandline cl = createCommandLine( scmFileSet );
51
52 ClearCaseStatusConsumer consumer = new ClearCaseStatusConsumer( getLogger(), scmFileSet.getBasedir() );
53
54 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
55
56 int exitCode;
57
58 try
59 {
60 if ( getLogger().isDebugEnabled() )
61 {
62 getLogger().debug(
63 "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
64 + cl.toString() );
65 }
66 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
67 }
68 catch ( CommandLineException ex )
69 {
70 throw new ScmException( "Error while executing clearcase command.", ex );
71 }
72
73 if ( exitCode != 0 )
74 {
75 return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
76 }
77
78 return new StatusScmResult( cl.toString(), consumer.getCheckedOutFiles() );
79 }
80
81
82
83
84
85 public static Commandline createCommandLine( ScmFileSet scmFileSet )
86 {
87 Commandline command = new Commandline();
88
89 File workingDirectory = scmFileSet.getBasedir();
90
91 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
92
93 command.setExecutable( "cleartool" );
94
95 command.createArg().setValue( "lscheckout" );
96 command.createArg().setValue( "-cview" );
97 command.createArg().setValue( "-r" );
98 command.createArg().setValue( "-fmt" );
99 command.createArg().setValue( "%n\\n" );
100
101 return command;
102 }
103 }