1 package org.apache.maven.scm.provider.integrity.command.update;
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.ScmFile;
30 import org.apache.maven.scm.ScmFileSet;
31 import org.apache.maven.scm.ScmFileStatus;
32 import org.apache.maven.scm.ScmVersion;
33 import org.apache.maven.scm.command.changelog.ChangeLogCommand;
34 import org.apache.maven.scm.command.update.AbstractUpdateCommand;
35 import org.apache.maven.scm.command.update.UpdateScmResult;
36 import org.apache.maven.scm.provider.ScmProviderRepository;
37 import org.apache.maven.scm.provider.integrity.ExceptionHandler;
38 import org.apache.maven.scm.provider.integrity.Sandbox;
39 import org.apache.maven.scm.provider.integrity.command.changelog.IntegrityChangeLogCommand;
40 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
41
42 import java.util.ArrayList;
43 import java.util.List;
44
45
46
47
48
49
50
51
52
53 public class IntegrityUpdateCommand
54 extends AbstractUpdateCommand
55 {
56
57
58
59 @Override
60 public UpdateScmResult executeUpdateCommand( ScmProviderRepository repository, ScmFileSet fileSet,
61 ScmVersion scmVersion )
62 throws ScmException
63 {
64 getLogger().info( "Attempting to synchronize sandbox in " + fileSet.getBasedir().getAbsolutePath() );
65 List<ScmFile> updatedFiles = new ArrayList<ScmFile>();
66 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
67 Sandbox siSandbox = iRepo.getSandbox();
68 try
69 {
70
71 if ( siSandbox.create() )
72 {
73 Response res = siSandbox.resync();
74
75 WorkItemIterator wit = res.getWorkItems();
76 while ( wit.hasNext() )
77 {
78 WorkItem wi = wit.next();
79 if ( wi.getModelType().equals( SIModelTypeName.MEMBER ) )
80 {
81 Result message = wi.getResult();
82 getLogger().debug( wi.getDisplayId() + " " + ( null != message ? message.getMessage() : "" ) );
83 if ( null != message && message.getMessage().length() > 0 )
84 {
85 updatedFiles.add( new ScmFile( wi.getDisplayId(),
86 message.getMessage().equalsIgnoreCase( "removed" )
87 ? ScmFileStatus.DELETED
88 : ScmFileStatus.UPDATED ) );
89 }
90 }
91 }
92 return new UpdateScmResult( res.getCommandString(), updatedFiles );
93 }
94 else
95 {
96 return new UpdateScmResult( "si resync", "Failed to synchronize workspace", "", false );
97 }
98 }
99 catch ( APIException aex )
100 {
101 ExceptionHandler eh = new ExceptionHandler( aex );
102 getLogger().error( "MKS API Exception: " + eh.getMessage() );
103 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
104 return new UpdateScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
105 }
106 }
107
108
109
110
111 @Override
112 protected ChangeLogCommand getChangeLogCommand()
113 {
114 IntegrityChangeLogCommand command = new IntegrityChangeLogCommand();
115 command.setLogger( getLogger() );
116 return command;
117 }
118 }