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 public class SvnAddCommand extends AbstractAddCommand implements SvnCommand {
42
43
44
45 protected ScmResult executeAddCommand(
46 ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
47 if (fileSet.getFileList().isEmpty()) {
48 throw new ScmException("You must provide at least one file/directory to add");
49 }
50
51 Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
52
53 if (binary) {
54 cl.createArg().setValue("--config-option");
55 cl.createArg().setValue("config:miscellany:enable-auto-props=no");
56 }
57
58 SvnAddConsumer consumer = new SvnAddConsumer();
59
60 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
61
62 if (logger.isInfoEnabled()) {
63 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
64
65 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
66 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
67 }
68 }
69
70 int exitCode;
71
72 try {
73 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
74 } catch (CommandLineException ex) {
75 throw new ScmException("Error while executing command.", ex);
76 }
77
78 if (exitCode != 0) {
79 return new AddScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
80 }
81
82 return new AddScmResult(cl.toString(), consumer.getAddedFiles());
83 }
84
85 private static Commandline createCommandLine(File workingDirectory, List<File> files) throws ScmException {
86
87
88 Commandline cl = new Commandline();
89
90 cl.setExecutable("svn");
91
92 cl.setWorkingDirectory(workingDirectory.getAbsolutePath());
93
94 cl.createArg().setValue("add");
95
96 cl.createArg().setValue("--parents");
97
98 cl.createArg().setValue("--non-recursive");
99
100 try {
101 SvnCommandLineUtils.addTarget(cl, files);
102 } catch (IOException e) {
103 throw new ScmException("Can't create the targets file", e);
104 }
105
106 return cl;
107 }
108 }