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.diff;
20
21 import java.io.File;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.apache.maven.scm.ScmException;
25 import org.apache.maven.scm.ScmFileSet;
26 import org.apache.maven.scm.ScmVersion;
27 import org.apache.maven.scm.command.diff.AbstractDiffCommand;
28 import org.apache.maven.scm.command.diff.DiffScmResult;
29 import org.apache.maven.scm.provider.ScmProviderRepository;
30 import org.apache.maven.scm.provider.svn.command.SvnCommand;
31 import org.apache.maven.scm.provider.svn.command.diff.SvnDiffConsumer;
32 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
33 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
34 import org.codehaus.plexus.util.Os;
35 import org.codehaus.plexus.util.cli.CommandLineException;
36 import org.codehaus.plexus.util.cli.CommandLineUtils;
37 import org.codehaus.plexus.util.cli.Commandline;
38
39
40
41
42
43 public class SvnDiffCommand extends AbstractDiffCommand implements SvnCommand {
44 private final boolean interactive;
45
46 public SvnDiffCommand(boolean interactive) {
47 this.interactive = interactive;
48 }
49
50
51
52
53 protected DiffScmResult executeDiffCommand(
54 ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion)
55 throws ScmException {
56 Commandline cl =
57 createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), startVersion, endVersion);
58
59 SvnDiffConsumer consumer = new SvnDiffConsumer(fileSet.getBasedir());
60
61 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
62
63 if (logger.isInfoEnabled()) {
64 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
65
66 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
67 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
68 }
69 }
70
71 int exitCode;
72
73 try {
74 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
75 } catch (CommandLineException ex) {
76 throw new ScmException("Error while executing command.", ex);
77 }
78
79 if (exitCode != 0) {
80 return new DiffScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
81 }
82
83 return new DiffScmResult(
84 cl.toString(), consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch());
85 }
86
87
88
89
90
91 public Commandline createCommandLine(
92 SvnScmProviderRepository repository,
93 File workingDirectory,
94 ScmVersion startVersion,
95 ScmVersion endVersion) {
96 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(workingDirectory, repository, interactive);
97
98 cl.createArg().setValue("diff");
99
100 cl.createArg().setValue("--internal-diff");
101
102 if (startVersion != null && StringUtils.isNotEmpty(startVersion.getName())) {
103 cl.createArg().setValue("-r");
104
105 if (endVersion != null && StringUtils.isNotEmpty(endVersion.getName())) {
106 cl.createArg().setValue(startVersion.getName() + ":" + endVersion.getName());
107 } else {
108 cl.createArg().setValue(startVersion.getName());
109 }
110 }
111
112 return cl;
113 }
114 }