1 | |
package org.apache.maven.scm.provider.clearcase.command.blame; |
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.blame.AbstractBlameCommand; |
25 | |
import org.apache.maven.scm.command.blame.BlameScmResult; |
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 | 0 | public class ClearCaseBlameCommand |
39 | |
extends AbstractBlameCommand |
40 | |
implements ClearCaseCommand |
41 | |
{ |
42 | |
|
43 | |
public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet workingDirectory, String filename ) |
44 | |
throws ScmException |
45 | |
{ |
46 | |
|
47 | 0 | if ( getLogger().isDebugEnabled() ) |
48 | |
{ |
49 | 0 | getLogger().debug( "executing blame command..." ); |
50 | |
} |
51 | 0 | Commandline cl = createCommandLine( workingDirectory.getBasedir(), filename ); |
52 | |
|
53 | 0 | ClearCaseBlameConsumer consumer = new ClearCaseBlameConsumer( getLogger() ); |
54 | |
|
55 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
56 | |
|
57 | |
int exitCode; |
58 | |
|
59 | |
try |
60 | |
{ |
61 | 0 | if ( getLogger().isDebugEnabled() ) |
62 | |
{ |
63 | 0 | getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() ); |
64 | |
} |
65 | 0 | exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
66 | |
} |
67 | 0 | catch ( CommandLineException ex ) |
68 | |
{ |
69 | 0 | throw new ScmException( "Error while executing cvs command.", ex ); |
70 | 0 | } |
71 | |
|
72 | 0 | if ( exitCode != 0 ) |
73 | |
{ |
74 | 0 | return new BlameScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false ); |
75 | |
} |
76 | |
|
77 | 0 | return new BlameScmResult( cl.toString(), consumer.getLines() ); |
78 | |
} |
79 | |
|
80 | |
public static Commandline createCommandLine( File workingDirectory, String filename ) |
81 | |
{ |
82 | 0 | Commandline command = new Commandline(); |
83 | 0 | command.setExecutable( "cleartool" ); |
84 | 0 | command.createArg().setValue( "annotate" ); |
85 | |
|
86 | 0 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
87 | |
|
88 | 0 | StringBuilder format = new StringBuilder(); |
89 | 0 | format.append( "VERSION:%Ln@@@" ); |
90 | 0 | format.append( "USER:%u@@@" ); |
91 | 0 | format.append( "DATE:%Nd@@@" ); |
92 | |
|
93 | 0 | command.createArg().setValue( "-out" ); |
94 | 0 | command.createArg().setValue( "-" ); |
95 | 0 | command.createArg().setValue( "-fmt" ); |
96 | 0 | command.createArg().setValue( format.toString() ); |
97 | 0 | command.createArg().setValue( "-nheader" ); |
98 | 0 | command.createArg().setValue( "-f" ); |
99 | 0 | command.createArg().setValue( filename ); |
100 | |
|
101 | 0 | return command; |
102 | |
} |
103 | |
} |