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