1 package org.apache.maven.scm.provider.cvslib.command.add;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.ScmFile;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmFileStatus;
26 import org.apache.maven.scm.ScmResult;
27 import org.apache.maven.scm.command.add.AbstractAddCommand;
28 import org.apache.maven.scm.command.add.AddScmResult;
29 import org.apache.maven.scm.provider.ScmProviderRepository;
30 import org.apache.maven.scm.provider.cvslib.command.CvsCommand;
31 import org.apache.maven.scm.provider.cvslib.command.CvsCommandUtils;
32 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36 import java.util.ArrayList;
37 import java.util.List;
38
39
40
41
42
43
44 public abstract class AbstractCvsAddCommand
45 extends AbstractAddCommand
46 implements CvsCommand
47 {
48
49 protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
50 boolean binary )
51 throws ScmException
52 {
53 CvsScmProviderRepository repository = (CvsScmProviderRepository) repo;
54
55 Commandline cl = CvsCommandUtils.getBaseCommand( "add", repository, fileSet );
56
57 if ( binary )
58 {
59 cl.createArg().setValue( "-kb" );
60 }
61
62 if ( message != null && message.length() > 0 )
63 {
64 cl.createArg().setValue( "-m" );
65
66 cl.createArg().setValue( "\"" + message + "\"" );
67 }
68
69
70 List<ScmFile> addedFiles = new ArrayList<ScmFile>( fileSet.getFileList().size() );
71
72 for ( File file : fileSet.getFileList() )
73 {
74 String path = file.getPath().replace( '\\', '/' );
75
76 cl.createArg().setValue( path );
77
78 addedFiles.add( new ScmFile( path, ScmFileStatus.ADDED ) );
79 }
80
81 if ( getLogger().isInfoEnabled() )
82 {
83 getLogger().info( "Executing: " + cl );
84 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
85 }
86
87 return executeCvsCommand( cl, addedFiles );
88 }
89
90 protected abstract AddScmResult executeCvsCommand( Commandline cl, List<ScmFile> addedFiles )
91 throws ScmException;
92 }