1 package org.apache.maven.scm.provider.integrity.command.lock;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.mks.api.response.APIException;
23 import com.mks.api.response.Response;
24 import org.apache.maven.scm.CommandParameter;
25 import org.apache.maven.scm.CommandParameters;
26 import org.apache.maven.scm.ScmException;
27 import org.apache.maven.scm.ScmFileSet;
28 import org.apache.maven.scm.ScmResult;
29 import org.apache.maven.scm.command.lock.AbstractLockCommand;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.integrity.ExceptionHandler;
32 import org.apache.maven.scm.provider.integrity.Sandbox;
33 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
34
35 import java.io.File;
36
37
38
39
40
41
42
43
44
45 public class IntegrityLockCommand
46 extends AbstractLockCommand
47 {
48
49
50
51 @Override
52 public ScmResult executeLockCommand( ScmProviderRepository repository, File workingDirectory, String filename )
53 throws ScmException
54 {
55 getLogger().info( "Attempting to lock file: " + filename );
56 if ( null == filename || filename.length() == 0 )
57 {
58 throw new ScmException( "A single filename is required to execute the lock command!" );
59 }
60
61 ScmResult result;
62 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
63 try
64 {
65 Sandbox siSandbox = iRepo.getSandbox();
66 File memberFile = new File( workingDirectory.getAbsoluteFile() + File.separator + filename );
67 Response res = siSandbox.lock( memberFile, filename );
68 int exitCode = res.getExitCode();
69 boolean success = ( exitCode == 0 ? true : false );
70 result = new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
71 }
72 catch ( APIException aex )
73 {
74 ExceptionHandler eh = new ExceptionHandler( aex );
75 getLogger().error( "MKS API Exception: " + eh.getMessage() );
76 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
77 result = new ScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
78 }
79
80 return result;
81 }
82
83
84
85
86 @Override
87 protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
88 CommandParameters parameters )
89 throws ScmException
90 {
91 return executeLockCommand( repository, fileSet.getBasedir(), parameters.getString( CommandParameter.FILE ) );
92 }
93
94 }