1 package org.apache.maven.scm.provider.integrity.command.status;
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.Item;
24 import com.mks.api.response.WorkItem;
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFile;
27 import org.apache.maven.scm.ScmFileSet;
28 import org.apache.maven.scm.ScmFileStatus;
29 import org.apache.maven.scm.ScmResult;
30 import org.apache.maven.scm.command.status.AbstractStatusCommand;
31 import org.apache.maven.scm.command.status.StatusScmResult;
32 import org.apache.maven.scm.provider.ScmProviderRepository;
33 import org.apache.maven.scm.provider.integrity.ExceptionHandler;
34 import org.apache.maven.scm.provider.integrity.Sandbox;
35 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
36
37 import java.io.File;
38 import java.util.ArrayList;
39 import java.util.Iterator;
40 import java.util.List;
41
42
43
44
45
46
47
48
49
50
51
52
53 public class IntegrityStatusCommand
54 extends AbstractStatusCommand
55 {
56
57
58
59 @Override
60 public StatusScmResult executeStatusCommand( ScmProviderRepository repository, ScmFileSet fileSet )
61 throws ScmException
62 {
63 StatusScmResult result;
64 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
65 getLogger().info( "Status of files changed in sandbox " + fileSet.getBasedir().getAbsolutePath() );
66 try
67 {
68
69 List<ScmFile> scmFileList = new ArrayList<ScmFile>();
70
71
72 Sandbox siSandbox = iRepo.getSandbox();
73
74 String excludes = Sandbox.formatFilePatterns( fileSet.getExcludes() );
75 String includes = Sandbox.formatFilePatterns( fileSet.getIncludes() );
76
77
78 List<ScmFile> newMemberList = siSandbox.getNewMembers( excludes, includes );
79
80 scmFileList.addAll( newMemberList );
81
82
83 List<WorkItem> changeList = siSandbox.getChangeList();
84 for ( Iterator<WorkItem> wit = changeList.iterator(); wit.hasNext(); )
85 {
86 WorkItem wi = wit.next();
87 File memberFile = new File( wi.getField( "name" ).getValueAsString() );
88
89 if ( siSandbox.hasWorkingFile( (Item) wi.getField( "wfdelta" ).getValue() ) )
90 {
91 scmFileList.add( new ScmFile( memberFile.getAbsolutePath(), ScmFileStatus.UPDATED ) );
92 }
93 else
94 {
95 scmFileList.add( new ScmFile( memberFile.getAbsolutePath(), ScmFileStatus.DELETED ) );
96 }
97 }
98
99 if ( scmFileList.size() == 0 )
100 {
101 getLogger().info( "No local changes found!" );
102 }
103 result = new StatusScmResult( scmFileList, new ScmResult( "si viewsandbox", "", "", true ) );
104 }
105 catch ( APIException aex )
106 {
107 ExceptionHandler eh = new ExceptionHandler( aex );
108 getLogger().error( "MKS API Exception: " + eh.getMessage() );
109 getLogger().debug( eh.getCommand() + " exited with return code " + eh.getExitCode() );
110 result = new StatusScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
111 }
112
113 return result;
114 }
115
116 }