1 package org.apache.maven.scm.provider.clearcase.command.update;
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.ScmVersion;
25 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
26 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
27 import org.apache.maven.scm.command.update.UpdateScmResult;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand;
30 import org.apache.maven.scm.provider.clearcase.command.changelog.ClearCaseChangeLogCommand;
31 import org.codehaus.plexus.util.cli.CommandLineException;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36
37
38
39
40
41
42 public class ClearCaseUpdateCommand
43 extends AbstractUpdateCommand
44 implements ClearCaseCommand
45 {
46
47 protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet,
48 ScmVersion version )
49 throws ScmException
50 {
51 if ( getLogger().isDebugEnabled() )
52 {
53 getLogger().debug( "executing update command..." );
54 }
55 Commandline cl = createCommandLine( fileSet );
56
57 ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( getLogger() );
58
59 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
60
61 int exitCode;
62
63 try
64 {
65 if ( getLogger().isDebugEnabled() )
66 {
67 getLogger().debug(
68 "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
69 + cl.toString() );
70 }
71 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
72 }
73 catch ( CommandLineException ex )
74 {
75 throw new ScmException( "Error while executing clearcase command.", ex );
76 }
77
78 if ( exitCode != 0 )
79 {
80 return new UpdateScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
81 }
82
83 return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() );
84 }
85
86
87 protected ChangeLogCommand getChangeLogCommand()
88 {
89 ClearCaseChangeLogCommand changeLogCmd = new ClearCaseChangeLogCommand();
90
91 changeLogCmd.setLogger( getLogger() );
92
93 return changeLogCmd;
94 }
95
96
97
98
99
100 public static Commandline createCommandLine( ScmFileSet scmFileSet )
101 {
102 Commandline command = new Commandline();
103
104 File workingDirectory = scmFileSet.getBasedir();
105
106 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
107
108 command.setExecutable( "cleartool" );
109
110 command.createArg().setValue( "update" );
111
112 command.createArg().setValue( "-f" );
113
114 return command;
115 }
116 }