1 package org.apache.maven.scm.provider.integrity.command.mkdir;
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.ScmException;
25 import org.apache.maven.scm.ScmFile;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmFileStatus;
28 import org.apache.maven.scm.ScmResult;
29 import org.apache.maven.scm.command.mkdir.AbstractMkdirCommand;
30 import org.apache.maven.scm.command.mkdir.MkdirScmResult;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.integrity.ExceptionHandler;
33 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
34
35 import java.io.File;
36 import java.util.ArrayList;
37 import java.util.Iterator;
38 import java.util.List;
39
40
41
42
43
44
45
46
47
48
49
50
51 public class IntegrityMkdirCommand
52 extends AbstractMkdirCommand
53 {
54
55
56
57
58
59 @Override
60 public MkdirScmResult executeMkdirCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
61 boolean createInLocal )
62 throws ScmException
63 {
64 String dirPath = "";
65 Iterator<File> fit = fileSet.getFileList().iterator();
66 if ( fit.hasNext() )
67 {
68 dirPath = fit.next().getPath().replace( '\\', '/' );
69 }
70 if ( null == dirPath || dirPath.length() == 0 )
71 {
72 throw new ScmException( "A relative directory path is required to execute this command!" );
73 }
74 getLogger().info( "Creating subprojects one per directory, as required for " + dirPath );
75 MkdirScmResult result;
76 IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
77 try
78 {
79 Response res = iRepo.getSandbox().createSubproject( dirPath );
80 String subProject = res.getWorkItems().next().getResult().getField( "resultant" ).getItem().getDisplayId();
81 List<ScmFile> createdDirs = new ArrayList<ScmFile>();
82 createdDirs.add( new ScmFile( subProject, ScmFileStatus.ADDED ) );
83 int exitCode = res.getExitCode();
84 boolean success = ( exitCode == 0 ? true : false );
85 getLogger().info( "Successfully created subproject " + subProject );
86 result = new MkdirScmResult( createdDirs,
87 new ScmResult( res.getCommandString(), "", "Exit Code: " + exitCode,
88 success ) );
89 }
90 catch ( APIException aex )
91 {
92 ExceptionHandler eh = new ExceptionHandler( aex );
93 getLogger().error( "MKS API Exception: " + eh.getMessage() );
94 getLogger().info( eh.getCommand() + " exited with return code " + eh.getExitCode() );
95 result = new MkdirScmResult( eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false );
96 }
97
98 return result;
99 }
100
101 }