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