1 package org.apache.maven.scm.provider.integrity.command.fileinfo;
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.CommandParameter;
23 import org.apache.maven.scm.CommandParameters;
24 import org.apache.maven.scm.ScmException;
25 import org.apache.maven.scm.ScmFileSet;
26 import org.apache.maven.scm.ScmResult;
27 import org.apache.maven.scm.command.fileinfo.AbstractFileInfoCommand;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.integrity.APISession;
30 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
31 import org.codehaus.plexus.util.cli.CommandLineException;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class IntegrityFileInfoCommand
50 extends AbstractFileInfoCommand
51 {
52
53
54
55
56
57 @Override
58 public ScmResult executeFileInfoCommand( ScmProviderRepository repository, File workingDirectory, String filename )
59 throws ScmException
60 {
61 getLogger().info( "Attempting to display scm file information for file: " + filename );
62 if ( null == filename || filename.length() == 0 )
63 {
64 throw new ScmException( "A single filename is required to execute the fileinfo command!" );
65 }
66 ScmResult result;
67 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
68 APISession api = iRepo.getAPISession();
69 Commandline shell = new Commandline();
70 shell.setWorkingDirectory( workingDirectory );
71 shell.setExecutable( "si" );
72 shell.createArg().setValue( "memberinfo" );
73 shell.createArg().setValue( "--hostname=" + api.getHostName() );
74 shell.createArg().setValue( "--port=" + api.getPort() );
75 shell.createArg().setValue( "--user=" + api.getUserName() );
76 shell.createArg().setValue( '"' + filename + '"' );
77 IntegrityFileInfoConsumer shellConsumer = new IntegrityFileInfoConsumer( getLogger() );
78
79 try
80 {
81 getLogger().debug( "Executing: " + shell.getCommandline() );
82 int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer,
83 new CommandLineUtils.StringStreamConsumer() );
84 boolean success = ( exitCode == 128 ? false : true );
85 result = new ScmResult( shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success );
86
87 }
88 catch ( CommandLineException cle )
89 {
90 getLogger().error( "Command Line Exception: " + cle.getMessage() );
91 result = new ScmResult( shell.getCommandline().toString(), cle.getMessage(), "", false );
92 }
93
94 return result;
95 }
96
97
98
99
100 @Override
101 protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
102 CommandParameters parameters )
103 throws ScmException
104 {
105 return executeFileInfoCommand( repository, fileSet.getBasedir(),
106 parameters.getString( CommandParameter.FILE ) );
107 }
108
109 }