1 package org.apache.maven.scm.provider.svn.svnexe.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.ScmFileSet;
24 import org.apache.maven.scm.ScmResult;
25 import org.apache.maven.scm.command.add.AbstractAddCommand;
26 import org.apache.maven.scm.command.add.AddScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.svn.command.SvnCommand;
29 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
30 import org.codehaus.plexus.util.Os;
31 import org.codehaus.plexus.util.cli.CommandLineException;
32 import org.codehaus.plexus.util.cli.CommandLineUtils;
33 import org.codehaus.plexus.util.cli.Commandline;
34
35 import java.io.File;
36 import java.io.IOException;
37 import java.util.List;
38
39
40
41
42
43 public class SvnAddCommand
44 extends AbstractAddCommand
45 implements SvnCommand
46 {
47
48 protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message,
49 boolean binary )
50 throws ScmException
51 {
52
53 if ( binary )
54 {
55 throw new ScmException( "This provider does not yet support binary files" );
56 }
57
58 if ( fileSet.getFileList().isEmpty() )
59 {
60 throw new ScmException( "You must provide at least one file/directory to add" );
61 }
62
63 Commandline cl = createCommandLine( fileSet.getBasedir(), fileSet.getFileList() );
64
65 SvnAddConsumer consumer = new SvnAddConsumer( getLogger() );
66
67 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
68
69 if ( getLogger().isInfoEnabled() )
70 {
71 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
72
73 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
74 {
75 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
76 }
77 }
78
79 int exitCode;
80
81 try
82 {
83 exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
84 }
85 catch ( CommandLineException ex )
86 {
87 throw new ScmException( "Error while executing command.", ex );
88 }
89
90 if ( exitCode != 0 )
91 {
92 return new AddScmResult( cl.toString(), "The svn command failed.", stderr.getOutput(), false );
93 }
94
95 return new AddScmResult( cl.toString(), consumer.getAddedFiles() );
96 }
97
98 private static Commandline createCommandLine( File workingDirectory, List<File> files )
99 throws ScmException
100 {
101
102
103 Commandline cl = new Commandline();
104
105 cl.setExecutable( "svn" );
106
107 cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
108
109 cl.createArg().setValue( "add" );
110
111 cl.createArg().setValue( "--non-recursive" );
112
113 try
114 {
115 SvnCommandLineUtils.addTarget( cl, files );
116 }
117 catch ( IOException e )
118 {
119 throw new ScmException( "Can't create the targets file", e );
120 }
121
122 return cl;
123 }
124
125 }