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