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.list;
20
21 import java.io.File;
22 import java.util.Iterator;
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.ScmRevision;
28 import org.apache.maven.scm.ScmVersion;
29 import org.apache.maven.scm.command.list.AbstractListCommand;
30 import org.apache.maven.scm.command.list.ListScmResult;
31 import org.apache.maven.scm.provider.ScmProviderRepository;
32 import org.apache.maven.scm.provider.svn.command.SvnCommand;
33 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
34 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
35 import org.codehaus.plexus.util.Os;
36 import org.codehaus.plexus.util.cli.CommandLineException;
37 import org.codehaus.plexus.util.cli.CommandLineUtils;
38 import org.codehaus.plexus.util.cli.Commandline;
39
40
41
42
43
44
45
46 public class SvnListCommand extends AbstractListCommand implements SvnCommand {
47 private static final File TMP_DIR = new File(System.getProperty("java.io.tmpdir"));
48
49
50 protected ListScmResult executeListCommand(
51 ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion version)
52 throws ScmException {
53 Commandline cl = createCommandLine((SvnScmProviderRepository) repository, fileSet, recursive, version);
54
55 SvnListConsumer consumer = new SvnListConsumer();
56
57 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
58
59 if (logger.isInfoEnabled()) {
60 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
61
62 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
63 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
64 }
65 }
66
67 int exitCode;
68
69 try {
70 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
71 } catch (CommandLineException ex) {
72 throw new ScmException("Error while executing command.", ex);
73 }
74
75 if (exitCode != 0) {
76 return new ListScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
77 }
78
79 return new ListScmResult(cl.toString(), consumer.getFiles());
80 }
81
82 static Commandline createCommandLine(
83 SvnScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion version) {
84 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(TMP_DIR, repository);
85
86 cl.createArg().setValue("list");
87
88 if (recursive) {
89 cl.createArg().setValue("--recursive");
90 }
91
92 if (version != null && StringUtils.isNotEmpty(version.getName())) {
93 if (version instanceof ScmRevision) {
94 cl.createArg().setValue("-r");
95
96 cl.createArg().setValue(version.getName());
97 }
98 }
99
100 Iterator<File> it = fileSet.getFileList().iterator();
101
102 while (it.hasNext()) {
103 File file = it.next();
104
105 cl.createArg().setValue(repository.getUrl() + "/" + file.getPath().replace('\\', '/') + "@");
106 }
107
108 return cl;
109 }
110 }