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