1 package org.apache.maven.scm.provider.local.command.mkdir;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.scm.CommandParameter;
27 import org.apache.maven.scm.CommandParameters;
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.command.add.AddScmResult;
33 import org.apache.maven.scm.command.mkdir.AbstractMkdirCommand;
34 import org.apache.maven.scm.command.mkdir.MkdirScmResult;
35 import org.apache.maven.scm.provider.ScmProviderRepository;
36 import org.apache.maven.scm.provider.local.command.add.LocalAddCommand;
37 import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
38 import org.codehaus.plexus.util.FileUtils;
39
40
41
42
43
44 public class LocalMkdirCommand
45 extends AbstractMkdirCommand
46 {
47 protected MkdirScmResult executeMkdirCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
48 boolean createInLocal )
49 throws ScmException
50 {
51 LocalScmProviderRepository repo = (LocalScmProviderRepository) repository;
52 List<ScmFile> createdDirs = new ArrayList<ScmFile>();
53
54
55 if ( !createInLocal )
56 {
57 File file = (File) fileSet.getFileList().get( 0 );
58 File modulePath = new File( repo.getRoot(), repo.getModule() );
59 File dir = new File( modulePath, file.getName() );
60
61 if ( dir.exists() )
62 {
63 return new MkdirScmResult( null, "Directory already exists!", "Directory already exists.", false );
64 }
65 else
66 {
67 if ( getLogger().isInfoEnabled() )
68 {
69 getLogger().info( "Creating directory in '" + modulePath.getAbsolutePath() + "'" );
70 }
71
72 FileUtils.mkdir( dir.getAbsolutePath() );
73 createdDirs.add( new ScmFile( dir.getPath(), ScmFileStatus.ADDED ) );
74 }
75 }
76 else
77 {
78
79 LocalAddCommand addCmd = new LocalAddCommand();
80 addCmd.setLogger( getLogger() );
81
82 CommandParameters parameters = new CommandParameters();
83 parameters.setString( CommandParameter.MESSAGE, message );
84 parameters.setString( CommandParameter.BINARY, "false" );
85
86 String path = ( (File) fileSet.getFileList().get( 0 ) ).getPath();
87 if ( repo.isFileAdded( path ) )
88 {
89 return new MkdirScmResult( null, "Directory already exists!", "Directory already exists.", false );
90 }
91
92 AddScmResult result = (AddScmResult) addCmd.execute( repository, fileSet, parameters );
93 createdDirs.addAll( result.getAddedFiles() );
94 }
95
96 return new MkdirScmResult( null, createdDirs );
97 }
98 }