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 | 0 | 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 | 0 | if ( getLogger().isDebugEnabled() ) |
52 | |
{ |
53 | 0 | getLogger().debug( "executing update command..." ); |
54 | |
} |
55 | 0 | Commandline cl = createCommandLine( fileSet ); |
56 | |
|
57 | 0 | ClearCaseUpdateConsumer consumer = new ClearCaseUpdateConsumer( getLogger() ); |
58 | |
|
59 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
60 | |
|
61 | |
int exitCode; |
62 | |
|
63 | |
try |
64 | |
{ |
65 | 0 | if ( getLogger().isDebugEnabled() ) |
66 | |
{ |
67 | 0 | getLogger().debug( |
68 | |
"Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" |
69 | |
+ cl.toString() ); |
70 | |
} |
71 | 0 | exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
72 | |
} |
73 | 0 | catch ( CommandLineException ex ) |
74 | |
{ |
75 | 0 | throw new ScmException( "Error while executing clearcase command.", ex ); |
76 | 0 | } |
77 | |
|
78 | 0 | if ( exitCode != 0 ) |
79 | |
{ |
80 | 0 | return new UpdateScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false ); |
81 | |
} |
82 | |
|
83 | 0 | return new UpdateScmResult( cl.toString(), consumer.getUpdatedFiles() ); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
protected ChangeLogCommand getChangeLogCommand() |
88 | |
{ |
89 | 0 | ClearCaseChangeLogCommand changeLogCmd = new ClearCaseChangeLogCommand(); |
90 | |
|
91 | 0 | changeLogCmd.setLogger( getLogger() ); |
92 | |
|
93 | 0 | return changeLogCmd; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public static Commandline createCommandLine( ScmFileSet scmFileSet ) |
101 | |
{ |
102 | 1 | Commandline command = new Commandline(); |
103 | |
|
104 | 1 | File workingDirectory = scmFileSet.getBasedir(); |
105 | |
|
106 | 1 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
107 | |
|
108 | 1 | command.setExecutable( "cleartool" ); |
109 | |
|
110 | 1 | command.createArg().setValue( "update" ); |
111 | |
|
112 | 1 | command.createArg().setValue( "-f" ); |
113 | |
|
114 | 1 | return command; |
115 | |
} |
116 | |
} |