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