1 package org.apache.maven.scm.provider.integrity.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.ScmFile;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmResult;
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.integrity.APISession;
31 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
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 import java.util.ArrayList;
37 import java.util.HashMap;
38
39
40
41
42
43
44
45
46
47
48 public class IntegrityDiffCommand
49 extends AbstractDiffCommand
50 {
51
52
53
54
55 @Override
56 public DiffScmResult executeDiffCommand( ScmProviderRepository repository, ScmFileSet fileSet,
57 ScmVersion startRevision, ScmVersion endRevision )
58 throws ScmException
59 {
60 DiffScmResult result;
61 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
62 APISession api = iRepo.getAPISession();
63 getLogger().info( "Showing differences bettween local files in " + fileSet.getBasedir().getAbsolutePath()
64 + " and server project " + iRepo.getConfigruationPath() );
65
66
67 Commandline shell = new Commandline();
68 shell.setWorkingDirectory( fileSet.getBasedir() );
69 shell.setExecutable( "si" );
70 shell.createArg().setValue( "diff" );
71 shell.createArg().setValue( "--hostname=" + api.getHostName() );
72 shell.createArg().setValue( "--port=" + api.getPort() );
73 shell.createArg().setValue( "--user=" + api.getUserName() );
74 shell.createArg().setValue( "-R" );
75 shell.createArg().setValue( "--filter=changed:all" );
76 shell.createArg().setValue( "--filter=format:text" );
77 IntegrityDiffConsumer shellConsumer = new IntegrityDiffConsumer( getLogger() );
78 String commandLine = CommandLineUtils.toString( shell.getCommandline() );
79
80 try
81 {
82 getLogger().debug( "Executing: " + commandLine );
83 int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer,
84 new CommandLineUtils.StringStreamConsumer() );
85 boolean success = ( exitCode == 128 ? false : true );
86 ScmResult scmResult = new ScmResult( commandLine, "", "Exit Code: " + exitCode, success );
87
88
89
90 return new DiffScmResult( new ArrayList<ScmFile>(), new HashMap<String, CharSequence>(), "", scmResult );
91
92 }
93 catch ( CommandLineException cle )
94 {
95 getLogger().error( "Command Line Exception: " + cle.getMessage() );
96 result = new DiffScmResult( commandLine, cle.getMessage(), "", false );
97 }
98
99 return result;
100 }
101
102 }