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