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