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