1 package org.apache.maven.scm.provider.integrity.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.ScmResult;
25 import org.apache.maven.scm.command.blame.AbstractBlameCommand;
26 import org.apache.maven.scm.command.blame.BlameScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.integrity.APISession;
29 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
30 import org.codehaus.plexus.util.cli.CommandLineException;
31 import org.codehaus.plexus.util.cli.CommandLineUtils;
32 import org.codehaus.plexus.util.cli.Commandline;
33
34
35
36
37
38
39
40
41
42 public class IntegrityBlameCommand
43 extends AbstractBlameCommand
44 {
45
46
47
48 @Override
49 public BlameScmResult executeBlameCommand( ScmProviderRepository repository, ScmFileSet workingDirectory,
50 String filename )
51 throws ScmException
52 {
53 getLogger().info( "Attempting to display blame results for file: " + filename );
54 if ( null == filename || filename.length() == 0 )
55 {
56 throw new ScmException( "A single filename is required to execute the blame command!" );
57 }
58 BlameScmResult result;
59 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
60 APISession api = iRepo.getAPISession();
61
62 Commandline shell = new Commandline();
63 shell.setWorkingDirectory( workingDirectory.getBasedir() );
64 shell.setExecutable( "si" );
65 shell.createArg().setValue( "annotate" );
66 shell.createArg().setValue( "--hostname=" + api.getHostName() );
67 shell.createArg().setValue( "--port=" + api.getPort() );
68 shell.createArg().setValue( "--user=" + api.getUserName() );
69 shell.createArg().setValue( "--fields=date,revision,author" );
70 shell.createArg().setValue( '"' + filename + '"' );
71 IntegrityBlameConsumer shellConsumer = new IntegrityBlameConsumer( getLogger() );
72
73 try
74 {
75 getLogger().debug( "Executing: " + shell.getCommandline() );
76 int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer,
77 new CommandLineUtils.StringStreamConsumer() );
78 boolean success = ( exitCode == 128 ? false : true );
79 ScmResult scmResult =
80 new ScmResult( shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success );
81 return new BlameScmResult( shellConsumer.getBlameList(), scmResult );
82 }
83 catch ( CommandLineException cle )
84 {
85 getLogger().error( "Command Line Exception: " + cle.getMessage() );
86 result = new BlameScmResult( shell.getCommandline().toString(), cle.getMessage(), "", false );
87 }
88
89 return result;
90 }
91
92 }