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 private final boolean interactive;
43
44 public SvnBlameCommand(boolean interactive) {
45 this.interactive = interactive;
46 }
47
48
49
50
51 public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename)
52 throws ScmException {
53 Commandline cl = createCommandLine((SvnScmProviderRepository) repo, workingDirectory.getBasedir(), filename);
54
55 SvnBlameConsumer consumer = new SvnBlameConsumer();
56
57 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
58
59 if (logger.isInfoEnabled()) {
60 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
61
62 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
63 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
64 }
65 }
66
67 int exitCode;
68
69 try {
70 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
71 } catch (CommandLineException ex) {
72 throw new ScmException("Error while executing command.", ex);
73 }
74
75 if (exitCode != 0) {
76 return new BlameScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
77 }
78
79 return new BlameScmResult(cl.toString(), consumer.getLines());
80 }
81
82 public Commandline createCommandLine(SvnScmProviderRepository repository, File workingDirectory, String filename) {
83 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(workingDirectory, repository, interactive);
84 cl.createArg().setValue("blame");
85 cl.createArg().setValue("--xml");
86 cl.createArg().setValue(filename);
87 return cl;
88 }
89 }