1 package org.apache.maven.scm.provider.integrity.command.checkout;
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 com.mks.api.response.Result;
25 import com.mks.api.response.WorkItem;
26 import com.mks.api.response.WorkItemIterator;
27 import com.mks.api.si.SIModelTypeName;
28 import org.apache.maven.scm.ScmException;
29 import org.apache.maven.scm.ScmFileSet;
30 import org.apache.maven.scm.ScmVersion;
31 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
32 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
33 import org.apache.maven.scm.provider.ScmProviderRepository;
34 import org.apache.maven.scm.provider.integrity.ExceptionHandler;
35 import org.apache.maven.scm.provider.integrity.Sandbox;
36 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
37
38
39
40
41
42
43
44
45
46
47
48 public class IntegrityCheckOutCommand
49 extends AbstractCheckOutCommand
50 {
51
52
53
54
55
56
57
58
59
60 @Override
61 public CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repository, ScmFileSet fileSet,
62 ScmVersion scmVersion, boolean recursive, boolean shallow )
63 throws ScmException
64 {
65 CheckOutScmResult result;
66 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
67 try
68 {
69 getLogger().info(
70 "Attempting to checkout source for project " + iRepo.getProject().getConfigurationPath() );
71 String checkoutDir = System.getProperty( "checkoutDirectory" );
72
73 Sandbox siSandbox;
74 if ( null != checkoutDir && checkoutDir.length() > 0 )
75 {
76 siSandbox = new Sandbox( iRepo.getAPISession(), iRepo.getProject(), checkoutDir );
77 iRepo.setSandbox( siSandbox );
78 }
79 else
80 {
81 siSandbox = iRepo.getSandbox();
82 }
83 getLogger().info( "Sandbox location is " + siSandbox.getSandboxDir() );
84
85 if ( siSandbox.create() )
86 {
87
88 Response res = siSandbox.resync();
89
90 WorkItemIterator wit = res.getWorkItems();
91 while ( wit.hasNext() )
92 {
93 WorkItem wi = wit.next();
94 if ( wi.getModelType().equals( SIModelTypeName.MEMBER ) )
95 {
96 Result message = wi.getResult();
97 getLogger().debug( wi.getDisplayId() + " " + ( null != message ? message.getMessage() : "" ) );
98 }
99 }
100 int exitCode = res.getExitCode();
101 boolean success = ( exitCode == 0 ? true : false );
102 result = new CheckOutScmResult( res.getCommandString(), "", "Exit Code: " + exitCode, success );
103 }
104 else
105 {
106 result = new CheckOutScmResult( "si createsandbox", "Failed to create sandbox!", "", false );
107 }
108 }
109 catch ( APIException aex )
110 {
111 ExceptionHandler eh = new ExceptionHandler( aex );
112 getLogger().error( "MKS API Exception: " + eh.getMessage() );
113 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
114 result = new CheckOutScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
115 }
116
117 return result;
118 }
119
120 }