1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.svn.svnexe.command.blame;
20
21 import java.io.File;
22
23 import org.apache.maven.scm.ScmException;
24 import org.apache.maven.scm.ScmFileSet;
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.svn.command.SvnCommand;
29 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
30 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
31 import org.codehaus.plexus.util.Os;
32 import org.codehaus.plexus.util.cli.CommandLineException;
33 import org.codehaus.plexus.util.cli.CommandLineUtils;
34 import org.codehaus.plexus.util.cli.Commandline;
35
36
37
38
39
40
41 public class SvnBlameCommand extends AbstractBlameCommand implements SvnCommand {
42
43
44
45 public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename)
46 throws ScmException {
47 Commandline cl = createCommandLine((SvnScmProviderRepository) repo, workingDirectory.getBasedir(), filename);
48
49 SvnBlameConsumer consumer = new SvnBlameConsumer();
50
51 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
52
53 if (logger.isInfoEnabled()) {
54 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
55
56 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
57 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
58 }
59 }
60
61 int exitCode;
62
63 try {
64 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
65 } catch (CommandLineException ex) {
66 throw new ScmException("Error while executing command.", ex);
67 }
68
69 if (exitCode != 0) {
70 return new BlameScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
71 }
72
73 return new BlameScmResult(cl.toString(), consumer.getLines());
74 }
75
76 public static Commandline createCommandLine(
77 SvnScmProviderRepository repository, File workingDirectory, String filename) {
78 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(workingDirectory, repository);
79 cl.createArg().setValue("blame");
80 cl.createArg().setValue("--xml");
81 cl.createArg().setValue(filename);
82 return cl;
83 }
84 }