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