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.info;
20
21 import java.io.File;
22 import java.util.Iterator;
23
24 import org.apache.maven.scm.CommandParameters;
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.AbstractCommand;
29 import org.apache.maven.scm.command.info.InfoScmResult;
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.repository.SvnScmProviderRepository;
33 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
34 import org.codehaus.plexus.util.Os;
35 import org.codehaus.plexus.util.cli.CommandLineException;
36 import org.codehaus.plexus.util.cli.CommandLineUtils;
37 import org.codehaus.plexus.util.cli.Commandline;
38
39
40
41
42
43 public class SvnInfoCommand extends AbstractCommand implements SvnCommand {
44
45
46 protected ScmResult executeCommand(
47 ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
48 return executeInfoCommand((SvnScmProviderRepository) repository, fileSet, parameters, false, null);
49 }
50
51 public InfoScmResult executeInfoCommand(
52 SvnScmProviderRepository repository,
53 ScmFileSet fileSet,
54 CommandParameters parameters,
55 boolean recursive,
56 String revision)
57 throws ScmException {
58 Commandline cl = createCommandLine(repository, fileSet, recursive, revision);
59
60 SvnInfoConsumer consumer = new SvnInfoConsumer();
61
62 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
63
64 if (logger.isInfoEnabled()) {
65 logger.info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
66
67 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
68 logger.info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
69 }
70 }
71
72 int exitCode;
73
74 try {
75 exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr);
76 } catch (CommandLineException ex) {
77 throw new ScmException("Error while executing command.", ex);
78 }
79
80 if (exitCode != 0) {
81 return new InfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
82 }
83
84 return new InfoScmResult(cl.toString(), consumer.getInfoItems());
85 }
86
87
88 protected static Commandline createCommandLine(
89 SvnScmProviderRepository repository, ScmFileSet fileSet, boolean recursive, String revision) {
90 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repository);
91
92 cl.createArg().setValue("info");
93
94 if (recursive) {
95 cl.createArg().setValue("--recursive");
96 }
97
98 if (revision != null && !revision.isEmpty()) {
99 cl.createArg().setValue("-r");
100
101 cl.createArg().setValue(revision);
102 }
103
104 Iterator<File> it = fileSet.getFileList().iterator();
105
106 while (it.hasNext()) {
107 File file = (File) it.next();
108
109 if (repository == null) {
110 cl.createArg().setValue(file.getPath());
111 } else {
112 cl.createArg()
113 .setValue(repository.getUrl() + "/" + file.getPath().replace('\\', '/') + "@");
114 }
115 }
116
117 return cl;
118 }
119 }