1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.svn.svnexe.command.add;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.util.List;
24
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmResult;
28 import org.apache.maven.scm.command.add.AbstractAddCommand;
29 import org.apache.maven.scm.command.add.AddScmResult;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.svn.command.SvnCommand;
32 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
33 import org.codehaus.plexus.util.Os;
34 import org.codehaus.plexus.util.cli.CommandLineException;
35 import org.codehaus.plexus.util.cli.CommandLineUtils;
36 import org.codehaus.plexus.util.cli.Commandline;
37
38
39
40
41
42 public class SvnAddCommand extends AbstractAddCommand implements SvnCommand {
43
44 protected ScmResult executeAddCommand(
45 ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
46 if (fileSet.getFileList().isEmpty()) {
47 throw new ScmException("You must provide at least one file/directory to add");
48 }
49
50 Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
51
52 if (binary) {
53 cl.createArg().setValue("--config-option");
54 cl.createArg().setValue("config:miscellany:enable-auto-props=no");
55 }
56
57 SvnAddConsumer consumer = new SvnAddConsumer();
58
59 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
60
61 if (logger.isInfoEnabled()) {
62 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
63
64 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
65 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
66 }
67 }
68
69 int exitCode;
70
71 try {
72 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
73 } catch (CommandLineException ex) {
74 throw new ScmException("Error while executing command.", ex);
75 }
76
77 if (exitCode != 0) {
78 return new AddScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
79 }
80
81 return new AddScmResult(cl.toString(), consumer.getAddedFiles());
82 }
83
84 private static Commandline createCommandLine(File workingDirectory, List<File> files) throws ScmException {
85
86
87 Commandline cl = new Commandline();
88
89 cl.setExecutable("svn");
90
91 cl.setWorkingDirectory(workingDirectory.getAbsolutePath());
92
93 cl.createArg().setValue("add");
94
95 cl.createArg().setValue("--parents");
96
97 cl.createArg().setValue("--non-recursive");
98
99 try {
100 SvnCommandLineUtils.addTarget(cl, files);
101 } catch (IOException e) {
102 throw new ScmException("Can't create the targets file", e);
103 }
104
105 return cl;
106 }
107 }