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.repository.IntegrityScmProviderRepository;
29 import org.codehaus.plexus.util.cli.CommandLineException;
30 import org.codehaus.plexus.util.cli.CommandLineUtils;
31 import org.codehaus.plexus.util.cli.Commandline;
32
33
34
35
36
37
38
39
40
41 public class IntegrityBlameCommand
42 extends AbstractBlameCommand
43 {
44
45
46
47 @Override
48 public BlameScmResult executeBlameCommand( ScmProviderRepository repository, ScmFileSet workingDirectory,
49 String filename )
50 throws ScmException
51 {
52 getLogger().info( "Attempting to display blame results for file: " + filename );
53 if ( null == filename || filename.length() == 0 )
54 {
55 throw new ScmException( "A single filename is required to execute the blame command!" );
56 }
57 BlameScmResult result;
58 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
59
60
61 doShellConnect( iRepo, workingDirectory );
62 result = doShellAnnotate( iRepo, workingDirectory, filename );
63
64 return result;
65 }
66
67
68
69
70
71
72
73
74 private void doShellConnect( IntegrityScmProviderRepository iRepo, ScmFileSet workingDirectory )
75 throws ScmException
76 {
77 Commandline shell = new Commandline();
78 shell.setWorkingDirectory( workingDirectory.getBasedir() );
79 shell.setExecutable( "si" );
80 shell.createArg().setValue( "connect" );
81 shell.createArg().setValue( "--hostname=" + iRepo.getHost() );
82 shell.createArg().setValue( "--port=" + iRepo.getPort() );
83 shell.createArg().setValue( "--user=" + iRepo.getUser() );
84 shell.createArg().setValue( "--batch" );
85 shell.createArg().setValue( "--password=" + iRepo.getPassword() );
86 CommandLineUtils.StringStreamConsumer shellConsumer = new CommandLineUtils.StringStreamConsumer();
87
88 try
89 {
90 getLogger().debug( "Executing: " + CommandLineUtils.toString( shell.getCommandline() ) );
91 int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer, shellConsumer );
92 if ( exitCode != 0 )
93 {
94 throw new ScmException( "Can't login to integrity. Message : " + shellConsumer.toString() );
95 }
96 }
97 catch ( CommandLineException cle )
98 {
99 getLogger().error( "Command Line Connect Exception: " + cle.getMessage() );
100 throw new ScmException( "Can't login to integrity. Message : " + cle.getMessage() );
101 }
102
103 }
104
105
106
107
108
109
110
111
112
113 private BlameScmResult doShellAnnotate( IntegrityScmProviderRepository iRepo, ScmFileSet workingDirectory,
114 String filename )
115 {
116 BlameScmResult result;
117 Commandline shell = new Commandline();
118 shell.setWorkingDirectory( workingDirectory.getBasedir() );
119 shell.setExecutable( "si" );
120 shell.createArg().setValue( "annotate" );
121 shell.createArg().setValue( "--hostname=" + iRepo.getHost() );
122 shell.createArg().setValue( "--port=" + iRepo.getPort() );
123 shell.createArg().setValue( "--user=" + iRepo.getUser() );
124 shell.createArg().setValue( "--fields=date,revision,author" );
125 shell.createArg().setValue( '"' + filename + '"' );
126 IntegrityBlameConsumer shellConsumer = new IntegrityBlameConsumer( getLogger() );
127
128 try
129 {
130 getLogger().debug( "Executing: " + CommandLineUtils.toString( shell.getCommandline() ) );
131 int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer,
132 new CommandLineUtils.StringStreamConsumer() );
133 boolean success = ( exitCode == 0 ? true : false );
134 ScmResult scmResult =
135 new ScmResult( shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success );
136 return new BlameScmResult( shellConsumer.getBlameList(), scmResult );
137 }
138 catch ( CommandLineException cle )
139 {
140 getLogger().error( "Command Line Exception: " + cle.getMessage() );
141 result = new BlameScmResult( shell.getCommandline().toString(), cle.getMessage(), "", false );
142 }
143
144 return result;
145 }
146
147 }