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
46 public class IntegrityLockCommand
47 extends AbstractLockCommand
48 {
49
50
51
52 @Override
53 public ScmResult executeLockCommand( ScmProviderRepository repository, File workingDirectory, String filename )
54 throws ScmException
55 {
56 getLogger().info( "Attempting to lock file: " + filename );
57 if ( null == filename || filename.length() == 0 )
58 {
59 throw new ScmException( "A single filename is required to execute the lock command!" );
60 }
61
62 ScmResult result;
63 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
64 try
65 {
66 Sandbox siSandbox = iRepo.getSandbox();
67 File memberFile = new File( workingDirectory.getAbsoluteFile() + File.separator + filename );
68 Response res = siSandbox.lock( memberFile, filename );
69 int exitCode = res.getExitCode();
70 boolean success = ( exitCode == 0 ? true : false );
71 result = new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
72 }
73 catch ( APIException aex )
74 {
75 ExceptionHandler eh = new ExceptionHandler( aex );
76 getLogger().error( "MKS API Exception: " + eh.getMessage() );
77 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
78 result = new ScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
79 }
80
81 return result;
82 }
83
84
85
86
87 @Override
88 protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
89 CommandParameters parameters )
90 throws ScmException
91 {
92 return executeLockCommand( repository, fileSet.getBasedir(), parameters.getString( CommandParameter.FILE ) );
93 }
94
95 }