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 public class SvnListCommand extends AbstractListCommand implements SvnCommand {
46 private static final File TMP_DIR = new File(System.getProperty("java.io.tmpdir"));
47 private final boolean interactive;
48
49 public SvnListCommand(boolean interactive) {
50 this.interactive = interactive;
51 }
52
53
54
55
56 protected ListScmResult executeListCommand(
57 ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion version)
58 throws ScmException {
59 Commandline cl = createCommandLine((SvnScmProviderRepository) repository, fileSet, recursive, version);
60
61 SvnListConsumer consumer = new SvnListConsumer();
62
63 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
64
65 if (logger.isInfoEnabled()) {
66 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
67
68 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
69 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
70 }
71 }
72
73 int exitCode;
74
75 try {
76 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
77 } catch (CommandLineException ex) {
78 throw new ScmException("Error while executing command.", ex);
79 }
80
81 if (exitCode != 0) {
82 return new ListScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
83 }
84
85 return new ListScmResult(cl.toString(), consumer.getFiles());
86 }
87
88 Commandline createCommandLine(
89 SvnScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, ScmVersion version) {
90 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(TMP_DIR, repository, interactive);
91
92 cl.createArg().setValue("list");
93
94 if (recursive) {
95 cl.createArg().setValue("--recursive");
96 }
97
98 if (version != null && StringUtils.isNotEmpty(version.getName())) {
99 if (version instanceof ScmRevision) {
100 cl.createArg().setValue("-r");
101
102 cl.createArg().setValue(version.getName());
103 }
104 }
105
106 Iterator<File> it = fileSet.getFileList().iterator();
107
108 while (it.hasNext()) {
109 File file = it.next();
110
111 cl.createArg().setValue(repository.getUrl() + "/" + file.getPath().replace('\\', '/') + "@");
112 }
113
114 return cl;
115 }
116 }